GridFieldBulkEditingTools/code/GridFieldBulkManager.php
colymba e4df616474 action button interactive styling
change action button style and icon depending on selected action
2012-08-11 16:21:53 +03:00

100 lines
2.4 KiB
PHP

<?php
/**
* GridField component for editing attached models in bulk
*
* @author colymba
* @package GridFieldBulkEditingTools
*/
class GridFieldBulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, GridField_URLHandler {
public function __construct()
{
}
/* GridField_ColumnProvider */
function augmentColumns($gridField, &$columns)
{
if(!in_array('BulkSelect', $columns)) $columns[] = 'BulkSelect';
}
function getColumnsHandled($gridField)
{
return array('BulkSelect');
}
function getColumnContent($gridField, $record, $columnName)
{
$cb = CheckboxField::create('bulkSelect_'.$record->ID)
->addExtraClass('bulkSelect');
return $cb->Field();
}
function getColumnAttributes($gridField, $record, $columnName)
{
return array('class' => 'col-bulkSelect');
}
function getColumnMetadata($gridField, $columnName)
{
return array('title' => null);
}
/* // GridField_ColumnProvider */
/**
*
* @param GridField $gridField
* @return array
*/
public function getHTMLFragments($gridField) {
Requirements::css(BULK_EDIT_TOOLS_PATH . '/css/GridFieldBulkManager.css');
Requirements::javascript(BULK_EDIT_TOOLS_PATH . '/javascript/GridFieldBulkManager.js');
$dropDownActionList = DropdownField::create('bulkActionName', '')
->setSource( array('Edit' => 'Edit','UnLink' => 'UnLink','Delete' => 'Delete') );
$actionButton = FormAction::create('doBulkAction', 'GO')
->setAttribute('id', 'doBulkActionButton')
//->addExtraClass('cms-panel-link')
->setAttribute('data-icon', 'pencil')
->setAttribute('data-url', 'bulkEdit')
->setUseButtonTag(true);
$html = '<div id="bulkManagerOptions">'.
$dropDownActionList->FieldHolder().
$actionButton->Field().
'</div>';
return array(
'bulk-edit-tools' => $html
);
}
/**
*
* @param GridField $gridField
* @return array
*/
public function getURLHandlers($gridField) {
return array(
'bulkEdit' => 'handlebulkEdit'
);
}
/**
* Pass control over to the RequestHandler
*
* @param GridField $gridField
* @param SS_HTTPRequest $request
* @return mixed
*/
public function handleBulkUpload($gridField, $request)
{
$controller = $gridField->getForm()->Controller();
$handler = new GridFieldBulkImageUpload_Request($gridField, $this, $controller);
return $handler->handleRequest($request, DataModel::inst());
}
}