Permalink
Browse files

Allow deletion of notes

  • Loading branch information...
1 parent 33660c2 commit 40812bd689ed25bc7faa6a9a36b92486693f80e4 @thedjpetersen committed Sep 25, 2012
Showing with 25 additions and 9 deletions.
  1. +23 −9 assets/js/views.js
  2. +2 −0 templates.html
View
@@ -2,14 +2,13 @@ var noteView = Backbone.View.extend({
initialize: function() {
this.parents = panda.notes.get_parents(this.options.model.get('parent_id'));
this.children = panda.notes.with_parent(this.options.model.get('id'));
-
- window.v = this;
},
events: {
'click .new_note': 'new_note',
- 'click .category, .note': 'view_note'
+ 'click .category, .note': 'view_note',
+ 'click .delete': 'delete_note'
},
attributes: {
@@ -27,15 +26,30 @@ var noteView = Backbone.View.extend({
},
new_note: function() {
- var id = this.options.model.get('id');
- panda.router.navigate('#!/new_note/' + id, {trigger: true});
+ var id = this.options.model.get('id');
+ panda.router.navigate('#!/new_note/' + id, {trigger: true});
},
view_note: function(event) {
- var target_href = $(event.target).attr('data-href');
- if(target_href) {
- panda.router.navigate(target_href, {trigger: true});
- }
+ var target_href = $(event.target).attr('data-href');
+ if(target_href) {
+ panda.router.navigate(target_href, {trigger: true});
+ }
+ },
+
+ delete_note: function(event) {
+ event.preventDefault();
+ var should_delete = confirm("Are you sure you want to delete this note/category? " +
+ "All children of this item will be inherited by this item's" +
+ " parent.");
+ if(should_delete) {
+ _.each(this.children, function(child) {
+ child.set({'parent_id': this.options.model.get('parent_id')});
+ }, this);
+ panda.notes.remove(this.options.model);
+ panda.notes.sync_notes();
+ panda.router.navigate("/#!/", {trigger: true});
+ }
}
});
View
@@ -50,6 +50,7 @@ <h3 class="category_title">{{model.name}}</h3>
<div class="span12">
{{#if parents.length}}
<a href="/#!/notes/{{model.id}}/edit" class="btn">Edit Category</a>
+ <a href="/#!/" class="btn btn-danger delete">Delete Category</a>
{{/if}}
</div>
</script>
@@ -77,6 +78,7 @@ <h3 class="category_title">{{model.name}}</h3>
<div class="span12">
<a href="/#!/notes/{{model.id}}/edit" class="btn">Edit Note</a>
<a href="/#!/new_note/{{model.id}}" class="btn btn-primary">Add Child</a>
+ <a href="/#!/" class="btn btn-danger delete">Delete Note</a>
</div>
{{#if children.length}}
<div class="span12">

0 comments on commit 40812bd

Please sign in to comment.