Skip to content

Commit

Permalink
pushed the destroy logic down to the node view... likely need to do t…
Browse files Browse the repository at this point in the history
…he same refactor for make_child
  • Loading branch information
jlebensold committed Oct 13, 2012
1 parent a5d8183 commit 6532182
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 24 deletions.
33 changes: 31 additions & 2 deletions app/css/app.css
Expand Up @@ -14,10 +14,38 @@ body {
.authority_manager .tree {
height: 300px;
overflow: scroll;
margin: 0 0;
}
.authority_manager .tree .buttons {
display:none;
float: right;
clear: both;
margin: 0 5px 0 0;
position: relative;

}
.authority_manager .tree .buttons a {
display:block;
position: absolute;
background: #FFF;
padding: 0x 2px;
}
.authority_manager .tree li div:hover > .buttons {
display: block;
}
.authority_manager .tree li div:hover > .buttons a:hover {
background: #E5E5E5;
}
.authority_manager .tree li,
.authority_manager .tree ul {
list-style:none;
padding: 0 0 0 8px;
margin: 0 0 0 0px;
}
.authority_manager ul.tree li div{
background: #F3F3F3;
margin: 1px 0px;
background: #FFF;
border-bottom: 1px solid #F0F0F0;
margin: 5px 0px;
font-size: 12px;

}
Expand Down Expand Up @@ -68,6 +96,7 @@ body {
padding: 5px;
}


/* tags */
div.tagsinput { border:1px solid #CCC; background: #FFF; padding:5px; width:300px; height:100px; overflow-y: auto;}
div.tagsinput span.tag { border: 1px solid #a5d24a; -moz-border-radius:2px; -webkit-border-radius:2px; display: block; float: left; padding: 5px; text-decoration:none; background: #cde69c; color: #638421; margin-right: 5px; margin-bottom:5px;font-family: helvetica; font-size:13px;}
Expand Down
22 changes: 4 additions & 18 deletions app/js/app/views/authority_manager_view.coffee
Expand Up @@ -4,35 +4,21 @@ class App.Views.AuthorityManagerView extends Backbone.View
{
'click .btn_add_node' : 'add_node'
'click .make_child' : 'make_child'
'click .destroy' : 'destroy'
}
initialize: ->
_.bindAll @, 'render', 'add_node', 'make_child', 'destroy'
_.bindAll @, 'render', 'add_node', 'make_child'
@template = _.template($('#authority_manager').html())
@treeview = new App.Views.TreeNodeView({model: @collection.first() })
@model = @collection.first()
@bulksave = new App.Models.AuthorityBulkSave()
@

destroy: (e) ->
e.preventDefault()
view = @
node = @model.search $(e.target).parent().data('node-id')
saveset = node.setup_children_for_persistence((n) ->
n.set('ancestry',node.parent().get('_id'))
n.detach()
node.get('parent').attach n
)
node.destroy()
@bulksave.save({ model: saveset })


make_child: (e) ->
e.preventDefault()
self = @model.search $(e.target).parent().data('node-id')
new_parent = @model.search $(e.target).parent().parent().prev().find('div').data('node-id')
view = @

self = @model.search $(e.target).parent().parent().parent().data('node-id')
new_parent = @model.search $(e.target).parent().parent().parent().parent().prev().find('div').data('node-id')

children = self.children()
self.detach()

Expand Down
2 changes: 1 addition & 1 deletion app/js/app/views/note_view.coffee
Expand Up @@ -2,7 +2,7 @@ class App.Views.NoteView extends Backbone.View
className: "note"
events: ->
{
'blur input': 'save_note'
'blur textarea': 'save_note'
'mouseover':'mouseon'
'mouseout':'mouseoff'
'click a.delete': 'delete_note'
Expand Down
19 changes: 18 additions & 1 deletion app/js/app/views/tree_node_view.coffee
@@ -1,10 +1,27 @@
class App.Views.TreeNodeView extends Backbone.View
tagName: "li"
events: ->
'click .destroy' : 'destroy'
initialize: ->
@template = _.template($('#tree_node').html())
_.bindAll @, 'render'
_.bindAll @, 'render', 'destroy'
@model.children().on('remove', @render)
@model.children().on('add', @render)
@bulksave = new App.Models.AuthorityBulkSave()

destroy: (e) ->
e.preventDefault()
node = @model

saveset = node.setup_children_for_persistence((n) ->
n.set('ancestry',node.parent().get('_id'))
n.detach()
node.get('parent').attach n
)
node.destroy()
if (saveset.length > 0)
@bulksave.save({ model: saveset })
false

render: ->

Expand Down
3 changes: 2 additions & 1 deletion public/javascripts/templates/note.ejs
@@ -1,5 +1,6 @@
<input type="text" name="text" class="text" value="<%= note.text %>" placeholder="note..." />
<textarea rows="6" style="width:95%" name="text" class="text" placeholder="note..."><%= note.text %></textarea>
<br/>

<input type="text" name="authorities" class="authorities" value="" />
<a href="#" class="delete btn btn-mini" style="position: absolute; top: 22px; left: -20px">x</a>
<a href="#" class="collapsable btn btn-mini" style="position: absolute; top: 0px; left: -20px">c</a>
8 changes: 7 additions & 1 deletion public/javascripts/templates/tree_node.ejs
@@ -1 +1,7 @@
<div style="position:relative;clear:left;" data-node-id="<%= _id %>"><em><%= name %></em><a style="float:right;z-index:30;margin: 0 10px;" class="make_child" href="#">mc</a><a style="float:right;z-index:30;margin: 0 10px;" href="#" class="destroy">x</a></div>
<div style="position:relative;clear:left;" data-node-id="<%= _id %>">
<em><%= name %></em>
<div class="buttons">
<a class="make_child" href="#" style="right: 30px;" ><i class="icon-arrow-right"></i></a>
<a class="destroy" href="#" style="right: 10px" ><i class="icon-remove">&nbsp;</i></a>
</div>
</div>

0 comments on commit 6532182

Please sign in to comment.