mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
ENHANCEMENT Added drag'n'drop support for tree
This commit is contained in:
parent
4f0c5d115a
commit
564038b463
@ -4,13 +4,15 @@
|
|||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#sitetree_ul').jstree({
|
var treeContainer = $('#sitetree_ul');
|
||||||
|
treeContainer
|
||||||
|
.jstree({
|
||||||
'core': {
|
'core': {
|
||||||
'initially_open': ['record-0']
|
'initially_open': ['record-0']
|
||||||
},
|
},
|
||||||
'html_data': {
|
'html_data': {
|
||||||
// TODO Hack to avoid ajax load on init, see http://code.google.com/p/jstree/issues/detail?id=911
|
// TODO Hack to avoid ajax load on init, see http://code.google.com/p/jstree/issues/detail?id=911
|
||||||
'data': $('#sitetree_ul').html(),
|
'data': treeContainer.html(),
|
||||||
'ajax': {
|
'ajax': {
|
||||||
'url': 'admin/getsubtree',
|
'url': 'admin/getsubtree',
|
||||||
'data': function(node) {
|
'data': function(node) {
|
||||||
@ -20,25 +22,48 @@
|
|||||||
},
|
},
|
||||||
'ui': {
|
'ui': {
|
||||||
"select_limit" : 1,
|
"select_limit" : 1,
|
||||||
'initially_select': [$('#sitetree_ul').find('.current').attr('id')]
|
'initially_select': [treeContainer.find('.current').attr('id')]
|
||||||
},
|
},
|
||||||
'plugins': ['themes', 'html_data', 'ui']
|
'plugins': ['themes', 'html_data', 'ui', 'dnd']
|
||||||
});
|
})
|
||||||
|
// .bind('before.jstree', function(e, data) {
|
||||||
|
// if(data.func == 'drag_start') {
|
||||||
|
// // Only allow drag'n'drop if it has been specifically enabled
|
||||||
|
// return $('input[id=sortitems]').is(':checked');
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// TODO Move to EditForm logic
|
||||||
|
.bind('select_node.jstree', function(e, data) {
|
||||||
|
var node = data.rslt.obj, loadedNodeID = $('#Form_EditForm :input[name=ID]').val()
|
||||||
|
|
||||||
|
// Don't allow reloading of currently selected node,
|
||||||
|
// mainly to avoid doing an ajax request on initial page load
|
||||||
|
if($(node).data('id') == loadedNodeID) return;
|
||||||
|
|
||||||
$('#sitetree_ul').bind('select_node.jstree', function(e, data) {
|
|
||||||
var node = data.rslt.obj;
|
|
||||||
var url = $(node).find('a:first').attr('href');
|
var url = $(node).find('a:first').attr('href');
|
||||||
if(url && url != '#') {
|
if(url && url != '#') {
|
||||||
var xmlhttp = $('#Form_EditForm').entwine('ss').loadForm(
|
var xmlhttp = $('#Form_EditForm').entwine('ss').loadForm(
|
||||||
url,
|
url,
|
||||||
function(response) {}
|
function(response) {}
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO Mark node as loading
|
|
||||||
// if(xmlhttp) this.addNodeClass('loading');
|
|
||||||
} else {
|
} else {
|
||||||
jQuery('#Form_EditForm').entwine('ss').removeForm();
|
$('#Form_EditForm').entwine('ss').removeForm();
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
.bind('move_node.jstree', function(e, data) {
|
||||||
|
var movedNode = data.rslt.o, newParentNode = data.rslt.np, oldParentNode = data.inst._get_parent(movedNode);
|
||||||
|
var siblingIDs = $.map($(movedNode).siblings().andSelf(), function(el) {
|
||||||
|
return $(el).data('id');
|
||||||
|
});
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
'url': 'admin/savetreenode',
|
||||||
|
'data': {
|
||||||
|
ID: $(movedNode).data('id'),
|
||||||
|
ParentID: $(newParentNode).data('id') || 0,
|
||||||
|
SiblingIDs: siblingIDs
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user