2010-05-08 04:45:05 +02:00
|
|
|
/**
|
|
|
|
* File: LeftAndMain.Tree.js
|
|
|
|
*/
|
|
|
|
|
2009-11-21 04:19:27 +01:00
|
|
|
(function($) {
|
2011-02-22 06:08:04 +01:00
|
|
|
$(document).ready(function() {
|
2011-03-10 04:46:08 +01:00
|
|
|
/**
|
|
|
|
* @todo Selectable tree with multiselect (toggled via "Batch Actions" panel)
|
|
|
|
* @todo Fix initial, unnecessary html_data replacement of existing tree (see below)
|
|
|
|
* @todo Icon and page type hover support
|
|
|
|
* @todo Sorting of sub nodes (originally placed in context menu)
|
|
|
|
* @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
|
|
|
|
*/
|
2011-03-01 21:52:15 +01:00
|
|
|
var treeContainer = $('#sitetree_ul');
|
|
|
|
treeContainer
|
|
|
|
.jstree({
|
|
|
|
'core': {
|
2011-03-03 01:59:03 +01:00
|
|
|
'initially_open': ['record-0'],
|
|
|
|
'animation': 0
|
2011-03-01 21:52:15 +01:00
|
|
|
},
|
|
|
|
'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': {
|
2011-03-10 04:13:43 +01:00
|
|
|
'url': treeContainer.data('url-tree'),
|
2011-03-01 21:52:15 +01:00
|
|
|
'data': function(node) {
|
|
|
|
return { ID : $(node).data("id") ? $(node).data("id") : 0 , ajax: 1};
|
|
|
|
}
|
2009-11-21 04:16:30 +01:00
|
|
|
}
|
2011-03-01 21:52:15 +01:00
|
|
|
},
|
|
|
|
'ui': {
|
|
|
|
"select_limit" : 1,
|
|
|
|
'initially_select': [treeContainer.find('.current').attr('id')]
|
|
|
|
},
|
2011-03-03 01:59:31 +01:00
|
|
|
"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']
|
2011-03-01 21:52:15 +01:00
|
|
|
})
|
2011-03-03 02:05:10 +01:00
|
|
|
.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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2011-03-01 21:52:15 +01:00
|
|
|
// 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;
|
|
|
|
|
|
|
|
var url = $(node).find('a:first').attr('href');
|
|
|
|
if(url && url != '#') {
|
|
|
|
var xmlhttp = $('#Form_EditForm').entwine('ss').loadForm(
|
|
|
|
url,
|
|
|
|
function(response) {}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$('#Form_EditForm').entwine('ss').removeForm();
|
2009-11-21 04:16:30 +01:00
|
|
|
}
|
2011-03-01 21:52:15 +01:00
|
|
|
})
|
|
|
|
.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({
|
2011-03-10 04:13:43 +01:00
|
|
|
'url': treeContainer.data('url-savetreenode'),
|
2011-03-01 21:52:15 +01:00
|
|
|
'data': {
|
|
|
|
ID: $(movedNode).data('id'),
|
|
|
|
ParentID: $(newParentNode).data('id') || 0,
|
|
|
|
SiblingIDs: siblingIDs
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2011-02-22 06:08:04 +01:00
|
|
|
});
|
2009-11-21 04:14:28 +01:00
|
|
|
|
2011-02-22 06:08:04 +01:00
|
|
|
}(jQuery));
|