diff --git a/code/CMSBatchActionHandler.php b/code/CMSBatchActionHandler.php
index 3ccadcee..bed33ba3 100644
--- a/code/CMSBatchActionHandler.php
+++ b/code/CMSBatchActionHandler.php
@@ -13,7 +13,8 @@ class CMSBatchActionHandler extends RequestHandler {
);
static $url_handlers = array(
- '$BatchAction' => 'handleAction'
+ '$BatchAction/applicablepages' => 'handleApplicablePages',
+ '$BatchAction' => 'handleAction',
);
protected $parentController;
@@ -80,6 +81,28 @@ class CMSBatchActionHandler extends RequestHandler {
return $actionHandler->run($pages);
}
+
+ function handleApplicablePages($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('applicablePages')) {
+ $applicableIDs = $actionHandler->applicablePages($ids);
+ } else {
+ $applicableIDs = $ids;
+ }
+
+ $response = new HTTPResponse(json_encode($applicableIDs));
+ $response->addHeader("Content-type", "application/json");
+ return $response;
+ }
/**
* Return a DataObjectSet of ArrayData objects containing the following pieces of info
diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php
index 743f8fd1..3a18553a 100644
--- a/code/SecurityAdmin.php
+++ b/code/SecurityAdmin.php
@@ -236,7 +236,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
// getChildrenAsUL is a flexible and complex way of traversing the tree
$siteTreeList = $obj->getChildrenAsUL(
'',
- '"
ID\" class=\"$child->class " . ($child->Locked ? " nodelete" : "") . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
+ '"ID\" class=\"$child->class " . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
'"Link(),0,-1), "show", $child->ID) . "\" >" . $child->TreeTitle() . "" ',
$this,
true
diff --git a/javascript/CMSMain_left.js b/javascript/CMSMain_left.js
index 83793f04..1a584db2 100755
--- a/javascript/CMSMain_left.js
+++ b/javascript/CMSMain_left.js
@@ -257,11 +257,13 @@ batchactionsclass.prototype = {
onclick : function() {
if(treeactions.toggleSelection(this)) {
this.multiselectTransform();
+ this.actionChanged();
}
return false;
},
actionChanged: function() {
+ // Show parameters form, if necessary
var urlSegment = $('choose_batch_action').value.split('/').pop();
if ($('BatchActionParameters_'+urlSegment)) {
jQuery('#BatchActionParameters .params').hide();
@@ -270,6 +272,8 @@ batchactionsclass.prototype = {
} else {
jQuery('#BatchActionParameters').hide();
}
+
+ batchActionGlobals.refreshSelected();
},
multiselectTransform : function() {
@@ -378,12 +382,53 @@ batchActionGlobals = {
getCsvIds : function() {
return (batchActionGlobals.getIds().toString());
},
- refreshSelected : function() {
+ refreshSelected : function(rootNode) {
var st = $('sitetree');
+
for(var idx in batchActionGlobals.selectedNodes) {
st.getTreeNodeByIdx(idx).addNodeClass('selected');
st.getTreeNodeByIdx(idx).selected = true;
}
+
+ // Default to refreshing the entire tree
+ if(rootNode == null) rootNode = st;
+
+ /// If batch actions is enabled, then enable/disable the appropriate tree fields
+ if($('batchactionsforms').style.display != 'none' && $('choose_batch_action').value) {
+ // Collect list of visible tree IDs
+ var ids = [];
+ jQuery(rootNode).find('li').each(function() {
+ var id = parseInt(this.id.replace('record-',''));
+ if(id) ids.push(id);
+
+ // Disable the nodes while the ajax request is being processed
+ this.addNodeClass('nodelete');
+ });
+
+ // Post to the server to ask which pages can have this batch action applied
+ var applicablePagesURL = $('choose_batch_action').value + '/applicablepages?csvIDs=' + ids.join(',') + ',horse';
+ jQuery.getJSON(applicablePagesURL, function(applicableIDs) {
+ var i;
+ var applicableIDMap = {};
+ for(i=0;i