elofgren: NEW FEATURE: Replace the 'Delete...' button with a 'Batch Actions' button and add a 'Publish the selected pages' button.

See: http://www.silverstripe.com/google-summer-of-code-forum/flat/1636?showPost=1859#post1859 
And: http://www.silverstripe.com/silverstripe-development/flat/3799?showPost=4070#post4070 
TODO: Make the new 'Search' button functional. 
(merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@42081 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-09-16 15:04:09 +00:00
parent 5dc37e418d
commit ed9bca2c68
6 changed files with 185 additions and 81 deletions

View File

@ -849,6 +849,53 @@ HTML;
))->renderWith('Dialog'); ))->renderWith('Dialog');
} }
/**
* Publishes a number of items.
* Called by AJAX
*/
public function publishitems() {
// This method can't be called without ajax.
if(!Director::is_ajax()) {
Director::redirectBack();
return;
}
$ids = split(' *, *', $_REQUEST['csvIDs']);
$notifications = array();
$idList = array();
// make sure all the ids are numeric.
// Add all the children to the list of IDs if they are missing
foreach($ids as $id) {
$brokenPageList = '';
if(is_numeric($id)) {
$record = DataObject::get_by_id($this->stat('tree_class'), $id);
if($record) {
// Publish this page
$this->performPublish($record);
// Now make sure the 'changed' icon is removed
$publishedRecord = DataObject::get_by_id($this->stat('tree_class'), $id);
$JS_title = Convert::raw2js($publishedRecord->TreeTitle());
FormResponse::add("\$('sitetree').setNodeTitle($id, '$JS_title');");
FormResponse::add("$('Form_EditForm').reloadIfSetTo($record->ID);");
$record->destroy();
unset($record);
}
}
}
if (sizeof($ids) > 1) $message = sprintf(_t('CMSMain.PAGESPUB', "%d pages published "), sizeof($ids));
else $message = sprintf(_t('CMSMain.PAGEPUB', "%d page published "), sizeof($ids));
FormResponse::add('statusMessage("'.$message.'","good");');
return FormResponse::respond();
}
/** /**
* Delete a number of items. * Delete a number of items.
* This code supports notification * This code supports notification
@ -933,13 +980,13 @@ HTML;
} }
} }
if (sizeof($ids) > 1) $message = sprintf(_t('CMSMain.PAGEDEL', "%d page deleted "), sizeof($ids)); if (sizeof($ids) > 1) $message = sprintf(_t('CMSMain.PAGESDEL', "%d pages deleted "), sizeof($ids));
else $message = sprintf(_t('CMSMain.PAGESDEL', "%d pages deleted "), sizeof($ids)); else $message = sprintf(_t('CMSMain.PAGEDEL', "%d page deleted "), sizeof($ids));
if(isset($brokenPageList) && $brokenPageList != '') { if(isset($brokenPageList) && $brokenPageList != '') {
$message .= _t('CMSMain.NOWBROKEN'," The following pages now have broken links:")."<ul>" . addslashes($brokenPageList) . "</ul>" . _t('CMSMain.NOWBROKEN2',"Their owners have been emailed and they will fix up those pages."); $message .= _t('CMSMain.NOWBROKEN'," The following pages now have broken links:")."<ul>" . addslashes($brokenPageList) . "</ul>" . _t('CMSMain.NOWBROKEN2',"Their owners have been emailed and they will fix up those pages.");
} }
FormResponse::status_message($message); FormResponse::add('statusMessage("'.$message.'","good");');
return FormResponse::respond(); return FormResponse::respond();
} }

View File

@ -385,7 +385,7 @@ input.delete:hover {
background: #ce0000; background: #ce0000;
color: #fff; color: #fff;
} }
.ajaxActions input.loading { input.loading {
background-color: #fff; background-color: #fff;
background-image: url(../images/network-save.gif); background-image: url(../images/network-save.gif);
background-position: center left; background-position: center left;

View File

@ -97,28 +97,42 @@ addpage.prototype = {
} }
/** /**
* Delete page action * Batch Actions button click action
*/ */
deletepage = { batchactions = Class.create();
button_onclick : function() { batchactions.applyTo('#batchactions');
batchactions.prototype = {
initialize : function() {
Observable.applyTo($(_HANDLER_FORMS.batchactions));
},
onclick : function() {
if(treeactions.toggleSelection(this)) { if(treeactions.toggleSelection(this)) {
deletepage.o1 = $('sitetree').observeMethod('SelectionChanged', deletepage.treeSelectionChanged); batchActionGlobals.o1 = $('sitetree').observeMethod('SelectionChanged', batchActionGlobals.treeSelectionChanged);
deletepage.o2 = $(_HANDLER_FORMS.deletepage).observeMethod('Close', deletepage.popupClosed); batchActionGlobals.o2 = $(_HANDLER_FORMS.batchactions).observeMethod('Close', batchActionGlobals.popupClosed);
addClass($('sitetree'),'multiselect'); addClass($('sitetree'),'multiselect');
deletepage.selectedNodes = { }; batchActionGlobals.selectedNodes = { };
var sel = $('sitetree').firstSelected(); var sel = $('sitetree').firstSelected();
if(sel && sel.className.indexOf('nodelete') == -1) { if(sel && sel.className.indexOf('nodelete') == -1) {
var selIdx = $('sitetree').getIdxOf(sel); var selIdx = $('sitetree').getIdxOf(sel);
deletepage.selectedNodes[selIdx] = true; batchActionGlobals.selectedNodes[selIdx] = true;
sel.removeNodeClass('current'); sel.removeNodeClass('current');
sel.addNodeClass('selected'); sel.addNodeClass('selected');
} }
} }
return false; return false;
}, }
}
// 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) { treeSelectionChanged : function(selectedNode) {
var idx = $('sitetree').getIdxOf(selectedNode); var idx = $('sitetree').getIdxOf(selectedNode);
@ -126,12 +140,12 @@ deletepage = {
if(selectedNode.selected) { if(selectedNode.selected) {
selectedNode.removeNodeClass('selected'); selectedNode.removeNodeClass('selected');
selectedNode.selected = false; selectedNode.selected = false;
deletepage.selectedNodes[idx] = false; batchActionGlobals.selectedNodes[idx] = false;
} else { } else {
selectedNode.addNodeClass('selected'); selectedNode.addNodeClass('selected');
selectedNode.selected = true; selectedNode.selected = true;
deletepage.selectedNodes[idx] = true; batchActionGlobals.selectedNodes[idx] = true;
} }
} }
@ -140,11 +154,11 @@ deletepage = {
popupClosed : function() { popupClosed : function() {
removeClass($('sitetree'),'multiselect'); removeClass($('sitetree'),'multiselect');
$('sitetree').stopObserving(deletepage.o1); $('sitetree').stopObserving(batchActionGlobals.o1);
$(_HANDLER_FORMS.deletepage).stopObserving(deletepage.o2); $(_HANDLER_FORMS.batchactions).stopObserving(batchActionGlobals.o2);
for(var idx in deletepage.selectedNodes) { for(var idx in batchActionGlobals.selectedNodes) {
if(deletepage.selectedNodes[idx]) { if(batchActionGlobals.selectedNodes[idx]) {
node = $('sitetree').getTreeNodeByIdx(idx); node = $('sitetree').getTreeNodeByIdx(idx);
if(node) { if(node) {
node.removeNodeClass('selected'); node.removeNodeClass('selected');
@ -152,41 +166,87 @@ deletepage = {
} }
} }
} }
batchActionGlobals.selectedNodes = { };
}, },
form_submit : function() { getCsvIds : function() {
var csvIDs = "", count = 0; var csvIDs = "";
batchActionGlobals.count = 0;
var st = $('sitetree'); var st = $('sitetree');
var newNodes = new Array(); batchActionGlobals.newNodes = new Array();
for(var idx in batchActionGlobals.selectedNodes) {
if(batchActionGlobals.selectedNodes[idx]) {
for(var idx in deletepage.selectedNodes) { // Delete/Publish new nodes? (Leftover from delete code?) TODO: Remove 'new-' code http://open.silverstripe.com/ticket/875
if(deletepage.selectedNodes[idx]) {
// delete new nodes
if( idx.match(/^new-[a-z0-9A-Z\-]+$/) ) { if( idx.match(/^new-[a-z0-9A-Z\-]+$/) ) {
newNodes.push( idx ); batchActionGlobals.newNodes.push( idx );
} else { } else {
var i, item, childrenToDelete = st.getTreeNodeByIdx(idx).getElementsByTagName('li'); var i, item, childrenTopublish = st.getTreeNodeByIdx(idx).getElementsByTagName('li');
for(i=0;item=childrenToDelete[i];i++) { for(i=0;item=childrenTopublish[i];i++) {
csvIDs += (csvIDs ? "," : "") + st.getIdxOf(childrenToDelete[i]); csvIDs += (csvIDs ? "," : "") + st.getIdxOf(childrenTopublish[i]);
count++; batchActionGlobals.count++;
} }
csvIDs += (csvIDs ? "," : "") + idx; csvIDs += (csvIDs ? "," : "") + idx;
count++; batchActionGlobals.count++;
} }
} }
} }
return csvIDs;
}
}
if(csvIDs || newNodes.length > 0) { /**
count += newNodes.length; * 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;
if(confirm("Do you really want to delete the " + count + " marked pages?")) { statusMessage('Publishing pages...');
$(_HANDLER_FORMS.deletepage).elements.csvIDs.value = csvIDs;
statusMessage('deleting 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.");
}
for( var idx = 0; idx < newNodes.length; idx++ ) { return false;
var newNode = $('sitetree').getTreeNodeByIdx( newNodes[idx] ); }
}
/**
* 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;
if(confirm("Do you really want to delete the " + batchActionGlobals.count + " marked pages?")) {
this.elements.csvIDs.value = csvIDs;
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] );
if( newNode.parentTreeNode ) if( newNode.parentTreeNode )
newNode.parentTreeNode.removeTreeNode( newNode ); newNode.parentTreeNode.removeTreeNode( newNode );
@ -196,16 +256,19 @@ deletepage = {
$('Form_EditForm').reloadIfSetTo(idx); $('Form_EditForm').reloadIfSetTo(idx);
} }
newNodes = new Array(); batchActionGlobals.newNodes = new Array();
// Put an AJAXY loading icon on the button
Ajax.SubmitForm(_HANDLER_FORMS.deletepage, null, { $('action_delete_selected').className = 'loading';
onSuccess : deletepage.submit_success, Ajax.SubmitForm(this, null, {
onSuccess : function(response) {
Ajax.Evaluator(response);
$('action_delete_selected').className = '';
treeactions.closeSelection($('batchactions'));
},
onFailure : function(response) { onFailure : function(response) {
errorMessage('Error deleting pages', response); errorMessage('Error deleting pages', response);
} }
}); });
$('deletepage').getElementsByTagName('button')[0].onclick();
} }
} else { } else {
@ -213,29 +276,9 @@ deletepage = {
} }
return false; return false;
},
submit_success: function(response) {
deletepage.selectedNodes = {};
Ajax.Evaluator(response);
treeactions.closeSelection($('deletepage'));
} }
} }
/**
* Initialisation function to set everything up
*/
appendLoader(function () {
// Set up deleet page
if( !$('deletepage') )
return;
Observable.applyTo($(_HANDLER_FORMS.deletepage));
$('deletepage').onclick = deletepage.button_onclick;
$('deletepage').getElementsByTagName('button')[0].onclick = function() { return false; };
$(_HANDLER_FORMS.deletepage).onsubmit = deletepage.form_submit;
});
/** /**
* Tree context menu * Tree context menu
*/ */

View File

@ -12,7 +12,7 @@ SiteTreeHandlers.controller_url = 'admin';
var _HANDLER_FORMS = { var _HANDLER_FORMS = {
addpage : 'Form_AddPageOptionsForm', addpage : 'Form_AddPageOptionsForm',
deletepage : 'deletepage_options' batchactions : 'batchactionsforms'
}; };

View File

@ -47,6 +47,8 @@ $lang['en_US']['CMSMain']['COMPARINGV'] = 'You are comparing versions #%d and #%
$lang['en_US']['CMSMain']['COPYPUBTOSTAGE'] = 'Do you really want to copy the published content to the stage site?'; $lang['en_US']['CMSMain']['COPYPUBTOSTAGE'] = 'Do you really want to copy the published content to the stage site?';
$lang['en_US']['CMSMain']['OK'] = 'OK'; $lang['en_US']['CMSMain']['OK'] = 'OK';
$lang['en_US']['CMSMain']['CANCEL'] = 'Cancel'; $lang['en_US']['CMSMain']['CANCEL'] = 'Cancel';
$lang['en_US']['CMSMain']['PAGEPUB'] = '%d page published ';
$lang['en_US']['CMSMain']['PAGESPUB'] = '%d pages published ';
$lang['en_US']['CMSMain']['PAGEDEL'] = '%d page deleted '; $lang['en_US']['CMSMain']['PAGEDEL'] = '%d page deleted ';
$lang['en_US']['CMSMain']['PAGESDEL'] = '%d pages deleted '; $lang['en_US']['CMSMain']['PAGESDEL'] = '%d pages deleted ';
$lang['en_US']['CMSMain']['NOWBROKEN'] = ' The following pages now have broken links:'; $lang['en_US']['CMSMain']['NOWBROKEN'] = ' The following pages now have broken links:';
@ -126,19 +128,24 @@ $lang['en_US']['CMSMain_left.ss']['SITECONTENT TITLE'] = array(
PR_HIGH PR_HIGH
); );
$lang['en_US']['CMSMain_left.ss']['CREATE'] = array( $lang['en_US']['CMSMain_left.ss']['CREATE'] = array(
'Create...', 'Create',
PR_HIGH PR_HIGH
); );
$lang['en_US']['CMSMain_left.ss']['DELETE'] = array( $lang['en_US']['CMSMain_left.ss']['SEARCH'] = array(
'Delete...', 'Search',
PR_HIGH
);
$lang['en_US']['CMSMain_left.ss']['BATCHACTIONS'] = array(
'Batch Actions',
PR_HIGH PR_HIGH
); );
$lang['en_US']['CMSMain_left.ss']['ENABLEDRAGGING'] = array( $lang['en_US']['CMSMain_left.ss']['ENABLEDRAGGING'] = array(
'Allow drag &amp; drop reordering', 'Allow drag &amp; drop reordering',
PR_HIGH PR_HIGH
); );
$lang['en_US']['CMSMain_left.ss']['SELECTPAGESDEL'] = 'Select the pages that you want to delete and then click the button below'; $lang['en_US']['CMSMain_left.ss']['SELECTPAGESACTIONS'] = 'Select the pages that you want to change &amp; then click an action:';
$lang['en_US']['CMSMain_left.ss']['DELETECONFIRM'] = 'Delete the selected pages'; $lang['en_US']['CMSMain_left.ss']['DELETECONFIRM'] = 'Delete the selected pages';
$lang['en_US']['CMSMain_left.ss']['PUBLISHCONFIRM'] = 'Publish the selected pages';
$lang['en_US']['CMSMain_left.ss']['SELECTPAGESDUP'] = 'Select the pages that you want to duplicate, whether it\'s children should be included, and where you want the duplicates placed'; $lang['en_US']['CMSMain_left.ss']['SELECTPAGESDUP'] = 'Select the pages that you want to duplicate, whether it\'s children should be included, and where you want the duplicates placed';
$lang['en_US']['CMSMain_left.ss']['KEY'] = 'Key:'; $lang['en_US']['CMSMain_left.ss']['KEY'] = 'Key:';
$lang['en_US']['CMSMain_left.ss']['ADDEDNOTPUB'] = 'Added to the draft site and not published yet'; $lang['en_US']['CMSMain_left.ss']['ADDEDNOTPUB'] = 'Added to the draft site and not published yet';

View File

@ -9,8 +9,9 @@
<div id="sitetree_holder"> <div id="sitetree_holder">
<ul id="TreeActions"> <ul id="TreeActions">
<li class="action" id="addpage"><button><% _t('CREATE','Create...',PR_HIGH); %></button></li> <li class="action" id="addpage"><button><% _t('CREATE','Create',PR_HIGH); %></button></li>
<li class="action" id="deletepage"><button><% _t('DELETE','Delete...',PR_HIGH); %></button></li> <li class="action" id="search"><button><% _t('SEARCH','Search',PR_HIGH); %></button></li>
<li class="action" id="batchactions"><button><% _t('BATCHACTIONS','Batch Actions',PR_HIGH); %></button></li>
<!-- <li class="action" id="duplicate"><a href="#">Duplicate</a></li> <!-- <li class="action" id="duplicate"><a href="#">Duplicate</a></li>
Sam: this should be put into the Create area, I think, so we don't stuff up the layout --> Sam: this should be put into the Create area, I think, so we don't stuff up the layout -->
</ul> </ul>
@ -41,15 +42,21 @@
</form> </form>
<% end_control %> <% end_control %>
<div id="batchactionsforms" style="display: none">
<form class="actionparams" id="deletepage_options" style="display: none" action="admin/deleteitems"> <form class="actionparams" style="border:0" id="deletepage_options" action="admin/deleteitems">
<p><% _t('SELECTPAGESDEL','Select the pages that you want to delete and then click the button below'); %></p> <p><% _t('SELECTPAGESACTIONS','Select the pages that you want to change &amp; then click an action:'); %></p>
<div> <div>
<input type="hidden" name="csvIDs" /> <input type="hidden" name="csvIDs" />
<input type="submit" value="<% _t('DELETECONFIRM','Delete the selected pages'); %>" /> <input type="submit" id="action_delete_selected" value="<% _t('DELETECONFIRM','Delete the selected pages'); %>" />
</div> </div>
</form> </form>
<form class="actionparams" style="border:0" id="publishpage_options" action="admin/publishitems">
<div>
<input type="hidden" name="csvIDs" />
<input type="submit" id="action_publish_selected" value="<% _t('PUBLISHCONFIRM','Publish the selected pages'); %>" />
</div>
</form>
</div>
<% control DuplicatePagesOptionsForm %> <% control DuplicatePagesOptionsForm %>
<form class="actionparams" id="duplicate_options" style="display: none" action="admin/duplicateSiteTree"> <form class="actionparams" id="duplicate_options" style="display: none" action="admin/duplicateSiteTree">
<p><% _t('SELECTPAGESDUP','Select the pages that you want to duplicate, whether it\'s children should be included, and where you want the duplicates placed'); %></p> <p><% _t('SELECTPAGESDUP','Select the pages that you want to duplicate, whether it\'s children should be included, and where you want the duplicates placed'); %></p>