Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Reorganize linked list logic.

  • Loading branch information...
commit 6e0159fb0010858b5d643bc44b48d37576b8c532 1 parent 788460b
@karthikv karthikv authored
Showing with 14 additions and 8 deletions.
  1. +14 −8 public/javascripts/views/element.js
View
22 public/javascripts/views/element.js
@@ -149,8 +149,20 @@ define(['jquery', 'backbone', 'underscore', './extended', 'helpers/screen-utils'
var model = this.model;
var previousElement = this.getPreviousElement();
+ model.set({
+ head: null,
+ nextId: null
+ });
+
if (previousElement) {
- model.set('nextId', previousElement.get('nextId'));
+ var nextId = previousElement.get('nextId');
+
+ if (nextId) {
+ model.set('nextId', nextId);
+ } else {
+ model.set('nextId', null);
+ }
+
previousElement.save({ nextId: model.get('id') }, { wait: true });
} else {
// no previous element means this is the head
@@ -175,7 +187,7 @@ define(['jquery', 'backbone', 'underscore', './extended', 'helpers/screen-utils'
if (nextId) {
// set the previous' nextId to this element's nextId
- previousElement.set('nextId', model.get('nextId'));
+ previousElement.set('nextId', nextId);
} else {
// there is no next; remove the previous' nextId
previousElement.set('nextId', null);
@@ -190,12 +202,6 @@ define(['jquery', 'backbone', 'underscore', './extended', 'helpers/screen-utils'
nextElement.save({ head: true }, { wait: true });
}
}
-
- // unset the element's nextId and head, but do not save; the element
- // will either be deleted promptly (see destroyElement below) or saved
- // later (see insertElement)
- model.set('nextId', null);
- model.set('head', null);
},
destroyElement: function() {
Please sign in to comment.
Something went wrong with that request. Please try again.