"keydown > .text": "keydown",
'Shortcut("combinePrevious", "Combine an item with the previous item", "backspace") > .text': "combinePrevious",
'Shortcut("combineNext", "Combine an item with the next item", "del") > .text': "combineNext",
- 'Shortcut("next", "Next", "down") > .text': 'next',
- 'Shortcut("previous", "Previous", "up") > .text': 'previous',
+ 'Shortcut("next", "Next", "down") > .text': 'focusNext',
+ 'Shortcut("previous", "Previous", "up") > .text': 'focusPrevious',
'Shortcut("zoomIn", "Not Done - Zoom in", "alt+right") > .text': 'zoomIn',
'Shortcut("zoomOut", "Not Done - Zoom out", "alt+left") > .text': 'zoomOut',
'Shortcut("expand", "Not Done - Expand / collapse", "ctrl+space") > .text': 'expand',
'Shortcut("moveDown", "Not Done - Move", "alt+shift+down") > .text': 'moveDown',
'Shortcut("moveUp", "Not Done - Move", "alt+shift+up") > .text': 'moveUp',
'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete",
- 'Shortcut("delete", "Not Done - Delete", "ctrl+shift+del") > .text': 'delete',
+ 'Shortcut("delete", "Delete", "ctrl+shift+backspace") > .text': 'delete',
},
initialize: function() {
this.childViewPositions = [];
} else {
this.stopEditingText();
this.model.toggleComplete();
- var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}) || this.model.getParent(this.model.collection);
+ var next = this.model.nextNode(this.model.collection, { childrenAllowed: false}) || this.model.getParent(this.model.collection, { rootAllowed: false});
if (!next) return false;
next.getView().startEditingText();
}
return false;
},
- next: function() {
+ focusNext: function() {
var nextNode = this.model.nextNode(this.model.collection, { childrenAllowed: true });
if (!nextNode) return false;
this.stopEditingText();
nextNode.getView().startEditingText();
return false;
},
- previous: function() {
+ focusPrevious: function() {
var previousNode = this.model.previousNode(this.model.collection, { childrenAllowed: true });
if (!previousNode) return false;
this.stopEditingText();
},
"delete": function() {
// Delete node and its entire subtree
- console.log("Delete not implemented"); // TODO
+ this.focusPrevious();
+ this.model.removeAll(this.model.collection);
+ return false;
},
indent: function() {
// Last child of previous sibling, then nothing
getChild: function(collection, index) {
return collection.get(this.get("bullets")[index]);
},
- getParent: function(collection) {
- return collection.get(this.get("parent"));
+ getParent: function(collection, options) {
+ options = _.defaults({}, options, { rootAllowed: true });
+ var parent = collection.get(this.get("parent"));
+ if (parent && parent.id == collection.rootId && !options.rootAllowed) return undefined;
+ return parent;
},
getPreviousSibling: function(collection) {
var parent = this.getParent(collection);
remove: function(collection) {
this.getParent(collection).removeChild(this, collection);
},
+ removeAll: function(collection) {
+ if (collection.rootId == this.id) {
+ console.log("Cannot remove root node of collection");
+ return;
+ }
+ if (this.hasChildren()) {
+ var children = _.clone(this.getChildren(collection));
+ _.each(children, function(child) {
+ child.removeAll(collection);
+ });
+ }
+ this.remove(collection);
+ },
addTodoBefore: function(todo, collection) {
// Todo always goes as the previous sibling
var parent = this.getParent(collection);
"keydown > .text": "keydown",
'Shortcut("combinePrevious", "Combine an item with the previous item", "backspace") > .text': "combinePrevious",
'Shortcut("combineNext", "Combine an item with the next item", "del") > .text': "combineNext",
- 'Shortcut("next", "Next", "down") > .text': 'next',
- 'Shortcut("previous", "Previous", "up") > .text': 'previous',
+ 'Shortcut("next", "Next", "down") > .text': 'focusNext',
+ 'Shortcut("previous", "Previous", "up") > .text': 'focusPrevious',
'Shortcut("zoomIn", "Not Done - Zoom in", "alt+right") > .text': 'zoomIn',
'Shortcut("zoomOut", "Not Done - Zoom out", "alt+left") > .text': 'zoomOut',
'Shortcut("expand", "Not Done - Expand / collapse", "ctrl+space") > .text': 'expand',
'Shortcut("moveDown", "Not Done - Move", "alt+shift+down") > .text': 'moveDown',
'Shortcut("moveUp", "Not Done - Move", "alt+shift+up") > .text': 'moveUp',
'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete",
- 'Shortcut("delete", "Not Done - Delete", "ctrl+shift+del") > .text': 'delete',
+ 'Shortcut("delete", "Delete", "ctrl+shift+backspace") > .text': 'delete',
},
initialize: function() {
this.childViewPositions = [];
} else {
this.stopEditingText();
this.model.toggleComplete();
- var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}) || this.model.getParent(this.model.collection);
+ var next = this.model.nextNode(this.model.collection, { childrenAllowed: false}) || this.model.getParent(this.model.collection, { rootAllowed: false});
if (!next) return false;
next.getView().startEditingText();
}
return false;
},
- next: function() {
+ focusNext: function() {
var nextNode = this.model.nextNode(this.model.collection, { childrenAllowed: true });
if (!nextNode) return false;
this.stopEditingText();
nextNode.getView().startEditingText();
return false;
},
- previous: function() {
+ focusPrevious: function() {
var previousNode = this.model.previousNode(this.model.collection, { childrenAllowed: true });
if (!previousNode) return false;
this.stopEditingText();
},
"delete": function() {
// Delete node and its entire subtree
- console.log("Delete not implemented"); // TODO
+ this.focusPrevious();
+ this.model.removeAll(this.model.collection);
+ return false;
},
indent: function() {
// Last child of previous sibling, then nothing
getChild: function(collection, index) {
return collection.get(this.get("bullets")[index]);
},
- getParent: function(collection) {
- return collection.get(this.get("parent"));
+ getParent: function(collection, options) {
+ options = _.defaults({}, options, { rootAllowed: true });
+ var parent = collection.get(this.get("parent"));
+ if (parent && parent.id == collection.rootId && !options.rootAllowed) return undefined;
+ return parent;
},
getPreviousSibling: function(collection) {
var parent = this.getParent(collection);
remove: function(collection) {
this.getParent(collection).removeChild(this, collection);
},
+ removeAll: function(collection) {
+ if (collection.rootId == this.id) {
+ console.log("Cannot remove root node of collection");
+ return;
+ }
+ if (this.hasChildren()) {
+ var children = _.clone(this.getChildren(collection));
+ _.each(children, function(child) {
+ child.removeAll(collection);
+ });
+ }
+ this.remove(collection);
+ },
addTodoBefore: function(todo, collection) {
// Todo always goes as the previous sibling
var parent = this.getParent(collection);
getChild: function(collection, index) {
return collection.get(this.get("bullets")[index]);
},
- getParent: function(collection) {
- return collection.get(this.get("parent"));
+ getParent: function(collection, options) {
+ options = _.defaults({}, options, { rootAllowed: true });
+ var parent = collection.get(this.get("parent"));
+ if (parent && parent.id == collection.rootId && !options.rootAllowed) return undefined;
+ return parent;
},
getPreviousSibling: function(collection) {
var parent = this.getParent(collection);
remove: function(collection) {
this.getParent(collection).removeChild(this, collection);
},
+ removeAll: function(collection) {
+ if (collection.rootId == this.id) {
+ console.log("Cannot remove root node of collection");
+ return;
+ }
+ if (this.hasChildren()) {
+ var children = _.clone(this.getChildren(collection));
+ _.each(children, function(child) {
+ child.removeAll(collection);
+ });
+ }
+ this.remove(collection);
+ },
addTodoBefore: function(todo, collection) {
// Todo always goes as the previous sibling
var parent = this.getParent(collection);
"keydown > .text": "keydown",
'Shortcut("combinePrevious", "Combine an item with the previous item", "backspace") > .text': "combinePrevious",
'Shortcut("combineNext", "Combine an item with the next item", "del") > .text': "combineNext",
- 'Shortcut("next", "Next", "down") > .text': 'next',
- 'Shortcut("previous", "Previous", "up") > .text': 'previous',
+ 'Shortcut("next", "Next", "down") > .text': 'focusNext',
+ 'Shortcut("previous", "Previous", "up") > .text': 'focusPrevious',
'Shortcut("zoomIn", "Not Done - Zoom in", "alt+right") > .text': 'zoomIn',
'Shortcut("zoomOut", "Not Done - Zoom out", "alt+left") > .text': 'zoomOut',
'Shortcut("expand", "Not Done - Expand / collapse", "ctrl+space") > .text': 'expand',
'Shortcut("moveDown", "Not Done - Move", "alt+shift+down") > .text': 'moveDown',
'Shortcut("moveUp", "Not Done - Move", "alt+shift+up") > .text': 'moveUp',
'Shortcut("toggleComplete", "Complete", "ctrl+enter") > .text': "toggleComplete",
- 'Shortcut("delete", "Not Done - Delete", "ctrl+shift+del") > .text': 'delete',
+ 'Shortcut("delete", "Delete", "ctrl+shift+backspace") > .text': 'delete',
},
initialize: function() {
this.childViewPositions = [];
} else {
this.stopEditingText();
this.model.toggleComplete();
- var next = this.model.nextNode(this.model.collection, {"childrenAllowed":false}) || this.model.getParent(this.model.collection);
+ var next = this.model.nextNode(this.model.collection, { childrenAllowed: false}) || this.model.getParent(this.model.collection, { rootAllowed: false});
if (!next) return false;
next.getView().startEditingText();
}
return false;
},
- next: function() {
+ focusNext: function() {
var nextNode = this.model.nextNode(this.model.collection, { childrenAllowed: true });
if (!nextNode) return false;
this.stopEditingText();
nextNode.getView().startEditingText();
return false;
},
- previous: function() {
+ focusPrevious: function() {
var previousNode = this.model.previousNode(this.model.collection, { childrenAllowed: true });
if (!previousNode) return false;
this.stopEditingText();
},
"delete": function() {
// Delete node and its entire subtree
- console.log("Delete not implemented"); // TODO
+ this.focusPrevious();
+ this.model.removeAll(this.model.collection);
+ return false;
},
indent: function() {
// Last child of previous sibling, then nothing