mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
BUGFIX Updated various CMS javascript functions to new jstree library
This commit is contained in:
parent
885597a754
commit
ea0f8b0e65
@ -208,8 +208,9 @@
|
|||||||
|
|
||||||
// integrate with sitetree selection changes
|
// integrate with sitetree selection changes
|
||||||
// TODO Only trigger when report is visible
|
// TODO Only trigger when report is visible
|
||||||
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
|
jQuery('#sitetree_ul').bind('select_node.jstree', function(e, data) {
|
||||||
self.find(':input[name=ID]').val(data.node.getIdx());
|
var node = data.rslt.obj;
|
||||||
|
self.find(':input[name=ID]').val(node ? $(node).data('id') : null);
|
||||||
self.trigger('submit');
|
self.trigger('submit');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -329,8 +330,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// integrate with sitetree selection changes
|
// integrate with sitetree selection changes
|
||||||
jQuery('#sitetree').bind('selectionchanged', function(e, data) {
|
jQuery('#sitetree_ul').bind('select_node.jstree', function(e, data) {
|
||||||
self.find(':input[name=ID]').val(data.node.getIdx());
|
var node = data.rslt.obj;
|
||||||
|
self.find(':input[name=ID]').val(node ? $(node).data('id') : null);
|
||||||
if(self.is(':visible')) self.trigger('submit');
|
if(self.is(':visible')) self.trigger('submit');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@
|
|||||||
|
|
||||||
Observable.applyTo(this[0]);
|
Observable.applyTo(this[0]);
|
||||||
|
|
||||||
var tree = jQuery('#sitetree')[0];
|
var tree = $('#sitetree_ul');
|
||||||
this.setTree(tree);
|
this.setTree(tree);
|
||||||
|
|
||||||
// Event bindings
|
// 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();});
|
typeDropdown.bind('change', function(e) {self.refresh();});
|
||||||
// TODO Bind on tree initialization to set dropdown for selected node
|
// TODO Bind on tree initialization to set dropdown for selected node
|
||||||
|
|
||||||
@ -66,16 +66,15 @@
|
|||||||
* (Event) e
|
* (Event) e
|
||||||
*/
|
*/
|
||||||
onsubmit: function(e) {
|
onsubmit: function(e) {
|
||||||
var newPages = this.getNewPages();
|
var newPages = this.getNewPages(), tree = this.getTree(), node = $(tree).jstree('get_selected');
|
||||||
var tree = this.getTree();
|
var parentID = (node.length) ? node.data('id') : 0;
|
||||||
var parentID = (tree.firstSelected()) ? tree.getIdxOf(tree.firstSelected()) : 0;
|
|
||||||
|
|
||||||
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
||||||
if(parentID && parentID.substr(0,3) == 'new') {
|
// if(parentID && parentID.substr(0,3) == 'new') {
|
||||||
alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
|
// alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
|
||||||
}
|
// }
|
||||||
|
|
||||||
if(tree.firstSelected() && jQuery(tree.firstSelected()).hasClass("nochildren")) {
|
if(node && node.hasClass("nochildren")) {
|
||||||
alert(ss.i18n._t('CMSMAIN.CANTADDCHILDREN') );
|
alert(ss.i18n._t('CMSMAIN.CANTADDCHILDREN') );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,17 +82,19 @@
|
|||||||
if(!newPages[parentID] ) newPages[parentID] = 1;
|
if(!newPages[parentID] ) newPages[parentID] = 1;
|
||||||
|
|
||||||
// default to first button
|
// default to first button
|
||||||
var button = jQuery(this).find(':submit:first');
|
var button = this.find(':submit:first');
|
||||||
button.addClass('loading');
|
button.addClass('loading');
|
||||||
|
|
||||||
// collect data and submit the form
|
// 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:'Suffix',value:newPages[parentID]++});
|
||||||
data.push({name:button.attr('name'),value:button.val()});
|
data.push({name:button.attr('name'),value:button.val()});
|
||||||
|
|
||||||
// TODO Should be set by hiddenfield already
|
// TODO Should be set by hiddenfield already
|
||||||
jQuery('#Form_EditForm').entwine('ss').loadForm(
|
jQuery('#Form_EditForm').entwine('ss').loadForm(
|
||||||
jQuery(this).attr('action'),
|
this.attr('action'),
|
||||||
function() {
|
function() {
|
||||||
|
// Tree updates are triggered by Form_EditForm load events
|
||||||
button.removeClass('loading');
|
button.removeClass('loading');
|
||||||
},
|
},
|
||||||
{type: 'POST', data: data}
|
{type: 'POST', data: data}
|
||||||
@ -113,9 +114,9 @@
|
|||||||
refresh: function(selectedNode) {
|
refresh: function(selectedNode) {
|
||||||
// Note: Uses siteTreeHints global
|
// Note: Uses siteTreeHints global
|
||||||
var tree = this.getTree(),
|
var tree = this.getTree(),
|
||||||
|
selectedNode = selectedNode || $(tree).jstree('get_selected')
|
||||||
origOptions = this.getOrigOptions(),
|
origOptions = this.getOrigOptions(),
|
||||||
dropdown = this.find('select[name=PageType]');
|
dropdown = this.find('select[name=PageType]');
|
||||||
if(!selectedNode) selectedNode = tree.firstSelected();
|
|
||||||
|
|
||||||
// Clear all existing <option> elements
|
// Clear all existing <option> elements
|
||||||
// (IE doesn't allow setting display:none on these elements)
|
// (IE doesn't allow setting display:none on these elements)
|
||||||
@ -155,8 +156,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set parent node (fallback to root)
|
// Set parent node (fallback to root)
|
||||||
var parentID = tree.getIdxOf(selectedNode);
|
this.find(':input[name=ParentID]').val(selectedNode ? selectedNode.data('id') : 0);
|
||||||
this.find(':input[name=ParentID]').val(parentID ? parentID : 0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -40,8 +40,8 @@
|
|||||||
|
|
||||||
this.setTree($('#sitetree')[0]);
|
this.setTree($('#sitetree')[0]);
|
||||||
|
|
||||||
$(this.getTree()).bind('selectionchanged', function(e, data) {
|
$(this.getTree()).bind('select_node.jstree', function(e, data) {
|
||||||
self._treeSelectionChanged(data.node);
|
self._treeSelectionChanged(data.rslt.obj);
|
||||||
});
|
});
|
||||||
|
|
||||||
// if tab which contains this form is shown, make the tree selectable
|
// if tab which contains this form is shown, make the tree selectable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user