mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
60451f7033
MINOR Renaming load() to loadForm() in LeftAndMain.EditForm.js, to avoid overloading jQuery's native methods MINOR Triggering jQuery events on top of prototype's Observable for better handling with concrete, in SecurityAdmin.js git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92719 467b73ca-7a2a-4603-9d3b-597d59a354a9
347 lines
10 KiB
JavaScript
Executable File
347 lines
10 KiB
JavaScript
Executable File
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';
|
|
|
|
SiteTreeFilter = Class.create();
|
|
SiteTreeFilter.applyTo('#siteTreeFilterList');
|
|
SiteTreeFilter.prototype = {
|
|
initialize: function () {
|
|
},
|
|
onchange : function() {
|
|
var value = this.options[this.selectedIndex].value;
|
|
|
|
if(value != 'all') {
|
|
$('sitetree').setCustomURL(SiteTreeHandlers.controller_url+'/getfilteredsubtree?filter='+escape(value));
|
|
} else {
|
|
$('sitetree').clearCustomURL();
|
|
}
|
|
|
|
// We can't update the tree while it's draggable; it gets b0rked.
|
|
var __makeDraggableAfterUpdate = false;
|
|
if($('sitetree').isDraggable) {
|
|
$('sitetree').stopBeingDraggable();
|
|
__makeDraggableAfterUpdate = true;
|
|
}
|
|
|
|
var indicator = $('siteTreeFilterActionIndicator');
|
|
indicator.style.display = 'inline';
|
|
|
|
$('sitetree').reload({
|
|
onSuccess: function() {
|
|
indicator.style.display = 'none';
|
|
if(__makeDraggableAfterUpdate) $('sitetree').makeDraggable();
|
|
},
|
|
onFailure: function(response) {
|
|
errorMessage('Could not update tree', response);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Batch Actions button click action
|
|
*/
|
|
batchactionsclass = Class.create();
|
|
batchactionsclass.applyTo('#batchactions');
|
|
batchactionsclass.prototype = {
|
|
|
|
initialize : function() {
|
|
Observable.applyTo($(_HANDLER_FORMS.batchactions));
|
|
},
|
|
onclick : function() {
|
|
if(treeactions.toggleSelection(this)) {
|
|
this.multiselectTransform();
|
|
}
|
|
return false;
|
|
},
|
|
|
|
actionChanged: function() {
|
|
var urlSegment = $('choose_batch_action').value.split('/').pop()
|
|
if ($('BatchActionParameters_'+urlSegment)) {
|
|
jQuery('#actionParams').empty();
|
|
jQuery('#BatchActionParameters_'+urlSegment).appendTo('#actionParams');
|
|
$('actionParams').style.display = 'block';
|
|
$('actionParams').style.padding = '4px';
|
|
} else {
|
|
$('actionParams').innerHTML = '';
|
|
$('actionParams').style.display = 'none';
|
|
}
|
|
},
|
|
|
|
multiselectTransform : function() {
|
|
batchActionGlobals.o1 = $('sitetree').observeMethod('SelectionChanged', batchActionGlobals.treeSelectionChanged);
|
|
batchActionGlobals.o2 = $(_HANDLER_FORMS.batchactions).observeMethod('Close', batchActionGlobals.popupClosed);
|
|
|
|
jQuery('#sitetree').addClass('multiselect');
|
|
|
|
batchActionGlobals.selectedNodes = { };
|
|
|
|
var selectedNode = $('sitetree').firstSelected();
|
|
if(selectedNode && selectedNode.className.indexOf('nodelete') == -1) {
|
|
var selIdx = $('sitetree').getIdxOf(selectedNode);
|
|
batchActionGlobals.selectedNodes[selIdx] = true;
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// 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: { },
|
|
treeSelectionChanged : function(selectedNode) {
|
|
var idx = $('sitetree').getIdxOf(selectedNode);
|
|
if(selectedNode.className.indexOf('nodelete') == -1) {
|
|
if(selectedNode.selected) {
|
|
selectedNode.removeNodeClass('selected');
|
|
selectedNode.selected = false;
|
|
batchActionGlobals.selectedNodes[idx] = false;
|
|
|
|
} else {
|
|
// Open node in order to allow proper selection of children
|
|
if(Element.hasClassName(selectedNode, 'unexpanded')) {
|
|
selectedNode.open();
|
|
}
|
|
|
|
// Select node
|
|
selectedNode.addNodeClass('selected');
|
|
selectedNode.selected = true;
|
|
batchActionGlobals.selectedNodes[idx] = true;
|
|
|
|
// 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();
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
},
|
|
|
|
popupClosed : function() {
|
|
jQuery('#sitetree').removeClass('multiselect');
|
|
$('sitetree').stopObserving(batchActionGlobals.o1);
|
|
$(_HANDLER_FORMS.batchactions).stopObserving(batchActionGlobals.o2);
|
|
|
|
for(var idx in batchActionGlobals.selectedNodes) {
|
|
if(batchActionGlobals.selectedNodes[idx]) {
|
|
node = $('sitetree').getTreeNodeByIdx(idx);
|
|
if(node) {
|
|
node.removeNodeClass('selected');
|
|
node.selected = false;
|
|
}
|
|
}
|
|
}
|
|
batchActionGlobals.selectedNodes = { };
|
|
},
|
|
|
|
getCsvIds : function() {
|
|
var csvIDs = new Array();
|
|
var st = $('sitetree');
|
|
batchActionGlobals.newNodes = new Array();
|
|
for(var idx in batchActionGlobals.selectedNodes) {
|
|
if(batchActionGlobals.selectedNodes[idx]) {
|
|
|
|
// Delete/Publish new nodes? (Leftover from delete code?) TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
|
|
if( idx.match(/^new-[a-z0-9A-Z\-]+$/) ) {
|
|
batchActionGlobals.newNodes.push( idx );
|
|
} else {
|
|
var i, item, childrenTopublish = st.getTreeNodeByIdx(idx).getElementsByTagName('li');
|
|
for(i=0;item=childrenTopublish[i];i++) {
|
|
if(csvIDs.indexOf(st.getIdxOf(childrenTopublish[i])) == -1) {
|
|
csvIDs.push(st.getIdxOf(childrenTopublish[i]));
|
|
}
|
|
}
|
|
if(csvIDs.indexOf(idx) == -1) {
|
|
csvIDs.push(idx);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
batchActionGlobals.count=csvIDs.length;
|
|
return (csvIDs.toString());
|
|
},
|
|
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($('sitetree_ul'));
|
|
$('SiteTreeIsFiltered').value = 0;
|
|
$('batchactions').multiselectTransform();
|
|
statusMessage(ss.i18n._t('CMSMAIN.SUCCESSUNFILTER'),'good');
|
|
},
|
|
onFailure : function(response) {
|
|
errorMessage(ss.i18n.sprintf(
|
|
ss.i18n._t('CMSMAIN.ERRORUNFILTER'),
|
|
response.responseText
|
|
));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
Behaviour.register({
|
|
'#choose_batch_action' : {
|
|
onchange : function() {
|
|
$('batchactions').actionChanged();
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
* Publish selected pages action
|
|
*/
|
|
publishpage = Class.create();
|
|
publishpage.applyTo('#batchactions_options');
|
|
publishpage.prototype = {
|
|
onsubmit : function() {
|
|
csvIDs = batchActionGlobals.getCsvIds();
|
|
if(csvIDs) {
|
|
var optionEl = $('choose_batch_action').options[$('choose_batch_action').selectedIndex];
|
|
var actionText = optionEl.text;
|
|
var optionParams = eval(optionEl.className);
|
|
var ingText = optionParams.doingText;
|
|
|
|
// Confirmation
|
|
if(!confirm("You have " + batchActionGlobals.count + " pages selected.\n\nDo your really want to " + actionText.toLowerCase() + "?")) {
|
|
return false;
|
|
}
|
|
|
|
this.elements.csvIDs.value = csvIDs;
|
|
|
|
// Select form submission URL
|
|
this.action = $('choose_batch_action').value;
|
|
|
|
// Loading indicator
|
|
statusMessage(ingText);
|
|
$('batchactions_go').className = 'loading';
|
|
|
|
// Submit form
|
|
Ajax.SubmitForm(this, null, {
|
|
onSuccess : function(response) {
|
|
Ajax.Evaluator(response);
|
|
$('batchactions_go').className = '';
|
|
treeactions.closeSelection($('batchactions'));
|
|
},
|
|
onFailure : function(response) {
|
|
errorMessage('Error ' + ingText, response);
|
|
}
|
|
});
|
|
} else {
|
|
alert(ss.i18n._t('CMSMAIN.SELECTONEPAGE'));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Delete selected pages action
|
|
*/
|
|
deletepage = Class.create();
|
|
deletepage.applyTo('#Form_DeleteItemsForm');
|
|
deletepage.prototype = {
|
|
onsubmit : function() {
|
|
csvIDs = batchActionGlobals.getCsvIds();
|
|
if(csvIDs || batchActionGlobals.newNodes.length > 0) {
|
|
batchActionGlobals.count += batchActionGlobals.newNodes.length;
|
|
|
|
if(confirm(ss.i18n.sprintf(
|
|
ss.i18n._t('CMSMAIN.REALLYDELETEPAGES'),
|
|
batchActionGlobals.count
|
|
))) {
|
|
this.elements.csvIDs.value = csvIDs;
|
|
|
|
statusMessage(ss.i18n._t('CMSMAIN.DELETINGPAGES'));
|
|
// 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] );
|
|
|
|
if( newNode.parentTreeNode )
|
|
newNode.parentTreeNode.removeTreeNode( newNode );
|
|
else
|
|
alert( newNode.id + ' has no parent node');
|
|
|
|
$('Form_EditForm').reloadIfSetTo(idx);
|
|
}
|
|
|
|
batchActionGlobals.newNodes = new Array();
|
|
// Put an AJAXY loading icon on the button
|
|
$('Form_DeleteItemsForm_action_deleteitems').className = 'loading';
|
|
Ajax.SubmitForm(this, null, {
|
|
onSuccess : function(response) {
|
|
Ajax.Evaluator(response);
|
|
$('Form_DeleteItemsForm_action_deleteitems').className = '';
|
|
treeactions.closeSelection($('batchactions'));
|
|
},
|
|
onFailure : function(response) {
|
|
errorMessage(ss.i18n._t('CMSMAIN.ERRORDELETINGPAGES'), response);
|
|
}
|
|
});
|
|
}
|
|
|
|
} else {
|
|
alert(ss.i18n._t('CMSMAIN.SELECTONEPAGE'));
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Tree context menu
|
|
*/
|
|
TreeContextMenu = {
|
|
'Edit this page' : function(treeNode) {
|
|
treeNode.selectTreeNode();
|
|
},
|
|
'Duplicate page and children' : function(treeNode) {
|
|
// First save the page silently (without confirmation) and then duplicate the page.
|
|
jQuery('#Form_EditForm').concrete('ss').ajaxSubmit(null, treeNode.duplicatePageWithChildren.bind(treeNode));
|
|
},
|
|
'Duplicate just this page' : function(treeNode) {
|
|
// First save the page silently (without confirmation) and then duplicate the page.
|
|
jQuery('#Form_EditForm').concrete('ss').ajaxSubmit(null, treeNode.duplicatePageWithChildren.bind(treeNode));
|
|
},
|
|
'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);
|
|
}
|
|
|
|
treeNode.onOrderChanged(sortedChildren,treeNode);
|
|
}
|
|
};
|