2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* LeftAndMain_left.js
|
|
|
|
* Code for supporting the left-hand panel of all the 2-pane admin windows
|
|
|
|
* This includes code for the action panel at the top, and the draggable, ajax-linked tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
|
|
|
|
SiteTreeHandlers.parentChanged_url = 'admin/ajaxupdateparent';
|
|
|
|
SiteTreeHandlers.orderChanged_url = 'admin/ajaxupdatesort';
|
|
|
|
SiteTreeHandlers.showRecord_url = 'admin/show/';
|
2007-09-04 06:12:30 +02:00
|
|
|
SiteTreeHandlers.controller_url = 'admin';
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
var _HANDLER_FORMS = {
|
2009-11-21 04:18:51 +01:00
|
|
|
addpage : 'Form_AddForm',
|
2007-09-16 17:19:17 +02:00
|
|
|
batchactions : 'batchactionsforms',
|
|
|
|
search : 'search_options'
|
2007-07-19 12:40:05 +02:00
|
|
|
};
|
|
|
|
|
2009-11-21 04:19:27 +01:00
|
|
|
(function($) {
|
2010-02-22 20:49:51 +01:00
|
|
|
$(window).bind('load', function(e) {
|
|
|
|
// behaviour.js load handlers need to be fired before this event, so we artificially delay it
|
|
|
|
setTimeout(function() {
|
|
|
|
// make sure current ID of loaded form is actually selected in tree
|
|
|
|
var tree = $('#sitetree')[0], id = $('#Form_EditForm :input[name=ID]').val();
|
|
|
|
if(!id) id = 0;
|
|
|
|
tree.setCurrentByIdx(id);
|
|
|
|
}, 200);
|
2009-11-21 04:19:27 +01:00
|
|
|
});
|
|
|
|
}(jQuery));
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overload this with a real context menu if necessary
|
|
|
|
*/
|
|
|
|
var TreeContextMenu = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extra methods for the tree when used in the LHS of the CMS
|
|
|
|
*/
|
|
|
|
TreeAPI = Class.create();
|
|
|
|
TreeAPI.prototype = {
|
2009-05-14 08:11:18 +02:00
|
|
|
|
|
|
|
setCustomURL: function(url, arguments) {
|
|
|
|
this.customURL = url;
|
|
|
|
this.customArguments = $H(arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
clearCustomURL: function() {
|
|
|
|
this.customURL = this.customArguments = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
url: function(args) {
|
|
|
|
var args = $H(args).merge(this.customArguments);
|
|
|
|
|
|
|
|
var url = this.customURL ? this.customURL : SiteTreeHandlers.loadTree_url;
|
|
|
|
url = url + (url.match(/\?/) ? '&' : '?') + args.toQueryString();
|
|
|
|
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
|
|
|
|
reload: function(options) {
|
|
|
|
this.innerHTML = 'Loading...';
|
|
|
|
|
|
|
|
var args = {ajax:1, ID:0};
|
2009-05-29 01:10:57 +02:00
|
|
|
if ($('LangSelector')) args.locale = $('LangSelector').value;
|
2009-05-14 08:11:18 +02:00
|
|
|
|
|
|
|
url = this.url(args);
|
|
|
|
|
|
|
|
var self = this;
|
2009-11-21 04:15:44 +01:00
|
|
|
jQuery.get(
|
|
|
|
url,
|
|
|
|
function(data, status){
|
|
|
|
self.innerHTML = data;
|
2009-05-14 08:11:18 +02:00
|
|
|
self.castAsTreeNode(self.firstChild);
|
2010-02-11 00:06:33 +01:00
|
|
|
if (options && options.onSuccess) options.onSuccess(data);
|
2009-05-14 08:11:18 +02:00
|
|
|
},
|
2009-11-21 04:15:44 +01:00
|
|
|
'html'
|
|
|
|
);
|
2009-05-14 08:11:18 +02:00
|
|
|
},
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
/**
|
|
|
|
* Perform the given code on the each tree node with the given index.
|
|
|
|
* There could be more than one :-)
|
|
|
|
* @param idx The index of the tree node
|
|
|
|
* @param code A method to be executed, that will be passed the tree node
|
|
|
|
*/
|
|
|
|
performOnTreeNode: function(idx, code) {
|
|
|
|
var treeNode = this.getTreeNodeByIdx(idx);
|
|
|
|
if(!treeNode) return;
|
|
|
|
|
|
|
|
if(treeNode.className.indexOf('manyparents') == -1) {
|
|
|
|
code(treeNode);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
var i,item,allNodes = this.getElementsByTagName('li');
|
|
|
|
for(i=0;item=allNodes[i];i++) {
|
|
|
|
if(treeNode.id == item.id) code(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getTreeNodeByIdx : function(idx) {
|
|
|
|
if(!idx) idx = "0";
|
|
|
|
var node = document.getElementById('record-' + idx);
|
|
|
|
if(idx == "0" && !node) node = document.getElementById('record-root');
|
|
|
|
return node;
|
|
|
|
},
|
|
|
|
getIdxOf : function(treeNode) {
|
|
|
|
if(treeNode && treeNode.id && treeNode.id.match(/record-([0-9a-zA-Z\-]+)$/))
|
|
|
|
return RegExp.$1;
|
|
|
|
},
|
|
|
|
createTreeNode : function(idx, title, pageType) {
|
|
|
|
var i;
|
|
|
|
var node = document.createElement('li');
|
|
|
|
node.id = 'record-' + idx;
|
|
|
|
node.className = pageType;
|
|
|
|
|
|
|
|
var aTag = document.createElement('a');
|
|
|
|
aTag.href = SiteTreeHandlers.showRecord_url + idx;
|
2007-09-14 21:42:24 +02:00
|
|
|
aTag.title = 'Page type: ' + pageType;
|
2007-07-19 12:40:05 +02:00
|
|
|
aTag.innerHTML = title;
|
|
|
|
node.appendChild(aTag);
|
|
|
|
|
|
|
|
SiteTreeNode.create(node, this.options);
|
|
|
|
|
|
|
|
return node;
|
|
|
|
},
|
|
|
|
|
|
|
|
setNodeIdx : function(idx, newIdx) {
|
|
|
|
this.performOnTreeNode(idx, function(treeNode) {
|
|
|
|
treeNode.id = 'record-' + newIdx;
|
|
|
|
var aTag = treeNode.getElementsByTagName('a')[0];
|
|
|
|
aTag.href = aTag.href.replace(idx, newIdx);
|
|
|
|
});
|
|
|
|
|
|
|
|
var treeNode = this.getTreeNodeByIdx(idx);
|
|
|
|
},
|
|
|
|
|
|
|
|
setNodeTitle : function(idx, title) {
|
|
|
|
this.performOnTreeNode(idx, function(treeNode) {
|
|
|
|
var aTag = treeNode.getElementsByTagName('a')[0];
|
|
|
|
aTag.innerHTML = title;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-11-21 03:38:56 +01:00
|
|
|
setNodeIcon: function(idx, newClassName) {
|
2007-07-19 12:40:05 +02:00
|
|
|
this.performOnTreeNode(idx, function(treeNode) {
|
2009-11-21 03:38:56 +01:00
|
|
|
treeNode.className = treeNode.className.replace(/(class-)[^\s]*/,'$1' + newClassName);
|
2007-07-19 12:40:05 +02:00
|
|
|
treeNode.aSpan.className = 'a ' + treeNode.className.replace('closed','spanClosed');
|
2007-09-14 21:42:24 +02:00
|
|
|
var aTag = treeNode.getElementsByTagName('a')[0];
|
|
|
|
aTag.title = 'Page type: ' + newClassName;
|
2007-07-19 12:40:05 +02:00
|
|
|
treeNode.setIconByClass();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2009-05-04 03:27:35 +02:00
|
|
|
/**
|
|
|
|
* Set the parent ID of a tree node
|
|
|
|
*/
|
|
|
|
setNodeParentID: function (idx, parentID) {
|
|
|
|
var treeNode = this.getTreeNodeByIdx(idx);
|
|
|
|
var parentNode = this.getTreeNodeByIdx(parentID);
|
2009-11-21 03:38:56 +01:00
|
|
|
var currentParentNode = jQuery(treeNode).parents('li')[0];
|
|
|
|
// Only change parent node if its different than the current,
|
|
|
|
// otherwise we affect the sort order unnecessarily due to
|
|
|
|
// appendTreeNode() not looking at existing sorts
|
|
|
|
if(!currentParentNode || parentNode != currentParentNode) parentNode.appendTreeNode(treeNode);
|
2009-05-04 03:27:35 +02:00
|
|
|
},
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
setCurrentByIdx : function(idx) {
|
|
|
|
if(this.selected) {
|
|
|
|
var i,item;
|
|
|
|
for(i=0;item=this.selected[i];i++) {
|
|
|
|
item.removeNodeClass('current');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__tree = this;
|
|
|
|
__tree.selected = [];
|
|
|
|
|
|
|
|
this.performOnTreeNode(idx, function(treeNode) {
|
|
|
|
__tree.selected.push(treeNode);
|
|
|
|
treeNode.expose();
|
|
|
|
treeNode.addNodeClass('current');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
changeCurrentTo : function(newNode) {
|
|
|
|
if(this.selected) {
|
|
|
|
var i,item;
|
|
|
|
for(i=0;item=this.selected[i];i++) {
|
|
|
|
item.removeNodeClass('current');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newNode.addNodeClass('current');
|
|
|
|
|
|
|
|
this.selected = [newNode];
|
|
|
|
newNode.expose();
|
|
|
|
},
|
|
|
|
|
|
|
|
firstSelected : function() {
|
|
|
|
if(this.selected) return this.selected[0];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extra methods for the tree node when used in the LHS of the CMS
|
|
|
|
*/
|
|
|
|
TreeNodeAPI = Class.create();
|
|
|
|
TreeNodeAPI.prototype = {
|
|
|
|
selectTreeNode : function() {
|
2009-11-21 04:14:22 +01:00
|
|
|
var url = jQuery(this).find('a').attr('href');
|
|
|
|
if(url && url != '#') {
|
2009-11-21 04:15:32 +01:00
|
|
|
jQuery('#sitetree').trigger('selectionchanged', {node: this});
|
2009-11-21 04:15:36 +01:00
|
|
|
// don't get page if either event was cancelled,
|
|
|
|
// or the tree is currently in a selectable state.
|
|
|
|
if($('sitetree').notify('SelectionChanged', this) && !jQuery(this.tree).hasClass('multiselect')) {
|
2009-11-21 04:14:14 +01:00
|
|
|
this.getPageFromServer();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2009-11-21 04:14:22 +01:00
|
|
|
} else {
|
|
|
|
jQuery('#Form_EditForm').concrete('ss').removeForm();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getPageFromServer : function() {
|
2009-11-21 03:39:08 +01:00
|
|
|
var self = this;
|
2009-11-21 04:15:32 +01:00
|
|
|
var xmlhttp = jQuery('#Form_EditForm').concrete('ss').loadForm(
|
2009-11-21 03:37:45 +01:00
|
|
|
jQuery(this).find('a').attr('href'),
|
|
|
|
function(response) {
|
2009-11-21 03:39:08 +01:00
|
|
|
self.removeNodeClass('loading');
|
|
|
|
|
2009-11-21 03:37:45 +01:00
|
|
|
var pageID = jQuery(this).find(':input[name=ID]').val();
|
2010-02-22 20:49:51 +01:00
|
|
|
jQuery('#sitetree')[0].setCurrentByIdx(pageID);
|
2009-11-21 03:37:45 +01:00
|
|
|
}
|
|
|
|
);
|
2009-11-21 04:14:14 +01:00
|
|
|
|
|
|
|
if(xmlhttp) this.addNodeClass('loading');
|
2007-07-19 12:40:05 +02:00
|
|
|
},
|
|
|
|
ajaxExpansion : function() {
|
|
|
|
this.addNodeClass('loading');
|
|
|
|
var ul = this.treeNodeHolder(false);
|
|
|
|
ul.innerHTML = 'loading...';
|
|
|
|
|
|
|
|
// Any attempts to add children to this page should, in fact, cue them up for insertion later
|
|
|
|
ul.cuedNewNodes = [];
|
|
|
|
ul.appendTreeNode = function(node) {
|
|
|
|
this.cuedNewNodes[this.cuedNewNodes.length] = node;
|
|
|
|
}
|
|
|
|
|
2009-05-14 08:11:18 +02:00
|
|
|
var args = {ajax:1, ID:this.getIdx()};
|
2009-07-09 07:36:47 +02:00
|
|
|
|
|
|
|
// Add current locale for any subtree selection
|
2009-05-29 01:10:57 +02:00
|
|
|
if ($('LangSelector')) args.locale = $('LangSelector').value;
|
2009-05-14 08:11:18 +02:00
|
|
|
|
2009-07-09 07:36:47 +02:00
|
|
|
// If the tree is selectable, we have to show all available children without
|
|
|
|
// artificial limitations from the serverside (minNodeCount). This is a measure
|
|
|
|
// to ensure no unexpanded nodes are missed in batch selection
|
|
|
|
if(Element.hasClassName('sitetree', 'multiselect')) args.minNodeCount = 0;
|
|
|
|
|
2009-05-14 08:11:18 +02:00
|
|
|
url = this.tree.url(args);
|
|
|
|
|
2009-01-05 07:17:59 +01:00
|
|
|
new Ajax.Request(url, {
|
2007-07-19 12:40:05 +02:00
|
|
|
onSuccess : this.installSubtree.bind(this),
|
|
|
|
onFailure : this.showSubtreeLoadingError
|
|
|
|
});
|
|
|
|
},
|
|
|
|
showSubtreeLoadingError: function(response) {
|
|
|
|
errorMessage('error loading subtree', response);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context menu
|
|
|
|
*/
|
|
|
|
oncontextmenu: function(event) {
|
|
|
|
if(TreeContextMenu) {
|
|
|
|
if(!event) event = window.event;
|
|
|
|
createContextMenu(event, this, TreeContextMenu);
|
|
|
|
Event.stop(event);
|
|
|
|
return false;
|
|
|
|
}
|
2007-09-15 23:56:40 +02:00
|
|
|
},
|
|
|
|
duplicatePage: function() {
|
2008-02-25 03:10:37 +01:00
|
|
|
// Pass the parent ID to the duplicator, which helps ensure that multi-parent pages are duplicated into the node that the user clicked
|
|
|
|
var parentClause = "";
|
|
|
|
if(this.parentTreeNode && this.parentTreeNode.getIdx) {
|
|
|
|
parentClause = "&parentID=" + this.parentTreeNode.getIdx();
|
|
|
|
}
|
|
|
|
|
2009-11-21 03:37:51 +01:00
|
|
|
new Ajax.Request(jQuery('base').attr('href') + 'admin/duplicate/' + this.getIdx() + '?ajax=1' + parentClause, {
|
2008-02-25 03:10:37 +01:00
|
|
|
method : 'get',
|
|
|
|
onSuccess : Ajax.Evaluator,
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Error: ', response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
duplicatePageWithChildren: function() {
|
2009-11-21 03:37:51 +01:00
|
|
|
new Ajax.Request(jQuery('base').attr('href') + 'admin/duplicatewithchildren/' + this.getIdx() + '?ajax=1', {
|
2008-01-24 01:01:52 +01:00
|
|
|
method : 'get',
|
|
|
|
onSuccess : Ajax.Evaluator,
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Error: ', response);
|
|
|
|
}
|
|
|
|
});
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* In the case of Tree & DraggableTree, the root tree and the sub-trees all use the same class.
|
|
|
|
* In this case, however, SiteTree has a much bigger API and so SiteSubTree is smaller.
|
|
|
|
*/
|
|
|
|
SiteSubTree = Class.extend('Tree').extend('TreeAPI');
|
|
|
|
SiteSubTree.prototype = {
|
|
|
|
castAsTreeNode: function(li) {
|
|
|
|
behaveAs(li, SiteTreeNode, this.options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Our SiteTree class extends the tree object with a richer manipulation API.
|
|
|
|
* The server will send a piece javascript that uses these functions. In this way, the server
|
|
|
|
* has flexibility over its operation, but the Script->HTML interface is kept client-side.
|
|
|
|
*/
|
|
|
|
SiteTree = Class.extend('SiteSubTree');
|
|
|
|
SiteTree.prototype = {
|
|
|
|
initialize : function() {
|
|
|
|
this.Tree.initialize();
|
|
|
|
|
|
|
|
/*
|
|
|
|
if(!this.tree.selected) this.tree.selected = [];
|
|
|
|
var els = this.getElementsByTagName('li');
|
|
|
|
for(var i=0;i<els.length;i++) if(els[i].className.indexOf('current') > -1) {
|
|
|
|
this.tree.selected.push(els[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
this.observeMethod('SelectionChanged', this.interruptLoading.bind(this) );
|
2009-11-21 03:39:12 +01:00
|
|
|
|
|
|
|
jQuery('#Form_EditForm').bind('loadnewpage', this.onLoadNewPage.bind(this));
|
2007-07-19 12:40:05 +02:00
|
|
|
},
|
|
|
|
destroy: function () {
|
|
|
|
if(this.Tree) this.Tree.destroy();
|
|
|
|
this.Tree = null;
|
|
|
|
this.SiteSubTree = null;
|
|
|
|
this.TreeAPI = null;
|
|
|
|
this.selected = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the currently loading node from loading.
|
|
|
|
*/
|
|
|
|
interruptLoading: function( newLoadingNode ) {
|
|
|
|
if( this.loadingNode ) this.loadingNode.removeNodeClass('loading');
|
|
|
|
this.loadingNode = newLoadingNode;
|
2009-11-21 03:39:12 +01:00
|
|
|
},
|
|
|
|
|
2009-11-21 04:15:32 +01:00
|
|
|
/**
|
|
|
|
* Assumes to be triggered by a form element with the following input fields:
|
|
|
|
* ID, ParentID, TreeTitle (or Title), ClassName
|
|
|
|
*/
|
2009-11-21 03:39:12 +01:00
|
|
|
onLoadNewPage: function(e, eventData) {
|
|
|
|
// finds a certain value in an array generated by jQuery.serializeArray()
|
|
|
|
var findInSerializedArray = function(arr, name) {
|
|
|
|
for(var i=0; i<arr.length; i++) {
|
|
|
|
if(arr[i].name == name) return arr[i].value;
|
|
|
|
};
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
var id = jQuery(e.target.ID).val();
|
|
|
|
|
|
|
|
// check if a form with a valid ID exists
|
|
|
|
if(id) {
|
|
|
|
var parentID = jQuery(e.target.ParentID).val();
|
|
|
|
|
|
|
|
// set title (either from TreeTitle or from Title fields)
|
|
|
|
// Treetitle has special HTML formatting to denote the status changes.
|
|
|
|
var title = jQuery((e.target.TreeTitle) ? e.target.TreeTitle : e.target.Title).val();
|
|
|
|
if(title) this.setNodeTitle(id, title);
|
|
|
|
|
|
|
|
// update icon (only if it has changed)
|
|
|
|
var className = jQuery(e.target.ClassName).val();
|
|
|
|
if(className) this.setNodeIcon(id, className);
|
|
|
|
|
2009-11-21 04:15:32 +01:00
|
|
|
// check if node exists, might have been created instead
|
|
|
|
if(!this.getTreeNodeByIdx(id)) {
|
|
|
|
var newNode = $('sitetree').createTreeNode(id, title, className);
|
|
|
|
var parentNode = $('sitetree').getTreeNodeByIdx(parentID);
|
|
|
|
if(parentNode) parentNode.appendTreeNode(newNode);
|
|
|
|
//newNode.selectTreeNode();
|
|
|
|
}
|
|
|
|
|
|
|
|
// set correct parent (only if it has changed)
|
|
|
|
if(parentID) this.setNodeParentID(id, jQuery(e.target.ParentID).val());
|
|
|
|
|
|
|
|
// set current tree element
|
|
|
|
this.setCurrentByIdx(id);
|
2009-11-21 03:39:12 +01:00
|
|
|
} else {
|
2009-11-21 03:39:22 +01:00
|
|
|
if(typeof eventData.origData != 'undefined') {
|
|
|
|
var node = this.getTreeNodeByIdx(eventData.origData.ID);
|
|
|
|
if(node && node.parentTreeNode) node.parentTreeNode.removeTreeNode(node);
|
|
|
|
}
|
2009-11-21 03:39:12 +01:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SiteTreeNode = Class.extend('TreeNode').extend('TreeNodeAPI');
|
|
|
|
SiteTreeNode.prototype = {
|
|
|
|
initialize: function(options) {
|
|
|
|
this.TreeNode.initialize(options);
|
|
|
|
|
|
|
|
if(this.className && this.className.match(/ *([^ ]+)( +|$)/)) {
|
|
|
|
if((typeof siteTreeHints != 'undefined') && siteTreeHints[ RegExp.$1 ]) {
|
|
|
|
this.hints = siteTreeHints[ RegExp.$1 ];
|
|
|
|
this.dropperOptions = {
|
|
|
|
accept : (this.hints.allowedChildren && (this.className.indexOf('nochildren') == -1))
|
|
|
|
? this.hints.allowedChildren : 'none'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.className.indexOf('current') > -1) {
|
|
|
|
if(!this.tree.selected) this.tree.selected = [];
|
|
|
|
this.tree.selected.push(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!this.hints) this.hints = {}
|
|
|
|
},
|
|
|
|
|
|
|
|
destroy: function () {
|
|
|
|
if(this.TreeNode) this.TreeNode.destroy();
|
|
|
|
this.TreeNode = null;
|
|
|
|
this.TreeNodeAPI = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
castAsTree: function(childUL) {
|
|
|
|
behaveAs(childUL, SiteSubTree, this.options);
|
|
|
|
if(this.draggableObj) childUL.makeDraggable();
|
|
|
|
},
|
|
|
|
|
|
|
|
onselect: function() {
|
|
|
|
this.selectTreeNode();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drag'n'drop handlers - Ajax saving
|
|
|
|
*/
|
|
|
|
onParentChanged : function(node, oldParent, newParent) {
|
2009-11-21 04:16:30 +01:00
|
|
|
var self = this;
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
if(newParent.id.match(/^record-new/)) {
|
|
|
|
alert("You must save the page before dragging children into it");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( node == newParent || node.getIdx() == newParent.getIdx() ) {
|
|
|
|
alert("You cannot add a page to itself");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(node.innerHTML.toLowerCase().indexOf('<del') > -1) {
|
|
|
|
alert("You can't moved deleted pages");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Element.hasClassName( newParent, 'nochildren' ) ) {
|
|
|
|
alert("You can't add children to that node");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-11-21 04:16:30 +01:00
|
|
|
jQuery.post(
|
|
|
|
SiteTreeHandlers.parentChanged_url,
|
|
|
|
'ID=' + node.getIdx() + '&ParentID=' + newParent.getIdx(),
|
|
|
|
function(data, status) {
|
|
|
|
// TODO This should use a more common serialization in a new tree library
|
|
|
|
if(data.modified) {
|
|
|
|
for(var id in data.modified) {
|
|
|
|
self.tree.setNodeTitle(id, data.modified[id]['TreeTitle']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if current page still exists, and refresh it.
|
|
|
|
// Otherwise remove the current form
|
|
|
|
var selectedNode = self.tree.firstSelected();
|
|
|
|
if(selectedNode) {
|
|
|
|
var selectedNodeId = self.tree.getIdxOf(selectedNode);
|
|
|
|
if(data.modified[selectedNode.getIdx()]) {
|
|
|
|
// only if the current page was modified
|
|
|
|
selectedNode.selectTreeNode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'json'
|
|
|
|
);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the tree has been resorted
|
|
|
|
* nodeList is a list of all the nodes in the correct rder
|
|
|
|
* movedNode is the node that actually got moved to trigger this resorting
|
|
|
|
*/
|
|
|
|
onOrderChanged : function(nodeList, movedNode) {
|
2009-11-21 04:16:30 +01:00
|
|
|
var self = this;
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
var i, parts = Array();
|
|
|
|
sort = 0;
|
|
|
|
|
|
|
|
for(i=0;i<nodeList.length;i++) {
|
|
|
|
if(nodeList[i].getIdx && nodeList[i].getIdx()) {
|
|
|
|
parts[parts.length] = 'ID[]=' + nodeList[i].getIdx();
|
|
|
|
|
|
|
|
// Ensure that the order of new records is preserved when they are moved THEN saved
|
2009-11-21 04:16:30 +01:00
|
|
|
if(
|
|
|
|
nodeList[i].id.indexOf("record-new") == 0
|
|
|
|
&& $('Form_EditForm_ID')
|
|
|
|
&& ('record-' + $('Form_EditForm_ID').value == nodeList[i].id)
|
|
|
|
&& $('Form_EditForm_Sort')
|
|
|
|
) {
|
|
|
|
$('Form_EditForm_Sort').value = ++sort
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(movedNode.getIdx && movedNode.getIdx()) {
|
|
|
|
parts[parts.length] = 'MovedNodeID=' + movedNode.getIdx();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parts) {
|
2009-11-21 04:16:30 +01:00
|
|
|
jQuery.post(
|
|
|
|
SiteTreeHandlers.orderChanged_url,
|
|
|
|
parts.join('&'),
|
|
|
|
function(data, status) {
|
|
|
|
// TODO This should use a more common serialization in a new tree library
|
|
|
|
if(data.modified) {
|
|
|
|
for(var id in data.modified) {
|
|
|
|
self.tree.setNodeTitle(id, data.modified[id]['TreeTitle']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if current page still exists, and refresh it.
|
|
|
|
// Otherwise remove the current form
|
|
|
|
var selectedNode = self.tree.firstSelected();
|
|
|
|
if(selectedNode) {
|
|
|
|
var selectedNodeId = self.tree.getIdxOf(selectedNode);
|
|
|
|
if(data.modified[selectedNode.getIdx()]) {
|
|
|
|
// only if the current page was modified
|
|
|
|
selectedNode.selectTreeNode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'json'
|
|
|
|
);
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the site tree
|
|
|
|
SiteTree.applyTo('#sitetree');
|
|
|
|
|
|
|
|
/**
|
2007-09-16 17:00:08 +02:00
|
|
|
* Reorganise action checkbox
|
2007-07-19 12:40:05 +02:00
|
|
|
*/
|
|
|
|
ReorganiseAction = Class.create();
|
|
|
|
ReorganiseAction.applyTo('#sortitems');
|
|
|
|
ReorganiseAction.prototype = {
|
|
|
|
initialize: function () {
|
|
|
|
},
|
|
|
|
|
|
|
|
onclick : function() {
|
2008-02-25 03:10:37 +01:00
|
|
|
if ($('sitetree').isDraggable == false) {
|
2007-07-19 12:40:05 +02:00
|
|
|
$('sitetree').makeDraggable();
|
2007-09-16 17:00:08 +02:00
|
|
|
} else {
|
|
|
|
$('sitetree').stopBeingDraggable();
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-11-21 04:14:28 +01:00
|
|
|
|
|
|
|
var _CURRENT_CONTEXT_MENU = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new context menu
|
|
|
|
* @param event The event object
|
|
|
|
* @param owner The DOM element that this context-menu was requested from
|
|
|
|
* @param menuItems A map of title -> method; context-menu operations to get called
|
|
|
|
*/
|
|
|
|
function createContextMenu(event, owner, menuItems) {
|
|
|
|
if(_CURRENT_CONTEXT_MENU) {
|
|
|
|
document.body.removeChild(_CURRENT_CONTEXT_MENU);
|
|
|
|
_CURRENT_CONTEXT_MENU = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var menu = document.createElement("ul");
|
|
|
|
menu.className = 'contextMenu';
|
|
|
|
menu.style.position = 'absolute';
|
|
|
|
menu.style.left = event.clientX + 'px';
|
|
|
|
menu.style.top = event.clientY + 'px';
|
|
|
|
|
|
|
|
var menuItemName, menuItemTag, menuATag;
|
|
|
|
for(menuItemName in menuItems) {
|
|
|
|
menuItemTag = document.createElement("li");
|
|
|
|
|
|
|
|
menuATag = document.createElement("a");
|
|
|
|
menuATag.href = "#";
|
|
|
|
menuATag.onclick = menuATag.oncontextmenu = contextmenu_onclick;
|
|
|
|
menuATag.innerHTML = menuItemName;
|
|
|
|
menuATag.handler = menuItems[menuItemName];
|
|
|
|
menuATag.owner = owner;
|
|
|
|
|
|
|
|
menuItemTag.appendChild(menuATag);
|
|
|
|
menu.appendChild(menuItemTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.appendChild(menu);
|
|
|
|
|
|
|
|
document.body.onclick = contextmenu_close;
|
|
|
|
|
|
|
|
_CURRENT_CONTEXT_MENU = menu;
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextmenu_close() {
|
|
|
|
if(_CURRENT_CONTEXT_MENU) {
|
|
|
|
document.body.removeChild(_CURRENT_CONTEXT_MENU);
|
|
|
|
_CURRENT_CONTEXT_MENU = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function contextmenu_onclick() {
|
|
|
|
this.handler(this.owner);
|
|
|
|
contextmenu_close();
|
|
|
|
return false;
|
|
|
|
}
|