Permalink
Browse files

BUGFIX Reinstated create page functionality in LeftAndMain.Tree.js

  • Loading branch information...
1 parent 20427cd commit 23cb19958f039354963190a3c763a8bbb95e0174 @chillu chillu committed Mar 10, 2011
Showing with 70 additions and 1 deletion.
  1. +70 −1 javascript/LeftAndMain.Tree.js
@@ -125,9 +125,78 @@
}
});
});
- }
+
+ var self = this;
+ $('#Form_EditForm').bind('loadnewpage', function(e, data) {
+ self._onLoadNewPage(e, data);
+ });
+ },
+ /**
+ * Assumes to be triggered by a form element with the following input fields:
+ * ID, ParentID, TreeTitle (or Title), ClassName
+ */
+ _onLoadNewPage: function(e, eventData) {
+ var self = this;
+ // finds a certain value in an array generated by jQuery.serializeArray()
+ var findInSerializedArray = function(arr, name) {
+ for(var i=0; i<arr.length; i++) {
+ if(arr[i].name == name) return arr[i].value;
+ };
+ return false;
+ };
+
+ var id = $(e.target.ID).val();
+
+ // check if a form with a valid ID exists
+ if(id) {
+ var parentID = $(e.target.ParentID).val(),
+ parentNode = this.find('li[data-id='+parentID+']');
+ node = this.find('li[data-id='+id+']'),
+ title = $((e.target.TreeTitle) ? e.target.TreeTitle : e.target.Title).val(),
+ className = $(e.target.ClassName).val();
+
+ // set title (either from TreeTitle or from Title fields)
+ // Treetitle has special HTML formatting to denote the status changes.
+ if(title) this.jstree('rename_node', node, title);
+
+ // TODO Fix node icon setting
+ // // update icon (only if it has changed)
+ // if(className) this.setNodeIcon(id, className);
+
+ // check if node exists, might have been created instead
+ if(!node.length) {
+ this.jstree(
+ 'create_node',
+ parentNode,
+ 'inside',
+ {data: '', attr: {'class': className, 'data-id': id}},
+ function() {
+ var newNode = self.find('li[data-id='+id+']');
+ // TODO Fix hardcoded link
+ // TODO Fix replacement of jstree-icon inside <a> tag
+ newNode.find('a:first').html(title).attr('href', 'admin/show/'+id);
+ self.jstree('deselect_node', parentNode);
+ self.jstree('select_node', newNode);
+ }
+ );
+ }
+
+ // TODO Fix node parent setting
+ // // set correct parent (only if it has changed)
+ // if(parentID) this.setNodeParentID(id, jQuery(e.target.ParentID).val());
+
+ // set current tree element
+ this.jstree('select_node', node);
+ } else {
+ if(typeof eventData.origData != 'undefined') {
+ var node = this.find('li[data-id='+eventData.origData.ID+']');
+ if(node && node.data('id') != 0) this.jstree('delete_node', node);
+ }
+ }
+
+ }
});
});

0 comments on commit 23cb199

Please sign in to comment.