mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
NEW Versioned Bulk Actions (Publish, Unpublish & Archive)
This commit is contained in:
parent
2eb86854d7
commit
cb123a1793
@ -7,6 +7,9 @@ en:
|
|||||||
DELETE_SELECT_LABEL: Delete
|
DELETE_SELECT_LABEL: Delete
|
||||||
ACTION_BTN_LABEL: Go
|
ACTION_BTN_LABEL: Go
|
||||||
SELECT_ALL_LABEL: Select all
|
SELECT_ALL_LABEL: Select all
|
||||||
|
PUBLISH_SELECT_LABEL: Publish
|
||||||
|
UNPUBLISH_SELECT_LABEL: UnPublish
|
||||||
|
ARCHIVE_SELECT_LABEL: Archive
|
||||||
GRIDFIELD_BULKMANAGER_EDIT_HANDLER:
|
GRIDFIELD_BULKMANAGER_EDIT_HANDLER:
|
||||||
HEADER_TEXT: Editing {count} {class}
|
HEADER_TEXT: Editing {count} {class}
|
||||||
TOGGLE_ALL_LINK: Show/Hide all
|
TOGGLE_ALL_LINK: Show/Hide all
|
||||||
|
121
src/BulkManager/BulkAction/ArchiveHandler.php
Normal file
121
src/BulkManager/BulkAction/ArchiveHandler.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk action handler for recursive archiving records.
|
||||||
|
*
|
||||||
|
* @author colymba
|
||||||
|
*/
|
||||||
|
class ArchiveHandler extends Handler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* URL segment used to call this handler
|
||||||
|
* If none given, @BulkManager will fallback to the Unqualified class name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $url_segment = 'archive';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RequestHandler allowed actions.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $allowed_actions = array('archive');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RequestHandler url => action map.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $url_handlers = array(
|
||||||
|
'' => 'archive',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front-end label for this handler's action
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $label = 'Archive';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front-end icon path for this handler's action.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $icon = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra classes to add to the bulk action button for this handler
|
||||||
|
* Can also be used to set the button font-icon e.g. font-icon-trash
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $buttonClasses = 'font-icon-trash';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this handler should be called via an XHR from the front-end
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $xhr = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to true is this handler will destroy any data.
|
||||||
|
* A warning and confirmation will be shown on the front-end.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $destructive = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return i18n localized front-end label
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getI18nLabel()
|
||||||
|
{
|
||||||
|
return _t('GRIDFIELD_BULK_MANAGER.ARCHIVE_SELECT_LABEL', $this->getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Archive the selected records passed from the archive bulk action.
|
||||||
|
*
|
||||||
|
* @param HTTPRequest $request
|
||||||
|
*
|
||||||
|
* @return HTTPResponse List of affected records ID
|
||||||
|
*/
|
||||||
|
public function archive(HTTPRequest $request)
|
||||||
|
{
|
||||||
|
$records = $this->getRecords();
|
||||||
|
|
||||||
|
$successes = array();
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
foreach ($records as $record)
|
||||||
|
{
|
||||||
|
$done = $record->doArchive();
|
||||||
|
if ($done)
|
||||||
|
{
|
||||||
|
array_push($successes, $record->ID);
|
||||||
|
}else{
|
||||||
|
array_push($errors, array('id' => $record->ID, 'message' => $done));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = new HTTPResponse(Convert::raw2json(array(
|
||||||
|
'done' => $successes,
|
||||||
|
'errors' => $errors,
|
||||||
|
)));
|
||||||
|
$response->addHeader('Content-Type', 'text/json');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
121
src/BulkManager/BulkAction/PublishHandler.php
Normal file
121
src/BulkManager/BulkAction/PublishHandler.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk action handler for recursive publishing records.
|
||||||
|
*
|
||||||
|
* @author colymba
|
||||||
|
*/
|
||||||
|
class PublishHandler extends Handler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* URL segment used to call this handler
|
||||||
|
* If none given, @BulkManager will fallback to the Unqualified class name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $url_segment = 'publish';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RequestHandler allowed actions.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $allowed_actions = array('publish');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RequestHandler url => action map.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $url_handlers = array(
|
||||||
|
'' => 'publish',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front-end label for this handler's action
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $label = 'Publish';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front-end icon path for this handler's action.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $icon = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra classes to add to the bulk action button for this handler
|
||||||
|
* Can also be used to set the button font-icon e.g. font-icon-trash
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $buttonClasses = 'font-icon-rocket';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this handler should be called via an XHR from the front-end
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $xhr = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to true is this handler will destroy any data.
|
||||||
|
* A warning and confirmation will be shown on the front-end.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $destructive = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return i18n localized front-end label
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getI18nLabel()
|
||||||
|
{
|
||||||
|
return _t('GRIDFIELD_BULK_MANAGER.PUBLISH_SELECT_LABEL', $this->getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish the selected records passed from the publish bulk action.
|
||||||
|
*
|
||||||
|
* @param HTTPRequest $request
|
||||||
|
*
|
||||||
|
* @return HTTPResponse List of affected records ID
|
||||||
|
*/
|
||||||
|
public function publish(HTTPRequest $request)
|
||||||
|
{
|
||||||
|
$records = $this->getRecords();
|
||||||
|
|
||||||
|
$successes = array();
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
foreach ($records as $record)
|
||||||
|
{
|
||||||
|
$done = $record->publishRecursive();
|
||||||
|
if ($done)
|
||||||
|
{
|
||||||
|
array_push($successes, $record->ID);
|
||||||
|
}else{
|
||||||
|
array_push($errors, array('id' => $record->ID, 'message' => $done));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = new HTTPResponse(Convert::raw2json(array(
|
||||||
|
'done' => $successes,
|
||||||
|
'errors' => $errors,
|
||||||
|
)));
|
||||||
|
$response->addHeader('Content-Type', 'text/json');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
121
src/BulkManager/BulkAction/UnPublishHandler.php
Normal file
121
src/BulkManager/BulkAction/UnPublishHandler.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk action handler for recursive unpublishing records.
|
||||||
|
*
|
||||||
|
* @author colymba
|
||||||
|
*/
|
||||||
|
class UnPublishHandler extends Handler
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* URL segment used to call this handler
|
||||||
|
* If none given, @BulkManager will fallback to the Unqualified class name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $url_segment = 'unpublish';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RequestHandler allowed actions.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $allowed_actions = array('unPublish');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RequestHandler url => action map.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $url_handlers = array(
|
||||||
|
'' => 'unPublish',
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front-end label for this handler's action
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $label = 'UnPublish';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Front-end icon path for this handler's action.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $icon = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extra classes to add to the bulk action button for this handler
|
||||||
|
* Can also be used to set the button font-icon e.g. font-icon-trash
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $buttonClasses = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this handler should be called via an XHR from the front-end
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $xhr = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to true is this handler will destroy any data.
|
||||||
|
* A warning and confirmation will be shown on the front-end.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $destructive = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return i18n localized front-end label
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getI18nLabel()
|
||||||
|
{
|
||||||
|
return _t('GRIDFIELD_BULK_MANAGER.UNPUBLISH_SELECT_LABEL', $this->getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UnPublish the selected records passed from the unPublish bulk action.
|
||||||
|
*
|
||||||
|
* @param HTTPRequest $request
|
||||||
|
*
|
||||||
|
* @return HTTPResponse List of affected records ID
|
||||||
|
*/
|
||||||
|
public function unPublish(HTTPRequest $request)
|
||||||
|
{
|
||||||
|
$records = $this->getRecords();
|
||||||
|
|
||||||
|
$successes = array();
|
||||||
|
$errors = array();
|
||||||
|
|
||||||
|
foreach ($records as $record)
|
||||||
|
{
|
||||||
|
$done = $record->doUnpublish();
|
||||||
|
if ($done)
|
||||||
|
{
|
||||||
|
array_push($successes, $record->ID);
|
||||||
|
}else{
|
||||||
|
array_push($errors, array('id' => $record->ID, 'message' => $done));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = new HTTPResponse(Convert::raw2json(array(
|
||||||
|
'done' => $successes,
|
||||||
|
'errors' => $errors,
|
||||||
|
)));
|
||||||
|
$response->addHeader('Content-Type', 'text/json');
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
}
|
@ -45,7 +45,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
|
|||||||
* @param array $editableFields List of editable fields
|
* @param array $editableFields List of editable fields
|
||||||
* @param bool $defaultActions Use default actions list. False to start fresh.
|
* @param bool $defaultActions Use default actions list. False to start fresh.
|
||||||
*/
|
*/
|
||||||
public function __construct($editableFields = null, $defaultActions = true)
|
public function __construct($editableFields = null, $defaultActions = true, $defaultVersionedActions = false)
|
||||||
{
|
{
|
||||||
if ($editableFields != null) {
|
if ($editableFields != null) {
|
||||||
$this->setConfig('editableFields', $editableFields);
|
$this->setConfig('editableFields', $editableFields);
|
||||||
@ -56,6 +56,13 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
|
|||||||
->addBulkAction(BulkAction\EditHandler::class)
|
->addBulkAction(BulkAction\EditHandler::class)
|
||||||
->addBulkAction(BulkAction\UnlinkHandler::class)
|
->addBulkAction(BulkAction\UnlinkHandler::class)
|
||||||
->addBulkAction(BulkAction\DeleteHandler::class);
|
->addBulkAction(BulkAction\DeleteHandler::class);
|
||||||
|
} elseif ($defaultVersionedActions) {
|
||||||
|
$this
|
||||||
|
->addBulkAction(BulkAction\EditHandler::class)
|
||||||
|
->addBulkAction(BulkAction\UnlinkHandler::class)
|
||||||
|
->addBulkAction(BulkAction\ArchiveHandler::class)
|
||||||
|
->addBulkAction(BulkAction\UnPublishHandler::class)
|
||||||
|
->addBulkAction(BulkAction\PublishHandler::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user