mirror of
https://github.com/colymba/GridFieldBulkEditingTools.git
synced 2024-10-22 11:05:57 +02:00
API: created ReqHdlr structure and delete routine
Request_Hanlder created with JS btn call and delete routine
This commit is contained in:
parent
e4df616474
commit
0d1f0af03a
@ -53,13 +53,13 @@ class GridFieldBulkManager implements GridField_HTMLProvider, GridField_ColumnPr
|
|||||||
Requirements::javascript(BULK_EDIT_TOOLS_PATH . '/javascript/GridFieldBulkManager.js');
|
Requirements::javascript(BULK_EDIT_TOOLS_PATH . '/javascript/GridFieldBulkManager.js');
|
||||||
|
|
||||||
$dropDownActionList = DropdownField::create('bulkActionName', '')
|
$dropDownActionList = DropdownField::create('bulkActionName', '')
|
||||||
->setSource( array('Edit' => 'Edit','UnLink' => 'UnLink','Delete' => 'Delete') );
|
->setSource( array('edit' => 'Edit','unlink' => 'UnLink','delete' => 'Delete') );
|
||||||
|
|
||||||
$actionButton = FormAction::create('doBulkAction', 'GO')
|
$actionButton = FormAction::create('doBulkAction', 'GO')
|
||||||
->setAttribute('id', 'doBulkActionButton')
|
->setAttribute('id', 'doBulkActionButton')
|
||||||
//->addExtraClass('cms-panel-link')
|
//->addExtraClass('cms-panel-link')
|
||||||
->setAttribute('data-icon', 'pencil')
|
->setAttribute('data-icon', 'pencil')
|
||||||
->setAttribute('data-url', 'bulkEdit')
|
->setAttribute('data-url', $gridField->Link('bulkEdit'))
|
||||||
->setUseButtonTag(true);
|
->setUseButtonTag(true);
|
||||||
|
|
||||||
$html = '<div id="bulkManagerOptions">'.
|
$html = '<div id="bulkManagerOptions">'.
|
||||||
@ -90,10 +90,10 @@ class GridFieldBulkManager implements GridField_HTMLProvider, GridField_ColumnPr
|
|||||||
* @param SS_HTTPRequest $request
|
* @param SS_HTTPRequest $request
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function handleBulkUpload($gridField, $request)
|
public function handlebulkEdit($gridField, $request)
|
||||||
{
|
{
|
||||||
$controller = $gridField->getForm()->Controller();
|
$controller = $gridField->getForm()->Controller();
|
||||||
$handler = new GridFieldBulkImageUpload_Request($gridField, $this, $controller);
|
$handler = new GridFieldBulkManager_Request($gridField, $this, $controller);
|
||||||
|
|
||||||
return $handler->handleRequest($request, DataModel::inst());
|
return $handler->handleRequest($request, DataModel::inst());
|
||||||
}
|
}
|
||||||
|
119
code/GridFieldBulkManager_Request.php
Normal file
119
code/GridFieldBulkManager_Request.php
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author colymba
|
||||||
|
* @package GridFieldBulkEditingTools
|
||||||
|
*/
|
||||||
|
class GridFieldBulkManager_Request extends RequestHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var GridField
|
||||||
|
*/
|
||||||
|
protected $gridField;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var GridField_URLHandler
|
||||||
|
*/
|
||||||
|
protected $component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @var Controller
|
||||||
|
*/
|
||||||
|
protected $controller;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static $url_handlers = array(
|
||||||
|
'$Action!' => '$Action'
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param GridFIeld $gridField
|
||||||
|
* @param GridField_URLHandler $component
|
||||||
|
* @param Controller $controller
|
||||||
|
*/
|
||||||
|
public function __construct($gridField, $component, $controller) {
|
||||||
|
$this->gridField = $gridField;
|
||||||
|
$this->component = $component;
|
||||||
|
$this->controller = $controller;
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the URL for this RequestHandler
|
||||||
|
*
|
||||||
|
* @author SilverStripe
|
||||||
|
* @see GridFieldDetailForm_ItemRequest
|
||||||
|
* @param string $action
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function Link($action = null) {
|
||||||
|
return Controller::join_links($this->gridField->Link(), 'bulkimageupload', $action);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function edit(SS_HTTPRequest $request)
|
||||||
|
{
|
||||||
|
$recordList = $request->requestVars();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function unlink(SS_HTTPRequest $request)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(SS_HTTPRequest $request)
|
||||||
|
{
|
||||||
|
$recordList = $this->getPOSTRecordList($request);
|
||||||
|
$recordClass = $this->gridField->list->dataClass;
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
foreach ( $recordList as $id )
|
||||||
|
{
|
||||||
|
$res = DataObject::delete_by_id($recordClass, $id);
|
||||||
|
array_push($result, array($id => $res));
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = new SS_HTTPResponse(Convert::raw2json(array($result)));
|
||||||
|
$response->addHeader('Content-Type', 'text/plain');
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getPOSTRecordList(SS_HTTPRequest $request)
|
||||||
|
{
|
||||||
|
$recordList = $request->requestVars();
|
||||||
|
return $recordList['records'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edited version of the GridFieldEditForm function
|
||||||
|
* adds the 'Bulk Upload' at the end of the crums
|
||||||
|
*
|
||||||
|
* CMS-specific functionality: Passes through navigation breadcrumbs
|
||||||
|
* to the template, and includes the currently edited record (if any).
|
||||||
|
* see {@link LeftAndMain->Breadcrumbs()} for details.
|
||||||
|
*
|
||||||
|
* @author SilverStripe original Breadcrumbs() method
|
||||||
|
* @see GridFieldDetailForm_ItemRequest
|
||||||
|
* @param boolean $unlinked
|
||||||
|
* @return ArrayData
|
||||||
|
*/
|
||||||
|
function Breadcrumbs($unlinked = false) {
|
||||||
|
if(!$this->controller->hasMethod('Breadcrumbs')) return;
|
||||||
|
|
||||||
|
$items = $this->controller->Breadcrumbs($unlinked);
|
||||||
|
$items->push(new ArrayData(array(
|
||||||
|
'Title' => 'Bulk Upload',
|
||||||
|
'Link' => false
|
||||||
|
)));
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
}
|
@ -32,7 +32,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#bulkActionName').entwine({
|
$('select#bulkActionName').entwine({
|
||||||
onmatch: function(){
|
onmatch: function(){
|
||||||
},
|
},
|
||||||
onunmatch: function(){
|
onunmatch: function(){
|
||||||
@ -44,19 +44,19 @@
|
|||||||
icon = $('#doBulkActionButton .ui-icon');
|
icon = $('#doBulkActionButton .ui-icon');
|
||||||
|
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case 'Edit':
|
case 'edit':
|
||||||
$(btn).removeClass('ss-ui-action-destructive');
|
$(btn).removeClass('ss-ui-action-destructive');
|
||||||
$(btn).attr('data-icon', 'pencil');
|
$(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').addClass('btn-icon-pencil');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'UnLink':
|
case 'unlink':
|
||||||
$(btn).removeClass('ss-ui-action-destructive');
|
$(btn).removeClass('ss-ui-action-destructive');
|
||||||
$(btn).attr('data-icon', 'chain--minus');
|
$(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').addClass('btn-icon-chain--minus');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Delete':
|
case 'delete':
|
||||||
$(btn).addClass('ss-ui-action-destructive');
|
$(btn).addClass('ss-ui-action-destructive');
|
||||||
$(btn).attr('data-icon', 'decline');
|
$(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').addClass('btn-icon-decline');
|
||||||
@ -66,12 +66,31 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//@TODO prevent button click to call default url request
|
||||||
$('#doBulkActionButton').entwine({
|
$('#doBulkActionButton').entwine({
|
||||||
onmatch: function(){
|
onmatch: function(){
|
||||||
},
|
},
|
||||||
onunmatch: function(){
|
onunmatch: function(){
|
||||||
},
|
},
|
||||||
onclick: function(e) {
|
onclick: function(e) {
|
||||||
|
var action, url, data = {}, ids = [], cacheBuster;
|
||||||
|
action = $('select#bulkActionName').val();
|
||||||
|
url = $(this).data('url');
|
||||||
|
cacheBuster = new Date().getTime();
|
||||||
|
|
||||||
|
$('.col-bulkSelect input:checked').each(function(){
|
||||||
|
ids.push( parseInt( $(this).attr('name').split('_')[1] ) );
|
||||||
|
});
|
||||||
|
data.records = ids;
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url + '/' + action + '?cacheBuster=' + cacheBuster,
|
||||||
|
data: data,
|
||||||
|
type: "POST",
|
||||||
|
context: $(this)
|
||||||
|
}).done(function() {
|
||||||
|
//@TODO refresh GridField
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user