2007-07-19 12:40:05 +02:00
|
|
|
if(typeof SiteTreeHandlers == 'undefined') SiteTreeHandlers = {};
|
|
|
|
SiteTreeHandlers.parentChanged_url = 'admin/ajaxupdateparent';
|
|
|
|
SiteTreeHandlers.orderChanged_url = 'admin/ajaxupdatesort';
|
|
|
|
SiteTreeHandlers.loadPage_url = 'admin/getitem';
|
|
|
|
SiteTreeHandlers.loadTree_url = 'admin/getsubtree';
|
|
|
|
|
|
|
|
_NEW_PAGES = new Array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add page action
|
|
|
|
*/
|
|
|
|
addpage = Class.create();
|
|
|
|
addpage.applyTo('#addpage');
|
|
|
|
addpage.prototype = {
|
|
|
|
initialize: function () {
|
|
|
|
Observable.applyTo($(_HANDLER_FORMS[this.id]));
|
2007-09-15 02:54:13 +02:00
|
|
|
this.getElementsByTagName('button')[0].onclick = returnFalse;
|
2007-07-19 12:40:05 +02:00
|
|
|
$(_HANDLER_FORMS[this.id]).onsubmit = this.form_submit;
|
|
|
|
},
|
|
|
|
|
|
|
|
onclick : function() {
|
|
|
|
if(treeactions.toggleSelection(this)) {
|
|
|
|
var selectedNode = $('sitetree').firstSelected();
|
|
|
|
if(selectedNode) {
|
|
|
|
while(selectedNode.parentTreeNode && !selectedNode.hints.defaultChild) {
|
|
|
|
$('sitetree').changeCurrentTo(selectedNode.parentTreeNode);
|
|
|
|
selectedNode = selectedNode.parentTreeNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( selectedNode.hints && selectedNode.hints.defaultChild )
|
|
|
|
$(_HANDLER_FORMS.addpage).elements.PageType.value = selectedNode.hints.defaultChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.o1 = $('sitetree').observeMethod('SelectionChanged', this.treeSelectionChanged.bind(this));
|
|
|
|
this.o2 = $(_HANDLER_FORMS[this.id]).observeMethod('Close', this.popupClosed.bind(this));
|
|
|
|
|
|
|
|
$(_HANDLER_FORMS[this.id]).elements.PageType.onchange = this.typeDropdown_change;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
treeSelectionChanged : function(selectedNode) {
|
|
|
|
$(_HANDLER_FORMS.addpage).elements.PageType.value = selectedNode.hints.defaultChild;
|
|
|
|
},
|
|
|
|
|
|
|
|
popupClosed : function() {
|
|
|
|
$('sitetree').stopObserving(this.o1);
|
|
|
|
$(_HANDLER_FORMS.addpage).stopObserving(this.o2);
|
|
|
|
},
|
|
|
|
|
|
|
|
typeDropdown_change : function() {
|
|
|
|
// Don't do anything if we're already on an appropriate node
|
|
|
|
var sel = $('sitetree').firstSelected();
|
|
|
|
if(sel && sel.hints && sel.hints.allowedChildren) {
|
|
|
|
var allowed = sel.hints.allowedChildren;
|
|
|
|
for(i=0;i<allowed.length;i++) if(allowed[i] == this.value) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( typeof siteTreeHints == 'undefined' )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Otherwise move to the default parent for that.
|
|
|
|
if( siteTreeHints && siteTreeHints[this.value] ) {
|
|
|
|
var newNode = $('sitetree').getTreeNodeByIdx(siteTreeHints[this.value].defaultParent);
|
|
|
|
if(newNode) $('sitetree').changeCurrentTo(newNode);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
form_submit : function() {
|
|
|
|
var st = $('sitetree');
|
|
|
|
var parentID = st.getIdxOf(st.firstSelected());
|
2007-09-16 17:05:25 +02:00
|
|
|
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
2007-07-19 12:40:05 +02:00
|
|
|
if(parentID && parentID.substr(0,3) == 'new') {
|
|
|
|
alert("You have to save a page before adding children underneath it");
|
|
|
|
|
|
|
|
} else if( Element.hasClassName( st.firstSelected(), "nochildren" ) ) {
|
|
|
|
alert("You can't add children to the selected node" );
|
|
|
|
} else {
|
|
|
|
$(_HANDLER_FORMS.addpage).elements.ParentID.value = parentID ? parentID : 0;
|
|
|
|
|
|
|
|
if( !_NEW_PAGES[parentID] )
|
|
|
|
_NEW_PAGES[parentID] = 1;
|
|
|
|
|
|
|
|
var suffix = _NEW_PAGES[parentID]++;
|
|
|
|
Ajax.SubmitForm(_HANDLER_FORMS.addpage, "action_addpage", {
|
|
|
|
onSuccess : Ajax.Evaluator,
|
|
|
|
onFailure : this.showAddPageError,
|
|
|
|
extraData: '&Suffix=' + suffix
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
showAddPageError: function(response) {
|
|
|
|
errorMessage('Error adding page', response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 17:19:17 +02:00
|
|
|
/**
|
|
|
|
* Search button click action
|
|
|
|
*/
|
|
|
|
search = Class.create();
|
|
|
|
search.applyTo('#search');
|
|
|
|
search.prototype = {
|
|
|
|
initialize : function() {
|
|
|
|
Observable.applyTo($(_HANDLER_FORMS.search));
|
|
|
|
},
|
|
|
|
onclick : function() {
|
|
|
|
if(treeactions.toggleSelection(this)) {
|
|
|
|
this.o2 = $(_HANDLER_FORMS[this.id]).observeMethod('Close', this.popupClosed.bind(this));
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
popupClosed : function() {
|
|
|
|
$(_HANDLER_FORMS.search).stopObserving(this.o2);
|
2007-09-16 17:20:02 +02:00
|
|
|
batchActionGlobals.unfilterSiteTree();
|
2007-09-16 17:19:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add Criteria Drop-down onchange action which allows more criteria to be shown
|
|
|
|
*/
|
|
|
|
SiteTreeFilterAddCriteria = Class.create();
|
|
|
|
SiteTreeFilterAddCriteria.applyTo('#SiteTreeFilterAddCriteria');
|
|
|
|
SiteTreeFilterAddCriteria.prototype = {
|
|
|
|
onchange : function() {
|
|
|
|
Element.show('Text' + this.value);
|
|
|
|
Element.show('Input' + this.value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
/**
|
2007-09-16 17:04:09 +02:00
|
|
|
* Batch Actions button click action
|
2007-07-19 12:40:05 +02:00
|
|
|
*/
|
2007-09-16 17:04:09 +02:00
|
|
|
batchactions = Class.create();
|
|
|
|
batchactions.applyTo('#batchactions');
|
|
|
|
batchactions.prototype = {
|
|
|
|
|
|
|
|
initialize : function() {
|
|
|
|
Observable.applyTo($(_HANDLER_FORMS.batchactions));
|
|
|
|
},
|
|
|
|
onclick : function() {
|
2007-07-19 12:40:05 +02:00
|
|
|
if(treeactions.toggleSelection(this)) {
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.o1 = $('sitetree').observeMethod('SelectionChanged', batchActionGlobals.treeSelectionChanged);
|
|
|
|
batchActionGlobals.o2 = $(_HANDLER_FORMS.batchactions).observeMethod('Close', batchActionGlobals.popupClosed);
|
2007-07-19 12:40:05 +02:00
|
|
|
addClass($('sitetree'),'multiselect');
|
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.selectedNodes = { };
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
var sel = $('sitetree').firstSelected();
|
|
|
|
if(sel && sel.className.indexOf('nodelete') == -1) {
|
|
|
|
var selIdx = $('sitetree').getIdxOf(sel);
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.selectedNodes[selIdx] = true;
|
2007-07-19 12:40:05 +02:00
|
|
|
sel.removeNodeClass('current');
|
|
|
|
sel.addNodeClass('selected');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2007-09-16 17:04:09 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:20:02 +02:00
|
|
|
/**
|
|
|
|
* Show only drafts checkbox click action
|
|
|
|
*/
|
|
|
|
showonlydrafts = Class.create();
|
|
|
|
showonlydrafts.applyTo('#publishpage_show_drafts');
|
|
|
|
showonlydrafts.prototype = {
|
|
|
|
onclick : function() {
|
|
|
|
if (0 == $('SiteTreeIsFiltered').value) {
|
|
|
|
// Show all items in Site Tree again
|
|
|
|
new Ajax.Request( 'admin/filterSiteTree?Status=Saved&ajax=1', {
|
|
|
|
onSuccess: function( response ) {
|
|
|
|
$('sitetree_ul').innerHTML = response.responseText;
|
|
|
|
Behaviour.apply();
|
|
|
|
$('SiteTreeIsFiltered').value = 1;
|
|
|
|
statusMessage('Filtered tree to only show changed pages','good');
|
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Could not filter tree to only show changed pages<br />' + response.responseText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
batchActionGlobals.unfilterSiteTree();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
// batchActionGlobals is needed because calls to observeMethod doesn't seem to preserve instance variables so a Prototype can't be used
|
|
|
|
batchActionGlobals = {
|
|
|
|
selectedNodes: { },
|
|
|
|
// count Int - The number of nodes selected
|
|
|
|
count: { },
|
|
|
|
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
|
|
|
newNodes: { },
|
2007-07-19 12:40:05 +02:00
|
|
|
treeSelectionChanged : function(selectedNode) {
|
|
|
|
var idx = $('sitetree').getIdxOf(selectedNode);
|
|
|
|
|
|
|
|
if(selectedNode.className.indexOf('nodelete') == -1) {
|
|
|
|
if(selectedNode.selected) {
|
|
|
|
selectedNode.removeNodeClass('selected');
|
|
|
|
selectedNode.selected = false;
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.selectedNodes[idx] = false;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
selectedNode.addNodeClass('selected');
|
|
|
|
selectedNode.selected = true;
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.selectedNodes[idx] = true;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
popupClosed : function() {
|
|
|
|
removeClass($('sitetree'),'multiselect');
|
2007-09-16 17:04:09 +02:00
|
|
|
$('sitetree').stopObserving(batchActionGlobals.o1);
|
|
|
|
$(_HANDLER_FORMS.batchactions).stopObserving(batchActionGlobals.o2);
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
for(var idx in batchActionGlobals.selectedNodes) {
|
|
|
|
if(batchActionGlobals.selectedNodes[idx]) {
|
2007-07-19 12:40:05 +02:00
|
|
|
node = $('sitetree').getTreeNodeByIdx(idx);
|
|
|
|
if(node) {
|
|
|
|
node.removeNodeClass('selected');
|
|
|
|
node.selected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.selectedNodes = { };
|
2007-07-19 12:40:05 +02:00
|
|
|
},
|
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
getCsvIds : function() {
|
|
|
|
var csvIDs = "";
|
|
|
|
batchActionGlobals.count = 0;
|
2007-07-19 12:40:05 +02:00
|
|
|
var st = $('sitetree');
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.newNodes = new Array();
|
|
|
|
for(var idx in batchActionGlobals.selectedNodes) {
|
|
|
|
if(batchActionGlobals.selectedNodes[idx]) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
// Delete/Publish new nodes? (Leftover from delete code?) TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
2007-07-19 12:40:05 +02:00
|
|
|
if( idx.match(/^new-[a-z0-9A-Z\-]+$/) ) {
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.newNodes.push( idx );
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
2007-09-16 17:04:09 +02:00
|
|
|
var i, item, childrenTopublish = st.getTreeNodeByIdx(idx).getElementsByTagName('li');
|
|
|
|
for(i=0;item=childrenTopublish[i];i++) {
|
|
|
|
csvIDs += (csvIDs ? "," : "") + st.getIdxOf(childrenTopublish[i]);
|
|
|
|
batchActionGlobals.count++;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
csvIDs += (csvIDs ? "," : "") + idx;
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.count++;
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-16 17:04:09 +02:00
|
|
|
return csvIDs;
|
2007-09-16 17:20:02 +02:00
|
|
|
},
|
|
|
|
unfilterSiteTree : function() {
|
|
|
|
// Reload the site tree if it has been filtered
|
|
|
|
if ($('SiteTreeIsFiltered').value == 1) {
|
|
|
|
// Show all items in Site Tree again
|
|
|
|
new Ajax.Request( 'admin/SiteTreeAsUL' + '&ajax=1', {
|
|
|
|
onSuccess: function( response ) {
|
|
|
|
$('sitetree_ul').innerHTML = response.responseText;
|
|
|
|
Behaviour.apply();
|
|
|
|
$('SiteTreeIsFiltered').value = 0;
|
|
|
|
statusMessage('Unfiltered tree','good');
|
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Could not unfilter site tree<br />' + response.responseText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2007-09-16 17:04:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Publish selected pages action
|
|
|
|
*/
|
|
|
|
publishpage = Class.create();
|
|
|
|
publishpage.applyTo('#publishpage_options');
|
|
|
|
publishpage.prototype = {
|
|
|
|
onsubmit : function() {
|
|
|
|
csvIDs = batchActionGlobals.getCsvIds();
|
|
|
|
if(csvIDs) {
|
|
|
|
this.elements.csvIDs.value = csvIDs;
|
|
|
|
|
|
|
|
statusMessage('Publishing pages...');
|
|
|
|
|
|
|
|
// Put an AJAXY loading icon on the button
|
|
|
|
$('action_publish_selected').className = 'loading';
|
|
|
|
Ajax.SubmitForm(this, null, {
|
|
|
|
onSuccess : function(response) {
|
|
|
|
Ajax.Evaluator(response);
|
|
|
|
$('action_publish_selected').className = '';
|
|
|
|
treeactions.closeSelection($('batchactions'));
|
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Error publishing pages', response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
alert("Please select at least 1 page.");
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete selected pages action
|
|
|
|
*/
|
|
|
|
deletepage = Class.create();
|
|
|
|
deletepage.applyTo('#deletepage_options');
|
|
|
|
deletepage.prototype = {
|
|
|
|
onsubmit : function() {
|
|
|
|
csvIDs = batchActionGlobals.getCsvIds();
|
|
|
|
if(csvIDs || batchActionGlobals.newNodes.length > 0) {
|
|
|
|
batchActionGlobals.count += batchActionGlobals.newNodes.length;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
if(confirm("Do you really want to delete the " + batchActionGlobals.count + " marked pages?")) {
|
|
|
|
this.elements.csvIDs.value = csvIDs;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
statusMessage('Deleting pages...');
|
|
|
|
// TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
|
|
|
for( var idx = 0; idx < batchActionGlobals.newNodes.length; idx++ ) {
|
|
|
|
var newNode = $('sitetree').getTreeNodeByIdx( batchActionGlobals.newNodes[idx] );
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
if( newNode.parentTreeNode )
|
|
|
|
newNode.parentTreeNode.removeTreeNode( newNode );
|
|
|
|
else
|
|
|
|
alert( newNode.id + ' has no parent node');
|
|
|
|
|
|
|
|
$('Form_EditForm').reloadIfSetTo(idx);
|
|
|
|
}
|
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.newNodes = new Array();
|
|
|
|
// Put an AJAXY loading icon on the button
|
|
|
|
$('action_delete_selected').className = 'loading';
|
|
|
|
Ajax.SubmitForm(this, null, {
|
|
|
|
onSuccess : function(response) {
|
|
|
|
Ajax.Evaluator(response);
|
|
|
|
$('action_delete_selected').className = '';
|
|
|
|
treeactions.closeSelection($('batchactions'));
|
|
|
|
},
|
2007-07-19 12:40:05 +02:00
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Error deleting pages', response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
alert("Please select at least 1 page.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tree context menu
|
|
|
|
*/
|
|
|
|
TreeContextMenu = {
|
|
|
|
'Edit this page' : function(treeNode) {
|
|
|
|
treeNode.selectTreeNode();
|
|
|
|
},
|
|
|
|
'Duplicate this page' : function(treeNode) {
|
2007-09-15 23:56:40 +02:00
|
|
|
// First save the page silently (without confirmation) and then duplicate the page.
|
|
|
|
autoSave(false, treeNode.duplicatePage.bind(treeNode));
|
2007-07-19 12:40:05 +02:00
|
|
|
},
|
|
|
|
'Sort sub-pages' : function(treeNode) {
|
|
|
|
var children = treeNode.treeNodeHolder().childTreeNodes();
|
|
|
|
var sortedChildren = children.sort(function(a, b) {
|
|
|
|
var titleA = a.aTag.innerHTML.replace(/<[^>]*>/g,'');
|
|
|
|
var titleB = b.aTag.innerHTML.replace(/<[^>]*>/g,'');
|
|
|
|
return titleA < titleB ? -1 : (titleA > titleB ? 1 : 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
var i,child;
|
|
|
|
for(i=0;child=sortedChildren[i];i++) {
|
|
|
|
treeNode.appendTreeNode(child);
|
|
|
|
}
|
|
|
|
|
2007-10-02 07:10:35 +02:00
|
|
|
treeNode.onOrderChanged(sortedChildren,treeNode);
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
};
|