mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 09:05:57 +00:00
FEATURE: Added publish and unpublish bulk actions request handler
This commit is contained in:
parent
a306ba448b
commit
96617d578a
87
code/VersionedGridFieldBulkManager_Request.php
Normal file
87
code/VersionedGridFieldBulkManager_Request.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Milkyway Multimedia
|
||||
* VersionedGridFieldBulkManager_Request.php
|
||||
*
|
||||
* Adding extra bulk edit actions specifically for versioned objects,
|
||||
* just like the Multi-selection action dropdown in the Pages section
|
||||
*
|
||||
* @package GridFieldBulkEditingTools
|
||||
* @author Mellisa Hankins
|
||||
* @author colymba
|
||||
*/
|
||||
|
||||
class VersionedGridFieldBulkManager_Request extends GridFieldBulkManager_Request {
|
||||
private static $allowed_actions = array(
|
||||
'edit',
|
||||
'update',
|
||||
'unlink',
|
||||
'delete',
|
||||
'publish',
|
||||
'unpublish',
|
||||
);
|
||||
|
||||
public function publish(SS_HTTPRequest $request) {
|
||||
$recordList = $this->getPOSTRecordList($request);
|
||||
$records = $this->gridField->List->byIDs($recordList);
|
||||
|
||||
foreach($records as $record) {
|
||||
if(!$this->doPublish($record))
|
||||
unset($recordList[$record->ID]);
|
||||
}
|
||||
|
||||
$this->completeAction($recordList);
|
||||
}
|
||||
|
||||
public function unpublish(SS_HTTPRequest $request) {
|
||||
$recordList = $this->getPOSTRecordList($request);
|
||||
$records = $this->gridField->List->byIDs($recordList);
|
||||
|
||||
foreach($records as $record) {
|
||||
if(!$this->doUnpublish($record))
|
||||
unset($recordList[$record->ID]);
|
||||
}
|
||||
|
||||
$this->completeAction($recordList);
|
||||
}
|
||||
|
||||
protected function doPublish($record) {
|
||||
if(!$record || !$record->hasExtension('Versioned') || ($record->hasMethod('canPublish') && !$record->canPublish())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($record->hasMethod('doPublish'))
|
||||
$record->doPublish();
|
||||
else
|
||||
$record->publish("Stage", "Live");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function doUnpublish($record) {
|
||||
if(!$record || !$record->hasExtension('Versioned') || ($record->hasMethod('canDeleteFromLive') && !$record->canDeleteFromLive())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if($record->hasMethod('doPublish'))
|
||||
$record->doUnpublish();
|
||||
else {
|
||||
$origStage = Versioned::current_stage();
|
||||
Versioned::reading_stage('Live');
|
||||
|
||||
// This way our ID won't be unset
|
||||
$clone = clone $record;
|
||||
$clone->delete();
|
||||
|
||||
Versioned::reading_stage($origStage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function completeAction($recordList = null) {
|
||||
$response = new SS_HTTPResponse(Convert::raw2json(array($recordList)));
|
||||
$response->addHeader('Content-Type', 'text/plain');
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -58,22 +58,36 @@
|
||||
case 'edit':
|
||||
$(btn).removeClass('ss-ui-action-destructive');
|
||||
$(btn).attr('data-icon', 'pencil');
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil').addClass('btn-icon-pencil');
|
||||
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil btn-icon-unpublish btn-icon-accept').addClass('btn-icon-pencil');
|
||||
|
||||
$(btn).attr('href', $(btn).data('url')+'/edit');
|
||||
break;
|
||||
|
||||
|
||||
case 'unlink':
|
||||
$(btn).removeClass('ss-ui-action-destructive');
|
||||
$(btn).attr('data-icon', 'chain--minus');
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil').addClass('btn-icon-chain--minus');
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil btn-icon-unpublish btn-icon-accept').addClass('btn-icon-chain--minus');
|
||||
$(btn).removeAttr('href');
|
||||
break;
|
||||
|
||||
|
||||
case 'delete':
|
||||
$(btn).addClass('ss-ui-action-destructive');
|
||||
$(btn).attr('data-icon', 'decline');
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil').addClass('btn-icon-decline');
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil btn-icon-unpublish btn-icon-accept').addClass('btn-icon-decline');
|
||||
$(btn).removeAttr('href');
|
||||
break;
|
||||
|
||||
case 'publish':
|
||||
$(btn).removeClass('ss-ui-action-destructive');
|
||||
$(btn).attr('data-icon', 'accept');
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil btn-icon-unpublish btn-icon-chain--minus').addClass('btn-icon-accept');
|
||||
$(btn).removeAttr('href');
|
||||
break;
|
||||
|
||||
case 'unpublish':
|
||||
$(btn).removeClass('ss-ui-action-destructive');
|
||||
$(btn).attr('data-icon', 'unpublish');
|
||||
$(icon).removeClass('btn-icon-decline btn-icon-pencil btn-icon-accept').addClass('btn-icon-unpublish');
|
||||
$(btn).removeAttr('href');
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user