mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
MINOR Wrapping LeftAndMain.Tree.js in entwine block
This commit is contained in:
parent
ea0f8b0e65
commit
cfb83e4e47
@ -3,120 +3,128 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
$(document).ready(function() {
|
|
||||||
/**
|
$.entwine('ss', function($){
|
||||||
* @todo Selectable tree with multiselect (toggled via "Batch Actions" panel)
|
|
||||||
* @todo Fix initial, unnecessary html_data replacement of existing tree (see below)
|
$('#sitetree_ul').entwine({
|
||||||
* @todo Icon and page type hover support
|
onmatch: function() {
|
||||||
* @todo Sorting of sub nodes (originally placed in context menu)
|
this._super();
|
||||||
* @todo Refresh after language <select> change (with Translatable enabled)
|
|
||||||
* @todo Automatic load of full subtree via ajax on node checkbox selection (minNodeCount = 0)
|
|
||||||
* to avoid doing partial selection with "hidden nodes" (unloaded markup)
|
|
||||||
* @todo Add siteTreeHints to field (as "data-hints" attribute with serialized JSON instead of javascript global variable)
|
|
||||||
* @todo Disallow drag'n'drop when not matching "allowedChildren" or "allowedParents" (see siteTreeHints)
|
|
||||||
* @todo Disallow drag'n'drop when node has "noChildren" set (see siteTreeHints)
|
|
||||||
* @todo Disallow moving of pages marked as deleted
|
|
||||||
* @todo Enforce sitetreeHints rules on page creation ("allowedChildren", "noChildren") -
|
|
||||||
* most likely by server response codes rather than clientside
|
|
||||||
* @todo "defaultChild" when creating a page (sitetreeHints)
|
|
||||||
* @todo Duplicate page (originally located in context menu)
|
|
||||||
* @todo Update tree node title information and modified state after reordering (response is a JSON array)
|
|
||||||
*
|
|
||||||
* Tasks most likely not required after moving to a standalone tree:
|
|
||||||
*
|
|
||||||
* @todo Context menu - to be replaced by a bezel UI
|
|
||||||
* @todo Refresh form for selected tree node if affected by reordering (new parent relationship)
|
|
||||||
* @todo Cancel current form load via ajax when new load is requested (synchronous loading)
|
|
||||||
* @todo When new edit form is loaded, automatically: Select matching node, set correct parent,
|
|
||||||
* update icon and title
|
|
||||||
*/
|
|
||||||
var treeContainer = $('#sitetree_ul');
|
|
||||||
treeContainer
|
|
||||||
.jstree({
|
|
||||||
'core': {
|
|
||||||
'initially_open': ['record-0'],
|
|
||||||
'animation': 0
|
|
||||||
},
|
|
||||||
'html_data': {
|
|
||||||
// TODO Hack to avoid ajax load on init, see http://code.google.com/p/jstree/issues/detail?id=911
|
|
||||||
'data': treeContainer.html(),
|
|
||||||
'ajax': {
|
|
||||||
'url': treeContainer.data('url-tree'),
|
|
||||||
'data': function(node) {
|
|
||||||
return { ID : $(node).data("id") ? $(node).data("id") : 0 , ajax: 1};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'ui': {
|
|
||||||
"select_limit" : 1,
|
|
||||||
'initially_select': [treeContainer.find('.current').attr('id')]
|
|
||||||
},
|
|
||||||
"crrm": {
|
|
||||||
'move': {
|
|
||||||
// Check if a node is allowed to be moved.
|
|
||||||
// Caution: Runs on every drag over a new node
|
|
||||||
'check_move': function(data) {
|
|
||||||
var movedNode = $(data.o), newParent = $(data.np),
|
|
||||||
isMovedOntoContainer = data.ot.get_container()[0] == data.np[0];
|
|
||||||
var isAllowed = (
|
|
||||||
// Don't allow moving the root node
|
|
||||||
movedNode.data('id') != 0
|
|
||||||
// Only allow moving node inside the root container, not before/after it
|
|
||||||
&& (!isMovedOntoContainer || data.p == 'inside')
|
|
||||||
);
|
|
||||||
return isAllowed;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'dnd': {
|
|
||||||
"drop_target" : false,
|
|
||||||
"drag_target" : false
|
|
||||||
},
|
|
||||||
'plugins': ['themes', 'html_data', 'ui', 'dnd', 'crrm']
|
|
||||||
})
|
|
||||||
.bind('before.jstree', function(e, data) {
|
|
||||||
if(data.func == 'start_drag') {
|
|
||||||
// Only allow drag'n'drop if it has been specifically enabled
|
|
||||||
if(!$('input[id=sortitems]').is(':checked')) {
|
|
||||||
e.stopImmediatePropagation();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// 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
|
* @todo Selectable tree with multiselect (toggled via "Batch Actions" panel)
|
||||||
if($(node).data('id') == loadedNodeID) return;
|
* @todo Fix initial, unnecessary html_data replacement of existing tree (see below)
|
||||||
|
* @todo Icon and page type hover support
|
||||||
var url = $(node).find('a:first').attr('href');
|
* @todo Sorting of sub nodes (originally placed in context menu)
|
||||||
if(url && url != '#') {
|
* @todo Refresh after language <select> change (with Translatable enabled)
|
||||||
var xmlhttp = $('#Form_EditForm').entwine('ss').loadForm(
|
* @todo Automatic load of full subtree via ajax on node checkbox selection (minNodeCount = 0)
|
||||||
url,
|
* to avoid doing partial selection with "hidden nodes" (unloaded markup)
|
||||||
function(response) {}
|
* @todo Add siteTreeHints to field (as "data-hints" attribute with serialized JSON instead of javascript global variable)
|
||||||
);
|
* @todo Disallow drag'n'drop when not matching "allowedChildren" or "allowedParents" (see siteTreeHints)
|
||||||
} else {
|
* @todo Disallow drag'n'drop when node has "noChildren" set (see siteTreeHints)
|
||||||
$('#Form_EditForm').entwine('ss').removeForm();
|
* @todo Disallow moving of pages marked as deleted
|
||||||
}
|
* @todo Enforce sitetreeHints rules on page creation ("allowedChildren", "noChildren") -
|
||||||
})
|
* most likely by server response codes rather than clientside
|
||||||
.bind('move_node.jstree', function(e, data) {
|
* @todo "defaultChild" when creating a page (sitetreeHints)
|
||||||
var movedNode = data.rslt.o, newParentNode = data.rslt.np, oldParentNode = data.inst._get_parent(movedNode);
|
* @todo Duplicate page (originally located in context menu)
|
||||||
var siblingIDs = $.map($(movedNode).siblings().andSelf(), function(el) {
|
* @todo Update tree node title information and modified state after reordering (response is a JSON array)
|
||||||
return $(el).data('id');
|
*
|
||||||
});
|
* Tasks most likely not required after moving to a standalone tree:
|
||||||
|
*
|
||||||
$.ajax({
|
* @todo Context menu - to be replaced by a bezel UI
|
||||||
'url': treeContainer.data('url-savetreenode'),
|
* @todo Refresh form for selected tree node if affected by reordering (new parent relationship)
|
||||||
'data': {
|
* @todo Cancel current form load via ajax when new load is requested (synchronous loading)
|
||||||
ID: $(movedNode).data('id'),
|
* @todo When new edit form is loaded, automatically: Select matching node, set correct parent,
|
||||||
ParentID: $(newParentNode).data('id') || 0,
|
* update icon and title
|
||||||
SiblingIDs: siblingIDs
|
*/
|
||||||
}
|
this
|
||||||
});
|
.jstree({
|
||||||
});
|
'core': {
|
||||||
|
'initially_open': ['record-0'],
|
||||||
});
|
'animation': 0
|
||||||
|
},
|
||||||
|
'html_data': {
|
||||||
|
// TODO Hack to avoid ajax load on init, see http://code.google.com/p/jstree/issues/detail?id=911
|
||||||
|
'data': this.html(),
|
||||||
|
'ajax': {
|
||||||
|
'url': this.data('url-tree'),
|
||||||
|
'data': function(node) {
|
||||||
|
return { ID : $(node).data("id") ? $(node).data("id") : 0 , ajax: 1};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'ui': {
|
||||||
|
"select_limit" : 1,
|
||||||
|
'initially_select': [this.find('.current').attr('id')]
|
||||||
|
},
|
||||||
|
"crrm": {
|
||||||
|
'move': {
|
||||||
|
// Check if a node is allowed to be moved.
|
||||||
|
// Caution: Runs on every drag over a new node
|
||||||
|
'check_move': function(data) {
|
||||||
|
var movedNode = $(data.o), newParent = $(data.np),
|
||||||
|
isMovedOntoContainer = data.ot.get_container()[0] == data.np[0];
|
||||||
|
var isAllowed = (
|
||||||
|
// Don't allow moving the root node
|
||||||
|
movedNode.data('id') != 0
|
||||||
|
// Only allow moving node inside the root container, not before/after it
|
||||||
|
&& (!isMovedOntoContainer || data.p == 'inside')
|
||||||
|
);
|
||||||
|
return isAllowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'dnd': {
|
||||||
|
"drop_target" : false,
|
||||||
|
"drag_target" : false
|
||||||
|
},
|
||||||
|
'plugins': ['html_data', 'ui', 'dnd', 'crrm']
|
||||||
|
})
|
||||||
|
.bind('before.jstree', function(e, data) {
|
||||||
|
if(data.func == 'start_drag') {
|
||||||
|
// Only allow drag'n'drop if it has been specifically enabled
|
||||||
|
if(!$('input[id=sortitems]').is(':checked')) {
|
||||||
|
e.stopImmediatePropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// TODO Move to EditForm logic
|
||||||
|
.bind('select_node.jstree', function(e, data) {
|
||||||
|
var node = data.rslt.obj, loadedNodeID = $('#Form_EditForm :input[name=ID]').val()
|
||||||
|
|
||||||
}(jQuery));
|
// 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;
|
||||||
|
|
||||||
|
var url = $(node).find('a:first').attr('href');
|
||||||
|
if(url && url != '#') {
|
||||||
|
var xmlhttp = $('#Form_EditForm').loadForm(
|
||||||
|
url,
|
||||||
|
function(response) {}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$('#Form_EditForm').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': this.data('url-savetreenode'),
|
||||||
|
'data': {
|
||||||
|
ID: $(movedNode).data('id'),
|
||||||
|
ParentID: $(newParentNode).data('id') || 0,
|
||||||
|
SiblingIDs: siblingIDs
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}(jQuery));
|
Loading…
x
Reference in New Issue
Block a user