FEATURE batch actions for setting/resetting embargo/expiry (from r85397)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@89221 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-10-15 22:44:08 +00:00
parent 2294857460
commit a7c07369e0
4 changed files with 36 additions and 7 deletions

View File

@ -38,10 +38,11 @@ abstract class CMSBatchAction extends Object {
* @param $helperMethod The method to call on each of those objects.
* @para
*/
public function batchaction(DataObjectSet $pages, $helperMethod, $successMessage) {
public function batchaction(DataObjectSet $pages, $helperMethod, $successMessage, $arguments = array()) {
foreach($pages as $page) {
// Perform the action
$page->$helperMethod();
call_user_func_array(array($page, $helperMethod), $arguments);
// Now make sure the tree title is appropriately updated
$publishedRecord = DataObject::get_by_id('SiteTree', $page->ID);
@ -59,6 +60,10 @@ abstract class CMSBatchAction extends Object {
return FormResponse::respond();
}
// if your batchaction has parameters, return a fieldset here
function getParameterFields() {
return false;
}
}
/**

View File

@ -1022,18 +1022,18 @@ JS;
$batchActions = CMSBatchActionHandler::$batch_actions;
$forms = array();
foreach($batchActions as $batchAction) {
foreach($batchActions as $urlSegment => $batchAction) {
if ($fieldset = singleton($batchAction)->getParameterFields()) {
$formHtml = '';
foreach($fieldset as $field) {
$formHtml .= $field->Field();
}
$forms[$batchAction] = $formHtml;
$forms[$urlSegment] = $formHtml;
}
}
$pageHtml = '';
foreach($forms as $class => $html) {
$pageHtml .= "<div id=\"BatchActionParameters_$class\" style=\"display:none\">$html</div>\n\n";
foreach($forms as $urlSegment => $html) {
$pageHtml .= "<div class=\"params\" id=\"BatchActionParameters_$urlSegment\">$html</div>\n\n";
}
return new LiteralField("BatchActionParameters", '<div id="BatchActionParameters" style="display:none">'.$pageHtml.'</div>');
}

View File

@ -258,6 +258,19 @@ batchactionsclass.prototype = {
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);
@ -388,6 +401,17 @@ batchActionGlobals = {
}
}
Behaviour.register({
'#choose_batch_action' : {
onchange : function() {
$('batchactions').actionChanged();
},
}
});
/**
* Publish selected pages action
*/

View File

@ -71,7 +71,7 @@
<p><% _t('SELECTPAGESACTIONS','Select the pages that you want to change &amp; then click an action:') %></p>
<input type="hidden" name="csvIDs" />
<div id="actionParams"></div>
<div>
<select id="choose_batch_action">
<% control BatchActionList %>