mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
ENHANCEMENT: Update the checkboxes available to batch-actions to show only the applicable pages for that particular action.
API CHANGE: Allow for an applicablePages($idArray) method to be defined on a CMSBatchAction class. (from r94761) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@96819 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7c6623373b
commit
ad92b80737
@ -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
|
||||
|
@ -236,7 +236,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
||||
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
||||
$siteTreeList = $obj->getChildrenAsUL(
|
||||
'',
|
||||
'"<li id=\"record-$child->ID\" class=\"$child->class " . ($child->Locked ? " nodelete" : "") . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
|
||||
'"<li id=\"record-$child->ID\" class=\"$child->class " . $child->markingClasses() . ($extraArg->isCurrentPage($child) ? " current" : "") . "\">" . ' .
|
||||
'"<a href=\"" . Controller::join_links(substr($extraArg->Link(),0,-1), "show", $child->ID) . "\" >" . $child->TreeTitle() . "</a>" ',
|
||||
$this,
|
||||
true
|
||||
|
@ -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<applicableIDs.length;i++) applicableIDMap[applicableIDs[i]] = true;
|
||||
|
||||
// Set a CSS class on each tree node indicating which can be batch-actioned and which can't
|
||||
jQuery(rootNode).find('li').each(function() {
|
||||
var id = parseInt(this.id.replace('record-',''));
|
||||
if(id) {
|
||||
if(applicableIDMap[id] === true) {
|
||||
this.removeNodeClass('nodelete');
|
||||
} else {
|
||||
// De-select the node if it's non-applicable
|
||||
delete batchActionGlobals.selectedNodes[id];
|
||||
|
||||
this.removeNodeClass('selected');
|
||||
this.addNodeClass('nodelete');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
unfilterSiteTree : function() {
|
||||
// Reload the site tree if it has been filtered
|
||||
|
@ -239,7 +239,7 @@ TreeNodeAPI.prototype = {
|
||||
installSubtreeAndRefresh : function(response){
|
||||
this.installSubtree(response);
|
||||
if(this.tree.className.indexOf('multiselect') != -1) {
|
||||
batchActionGlobals.refreshSelected();
|
||||
batchActionGlobals.refreshSelected(this);
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user