2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* File: LeftAndMain.Tree.js
|
|
|
|
*/
|
|
|
|
|
|
|
|
(function($) {
|
2011-05-08 06:02:28 +02:00
|
|
|
|
2012-05-18 02:07:40 +02:00
|
|
|
$.entwine('ss.tree', function($){
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2011-04-17 09:55:23 +02:00
|
|
|
$('.cms-tree').entwine({
|
2011-05-08 06:02:28 +02:00
|
|
|
|
|
|
|
Hints: null,
|
2012-06-12 12:48:08 +02:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
IsUpdatingTree: false,
|
|
|
|
|
|
|
|
IsLoaded: false,
|
|
|
|
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function(){
|
2011-03-23 10:51:00 +01:00
|
|
|
this._super();
|
2012-03-06 20:17:57 +01:00
|
|
|
|
|
|
|
// Don't reapply (expensive) tree behaviour if already present
|
2012-05-10 06:21:11 +02:00
|
|
|
if($.isNumeric(this.data('jstree_instance_id'))) return;
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2011-12-18 16:01:36 +01:00
|
|
|
var hints = this.attr('data-hints');
|
|
|
|
if(hints) this.setHints($.parseJSON(hints));
|
2011-05-08 06:02:28 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
|
|
|
* @todo Icon and page type hover support
|
|
|
|
* @todo Sorting of sub nodes (originally placed in context menu)
|
|
|
|
* @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 Disallow drag'n'drop when node has "noChildren" set (see siteTreeHints)
|
|
|
|
* @todo Disallow moving of pages marked as deleted
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
var self = this;
|
|
|
|
this
|
2012-03-12 11:40:08 +01:00
|
|
|
.jstree(this.getTreeConfig())
|
2011-03-23 10:51:00 +01:00
|
|
|
.bind('loaded.jstree', function(e, data) {
|
2012-07-17 15:04:27 +02:00
|
|
|
self.setIsLoaded(true);
|
2012-06-03 18:10:57 +02:00
|
|
|
self.updateFromEditForm();
|
2011-12-14 16:54:52 +01:00
|
|
|
self.css('visibility', 'visible');
|
2011-03-23 10:51:00 +01:00
|
|
|
// Add ajax settings after init period to avoid unnecessary initial ajax load
|
|
|
|
// of existing tree in DOM - see load_node_html()
|
|
|
|
data.inst._set_settings({'html_data': {'ajax': {
|
2012-02-23 16:07:38 +01:00
|
|
|
'url': self.data('urlTree'),
|
2011-03-23 10:51:00 +01:00
|
|
|
'data': function(node) {
|
|
|
|
var params = self.data('searchparams') || [];
|
|
|
|
// Avoid duplication of parameters
|
|
|
|
params = $.grep(params, function(n, i) {return (n.name != 'ID' && n.name != 'value');});
|
|
|
|
params.push({name: 'ID', value: $(node).data("id") ? $(node).data("id") : 0});
|
|
|
|
params.push({name: 'ajax', value: 1});
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
}}});
|
|
|
|
|
|
|
|
// Only show checkboxes with .multiple class
|
|
|
|
data.inst.hide_checkboxes();
|
|
|
|
})
|
|
|
|
.bind('before.jstree', function(e, data) {
|
|
|
|
if(data.func == 'start_drag') {
|
2011-04-22 13:34:01 +02:00
|
|
|
// Don't allow drag'n'drop if multi-select is enabled'
|
|
|
|
if(!self.hasClass('draggable') || self.hasClass('multiselect')) {
|
2011-03-23 10:51:00 +01:00
|
|
|
e.stopImmediatePropagation();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($.inArray(data.func, ['check_node', 'uncheck_node'])) {
|
2012-09-28 02:08:14 +02:00
|
|
|
// don't allow check and uncheck if parent is disabled
|
2011-03-23 10:51:00 +01:00
|
|
|
var node = $(data.args[0]).parents('li:first');
|
2012-09-28 02:08:14 +02:00
|
|
|
var allowedChildren = node.find('li:not(.disabled)');
|
|
|
|
|
|
|
|
// if there are child nodes that aren't disabled, allow expanding the tree
|
|
|
|
if(node.hasClass('disabled') && allowedChildren == 0) {
|
2011-03-23 10:51:00 +01:00
|
|
|
e.stopImmediatePropagation();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind('move_node.jstree', function(e, data) {
|
2012-07-17 15:04:27 +02:00
|
|
|
if(self.getIsUpdatingTree()) return;
|
|
|
|
|
2012-08-29 10:33:03 +02:00
|
|
|
var movedNode = data.rslt.o, newParentNode = data.rslt.np, oldParentNode = data.inst._get_parent(movedNode), newParentID = $(newParentNode).data('id') || 0, nodeID = $(movedNode).data('id');
|
2011-03-23 10:51:00 +01:00
|
|
|
var siblingIDs = $.map($(movedNode).siblings().andSelf(), function(el) {
|
|
|
|
return $(el).data('id');
|
|
|
|
});
|
|
|
|
|
|
|
|
$.ajax({
|
2012-02-23 16:07:38 +01:00
|
|
|
'url': self.data('urlSavetreenode'),
|
2011-03-23 10:51:00 +01:00
|
|
|
'data': {
|
2012-08-29 10:33:03 +02:00
|
|
|
ID: nodeID,
|
|
|
|
ParentID: newParentID,
|
2011-03-23 10:51:00 +01:00
|
|
|
SiblingIDs: siblingIDs
|
2012-06-14 07:17:27 +02:00
|
|
|
},
|
2012-08-29 10:33:03 +02:00
|
|
|
success: function() {
|
|
|
|
$('.cms-edit-form :input[name=ParentID]').val(newParentID);
|
|
|
|
self.updateNodesFromServer([nodeID]);
|
|
|
|
},
|
2012-06-14 07:17:27 +02:00
|
|
|
statusCode: {
|
|
|
|
403: function() {
|
|
|
|
$.jstree.rollback(data.rlbk);
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
}
|
|
|
|
});
|
2012-06-18 00:23:04 +02:00
|
|
|
})
|
|
|
|
// Make some jstree events delegatable
|
2012-06-22 00:46:03 +02:00
|
|
|
.bind('select_node.jstree check_node.jstree uncheck_node.jstree', function(e, data) {
|
2012-06-18 00:23:04 +02:00
|
|
|
$(document).triggerHandler(e, data);
|
2012-07-17 15:04:27 +02:00
|
|
|
});
|
2011-03-23 10:51:00 +01:00
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
onremove: function(){
|
|
|
|
this.jstree('destroy');
|
2012-05-11 07:36:18 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-03-12 11:40:08 +01:00
|
|
|
|
2012-06-12 12:48:08 +02:00
|
|
|
'from .cms-container': {
|
|
|
|
onafterstatechange: function(e){
|
2012-07-17 15:04:27 +02:00
|
|
|
this.updateFromEditForm();
|
|
|
|
// No need to refresh tree nodes, we assume only form submits cause state changes
|
|
|
|
}
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
'from .cms-container form': {
|
2012-06-12 12:48:08 +02:00
|
|
|
onaftersubmitform: function(e){
|
2012-07-17 15:04:27 +02:00
|
|
|
var id = $('.cms-edit-form :input[name=ID]').val();
|
|
|
|
// TODO Trigger by implementing and inspecting "changed records" metadata
|
|
|
|
// sent by form submission response (as HTTP response headers)
|
|
|
|
this.updateNodesFromServer([id]);
|
2012-06-12 12:48:08 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-03-12 11:40:08 +01:00
|
|
|
getTreeConfig: function() {
|
2012-03-12 14:44:09 +01:00
|
|
|
var self = this;
|
2012-03-12 11:40:08 +01:00
|
|
|
return {
|
|
|
|
'core': {
|
|
|
|
'initially_open': ['record-0'],
|
|
|
|
'animation': 0,
|
|
|
|
'html_titles': true
|
|
|
|
},
|
|
|
|
'html_data': {
|
|
|
|
// 'ajax' will be set on 'loaded.jstree' event
|
|
|
|
},
|
|
|
|
'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],
|
|
|
|
movedNodeClass = movedNode.getClassname(),
|
|
|
|
newParentClass = newParent.getClassname(),
|
|
|
|
// Check allowedChildren of newParent or against root node rules
|
|
|
|
hints = self.getHints(),
|
|
|
|
disallowedChildren = [],
|
|
|
|
hintKey = newParentClass ? newParentClass : 'Root',
|
2012-06-13 00:51:53 +02:00
|
|
|
hint = (hints && typeof hints[hintKey] != 'undefined') ? hints[hintKey] : null;
|
2012-03-12 11:40:08 +01:00
|
|
|
|
|
|
|
// Special case for VirtualPage: Check that original page type is an allowed child
|
|
|
|
if(hint && movedNode.attr('class').match(/VirtualPage-([^\s]*)/)) movedNodeClass = RegExp.$1;
|
|
|
|
|
|
|
|
if(hint) disallowedChildren = (typeof hint.disallowedChildren != 'undefined') ? hint.disallowedChildren : [];
|
|
|
|
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')
|
|
|
|
// Children are generally allowed on parent
|
|
|
|
&& !newParent.hasClass('nochildren')
|
|
|
|
// movedNode is allowed as a child
|
|
|
|
&& (!disallowedChildren.length || $.inArray(movedNodeClass, disallowedChildren) == -1)
|
|
|
|
);
|
|
|
|
|
|
|
|
return isAllowed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'dnd': {
|
|
|
|
"drop_target" : false,
|
|
|
|
"drag_target" : false
|
|
|
|
},
|
|
|
|
'checkbox': {
|
|
|
|
'two_state': true
|
|
|
|
},
|
|
|
|
'themes': {
|
|
|
|
'theme': 'apple',
|
2012-03-24 04:38:57 +01:00
|
|
|
'url': $('body').data('frameworkpath') + '/thirdparty/jstree/themes/apple/style.css'
|
2012-03-12 11:40:08 +01:00
|
|
|
},
|
|
|
|
// Caution: SilverStripe has disabled $.vakata.css.add_sheet() for performance reasons,
|
2012-03-24 04:38:57 +01:00
|
|
|
// which means you need to add any CSS manually to framework/admin/scss/_tree.css
|
2012-03-12 11:40:08 +01:00
|
|
|
'plugins': [
|
|
|
|
'html_data', 'ui', 'dnd', 'crrm', 'themes',
|
|
|
|
'checkbox' // checkboxes are hidden unless .multiple is set
|
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
2011-03-23 10:51:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function:
|
|
|
|
* search
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Object) data Pass empty data to cancel search
|
|
|
|
* (Function) callback Success callback
|
|
|
|
*/
|
|
|
|
search: function(params, callback) {
|
|
|
|
if(params) this.data('searchparams', params);
|
|
|
|
else this.removeData('searchparams');
|
|
|
|
this.jstree('refresh', -1, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: getNodeByID
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Int) id
|
|
|
|
*
|
|
|
|
* Returns
|
|
|
|
* DOMElement
|
|
|
|
*/
|
|
|
|
getNodeByID: function(id) {
|
2012-03-06 21:36:53 +01:00
|
|
|
return this.find('*[data-id='+id+']');
|
2011-03-23 10:51:00 +01:00
|
|
|
},
|
2012-07-17 15:04:27 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
/**
|
2012-07-17 15:04:27 +02:00
|
|
|
* Creates a new node from the given HTML.
|
|
|
|
* Wrapping around jstree API because we want the flexibility to define
|
|
|
|
* the node's <li> ourselves. Places the node in the tree
|
|
|
|
* according to data.ParentID
|
2012-06-12 17:13:36 +02:00
|
|
|
*
|
2012-07-17 15:04:27 +02:00
|
|
|
* Parameters:
|
|
|
|
* (String) HTML New node content (<li>)
|
|
|
|
* (Object) Map of additional data, e.g. ParentID
|
|
|
|
* (Function) Success callback
|
2012-03-12 11:40:08 +01:00
|
|
|
*/
|
2012-07-17 15:04:27 +02:00
|
|
|
createNode: function(html, data, callback) {
|
2012-06-03 18:10:57 +02:00
|
|
|
var self = this,
|
2012-07-17 15:04:27 +02:00
|
|
|
parentNode = data.ParentID ? self.find('li[data-id='+data.ParentID+']') : false,
|
|
|
|
newNode = $(html);
|
|
|
|
|
|
|
|
this.jstree(
|
|
|
|
'create_node',
|
|
|
|
parentNode.length ? parentNode : -1,
|
|
|
|
'last',
|
|
|
|
'',
|
|
|
|
function(node) {
|
|
|
|
var origClasses = node.attr('class');
|
|
|
|
// Copy attributes
|
|
|
|
for(var i=0; i<newNode[0].attributes.length; i++){
|
|
|
|
var attr = newNode[0].attributes[i];
|
|
|
|
node.attr(attr.name, attr.value);
|
|
|
|
}
|
|
|
|
node.addClass(origClasses).html(newNode.html());
|
|
|
|
callback(node);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
/**
|
|
|
|
* Updates a node's state in the tree,
|
|
|
|
* including all of its HTML, as well as its position.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (DOMElement) Existing node
|
|
|
|
* (String) HTML New node content (<li>)
|
|
|
|
* (Object) Map of additional data, e.g. ParentID
|
|
|
|
*/
|
|
|
|
updateNode: function(node, html, data) {
|
2012-07-23 12:15:11 +02:00
|
|
|
var self = this, newNode = $(html), origClasses = node.attr('class');
|
|
|
|
|
|
|
|
var nextNode = data.NextID ? this.find('li[data-id='+data.NextID+']') : false;
|
|
|
|
var prevNode = data.PrevID ? this.find('li[data-id='+data.PrevID+']') : false;
|
|
|
|
var parentNode = data.ParentID ? this.find('li[data-id='+data.ParentID+']') : false;
|
2012-06-12 19:16:34 +02:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
// Copy attributes. We can't replace the node completely
|
|
|
|
// without removing or detaching its children nodes.
|
|
|
|
for(var i=0; i<newNode[0].attributes.length; i++){
|
|
|
|
var attr = newNode[0].attributes[i];
|
|
|
|
node.attr(attr.name, attr.value);
|
|
|
|
}
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
// Replace inner content
|
2012-08-22 15:33:28 +02:00
|
|
|
var origChildren = node.children('ul').detach();
|
|
|
|
node.addClass(origClasses).html(newNode.html()).append(origChildren);
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-07-23 12:15:11 +02:00
|
|
|
if (nextNode && nextNode.length) {
|
|
|
|
this.jstree('move_node', node, nextNode, 'before');
|
|
|
|
}
|
|
|
|
else if (prevNode && prevNode.length) {
|
|
|
|
this.jstree('move_node', node, prevNode, 'after');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.jstree('move_node', node, parentNode.length ? parentNode : -1);
|
|
|
|
}
|
2012-07-17 15:04:27 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the current state based on the form the tree is managing.
|
|
|
|
*/
|
|
|
|
updateFromEditForm: function() {
|
|
|
|
var node, id = $('.cms-edit-form :input[name=ID]').val();
|
|
|
|
if(id) {
|
|
|
|
node = this.getNodeByID(id);
|
2012-06-04 11:05:05 +02:00
|
|
|
if(node.length) {
|
2012-08-27 16:46:25 +02:00
|
|
|
this.jstree('deselect_all');
|
2012-06-04 11:05:05 +02:00
|
|
|
this.jstree('select_node', node);
|
2012-07-17 15:04:27 +02:00
|
|
|
} else {
|
|
|
|
// If form is showing an ID that doesn't exist in the tree,
|
|
|
|
// get it from the server
|
|
|
|
this.updateNodesFromServer([id]);
|
2012-06-04 11:05:05 +02:00
|
|
|
}
|
2012-03-12 11:40:08 +01:00
|
|
|
} else {
|
2012-06-03 18:10:57 +02:00
|
|
|
// If no ID exists in a form view, we're displaying the tree on its own,
|
|
|
|
// hence to page should show as active
|
|
|
|
this.jstree('deselect_all');
|
2012-03-12 11:40:08 +01:00
|
|
|
}
|
2012-07-17 15:04:27 +02:00
|
|
|
},
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
/**
|
|
|
|
* Reloads the view of one or more tree nodes
|
|
|
|
* from the server, ensuring that their state is up to date
|
|
|
|
* (icon, title, hierarchy, badges, etc).
|
|
|
|
* This is easier, more consistent and more extensible
|
|
|
|
* than trying to correct all aspects via DOM modifications,
|
|
|
|
* based on the sparse data available in the current edit form.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (Array) List of IDs to retrieve
|
|
|
|
*/
|
|
|
|
updateNodesFromServer: function(ids) {
|
|
|
|
if(this.getIsUpdatingTree() || !this.getIsLoaded()) return;
|
|
|
|
|
|
|
|
var self = this, includesNewNode = false;
|
|
|
|
this.setIsUpdatingTree(true);
|
|
|
|
|
|
|
|
// TODO 'initially_opened' config doesn't apply here
|
|
|
|
self.jstree('open_node', this.getNodeByID(0));
|
|
|
|
self.jstree('save_opened');
|
|
|
|
self.jstree('save_selected');
|
|
|
|
|
|
|
|
$.ajax({
|
2012-08-03 12:17:46 +02:00
|
|
|
url: $.path.addSearchParams(this.data('urlUpdatetreenodes'), 'ids=' + ids.join(',')),
|
2012-07-17 15:04:27 +02:00
|
|
|
dataType: 'json',
|
|
|
|
success: function(data, xhr) {
|
|
|
|
$.each(data, function(nodeId, nodeData) {
|
|
|
|
var node = self.getNodeByID(nodeId);
|
|
|
|
|
|
|
|
// If no node data is given, assume the node has been removed
|
|
|
|
if(!nodeData) {
|
|
|
|
self.jstree('delete_node', node);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:33:28 +02:00
|
|
|
var correctStateFn = function(node) {
|
|
|
|
self.jstree('deselect_all');
|
|
|
|
self.jstree('select_node', node);
|
|
|
|
// Similar to jstree's correct_state, but doesn't remove children
|
|
|
|
var hasChildren = (node.children('ul').length > 0);
|
|
|
|
node.toggleClass('jstree-leaf', !hasChildren);
|
|
|
|
if(!hasChildren) node.removeClass('jstree-closed jstree-open');
|
|
|
|
};
|
|
|
|
|
2012-07-17 15:04:27 +02:00
|
|
|
// Check if node exists, create if necessary
|
|
|
|
if(node.length) {
|
|
|
|
self.updateNode(node, nodeData.html, nodeData);
|
|
|
|
setTimeout(function() {
|
2012-08-22 15:33:28 +02:00
|
|
|
correctStateFn(node) ;
|
2012-07-17 15:04:27 +02:00
|
|
|
}, 500);
|
|
|
|
} else {
|
|
|
|
includesNewNode = true;
|
|
|
|
self.createNode(nodeData.html, nodeData, function(newNode) {
|
2012-08-22 15:33:28 +02:00
|
|
|
correctStateFn(newNode);
|
2012-07-17 15:04:27 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if(!includesNewNode) {
|
|
|
|
self.jstree('deselect_all');
|
|
|
|
self.jstree('reselect');
|
|
|
|
self.jstree('reopen');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
complete: function() {
|
|
|
|
self.setIsUpdatingTree(false);
|
|
|
|
}
|
|
|
|
});
|
2012-03-12 11:40:08 +01:00
|
|
|
}
|
2012-05-11 06:07:07 +02:00
|
|
|
|
2011-03-23 10:51:00 +01:00
|
|
|
});
|
|
|
|
|
2012-03-06 20:17:42 +01:00
|
|
|
$('.cms-tree.multiple').entwine({
|
|
|
|
onmatch: function() {
|
|
|
|
this._super();
|
|
|
|
this.jstree('show_checkboxes');
|
|
|
|
},
|
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
this.jstree('uncheck_all');
|
|
|
|
this.jstree('hide_checkboxes');
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Function: getSelectedIDs
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* (Array)
|
|
|
|
*/
|
|
|
|
getSelectedIDs: function() {
|
|
|
|
return $.map($(this).jstree('get_checked'), function(el, i) {return $(el).data('id');});
|
|
|
|
}
|
|
|
|
});
|
2011-03-23 10:51:00 +01:00
|
|
|
|
2012-03-06 20:17:42 +01:00
|
|
|
$('.cms-tree li').entwine({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: setEnabled
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* (bool)
|
|
|
|
*/
|
|
|
|
setEnabled: function(bool) {
|
|
|
|
this.toggleClass('disabled', !(bool));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: getClassname
|
|
|
|
*
|
|
|
|
* Returns PHP class for this element. Useful to check business rules like valid drag'n'drop targets.
|
|
|
|
*/
|
|
|
|
getClassname: function() {
|
|
|
|
var matches = this.attr('class').match(/class-([^\s]*)/i);
|
|
|
|
return matches ? matches[1] : '';
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function: getID
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* (Number)
|
|
|
|
*/
|
|
|
|
getID: function() {
|
|
|
|
return this.data('id');
|
|
|
|
}
|
|
|
|
});
|
2011-04-05 23:50:20 +02:00
|
|
|
|
2012-10-12 05:02:04 +02:00
|
|
|
$('.cms-content-batchactions input[name=view-mode-batchactions]').entwine({
|
2012-03-06 20:17:42 +01:00
|
|
|
onmatch: function() {
|
|
|
|
// set active by default
|
2012-05-01 14:10:09 +02:00
|
|
|
this.redraw();
|
2012-03-06 20:17:42 +01:00
|
|
|
this._super();
|
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2012-03-06 20:17:42 +01:00
|
|
|
onclick: function(e) {
|
2012-05-01 14:10:09 +02:00
|
|
|
this.redraw();
|
|
|
|
},
|
|
|
|
redraw: function(type) {
|
2012-05-30 20:57:18 +02:00
|
|
|
if(window.debug) console.log('redraw', this.attr('class'), this.get(0));
|
|
|
|
|
2012-03-06 20:17:42 +01:00
|
|
|
$('.cms-tree')
|
2012-10-12 05:02:04 +02:00
|
|
|
.toggleClass('draggable', !this.is(':checked'))
|
|
|
|
.toggleClass('multiple', this.is(':checked'));
|
2012-03-06 20:17:42 +01:00
|
|
|
}
|
|
|
|
});
|
2011-04-22 13:34:01 +02:00
|
|
|
});
|
2012-03-24 04:38:57 +01:00
|
|
|
}(jQuery));
|