mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
147 lines
4.0 KiB
JavaScript
147 lines
4.0 KiB
JavaScript
|
SiteTreeHandlers.parentChanged_url = 'admin/security/ajaxupdateparent';
|
||
|
SiteTreeHandlers.orderChanged_url = 'admin/security/ajaxupdatesort';
|
||
|
SiteTreeHandlers.loadPage_url = 'admin/security/getitem';
|
||
|
|
||
|
_HANDLER_FORMS['deletegroup'] = 'deletegroup_options';
|
||
|
|
||
|
/**
|
||
|
* Add page action
|
||
|
* @todo Remove duplication between this and the CMSMain Add page action
|
||
|
*/
|
||
|
addgroup = {
|
||
|
button_onclick : function() {
|
||
|
addgroup.form_submit();
|
||
|
return false;
|
||
|
},
|
||
|
|
||
|
form_submit : function() {
|
||
|
var st = $('sitetree');
|
||
|
$('addgroup_options').elements.ParentID.value = st.firstSelected() ? st.getIdxOf(st.firstSelected()) : 0;
|
||
|
Ajax.SubmitForm('addgroup_options', null, {
|
||
|
onSuccess : Ajax.Evaluator,
|
||
|
onFailure : function(response) {
|
||
|
errorMessage('Error adding page', response);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Delete page action
|
||
|
*/
|
||
|
deletegroup = {
|
||
|
button_onclick : function() {
|
||
|
/*if( $('deletegroup_options').style.display == 'none' )
|
||
|
$('deletegroup_options').style.display = 'block';
|
||
|
else
|
||
|
$('deletegroup_options').style.display = 'none';*/
|
||
|
|
||
|
if(treeactions.toggleSelection(this)) {
|
||
|
$('deletegroup_options').style.display = 'block';
|
||
|
|
||
|
deletegroup.o1 = $('sitetree').observeMethod('SelectionChanged', deletegroup.treeSelectionChanged);
|
||
|
deletegroup.o2 = $('deletegroup_options').observeMethod('Close', deletegroup.popupClosed);
|
||
|
addClass($('sitetree'),'multiselect');
|
||
|
|
||
|
deletegroup.selectedNodes = { };
|
||
|
|
||
|
var sel = $('sitetree').firstSelected();
|
||
|
if(sel && sel.className.indexOf('nodelete') == -1) {
|
||
|
var selIdx = $('sitetree').getIdxOf(sel);
|
||
|
deletegroup.selectedNodes[selIdx] = true;
|
||
|
sel.removeNodeClass('current');
|
||
|
sel.addNodeClass('selected');
|
||
|
}
|
||
|
} else
|
||
|
$('deletegroup_options').style.display = 'none';
|
||
|
|
||
|
return false;
|
||
|
},
|
||
|
|
||
|
treeSelectionChanged : function(selectedNode) {
|
||
|
var idx = $('sitetree').getIdxOf(selectedNode);
|
||
|
|
||
|
if(selectedNode.className.indexOf('nodelete') == -1) {
|
||
|
if(selectedNode.selected) {
|
||
|
selectedNode.removeNodeClass('selected');
|
||
|
selectedNode.selected = false;
|
||
|
deletegroup.selectedNodes[idx] = false;
|
||
|
|
||
|
} else {
|
||
|
selectedNode.addNodeClass('selected');
|
||
|
selectedNode.selected = true;
|
||
|
deletegroup.selectedNodes[idx] = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
},
|
||
|
|
||
|
popupClosed : function() {
|
||
|
removeClass($('sitetree'),'multiselect');
|
||
|
$('sitetree').stopObserving(deletegroup.o1);
|
||
|
$('deletegroup_options').stopObserving(deletegroup.o2);
|
||
|
|
||
|
for(var idx in deletegroup.selectedNodes) {
|
||
|
if(deletegroup.selectedNodes[idx]) {
|
||
|
node = $('sitetree').getTreeNodeByIdx(idx);
|
||
|
if(node) {
|
||
|
node.removeNodeClass('selected');
|
||
|
node.selected = false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
form_submit : function() {
|
||
|
var csvIDs = "";
|
||
|
for(var idx in deletegroup.selectedNodes) {
|
||
|
if(deletegroup.selectedNodes[idx]) csvIDs += (csvIDs ? "," : "") + idx;
|
||
|
}
|
||
|
if(csvIDs) {
|
||
|
$('deletegroup_options').elements.csvIDs.value = csvIDs;
|
||
|
|
||
|
Ajax.SubmitForm('deletegroup_options', null, {
|
||
|
onSuccess : function(response) {
|
||
|
Ajax.Evaluator(response);
|
||
|
|
||
|
var sel;
|
||
|
if((sel = $('sitetree').firstSelected()) && sel.parentNode) sel.addNodeClass('current');
|
||
|
else $('Form_EditForm').innerHTML = "";
|
||
|
|
||
|
treeactions.closeSelection($('deletegroup'));
|
||
|
},
|
||
|
onFailure : function(response) {
|
||
|
errorMessage('Error deleting pages', response);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
$('deletegroup').getElementsByTagName('a')[0].onclick();
|
||
|
|
||
|
} else {
|
||
|
alert("Please select at least 1 page.");
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Initialisation function to set everything up
|
||
|
*/
|
||
|
Behaviour.addLoader(function () {
|
||
|
// Set up add page
|
||
|
Observable.applyTo($('addgroup_options'));
|
||
|
$('addgroup').onclick = addgroup.button_onclick;
|
||
|
$('addgroup').getElementsByTagName('a')[0].onclick = function() {return false;};
|
||
|
$('addgroup_options').onsubmit = addgroup.form_submit;
|
||
|
|
||
|
// Set up delete page
|
||
|
Observable.applyTo($('deletegroup_options'));
|
||
|
$('deletegroup').onclick = deletegroup.button_onclick;
|
||
|
$('deletegroup').getElementsByTagName('a')[0].onclick = function() {return false;};
|
||
|
$('deletegroup_options').onsubmit = deletegroup.form_submit;
|
||
|
});
|