Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

BUGFIX Updating tree state (after adding/renaming nodes, changing par…

…ent). Deselecting nodes when switching to edit view (fixes #7389, #7336, #7309)
  • Loading branch information...
commit c18c29f464f1b624bb665e67f4ce2183af839250 1 parent 9898cd9
Ingo Schommer chillu authored
3  admin/javascript/LeftAndMain.Content.js
View
@@ -226,6 +226,9 @@
var url = $(node).find('a:first').attr('href');
if(url && url != '#') {
+ // Deselect all nodes (will be reselected after load according to form state)
+ self.jstree('deselect_all');
+ self.jstree('uncheck_all');
// Ensure URL is absolute (important for IE)
if($.path.isExternal($(node).find('a:first'))) url = url = $.path.makeUrlAbsolute(url, $('base').attr('href'));
72 admin/javascript/LeftAndMain.Tree.js
View
@@ -44,6 +44,7 @@
this
.jstree(this.getTreeConfig())
.bind('loaded.jstree', function(e, data) {
+ self.updateFromEditForm();
self.css('visibility', 'visible');
// Add ajax settings after init period to avoid unnecessary initial ajax load
// of existing tree in DOM - see load_node_html()
@@ -96,11 +97,16 @@
});
});
- this.parents('.cms-container').bind('afterstatechange', function(e, data) {
- self._onLoadNewPage(e, data);
+ $('.cms-container').bind('afterstatechange.tree', function(e, data) {
+ self.updateFromEditForm(e.origData);
+ });
+ $('.cms-content').bind('reloadeditform.tree', function(e, data) {
+ self.updateFromEditForm(e.origData);
});
},
onunmatch: function() {
+ $('.cms-container').unbind('afterstatechange.tree');
+ $('.cms-content').unbind('reloadeditform.tree');
this._super();
},
@@ -204,48 +210,43 @@
* 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 handledform = $(e.target).is('.cms-edit-form') ? $(e.target)[0] : $(e.target).find('.cms-edit-form')[0];
- var id = handledform ? $(handledform.ID).val() : null;
+ updateFromEditForm: function(origData) {
+ var self = this,
+ form = $('.cms-edit-form').get(0),
+ id = form ? $(form.ID).val() : null;
// check if a form with a valid ID exists
if(id) {
- var parentID = $(handledform.ParentID).val(),
+ var parentID = $(form.ParentID).val(),
parentNode = this.find('li[data-id='+parentID+']');
node = this.find('li[data-id='+id+']'),
- title = $((handledform.TreeTitle) ? handledform.TreeTitle : handledform.Title).val(),
- className = $(handledform.ClassName).val();
+ title = $((form.TreeTitle) ? form.TreeTitle : form.Title).val(),
+ className = $(form.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}},
+ {
+ data: '',
+ attr: {
+ 'data-class': className,
+ 'class': '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);
+ newNode.find('a:first').html(title).attr('href', ss.i18n.sprintf(
+ self.data('urlEditpage'), id
+ ));
self.jstree('deselect_node', parentNode);
self.jstree('select_node', newNode);
}
@@ -254,17 +255,20 @@
this.jstree('select_node', node);
}
- // TODO Fix node parent setting
- // // set correct parent (only if it has changed)
- // if(parentID) this.setNodeParentID(id, jQuery(e.target.ParentID).val());
+ // set correct parent (only if it has changed)
+ if(parentID && parentID != node.parents('li:first').data('id')) {
+ this.jstree('move_node', node, parentNode.length ? parentNode : -1, 'last');
+ }
- // TODO Fix doubleup when replacing page form with root form, reloads the old form over the root
- // set current tree element regardless of wether the item was new
- // this.jstree('select_node', node);
+ 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);
+ // If no ID exists in a form view, we're displaying the tree on its own,
+ // hence to page should show as active
+ this.jstree('deselect_all');
+
+ if(typeof origData != 'undefined') {
+ var node = this.find('li[data-id='+origData.ID+']');
+ if(node && node.data('id') !== 0) this.jstree('delete_node', node);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.