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
|
|
|
|
*/
|
2009-11-27 02:42:24 +01:00
|
|
|
var addpageclass;
|
2008-11-13 05:24:02 +01:00
|
|
|
addpageclass = Class.create();
|
|
|
|
addpageclass.applyTo('#addpage');
|
|
|
|
addpageclass.prototype = {
|
2010-01-28 21:10:58 +01:00
|
|
|
originalValues: new Array(),
|
2007-07-19 12:40:05 +02:00
|
|
|
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;
|
2010-01-28 21:10:58 +01:00
|
|
|
|
|
|
|
// Save the original page types in to this object
|
|
|
|
if ($(_HANDLER_FORMS.addpage).elements.PageType) {
|
|
|
|
var options = $(_HANDLER_FORMS.addpage).elements.PageType.options;
|
|
|
|
for(var i = 0; i < options.length; i++) {
|
|
|
|
this.originalValues.push({
|
|
|
|
'value': options[i].value,
|
2010-01-28 23:29:47 +01:00
|
|
|
'label': options[i].innerHTML
|
2010-01-28 21:10:58 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var selectedNode = $('sitetree').firstSelected();
|
|
|
|
if(selectedNode) this.showApplicableChildrenPageTypes(selectedNode.hints);
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2010-01-28 21:10:58 +01:00
|
|
|
// Reset the page types dropdown to its original state
|
|
|
|
resetPageTypeOptions: function() {
|
|
|
|
var select = $(_HANDLER_FORMS.addpage).elements.PageType;
|
|
|
|
while (select.childNodes.length >= 1) { select.removeChild(select.firstChild); }
|
|
|
|
for(var i = 0; i < this.originalValues.length; i++) {
|
|
|
|
var option = document.createElement('option');
|
|
|
|
option.value = this.originalValues[i].value;
|
|
|
|
option.innerHTML = this.originalValues[i].label;
|
|
|
|
select.appendChild(option);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Hide the <option> elements in the new page <select> unless
|
|
|
|
// they are in the allowChildren array of the selected tree node
|
|
|
|
showApplicableChildrenPageTypes: function(hints) {
|
|
|
|
this.resetPageTypeOptions();
|
|
|
|
if (typeof hints.allowedChildren != 'undefined') {
|
|
|
|
var select = $(_HANDLER_FORMS.addpage).elements.PageType;
|
|
|
|
|
|
|
|
var toRemove = new Array();
|
|
|
|
for(var i = 0; i < select.options.length; i++) {
|
|
|
|
var itemFound = false;
|
|
|
|
for(var j = 0; j < hints.allowedChildren.length; j++) {
|
|
|
|
if (select.options[i].value == hints.allowedChildren[j]) { itemFound = true; break; }
|
|
|
|
}
|
|
|
|
if (!itemFound) toRemove.push(select.options[i]);
|
|
|
|
}
|
|
|
|
for(var i = 0; i < toRemove.length; i++) { select.removeChild(toRemove[i]); }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
treeSelectionChanged : function(selectedNode) {
|
2010-01-28 21:10:58 +01:00
|
|
|
this.showApplicableChildrenPageTypes(selectedNode.hints);
|
2007-07-19 12:40:05 +02:00
|
|
|
$(_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') {
|
2008-10-03 02:48:34 +02:00
|
|
|
alert(ss.i18n._t('CMSMAIN.WARNINGSAVEPAGESBEFOREADDING'));
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
} else if( Element.hasClassName( st.firstSelected(), "nochildren" ) ) {
|
2008-10-03 02:48:34 +02:00
|
|
|
alert(ss.i18n._t('CMSMAIN.CANTADDCHILDREN') );
|
2007-07-19 12:40:05 +02:00
|
|
|
} else {
|
|
|
|
$(_HANDLER_FORMS.addpage).elements.ParentID.value = parentID ? parentID : 0;
|
|
|
|
|
|
|
|
if( !_NEW_PAGES[parentID] )
|
|
|
|
_NEW_PAGES[parentID] = 1;
|
2010-02-04 05:39:58 +01:00
|
|
|
|
2007-07-19 12:40:05 +02:00
|
|
|
var suffix = _NEW_PAGES[parentID]++;
|
|
|
|
Ajax.SubmitForm(_HANDLER_FORMS.addpage, "action_addpage", {
|
|
|
|
onSuccess : Ajax.Evaluator,
|
2010-02-04 05:39:58 +01:00
|
|
|
onFailure : function(response) { if (response.status == 403) {
|
|
|
|
alert('You cannot add that page at that location.');
|
|
|
|
}},
|
2007-07-19 12:40:05 +02:00
|
|
|
extraData: '&Suffix=' + suffix
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2010-02-04 05:40:35 +01:00
|
|
|
}
|
2009-11-27 02:42:24 +01:00
|
|
|
};
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:19:17 +02:00
|
|
|
/**
|
|
|
|
* Search button click action
|
|
|
|
*/
|
2009-11-27 02:42:24 +01:00
|
|
|
var searchclass;
|
2008-11-13 05:24:02 +01:00
|
|
|
searchclass = Class.create();
|
|
|
|
searchclass.applyTo('#search');
|
|
|
|
searchclass.prototype = {
|
2007-09-16 17:19:17 +02:00
|
|
|
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
|
|
|
}
|
2010-01-13 00:49:00 +01:00
|
|
|
};
|
2007-09-16 17:19:17 +02:00
|
|
|
|
2009-11-27 02:42:24 +01:00
|
|
|
var SiteTreeFilter = Class.create();
|
2009-08-04 05:09:26 +02:00
|
|
|
SiteTreeFilter.applyTo('#siteTreeFilterList');
|
|
|
|
SiteTreeFilter.prototype = {
|
2009-05-01 00:47:28 +02:00
|
|
|
initialize: function () {
|
|
|
|
},
|
2010-02-04 05:40:29 +01:00
|
|
|
reapplyIfNeeded: function() {
|
|
|
|
if(this.options[this.selectedIndex].value != 'all') this.onchange();
|
|
|
|
},
|
2009-08-04 05:09:26 +02:00
|
|
|
onchange : function() {
|
|
|
|
var value = this.options[this.selectedIndex].value;
|
|
|
|
|
|
|
|
if(value != 'all') {
|
|
|
|
$('sitetree').setCustomURL(SiteTreeHandlers.controller_url+'/getfilteredsubtree?filter='+escape(value));
|
2009-05-01 00:47:28 +02:00
|
|
|
} else {
|
2009-05-14 08:11:18 +02:00
|
|
|
$('sitetree').clearCustomURL();
|
2009-05-01 00:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// We can't update the tree while it's draggable; it gets b0rked.
|
|
|
|
var __makeDraggableAfterUpdate = false;
|
|
|
|
if($('sitetree').isDraggable) {
|
|
|
|
$('sitetree').stopBeingDraggable();
|
|
|
|
__makeDraggableAfterUpdate = true;
|
|
|
|
}
|
2009-08-04 05:09:26 +02:00
|
|
|
|
|
|
|
var indicator = $('siteTreeFilterActionIndicator');
|
|
|
|
indicator.style.display = 'inline';
|
|
|
|
|
2009-05-14 08:11:18 +02:00
|
|
|
$('sitetree').reload({
|
|
|
|
onSuccess: function() {
|
2009-05-06 08:22:00 +02:00
|
|
|
indicator.style.display = 'none';
|
2009-08-04 05:09:26 +02:00
|
|
|
if(__makeDraggableAfterUpdate) $('sitetree').makeDraggable();
|
2010-01-13 01:05:48 +01:00
|
|
|
batchActionGlobals.refreshSelected();
|
2009-05-01 00:47:28 +02:00
|
|
|
},
|
|
|
|
onFailure: function(response) {
|
|
|
|
errorMessage('Could not update tree', response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-01-13 00:49:00 +01:00
|
|
|
};
|
2009-05-14 08:11:18 +02:00
|
|
|
/**
|
|
|
|
* Control the site tree filter
|
|
|
|
*/
|
2009-11-27 02:42:24 +01:00
|
|
|
var SiteTreeFilterForm = Class.create();
|
2009-05-14 08:11:18 +02:00
|
|
|
SiteTreeFilterForm.applyTo('form#search_options');
|
|
|
|
SiteTreeFilterForm.prototype = {
|
|
|
|
initialize: function() {
|
|
|
|
var self = this;
|
|
|
|
Form.getElements(this).each(function(el){
|
2009-05-21 07:08:44 +02:00
|
|
|
if (el.type == 'submit') el.onclick = function(){self.clicked = $F(this);};
|
2009-05-14 08:11:18 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onsubmit: function() {
|
|
|
|
var filters = $H();
|
|
|
|
|
2009-05-18 01:19:51 +02:00
|
|
|
if (this.clicked == 'Clear') {
|
|
|
|
Form.getElements(this).each(function(el){
|
|
|
|
if (el.type == 'text') el.value = '';
|
|
|
|
else if (el.type == 'select-one') el.value = 'All';
|
|
|
|
});
|
|
|
|
document.getElementsBySelector('.SearchCriteriaContainer', this).each(function(el){
|
|
|
|
Element.hide(el);
|
2010-01-13 00:49:00 +01:00
|
|
|
});
|
2009-05-18 01:19:51 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-05-14 08:11:18 +02:00
|
|
|
Form.getElements(this).each(function(el){
|
|
|
|
if (el.type == 'text') {
|
|
|
|
if ($F(el)) filters[el.name] = $F(el);
|
|
|
|
}
|
|
|
|
else if (el.type == 'select-one') {
|
|
|
|
if ($F(el) && $F(el) != 'All') filters[el.name] = $F(el);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filters.keys().length) {
|
|
|
|
// Set new URL
|
2009-08-18 00:31:16 +02:00
|
|
|
$('sitetree').setCustomURL(SiteTreeHandlers.controller_url + '/getfilteredsubtree?filter=CMSSiteTreeFilter_Search', filters);
|
2009-05-14 08:11:18 +02:00
|
|
|
|
|
|
|
// Disable checkbox tree controls that currently don't work with search.
|
|
|
|
// @todo: Make them work together
|
|
|
|
if ($('sitetree').isDraggable) $('sitetree').stopBeingDraggable();
|
|
|
|
document.getElementsBySelector('.checkboxAboveTree input[type=checkbox]').each(function(el){
|
|
|
|
el.value = false; el.disabled = true;
|
2010-01-13 00:49:00 +01:00
|
|
|
});
|
2009-05-14 08:11:18 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Reset URL to default
|
|
|
|
$('sitetree').clearCustomURL();
|
|
|
|
|
|
|
|
// Enable checkbox tree controls
|
|
|
|
document.getElementsBySelector('.checkboxAboveTree input[type=checkbox]').each(function(el){
|
|
|
|
el.disabled = false;
|
2010-01-13 00:49:00 +01:00
|
|
|
});
|
2009-05-14 08:11:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$('SiteTreeSearchButton').className = $('SiteTreeSearchClearButton').className = 'hidden';
|
|
|
|
$('searchIndicator').className = 'loading';
|
|
|
|
|
|
|
|
$('sitetree').reload({
|
|
|
|
onSuccess : function(response) {
|
|
|
|
$('SiteTreeSearchButton').className = $('SiteTreeSearchClearButton').className = 'action';
|
|
|
|
$('searchIndicator').className = '';
|
|
|
|
statusMessage('Filtered tree','good');
|
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Could not filter site tree<br />' + response.responseText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-13 00:49:00 +01:00
|
|
|
};
|
2009-05-14 08:11:18 +02:00
|
|
|
|
2007-09-16 17:19:17 +02:00
|
|
|
/**
|
|
|
|
* Add Criteria Drop-down onchange action which allows more criteria to be shown
|
|
|
|
*/
|
2009-11-27 02:42:24 +01:00
|
|
|
var SiteTreeFilterAddCriteria = Class.create();
|
2007-09-16 17:19:17 +02:00
|
|
|
SiteTreeFilterAddCriteria.applyTo('#SiteTreeFilterAddCriteria');
|
|
|
|
SiteTreeFilterAddCriteria.prototype = {
|
|
|
|
onchange : function() {
|
2009-02-03 04:52:06 +01:00
|
|
|
Element.show('Container' + this.value);
|
|
|
|
// Element.show('Text' + this.value);
|
|
|
|
// Element.show('Input' + this.value);
|
|
|
|
this.selectedIndex = 0; //reset selected criteria to prompt
|
2007-09-16 17:19:17 +02:00
|
|
|
}
|
2010-01-13 00:49:00 +01:00
|
|
|
};
|
2007-09-16 17:19:17 +02:00
|
|
|
|
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
|
|
|
*/
|
2009-11-27 02:42:24 +01:00
|
|
|
var batchactionsclass = Class.create();
|
2008-11-13 05:24:02 +01:00
|
|
|
batchactionsclass.applyTo('#batchactions');
|
|
|
|
batchactionsclass.prototype = {
|
2007-09-16 17:04:09 +02:00
|
|
|
|
|
|
|
initialize : function() {
|
|
|
|
Observable.applyTo($(_HANDLER_FORMS.batchactions));
|
|
|
|
},
|
|
|
|
onclick : function() {
|
2007-07-19 12:40:05 +02:00
|
|
|
if(treeactions.toggleSelection(this)) {
|
2007-10-29 03:36:44 +01:00
|
|
|
this.multiselectTransform();
|
2010-01-13 01:08:27 +01:00
|
|
|
this.actionChanged();
|
2007-10-29 03:36:44 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2009-10-16 00:44:08 +02:00
|
|
|
actionChanged: function() {
|
2010-01-13 01:08:27 +01:00
|
|
|
// Show parameters form, if necessary
|
2010-01-13 00:49:00 +01:00
|
|
|
var urlSegment = $('choose_batch_action').value.split('/').pop();
|
2009-10-16 00:44:08 +02:00
|
|
|
if ($('BatchActionParameters_'+urlSegment)) {
|
2010-01-13 00:57:47 +01:00
|
|
|
jQuery('#BatchActionParameters .params').hide();
|
|
|
|
jQuery('#BatchActionParameters_'+urlSegment).show();
|
|
|
|
jQuery('#BatchActionParameters').show();
|
2009-10-16 00:44:08 +02:00
|
|
|
} else {
|
2010-01-13 00:57:47 +01:00
|
|
|
jQuery('#BatchActionParameters').hide();
|
2009-10-16 00:44:08 +02:00
|
|
|
}
|
2010-01-13 01:08:27 +01:00
|
|
|
|
2010-01-13 01:14:29 +01:00
|
|
|
// Don't show actions that have failed from the previous execution
|
|
|
|
batchActionGlobals.removeFailures();
|
|
|
|
|
2010-01-13 01:08:27 +01:00
|
|
|
batchActionGlobals.refreshSelected();
|
2009-10-16 00:44:08 +02:00
|
|
|
},
|
|
|
|
|
2007-10-29 03:36:44 +01:00
|
|
|
multiselectTransform : function() {
|
|
|
|
batchActionGlobals.o1 = $('sitetree').observeMethod('SelectionChanged', batchActionGlobals.treeSelectionChanged);
|
|
|
|
batchActionGlobals.o2 = $(_HANDLER_FORMS.batchactions).observeMethod('Close', batchActionGlobals.popupClosed);
|
|
|
|
|
|
|
|
addClass($('sitetree'),'multiselect');
|
2010-01-13 01:05:48 +01:00
|
|
|
|
2007-10-29 03:36:44 +01:00
|
|
|
batchActionGlobals.selectedNodes = { };
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2009-07-09 07:40:45 +02:00
|
|
|
var selectedNode = $('sitetree').firstSelected();
|
|
|
|
if(selectedNode && selectedNode.className.indexOf('nodelete') == -1) {
|
|
|
|
var selIdx = $('sitetree').getIdxOf(selectedNode);
|
2007-10-29 03:36:44 +01:00
|
|
|
batchActionGlobals.selectedNodes[selIdx] = true;
|
2009-07-09 07:40:45 +02:00
|
|
|
selectedNode.removeNodeClass('current');
|
|
|
|
selectedNode.addNodeClass('selected');
|
|
|
|
selectedNode.open();
|
|
|
|
|
|
|
|
// Open all existing children, which might trigger further
|
|
|
|
// ajaxExansion calls to ensure all nodes are selectable
|
|
|
|
var children = selectedNode.getElementsByTagName('li');
|
|
|
|
for(var i=0; i<children.length; i++) {
|
|
|
|
children[i].open();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
2007-09-16 17:04:09 +02:00
|
|
|
}
|
2010-01-13 00:49:00 +01:00
|
|
|
};
|
2007-07-19 12:40:05 +02:00
|
|
|
|
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
|
2010-01-13 01:05:48 +01:00
|
|
|
count: function() {
|
|
|
|
return batchActionGlobals.getIds().length;
|
|
|
|
},
|
2007-09-16 17:04:09 +02:00
|
|
|
// 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 {
|
2009-07-09 07:36:24 +02:00
|
|
|
// Open node in order to allow proper selection of children
|
|
|
|
if(Element.hasClassName(selectedNode, 'unexpanded')) {
|
|
|
|
selectedNode.open();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select node
|
2007-07-19 12:40:05 +02:00
|
|
|
selectedNode.addNodeClass('selected');
|
|
|
|
selectedNode.selected = true;
|
2007-09-16 17:04:09 +02:00
|
|
|
batchActionGlobals.selectedNodes[idx] = true;
|
2009-07-09 07:36:24 +02:00
|
|
|
|
|
|
|
// Open all existing children, which might trigger further
|
|
|
|
// ajaxExansion calls to ensure all nodes are selectable
|
|
|
|
var children = selectedNode.getElementsByTagName('li');
|
|
|
|
for(var i=0; i<children.length; i++) {
|
|
|
|
children[i].open();
|
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
popupClosed : function() {
|
|
|
|
removeClass($('sitetree'),'multiselect');
|
2010-01-13 01:05:48 +01:00
|
|
|
|
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
|
|
|
},
|
2010-01-13 01:05:48 +01:00
|
|
|
|
|
|
|
getIds: function() {
|
2009-02-03 03:50:25 +01:00
|
|
|
var csvIDs = new Array();
|
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 {
|
2009-02-03 03:50:25 +01:00
|
|
|
if(csvIDs.indexOf(idx) == -1) {
|
|
|
|
csvIDs.push(idx);
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-13 01:05:48 +01:00
|
|
|
return csvIDs;
|
|
|
|
},
|
|
|
|
getCsvIds : function() {
|
|
|
|
return (batchActionGlobals.getIds().toString());
|
|
|
|
},
|
2010-01-13 01:08:27 +01:00
|
|
|
refreshSelected : function(rootNode) {
|
2010-01-13 01:05:48 +01:00
|
|
|
var st = $('sitetree');
|
2010-01-13 01:08:27 +01:00
|
|
|
|
2010-01-13 01:05:48 +01:00
|
|
|
for(var idx in batchActionGlobals.selectedNodes) {
|
|
|
|
st.getTreeNodeByIdx(idx).addNodeClass('selected');
|
|
|
|
st.getTreeNodeByIdx(idx).selected = true;
|
|
|
|
}
|
2010-01-13 01:08:27 +01:00
|
|
|
|
|
|
|
// Default to refreshing the entire tree
|
|
|
|
if(rootNode == null) rootNode = st;
|
|
|
|
|
|
|
|
/// If batch actions is enabled, then enable/disable the appropriate tree fields
|
|
|
|
if($('batchactionsforms').style.display != 'none' && $('choose_batch_action').value) {
|
|
|
|
// Collect list of visible tree IDs
|
|
|
|
var ids = [];
|
|
|
|
jQuery(rootNode).find('li').each(function() {
|
|
|
|
var id = parseInt(this.id.replace('record-',''));
|
|
|
|
if(id) ids.push(id);
|
|
|
|
|
|
|
|
// Disable the nodes while the ajax request is being processed
|
2010-01-13 01:08:37 +01:00
|
|
|
this.removeNodeClass('nodelete');
|
|
|
|
this.addNodeClass('treeloading');
|
2010-01-13 01:08:27 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Post to the server to ask which pages can have this batch action applied
|
2010-01-13 01:14:29 +01:00
|
|
|
var applicablePagesURL = $('choose_batch_action').value + '/applicablepages?csvIDs=' + ids.join(',');
|
2010-01-13 01:08:27 +01:00
|
|
|
jQuery.getJSON(applicablePagesURL, function(applicableIDs) {
|
|
|
|
var i;
|
|
|
|
var applicableIDMap = {};
|
|
|
|
for(i=0;i<applicableIDs.length;i++) applicableIDMap[applicableIDs[i]] = true;
|
|
|
|
|
|
|
|
// Set a CSS class on each tree node indicating which can be batch-actioned and which can't
|
|
|
|
jQuery(rootNode).find('li').each(function() {
|
2010-01-13 01:08:37 +01:00
|
|
|
this.removeNodeClass('treeloading');
|
|
|
|
|
2010-01-13 01:08:27 +01:00
|
|
|
var id = parseInt(this.id.replace('record-',''));
|
|
|
|
if(id) {
|
|
|
|
if(applicableIDMap[id] === true) {
|
|
|
|
this.removeNodeClass('nodelete');
|
|
|
|
} else {
|
|
|
|
// De-select the node if it's non-applicable
|
|
|
|
delete batchActionGlobals.selectedNodes[id];
|
|
|
|
|
|
|
|
this.removeNodeClass('selected');
|
|
|
|
this.addNodeClass('nodelete');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2007-09-16 17:20:02 +02:00
|
|
|
},
|
2010-01-13 01:14:29 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deselect all nodes in the tree
|
|
|
|
*/
|
|
|
|
deselectAll : function() {
|
|
|
|
batchActionGlobals.selectedNodes = {}
|
|
|
|
jQuery('#sitetree').find('li').each(function() {
|
|
|
|
this.removeNodeClass('selected');
|
|
|
|
this.selected = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the indications of failed batch actions
|
|
|
|
*/
|
|
|
|
removeFailures : function() {
|
|
|
|
jQuery('#sitetree').find('li.failed').each(function() {
|
|
|
|
this.removeNodeClass('failed');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
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;
|
2009-02-03 03:50:25 +01:00
|
|
|
Behaviour.apply($('sitetree_ul'));
|
2007-09-16 17:20:02 +02:00
|
|
|
$('SiteTreeIsFiltered').value = 0;
|
2007-10-29 03:36:44 +01:00
|
|
|
$('batchactions').multiselectTransform();
|
2008-10-03 02:48:34 +02:00
|
|
|
statusMessage(ss.i18n._t('CMSMAIN.SUCCESSUNFILTER'),'good');
|
2007-09-16 17:20:02 +02:00
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
2008-10-10 23:07:09 +02:00
|
|
|
errorMessage(ss.i18n.sprintf(
|
2008-10-03 02:48:34 +02:00
|
|
|
ss.i18n._t('CMSMAIN.ERRORUNFILTER'),
|
|
|
|
response.responseText
|
|
|
|
));
|
2007-09-16 17:20:02 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2007-09-16 17:04:09 +02:00
|
|
|
}
|
2010-01-13 00:49:00 +01:00
|
|
|
};
|
2007-09-16 17:04:09 +02:00
|
|
|
|
2009-10-16 00:44:08 +02:00
|
|
|
|
|
|
|
Behaviour.register({
|
|
|
|
'#choose_batch_action' : {
|
|
|
|
onchange : function() {
|
|
|
|
$('batchactions').actionChanged();
|
2009-11-03 03:01:19 +01:00
|
|
|
}
|
2009-10-16 00:44:08 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
/**
|
|
|
|
* Publish selected pages action
|
|
|
|
*/
|
2009-11-27 02:42:24 +01:00
|
|
|
var publishpage = Class.create();
|
2009-05-14 08:11:18 +02:00
|
|
|
publishpage.applyTo('#batchactions_options');
|
2007-09-16 17:04:09 +02:00
|
|
|
publishpage.prototype = {
|
|
|
|
onsubmit : function() {
|
|
|
|
csvIDs = batchActionGlobals.getCsvIds();
|
|
|
|
if(csvIDs) {
|
2009-05-14 08:11:18 +02:00
|
|
|
var optionEl = $('choose_batch_action').options[$('choose_batch_action').selectedIndex];
|
|
|
|
var actionText = optionEl.text;
|
2010-01-13 01:14:29 +01:00
|
|
|
|
2010-02-04 05:56:16 +01:00
|
|
|
var confirmationURL = $('choose_batch_action').value + '/confirmation?csvIDs=' + csvIDs;
|
|
|
|
jQuery.getJSON(confirmationURL, function(data) {
|
|
|
|
// If a custom alert has been provided, show that.
|
|
|
|
// otherwise, show the default one
|
|
|
|
if (data.alert) {
|
|
|
|
if (!confirm(data.content)) return false;
|
|
|
|
} else {
|
|
|
|
if(!confirm("You have " + batchActionGlobals.count() + " pages selected.\n\nDo your really want to " + actionText.toLowerCase() + "?")) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-09-16 17:04:09 +02:00
|
|
|
}
|
2010-02-04 05:56:16 +01:00
|
|
|
|
|
|
|
$('batchactions_options').submitform();
|
2007-09-16 17:04:09 +02:00
|
|
|
});
|
|
|
|
} else {
|
2008-10-03 02:48:34 +02:00
|
|
|
alert(ss.i18n._t('CMSMAIN.SELECTONEPAGE'));
|
2007-09-16 17:04:09 +02:00
|
|
|
}
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2007-09-16 17:04:09 +02:00
|
|
|
return false;
|
2010-02-04 05:56:16 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
submitform: function() {
|
|
|
|
csvIDs = batchActionGlobals.getCsvIds();
|
|
|
|
|
|
|
|
var optionEl = $('choose_batch_action').options[$('choose_batch_action').selectedIndex];
|
|
|
|
var optionParams = eval(optionEl.className);
|
|
|
|
var ingText = optionParams.doingText;
|
|
|
|
|
|
|
|
this.elements.csvIDs.value = csvIDs;
|
|
|
|
|
|
|
|
// Select form submission URL
|
|
|
|
this.action = $('choose_batch_action').value;
|
|
|
|
|
|
|
|
// Loading indicator
|
|
|
|
statusMessage(ingText);
|
|
|
|
$('batchactions_go').className = 'loading';
|
|
|
|
|
|
|
|
// Don't show actions that have failed from the previous execution
|
|
|
|
batchActionGlobals.removeFailures();
|
|
|
|
|
|
|
|
// Submit form
|
|
|
|
Ajax.SubmitForm(this, null, {
|
|
|
|
onSuccess : function(response) {
|
|
|
|
Ajax.Evaluator(response);
|
|
|
|
$('batchactions_go').className = '';
|
|
|
|
batchActionGlobals.deselectAll();
|
|
|
|
},
|
|
|
|
onFailure : function(response) {
|
|
|
|
errorMessage('Error ' + ingText, response);
|
|
|
|
}
|
|
|
|
});
|
2007-09-16 17:04:09 +02:00
|
|
|
}
|
2009-11-27 02:42:24 +01:00
|
|
|
};
|
2007-09-16 17:04:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete selected pages action
|
|
|
|
*/
|
2009-11-27 02:42:24 +01:00
|
|
|
var deletepage;
|
2007-09-16 17:04:09 +02:00
|
|
|
deletepage = Class.create();
|
2009-01-06 03:18:33 +01:00
|
|
|
deletepage.applyTo('#Form_DeleteItemsForm');
|
2007-09-16 17:04:09 +02:00
|
|
|
deletepage.prototype = {
|
|
|
|
onsubmit : function() {
|
|
|
|
csvIDs = batchActionGlobals.getCsvIds();
|
|
|
|
if(csvIDs || batchActionGlobals.newNodes.length > 0) {
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-10 23:07:09 +02:00
|
|
|
if(confirm(ss.i18n.sprintf(
|
2008-10-03 02:48:34 +02:00
|
|
|
ss.i18n._t('CMSMAIN.REALLYDELETEPAGES'),
|
2010-01-13 01:05:48 +01:00
|
|
|
batchActionGlobals.count()
|
2008-10-03 02:48:34 +02:00
|
|
|
))) {
|
2007-09-16 17:04:09 +02:00
|
|
|
this.elements.csvIDs.value = csvIDs;
|
2007-07-19 12:40:05 +02:00
|
|
|
|
2008-10-03 02:48:34 +02:00
|
|
|
statusMessage(ss.i18n._t('CMSMAIN.DELETINGPAGES'));
|
2007-09-16 17:04:09 +02:00
|
|
|
// 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
|
2009-01-06 03:18:33 +01:00
|
|
|
$('Form_DeleteItemsForm_action_deleteitems').className = 'loading';
|
2007-09-16 17:04:09 +02:00
|
|
|
Ajax.SubmitForm(this, null, {
|
|
|
|
onSuccess : function(response) {
|
|
|
|
Ajax.Evaluator(response);
|
2009-01-06 03:18:33 +01:00
|
|
|
$('Form_DeleteItemsForm_action_deleteitems').className = '';
|
2007-09-16 17:04:09 +02:00
|
|
|
treeactions.closeSelection($('batchactions'));
|
|
|
|
},
|
2007-07-19 12:40:05 +02:00
|
|
|
onFailure : function(response) {
|
2008-10-03 02:48:34 +02:00
|
|
|
errorMessage(ss.i18n._t('CMSMAIN.ERRORDELETINGPAGES'), response);
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2008-10-03 02:48:34 +02:00
|
|
|
alert(ss.i18n._t('CMSMAIN.SELECTONEPAGE'));
|
2007-07-19 12:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-11-27 02:42:24 +01:00
|
|
|
};
|
2007-07-19 12:40:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tree context menu
|
|
|
|
*/
|
|
|
|
TreeContextMenu = {
|
|
|
|
'Edit this page' : function(treeNode) {
|
|
|
|
treeNode.selectTreeNode();
|
|
|
|
},
|
2008-02-25 03:10:37 +01:00
|
|
|
'Duplicate page and children' : function(treeNode) {
|
|
|
|
// First save the page silently (without confirmation) and then duplicate the page.
|
|
|
|
autoSave(false, treeNode.duplicatePageWithChildren.bind(treeNode));
|
|
|
|
},
|
|
|
|
'Duplicate just 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
|
|
|
}
|
2009-05-14 08:11:18 +02:00
|
|
|
};
|