Skip to content
Browse files

BUGFIX Updated various CMS javascript functions to new jstree library

  • Loading branch information...
1 parent 885597a commit ea0f8b0e654b3bdade06fe48fe3e3eb2215f39ca @chillu chillu committed Mar 10, 2011
Showing with 25 additions and 23 deletions.
  1. +6 −4 javascript/CMSMain.js
  2. +17 −17 javascript/LeftAndMain.AddForm.js
  3. +2 −2 javascript/LeftAndMain.BatchActions.js
View
10 javascript/CMSMain.js
@@ -208,8 +208,9 @@
// integrate with sitetree selection changes
// TODO Only trigger when report is visible
- jQuery('#sitetree').bind('selectionchanged', function(e, data) {
- self.find(':input[name=ID]').val(data.node.getIdx());
+ jQuery('#sitetree_ul').bind('select_node.jstree', function(e, data) {
+ var node = data.rslt.obj;
+ self.find(':input[name=ID]').val(node ? $(node).data('id') : null);
self.trigger('submit');
});
@@ -329,8 +330,9 @@
});
// integrate with sitetree selection changes
- jQuery('#sitetree').bind('selectionchanged', function(e, data) {
- self.find(':input[name=ID]').val(data.node.getIdx());
+ jQuery('#sitetree_ul').bind('select_node.jstree', function(e, data) {
+ var node = data.rslt.obj;
+ self.find(':input[name=ID]').val(node ? $(node).data('id') : null);
if(self.is(':visible')) self.trigger('submit');
});
View
34 javascript/LeftAndMain.AddForm.js
@@ -40,11 +40,11 @@
Observable.applyTo(this[0]);
- var tree = jQuery('#sitetree')[0];
+ var tree = $('#sitetree_ul');
this.setTree(tree);
// Event bindings
- jQuery(tree).bind('selectionchanged', function(e, data) {self.refresh(data.node);});
+ $(tree).bind('select_node.jstree', function(e, data) {self.refresh(data.rslt.obj);});
typeDropdown.bind('change', function(e) {self.refresh();});
// TODO Bind on tree initialization to set dropdown for selected node
@@ -66,34 +66,35 @@
* (Event) e
*/
onsubmit: function(e) {
- var newPages = this.getNewPages();
- var tree = this.getTree();
- var parentID = (tree.firstSelected()) ? tree.getIdxOf(tree.firstSelected()) : 0;
+ var newPages = this.getNewPages(), tree = this.getTree(), node = $(tree).jstree('get_selected');
+ var parentID = (node.length) ? node.data('id') : 0;
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
- if(parentID && parentID.substr(0,3) == 'new') {
- alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
- }
-
- if(tree.firstSelected() && jQuery(tree.firstSelected()).hasClass("nochildren")) {
+ // if(parentID && parentID.substr(0,3) == 'new') {
+ // alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
+ // }
+
+ if(node && node.hasClass("nochildren")) {
alert(ss.i18n._t('CMSMAIN.CANTADDCHILDREN') );
}
// Optionally initalize the new pages tracker
if(!newPages[parentID] ) newPages[parentID] = 1;
// default to first button
- var button = jQuery(this).find(':submit:first');
+ var button = this.find(':submit:first');
button.addClass('loading');
// collect data and submit the form
- var data = jQuery(this).serializeArray();
+ var data = this.serializeArray();
data.push({name:'Suffix',value:newPages[parentID]++});
data.push({name:button.attr('name'),value:button.val()});
+
// TODO Should be set by hiddenfield already
jQuery('#Form_EditForm').entwine('ss').loadForm(
- jQuery(this).attr('action'),
+ this.attr('action'),
function() {
+ // Tree updates are triggered by Form_EditForm load events
button.removeClass('loading');
},
{type: 'POST', data: data}
@@ -112,10 +113,10 @@
*/
refresh: function(selectedNode) {
// Note: Uses siteTreeHints global
- var tree = this.getTree(),
+ var tree = this.getTree(),
+ selectedNode = selectedNode || $(tree).jstree('get_selected')
origOptions = this.getOrigOptions(),
dropdown = this.find('select[name=PageType]');
- if(!selectedNode) selectedNode = tree.firstSelected();
// Clear all existing <option> elements
// (IE doesn't allow setting display:none on these elements)
@@ -155,8 +156,7 @@
}
// Set parent node (fallback to root)
- var parentID = tree.getIdxOf(selectedNode);
- this.find(':input[name=ParentID]').val(parentID ? parentID : 0);
+ this.find(':input[name=ParentID]').val(selectedNode ? selectedNode.data('id') : 0);
}
});
});
View
4 javascript/LeftAndMain.BatchActions.js
@@ -40,8 +40,8 @@
this.setTree($('#sitetree')[0]);
- $(this.getTree()).bind('selectionchanged', function(e, data) {
- self._treeSelectionChanged(data.node);
+ $(this.getTree()).bind('select_node.jstree', function(e, data) {
+ self._treeSelectionChanged(data.rslt.obj);
});
// if tab which contains this form is shown, make the tree selectable

0 comments on commit ea0f8b0

Please sign in to comment.
Something went wrong with that request. Please try again.