From ba0adbc48dabe300ded779c28f67e09f5193f17a Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 4 Feb 2010 04:56:16 +0000 Subject: [PATCH] ENHANCEMENT batchactions can now implement confirmationDialog() to provide a custom confirmation dialog to the front end. MINOR added above confiration to batch setting expiry (from r97215) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@98211 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/CMSBatchActionHandler.php | 22 ++++++++++ javascript/CMSMain_left.js | 74 ++++++++++++++++++++-------------- 2 files changed, 66 insertions(+), 30 deletions(-) diff --git a/code/CMSBatchActionHandler.php b/code/CMSBatchActionHandler.php index e4ae65d4..ff8f1617 100644 --- a/code/CMSBatchActionHandler.php +++ b/code/CMSBatchActionHandler.php @@ -14,6 +14,7 @@ class CMSBatchActionHandler extends RequestHandler { static $url_handlers = array( '$BatchAction/applicablepages' => 'handleApplicablePages', + '$BatchAction/confirmation' => 'handleConfirmation', '$BatchAction' => 'handleAction', ); @@ -104,6 +105,27 @@ class CMSBatchActionHandler extends RequestHandler { return $response; } + function handleConfirmation($request) { + // Find the action handler + $actions = Object::get_static($this->class, 'batch_actions'); + $actionClass = $actions[$request->param('BatchAction')]; + $actionHandler = new $actionClass(); + + // Sanitise ID list and query the database for apges + $ids = split(' *, *', trim($request->requestVar('csvIDs'))); + foreach($ids as $k => $id) $ids[$k] = (int)$id; + $ids = array_filter($ids); + + if($actionHandler->hasMethod('confirmationDialog')) { + $response = new HTTPResponse(json_encode($actionHandler->confirmationDialog($ids))); + } else { + $response = new HTTPResponse(json_encode(array('alert' => false))); + } + + $response->addHeader("Content-type", "application/json"); + return $response; + } + /** * Return a DataObjectSet of ArrayData objects containing the following pieces of info * about each batch action: diff --git a/javascript/CMSMain_left.js b/javascript/CMSMain_left.js index b1c60d9a..8b1f2b7d 100755 --- a/javascript/CMSMain_left.js +++ b/javascript/CMSMain_left.js @@ -537,8 +537,6 @@ Behaviour.register({ } }); - - /** * Publish selected pages action */ @@ -550,42 +548,58 @@ publishpage.prototype = { 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'; - - // 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); + 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; + } } + + $('batchactions_options').submitform(); }); } else { alert(ss.i18n._t('CMSMAIN.SELECTONEPAGE')); } return false; + }, + + 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); + } + }); } };