diff --git a/.upgrade.yml b/.upgrade.yml
new file mode 100644
index 0000000..49a211d
--- /dev/null
+++ b/.upgrade.yml
@@ -0,0 +1,10 @@
+mappings:
+ GridFieldBulkActionDeleteHandler: Colymba\BulkManager\BulkAction\DeleteHandler
+ GridFieldBulkActionEditHandler: Colymba\BulkManager\BulkAction\EditHandler
+ GridFieldBulkActionHandler: Colymba\BulkManager\BulkAction\Handler
+ GridFieldBulkActionUnlinkHandler: Colymba\BulkManager\BulkAction\UnlinkHandler
+ GridFieldBulkManager: Colymba\BulkManager\BulkManager
+ BulkUploadField: Colymba\BulkUpload\BulkUploadField
+ GridFieldBulkImageUpload: Colymba\BulkUpload\GridFieldBulkImageUpload
+ GridFieldBulkUpload: Colymba\BulkUpload\BulkUploader
+ GridFieldBulkUpload_Request: Colymba\BulkUpload\BulkUploadRequest
diff --git a/README.md b/README.md
index 45cee45..3c0c7e6 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ GridField Bulk Editing Tools
[![Latest Unstable Version](https://poser.pugx.org/colymba/gridfield-bulk-editing-tools/v/unstable.svg)](https://github.com/colymba/GridFieldBulkEditingTools/tree/master)
[![License](https://poser.pugx.org/colymba/gridfield-bulk-editing-tools/license.svg)](#license-bsd-simplified)
-Set of SilverStripe 3 GridField components to facilitate bulk file upload & record editing.
+Set of SilverStripe 4 GridField components to facilitate bulk file upload & record editing.
![preview](screenshots/preview.png)
@@ -16,37 +16,47 @@ Set of SilverStripe 3 GridField components to facilitate bulk file upload & reco
[More screenshots here.](screenshots)
## Requirements
-* SilverStripe 3.1 (version master / 2.+ / 1.+)
+* SilverStripe 4.0 (version master / 3.+)
+* SilverStripe 3.1 (version 2.+ / 1.+)
* Silverstripe 3.0 (version [0.5](https://github.com/colymba/GridFieldBulkEditingTools/tree/0.5))
## Installation
### Composer
-* `composer require "colymba/gridfield-bulk-editing-tools:*"`
+* `composer require colymba/gridfield-bulk-editing-tools`
### Manual
* Download and copy module in SilverStripe root directory
+## 3.0.0 deprecations
+The 3.x versions of this module require SilverStripe 4.x+, and PHP 5.5 or above:
+
+* Namespaces are implemented, and some class names have changed (see `.upgrade.yml` for mapping)
+
## 2.0.0 deprecations
-Major depractions in latest 2.0.0 release:
+Major deprections in latest 2.0.0 release:
* The `GridFieldBulkImageUpload` has been renamed to `GridFieldBulkUpload`.
* `onBulkImageUpload` callback has been renamed to `onBulkUpload`
## Bulk Upload
Upload multiple images or files at once into DataObjects. Perfect for galleries and the like.
- $config->addComponent(new GridFieldBulkUpload());
+```php
+$config->addComponent(new \Colymba\BulkUpload\BulkUploader());
+```
See [BULK_UPLOAD.md](bulkUpload/BULK_UPLOAD.md) for detailed configuration.
## Bulk Manager
Perform actions on multiple records straight from the GridField
- $config->addComponent(new GridFieldBulkManager());
+```php
+$config->addComponent(new \Colymba\BulkManager\BulkManager());
+```
See [BULK_MANAGER.md](bulkManager/BULK_MANAGER.md) for detailed configuration.
## Interdependencies
-The `GridFieldBulkUpload` component makes use of `GridFieldBulkManager` to allow quick editing of the newly uploaded files. Although not nescessary for the component to work, adding `GridFieldBulkManager` too to your `GridFieldConfig` will give you this advantage.
+The `BulkUploader` component makes use of `BulkManager` to allow quick editing of the newly uploaded files. Although not nescessary for the component to work, adding `Colymba\BulkManager\BulkManager` too to your `GridFieldConfig` will give you this advantage.
#### @TODO
* Add individual actions for each upload (update + cancel)
@@ -69,5 +79,5 @@ Redistribution and use in source and binary forms, with or without modification,
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Thierry Francois, colymba nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/_config.php b/_config.php
index 5ed7c55..332f216 100644
--- a/_config.php
+++ b/_config.php
@@ -3,6 +3,6 @@
if (!defined('BULKEDITTOOLS_PATH')) {
$folder = rtrim(basename(dirname(__FILE__)));
define('BULKEDITTOOLS_PATH', $folder);
- define('BULKEDITTOOLS_UPLOAD_PATH', $folder.'/bulkUpload');
- define('BULKEDITTOOLS_MANAGER_PATH', $folder.'/bulkManager');
+ define('BULKEDITTOOLS_UPLOAD_PATH', $folder . '/bulkUpload');
+ define('BULKEDITTOOLS_MANAGER_PATH', $folder . '/bulkManager');
}
diff --git a/build.xml b/build.xml
deleted file mode 100644
index 1fdf69a..0000000
--- a/build.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/bulkManager/BULK_MANAGER.md b/bulkManager/BULK_MANAGER.md
index b975f8b..061e939 100644
--- a/bulkManager/BULK_MANAGER.md
+++ b/bulkManager/BULK_MANAGER.md
@@ -3,14 +3,18 @@ Perform actions on multiple records straight from the GridField. Comes with *unl
## Usage
Simply add component to your `GridFieldConfig`
-
- $config->addComponent(new GridFieldBulkManager());
-
+
+```php
+$config->addComponent(new \Colymba\BulkManager\BulkManager());
+```
+
## Configuration
The component's options can be configurated individually or in bulk through the 'config' functions like this:
- $config->getComponentByType('GridFieldBulkManager')->setConfig($reference, $value);
-
+```php
+$config->getComponentByType('Colymba\\BulkManager\\BulkManager')->setConfig($reference, $value);
+```
+
### $config overview
The available configuration options are:
* 'editableFields' : array of string referencing specific CMS fields available for editing
@@ -21,19 +25,23 @@ You can remove or add individual action or replace them all via `addBulkAction()
### Adding a custom action
To add a custom bulk action to the list use:
- $config->getComponentByType('GridFieldBulkManager')->addBulkAction('actionName', 'Dropdown label', 'ActionHandlerClassName', $frontEndConfig)
+```php
+$config
+ ->getComponentByType('Colymba\\BulkManager\\BulkManager')
+ ->addBulkAction('actionName', 'Dropdown label', 'ActionHandlerClassName', $frontEndConfig)
+```
You can omit the handler's class name and the front-end config array, those will default to:
* `'GridFieldBulkAction'.ucfirst($name).'Handler'`
* `$config = array( 'isAjax' => true, 'icon' => 'accept', 'isDestructive' => false )`
#### Custom action handler
-When creating your own bulk action `RequestHandler`, you should extend `GridFieldBulkActionHandler` which will expose 2 usefull functions `getRecordIDList()` and `getRecords()` returning either an array with the selected records IDs or a `DataList` of the selected records.
+When creating your own bulk action `RequestHandler`, you should extend `Colymba\BulkManager\BulkAction\Handler` which will expose 2 useful functions `getRecordIDList()` and `getRecords()` returning either an array with the selected records IDs or a `DataList` of the selected records.
-Make sure to define your `$allowed_actions` and `$url_handlers` on your custom bulk action handler. See `GridFieldBulkActionEditHandler`, `GridFieldBulkActionDeleteHandler` and `GridFieldBulkActionUnlinkHandler` for examples.
+Make sure to define your `$allowed_actions` and `$url_handlers` on your custom bulk action handler. See `Handler`, `DeleteHandler` and `UnlinkHandler` for examples.
#### Front-end config
The last `addBulkAction()` parameter lets you pass an array with configuration options for the UI/UX:
* `isAjax`: if true the action will be called via XHR request otherwise the browser will be redirected to the action's URL
* `icon`: lets you define which icon to use on the button when the action is selected (SilverStripe button icon name only)
-* `isDestructive`: if true, a confirmation dialog will be shown before the action is processed
\ No newline at end of file
+* `isDestructive`: if true, a confirmation dialog will be shown before the action is processed
diff --git a/bulkManager/code/GridFieldBulkActionDeleteHandler.php b/bulkManager/code/BulkAction/DeleteHandler.php
similarity index 64%
rename from bulkManager/code/GridFieldBulkActionDeleteHandler.php
rename to bulkManager/code/BulkAction/DeleteHandler.php
index b6f5f06..4453ccc 100644
--- a/bulkManager/code/GridFieldBulkActionDeleteHandler.php
+++ b/bulkManager/code/BulkAction/DeleteHandler.php
@@ -1,10 +1,18 @@
delete();
}
- $response = new SS_HTTPResponse(Convert::raw2json(array(
+ $response = new HTTPResponse(Convert::raw2json(array(
'done' => true,
'records' => $ids,
)));
diff --git a/bulkManager/code/GridFieldBulkActionEditHandler.php b/bulkManager/code/BulkAction/EditHandler.php
similarity index 81%
rename from bulkManager/code/GridFieldBulkActionEditHandler.php
rename to bulkManager/code/BulkAction/EditHandler.php
index 43798ad..cb8898c 100644
--- a/bulkManager/code/GridFieldBulkActionEditHandler.php
+++ b/bulkManager/code/BulkAction/EditHandler.php
@@ -1,10 +1,25 @@
'bulkEditForm',
- 'bulkEdit/recordEditForm' => 'recordEditForm',
- 'bulkEdit' => 'index',
+ 'bulkEdit/bulkEditForm' => 'bulkEditForm',
+ 'bulkEdit/recordEditForm' => 'recordEditForm',
+ 'bulkEdit' => 'index',
);
/**
@@ -43,7 +58,7 @@ public function Link($action = null)
/**
* Return a form for all the selected DataObjects
* with their respective editable fields.
- *
+ *
* @return Form Selected DataObjects editable fields
*/
public function bulkEditForm()
@@ -58,7 +73,7 @@ public function bulkEditForm()
$actions->push(
FormAction::create('doSave', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.SAVE_BTN_LABEL', 'Save all'))
->setAttribute('id', 'bulkEditingSaveBtn')
- ->addExtraClass('ss-ui-action-constructive')
+ ->addExtraClass('btn btn-success')
->setAttribute('data-icon', 'accept')
->setUseButtonTag(true)
);
@@ -66,7 +81,7 @@ public function bulkEditForm()
$actions->push(
FormAction::create('Cancel', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.CANCEL_BTN_LABEL', 'Cancel'))
->setAttribute('id', 'bulkEditingUpdateCancelBtn')
- ->addExtraClass('ss-ui-action-destructive cms-panel-link')
+ ->addExtraClass('btn btn-danger cms-panel-link')
->setAttribute('data-icon', 'decline')
->setAttribute('href', $one_level_up->Link)
->setUseButtonTag(true)
@@ -82,9 +97,10 @@ public function bulkEditForm()
$singleton = singleton($modelClass);
$titleModelClass = (($editingCount > 1) ? $singleton->i18n_plural_name() : $singleton->i18n_singular_name());
- //some cosmetics
- $headerText = _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.HEADER_TEXT',
- 'Editing {count} {class}',
+ //some cosmetics
+ $headerText = _t(
+ 'GRIDFIELD_BULKMANAGER_EDIT_HANDLER.HEADER_TEXT',
+ 'Editing {count} {class}',
array(
'count' => $editingCount,
'class' => $titleModelClass,
@@ -96,16 +112,19 @@ public function bulkEditForm()
);
$recordsFieldList->push($header);
- $toggle = LiteralField::create('bulkEditToggle', ''._t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.TOGGLE_ALL_LINK', 'Show/Hide all').'');
+ $toggle = LiteralField::create(
+ 'bulkEditToggle',
+ '' . _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.TOGGLE_ALL_LINK', 'Show/Hide all') . ''
+ );
$recordsFieldList->push($toggle);
- //fetch fields for each record and push to fieldList
+ //fetch fields for each record and push to fieldList
foreach ($recordList as $id) {
$record = DataObject::get_by_id($modelClass, $id);
$recordEditingFields = $this->getRecordEditingFields($record);
$toggleField = ToggleCompositeField::create(
- 'RecordFields_'.$id,
+ 'RecordFields_' . $id,
$record->getTitle(),
$recordEditingFields
)
@@ -128,7 +147,7 @@ public function bulkEditForm()
}
//override form action URL back to bulkEditForm
- //and add record ids GET var
+ //and add record ids GET var
$bulkEditForm->setAttribute(
'action',
$this->Link('bulkEditForm?records[]='.implode('&', $recordList))
@@ -140,7 +159,7 @@ public function bulkEditForm()
/**
* Return's a form with only one record's fields
* Used for bulkEditForm subForm requests via ajax.
- *
+ *
* @return Form Currently being edited form
*/
public function recordEditForm()
@@ -184,7 +203,7 @@ public function recordEditForm()
* with all filtering done ready to be included in the main form.
*
* @uses DataObject::getCMSFields()
- *
+ *
* @param DataObject $record The record to get the fields from
*
* @return array The record's editable fields
@@ -192,7 +211,8 @@ public function recordEditForm()
private function getRecordEditingFields(DataObject $record)
{
$tempForm = Form::create(
- $this, 'TempEditForm',
+ $this,
+ 'TempEditForm',
$record->getCMSFields(),
FieldList::create()
);
@@ -210,8 +230,8 @@ private function getRecordEditingFields(DataObject $record)
* based on component's config
* and escape each field with unique name.
*
- * See {@link GridFieldBulkManager} component for filtering config.
- *
+ * See {@link BulkManager} component for filtering config.
+ *
* @param FieldList $fields Record's CMS Fields
* @param int $id Record's ID, used fir unique name
*
@@ -222,7 +242,7 @@ private function filterRecordEditingFields(FieldList $fields, $id)
$config = $this->component->getConfig();
$editableFields = $config['editableFields'];
- // get all dataFields or just the ones allowed in config
+ // get all dataFields or just the ones allowed in config
if ($editableFields) {
$dataFields = array();
@@ -244,7 +264,7 @@ private function filterRecordEditingFields(FieldList $fields, $id)
/**
* Escape a fieldName with a unique prefix.
- *
+ *
* @param int $recordID Record id from who the field belongs
* @param string $name Field name
*
@@ -252,12 +272,12 @@ private function filterRecordEditingFields(FieldList $fields, $id)
*/
protected function escapeFieldName($recordID, $name)
{
- return 'record_'.$recordID.'_'.$name;
+ return 'record_' . $recordID . '_' . $name;
}
/**
* Un-escape a previously escaped field name.
- *
+ *
* @param string $fieldName Escaped field name
*
* @return array|false Fasle if the fieldName was not escaped. Or Array map with record 'id' and field 'name'
@@ -271,35 +291,38 @@ protected function unEscapeFieldName($fieldName)
return false;
} else {
return array(
- 'id' => $parts[1],
- 'name' => $parts[2],
+ 'id' => $parts[1],
+ 'name' => $parts[2],
);
}
}
/**
* Creates and return the bulk editing interface.
- *
+ *
* @return string Form's HTML
*/
public function index()
{
$form = $this->bulkEditForm();
- $form->setTemplate('LeftAndMain_EditForm');
+ $form->setTemplate([
+ 'type' => 'Includes',
+ 'SilverStripe\\Admin\\LeftAndMain_EditForm',
+ ]);
$form->addExtraClass('center cms-content');
$form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
- Requirements::javascript(BULKEDITTOOLS_MANAGER_PATH.'/javascript/GridFieldBulkEditingForm.js');
- Requirements::css(BULKEDITTOOLS_MANAGER_PATH.'/css/GridFieldBulkEditingForm.css');
- Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH.'/lang/js');
+ Requirements::javascript(BULKEDITTOOLS_MANAGER_PATH . '/javascript/GridFieldBulkEditingForm.js');
+ Requirements::css(BULKEDITTOOLS_MANAGER_PATH . '/css/GridFieldBulkEditingForm.css');
+ Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH . '/lang/js');
if ($this->request->isAjax()) {
- $response = new SS_HTTPResponse(
+ $response = new HTTPResponse(
Convert::raw2json(array('Content' => $form->forAjaxTemplate()->getValue()))
);
$response->addHeader('X-Pjax', 'Content');
$response->addHeader('Content-Type', 'text/json');
- $response->addHeader('X-Title', 'SilverStripe - Bulk '.$this->gridField->list->dataClass.' Editing');
+ $response->addHeader('X-Title', 'SilverStripe - Bulk ' . $this->gridField->list->dataClass . ' Editing');
return $response;
} else {
@@ -312,7 +335,7 @@ public function index()
/**
* Handles bulkEditForm submission
* and parses and saves each records data.
- *
+ *
* @param array $data Sumitted form data
* @param Form $form Form
*/
@@ -340,7 +363,8 @@ public function doSave($data, $form)
foreach ($formsData as $recordID => $recordData) {
$record = DataObject::get_by_id($className, $recordID);
$recordForm = Form::create(
- $this, 'RecordForm',
+ $this,
+ 'RecordForm',
$record->getCMSFields(),
FieldList::create()
);
@@ -358,8 +382,9 @@ public function doSave($data, $form)
//compose form message
$messageModelClass = (($done > 1) ? $singleton->i18n_plural_name() : $singleton->i18n_singular_name());
- $message = _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.SAVE_RESULT_TEXT',
- '{count} {class} saved successfully.',
+ $message = _t(
+ 'GRIDFIELD_BULKMANAGER_EDIT_HANDLER.SAVE_RESULT_TEXT',
+ '{count} {class} saved successfully.',
array(
'count' => $done,
'class' => $messageModelClass,
@@ -368,7 +393,7 @@ public function doSave($data, $form)
$form->sessionMessage($message, 'good');
//return back to form
- return Controller::curr()->redirect($this->Link('?records[]='.implode('&records[]=', $ids)));
+ return Controller::curr()->redirect($this->Link('?records[]=' . implode('&records[]=', $ids)));
//return Controller::curr()->redirect($form->Backlink); //returns to gridField
}
}
diff --git a/bulkManager/code/GridFieldBulkActionHandler.php b/bulkManager/code/BulkAction/Handler.php
similarity index 86%
rename from bulkManager/code/GridFieldBulkActionHandler.php
rename to bulkManager/code/BulkAction/Handler.php
index 8cd5bd3..f68a82e 100644
--- a/bulkManager/code/GridFieldBulkActionHandler.php
+++ b/bulkManager/code/BulkAction/Handler.php
@@ -1,12 +1,22 @@
Breadcrumbs()} for details.
- *
+ *
* @author SilverStripe original Breadcrumbs() method
*
* @see GridFieldDetailForm_ItemRequest
@@ -99,16 +109,16 @@ public function Breadcrumbs($unlinked = false)
$items = $this->controller->Breadcrumbs($unlinked);
$items->push(new ArrayData(array(
- 'Title' => 'Bulk Editing',
- 'Link' => false,
- )));
+ 'Title' => 'Bulk Editing',
+ 'Link' => false,
+ )));
return $items;
}
/**
* Returns the list of record IDs selected in the front-end.
- *
+ *
* @return array List of IDs
*/
public function getRecordIDList()
@@ -120,7 +130,7 @@ public function getRecordIDList()
/**
* Returns a DataList of the records selected in the front-end.
- *
+ *
* @return DataList List of records
*/
public function getRecords()
diff --git a/bulkManager/code/GridFieldBulkActionUnlinkHandler.php b/bulkManager/code/BulkAction/UnlinkHandler.php
similarity index 62%
rename from bulkManager/code/GridFieldBulkActionUnlinkHandler.php
rename to bulkManager/code/BulkAction/UnlinkHandler.php
index 547cf9a..48fc3b6 100644
--- a/bulkManager/code/GridFieldBulkActionUnlinkHandler.php
+++ b/bulkManager/code/BulkAction/UnlinkHandler.php
@@ -1,10 +1,18 @@
getRecordIDList();
$this->gridField->list->removeMany($ids);
- $response = new SS_HTTPResponse(Convert::raw2json(array(
+ $response = new HTTPResponse(Convert::raw2json(array(
'done' => true,
'records' => $ids,
)));
diff --git a/bulkManager/code/GridFieldBulkManager.php b/bulkManager/code/BulkManager.php
similarity index 74%
rename from bulkManager/code/GridFieldBulkManager.php
rename to bulkManager/code/BulkManager.php
index 6a95c8d..cb388e4 100644
--- a/bulkManager/code/GridFieldBulkManager.php
+++ b/bulkManager/code/BulkManager.php
@@ -1,27 +1,42 @@
fields editable on the Model
* 'actions' => maps of action name and configuration
- *
+ *
* @var array
*/
protected $config = array(
- 'editableFields' => null,
- 'actions' => array(),
+ 'editableFields' => null,
+ 'actions' => array(),
);
/**
* GridFieldBulkManager component constructor.
- *
+ *
* @param array $editableFields List of editable fields
* @param bool $defaultActions Use default actions list. False to start fresh.
*/
@@ -33,33 +48,33 @@ public function __construct($editableFields = null, $defaultActions = true)
if ($defaultActions) {
$this->config['actions'] = array(
- 'bulkEdit' => array(
- 'label' => _t('GRIDFIELD_BULK_MANAGER.EDIT_SELECT_LABEL', 'Edit'),
- 'handler' => 'GridFieldBulkActionEditHandler',
- 'config' => array(
+ 'bulkEdit' => array(
+ 'label' => _t('GRIDFIELD_BULK_MANAGER.EDIT_SELECT_LABEL', 'Edit'),
+ 'handler' => 'Colymba\\BulkManager\\BulkAction\\EditHandler',
+ 'config' => array(
'isAjax' => false,
'icon' => 'pencil',
'isDestructive' => false,
),
- ),
- 'unLink' => array(
- 'label' => _t('GRIDFIELD_BULK_MANAGER.UNLINK_SELECT_LABEL', 'UnLink'),
- 'handler' => 'GridFieldBulkActionUnlinkHandler',
- 'config' => array(
+ ),
+ 'unLink' => array(
+ 'label' => _t('GRIDFIELD_BULK_MANAGER.UNLINK_SELECT_LABEL', 'UnLink'),
+ 'handler' => 'Colymba\\BulkManager\\BulkAction\\UnlinkHandler',
+ 'config' => array(
'isAjax' => true,
'icon' => 'chain--minus',
'isDestructive' => false,
),
- ),
- 'delete' => array(
- 'label' => _t('GRIDFIELD_BULK_MANAGER.DELETE_SELECT_LABEL', 'Delete'),
- 'handler' => 'GridFieldBulkActionDeleteHandler',
- 'config' => array(
+ ),
+ 'delete' => array(
+ 'label' => _t('GRIDFIELD_BULK_MANAGER.DELETE_SELECT_LABEL', 'Delete'),
+ 'handler' => 'Colymba\\BulkManager\\BulkAction\\DeleteHandler',
+ 'config' => array(
'isAjax' => true,
'icon' => 'decline',
'isDestructive' => true,
),
- ),
+ )
);
}
}
@@ -70,7 +85,7 @@ public function __construct($editableFields = null, $defaultActions = true)
/**
* Sets the component configuration parameter.
- *
+ *
* @param string $reference
* @param mixed $value
*/
@@ -95,7 +110,7 @@ public function setConfig($reference, $value)
/**
* Returns one $config parameter of the full $config.
- *
+ *
* @param string $reference $congif parameter to return
*
* @return mixed
@@ -113,7 +128,7 @@ public function getConfig($reference = false)
* Lets you add custom bulk actions to the bulk manager interface.
*
* @todo add config options for front-end: isAjax, icon
- *
+ *
* @param string $name Bulk action's name. Used by RequestHandler.
* @param string $label Dropdown menu action's label. Default to ucfirst($name).
* @param string $handler RequestHandler class name for this action. Default to 'GridFieldBulkAction'.ucfirst($name).'Handler'
@@ -132,7 +147,7 @@ public function addBulkAction($name, $label = null, $handler = null, $config = n
}
if (!$handler) {
- $handler = 'GridFieldBulkAction'.ucfirst($name).'Handler';
+ $handler = 'Colymba\\BulkManager\\BulkAction\\' . ucfirst($name) . 'Handler';
}
if (!ClassInfo::exists($handler)) {
@@ -150,17 +165,17 @@ public function addBulkAction($name, $label = null, $handler = null, $config = n
}
$this->config['actions'][$name] = array(
- 'label' => $label,
- 'handler' => $handler,
- 'config' => $config,
- );
+ 'label' => $label,
+ 'handler' => $handler,
+ 'config' => $config,
+ );
return $this;
}
/**
* Removes a bulk actions from the bulk manager interface.
- *
+ *
* @param string $name Bulk action's name
*
* @return GridFieldBulkManager Current GridFieldBulkManager instance
@@ -182,7 +197,7 @@ public function removeBulkAction($name)
/**
* Add bulk select column.
- *
+ *
* @param GridField $gridField Current GridField instance
* @param array $columns Columns list
*/
@@ -195,7 +210,7 @@ public function augmentColumns($gridField, &$columns)
/**
* Which columns are handled by the component.
- *
+ *
* @param GridField $gridField Current GridField instance
*
* @return array List of handled column names
@@ -207,7 +222,7 @@ public function getColumnsHandled($gridField)
/**
* Sets the column's content.
- *
+ *
* @param GridField $gridField Current GridField instance
* @param DataObject $record Record intance for this row
* @param string $columnName Column's name for which we need content
@@ -216,16 +231,16 @@ public function getColumnsHandled($gridField)
*/
public function getColumnContent($gridField, $record, $columnName)
{
- $cb = CheckboxField::create('bulkSelect_'.$record->ID)
- ->addExtraClass('bulkSelect no-change-track')
- ->setAttribute('data-record', $record->ID);
+ $cb = CheckboxField::create('bulkSelect_' . $record->ID)
+ ->addExtraClass('bulkSelect no-change-track')
+ ->setAttribute('data-record', $record->ID);
return $cb->Field();
}
/**
* Set the column's HTML attributes.
- *
+ *
* @param GridField $gridField Current GridField instance
* @param DataObject $record Record intance for this row
* @param string $columnName Column's name for which we need attributes
@@ -239,7 +254,7 @@ public function getColumnAttributes($gridField, $record, $columnName)
/**
* Set the column's meta data.
- *
+ *
* @param GridField $gridField Current GridField instance
* @param string $columnName Column's name for which we need meta data
*
@@ -263,9 +278,9 @@ public function getColumnMetadata($gridField, $columnName)
*/
public function getHTMLFragments($gridField)
{
- Requirements::css(BULKEDITTOOLS_MANAGER_PATH.'/css/GridFieldBulkManager.css');
- Requirements::javascript(BULKEDITTOOLS_MANAGER_PATH.'/javascript/GridFieldBulkManager.js');
- Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH.'/lang/js');
+ Requirements::css(BULKEDITTOOLS_MANAGER_PATH . '/css/GridFieldBulkManager.css');
+ Requirements::javascript(BULKEDITTOOLS_MANAGER_PATH . '/javascript/GridFieldBulkManager.js');
+ Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH . '/lang/js');
if (!count($this->config['actions'])) {
user_error('Trying to use GridFieldBulkManager without any bulk action.', E_USER_ERROR);
@@ -284,22 +299,22 @@ public function getHTMLFragments($gridField)
$dropDownActionsList = DropdownField::create('bulkActionName', '')
->setSource($actionsListSource)
- ->setAttribute('class', 'bulkActionName no-change-track')
+ ->addExtraClass('bulkActionName no-change-track no-chosen')
->setAttribute('id', '');
$templateData = array(
- 'Menu' => $dropDownActionsList->FieldHolder(),
- 'Button' => array(
- 'Label' => _t('GRIDFIELD_BULK_MANAGER.ACTION_BTN_LABEL', 'Go'),
- 'DataURL' => $gridField->Link('bulkAction'),
- 'Icon' => $this->config['actions'][$firstAction]['config']['icon'],
- 'DataConfig' => htmlspecialchars(json_encode($actionsConfig), ENT_QUOTES, 'UTF-8'),
- ),
- 'Select' => array(
- 'Label' => _t('GRIDFIELD_BULK_MANAGER.SELECT_ALL_LABEL', 'Select all'),
- ),
- 'Colspan' => (count($gridField->getColumns()) - 1),
- );
+ 'Menu' => $dropDownActionsList,
+ 'Button' => array(
+ 'Label' => _t('GRIDFIELD_BULK_MANAGER.ACTION_BTN_LABEL', 'Go'),
+ 'DataURL' => $gridField->Link('bulkAction'),
+ 'Icon' => $this->config['actions'][$firstAction]['config']['icon'],
+ 'DataConfig' => json_encode($actionsConfig),
+ ),
+ 'Select' => array(
+ 'Label' => _t('GRIDFIELD_BULK_MANAGER.SELECT_ALL_LABEL', 'Select all'),
+ ),
+ 'Colspan' => (count($gridField->getColumns()) - 1),
+ );
$templateData = new ArrayData($templateData);
@@ -314,7 +329,7 @@ public function getHTMLFragments($gridField)
/**
* Returns an action => handler list.
- *
+ *
* @param GridField $gridField
*
* @return array
@@ -322,8 +337,8 @@ public function getHTMLFragments($gridField)
public function getURLHandlers($gridField)
{
return array(
- 'bulkAction' => 'handleBulkAction',
- );
+ 'bulkAction' => 'handleBulkAction',
+ );
}
/**
@@ -333,15 +348,15 @@ public function getURLHandlers($gridField)
*
* $url_handlers rule should not use wildcards like '$Action' => '$Action'
* but have more specific path defined
- *
+ *
* @param GridField $gridField
- * @param SS_HTTPRequest $request
+ * @param HTTPRequest $request
*
* @return mixed
*/
public function handleBulkAction($gridField, $request)
{
- $controller = $gridField->getForm()->Controller();
+ $controller = $gridField->getForm()->getController();
foreach ($this->config['actions'] as $name => $data) {
$handlerClass = $data['handler'];
@@ -351,7 +366,7 @@ public function handleBulkAction($gridField, $request)
foreach ($urlHandlers as $rule => $action) {
if ($request->match($rule, false)) {
//print_r('matched ' . $handlerClass . ' to ' . $rule);
- $handler = Injector::inst()->create($handlerClass, $gridField, $this, $controller);
+ $handler = Injector::inst()->create($handlerClass, $gridField, $this, $controller);
return $handler->handleRequest($request, DataModel::inst());
}
@@ -359,6 +374,6 @@ public function handleBulkAction($gridField, $request)
}
}
- user_error('Unable to find matching bulk action handler for '.$request->remaining().'.', E_USER_ERROR);
+ user_error('Unable to find matching bulk action handler for ' . $request->remaining() . '.', E_USER_ERROR);
}
}
diff --git a/bulkManager/css/GridFieldBulkEditingForm.css b/bulkManager/css/GridFieldBulkEditingForm.css
index d5aca2a..cfdea76 100644
--- a/bulkManager/css/GridFieldBulkEditingForm.css
+++ b/bulkManager/css/GridFieldBulkEditingForm.css
@@ -31,12 +31,14 @@
text-shadow: none; }
.bulkEditingFieldHolder.updated .ui-accordion-header {
background-color: #a4ca3a;
- background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #a4ca3a), color-stop(100%, #59781d));
- background-image: -webkit-linear-gradient(top, #a4ca3a 0%, #59781d 100%);
- background-image: -moz-linear-gradient(top, #a4ca3a 0%, #59781d 100%);
- background-image: -o-linear-gradient(top, #a4ca3a 0%, #59781d 100%);
- background-image: -ms-linear-gradient(top, #a4ca3a 0%, #59781d 100%);
- background-image: linear-gradient(top, #a4ca3a 0%, #59781d 100%); }
+ background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #a4ca3a), color-stop(100%, #59781D));
+ background-image: -webkit-linear-gradient(top, #a4ca3a 0%, #59781D 100%);
+ background-image: -moz-linear-gradient(top, #a4ca3a 0%, #59781D 100%);
+ background-image: -o-linear-gradient(top, #a4ca3a 0%, #59781D 100%);
+ background-image: -ms-linear-gradient(top, #a4ca3a 0%, #59781D 100%);
+ background-image: linear-gradient(top, #a4ca3a 0%, #59781D 100%); }
.bulkEditingFieldHolder.updated .ui-accordion-header a {
color: #fff;
text-shadow: none; }
+
+/*# sourceMappingURL=GridFieldBulkEditingForm.css.map */
diff --git a/bulkManager/css/GridFieldBulkEditingForm.css.map b/bulkManager/css/GridFieldBulkEditingForm.css.map
new file mode 100644
index 0000000..3410ecf
--- /dev/null
+++ b/bulkManager/css/GridFieldBulkEditingForm.css.map
@@ -0,0 +1,7 @@
+{
+"version": 3,
+"mappings": "AACA,eACA;EACC,KAAK,EAAE,IAAI;EACX,KAAK,EAAE,GAAG;EAEV,MAAM,EAAE,aAAa;EAErB,SAAS,EAAE,IAAI;EACf,WAAW,EAAE,IAAI;;AAGlB,eACA;EACC,KAAK,EAAE,KAAK;EACZ,KAAK,EAAE,KAAK;EACZ,KAAK,EAAE,GAAG;EAEV,MAAM,EAAE,aAAa;EAErB,eAAe,EAAE,SAAS;EAC1B,UAAU,EAAE,KAAK;EACjB,MAAM,EAAE,OAAO;;AAGhB,uBACA;EACC,QAAQ,EAAE,QAAQ;EAClB,KAAK,EAAE,IAAI;EACX,KAAK,EAAE,IAAI;EAEX,sDACA;IACC,gBAAgB,EAAE,OAAO;IAEzB,gBAAgB,EAAE,8FAA8F;IAChH,gBAAgB,EAAE,sDAAsD;IACxE,gBAAgB,EAAE,mDAAmD;IACrE,gBAAgB,EAAE,iDAAiD;IACnE,gBAAgB,EAAE,kDAAkD;IACpE,gBAAgB,EAAE,8CAA8C;IAEhE,wDACA;MACC,KAAK,EAAE,IAAI;MACX,WAAW,EAAE,IAAI;EAInB,oDACA;IACC,gBAAgB,EAAE,OAAO;IAEzB,gBAAgB,EAAE,8FAA8F;IAChH,gBAAgB,EAAE,sDAAsD;IACxE,gBAAgB,EAAE,mDAAmD;IACrE,gBAAgB,EAAE,iDAAiD;IACnE,gBAAgB,EAAE,kDAAkD;IACpE,gBAAgB,EAAE,8CAA8C;IAEhE,sDACA;MACC,KAAK,EAAE,IAAI;MACX,WAAW,EAAE,IAAI",
+"sources": ["GridFieldBulkEditingForm.scss"],
+"names": [],
+"file": "GridFieldBulkEditingForm.css"
+}
\ No newline at end of file
diff --git a/bulkManager/css/GridFieldBulkManager.css b/bulkManager/css/GridFieldBulkManager.css
index 1fc75eb..cd9c3e8 100644
--- a/bulkManager/css/GridFieldBulkManager.css
+++ b/bulkManager/css/GridFieldBulkManager.css
@@ -1,10 +1,12 @@
-.cms table.ss-gridfield-table tr.bulkManagerOptions th.bulkmanagerselect {
+.cms table.grid-field__table tr.bulkManagerOptions th.bulkmanagerheading {
+ padding-left: 40px; }
+.cms table.grid-field__table tr.bulkManagerOptions th.bulkmanagerselect {
text-align: center; }
- .cms table.ss-gridfield-table tr.bulkManagerOptions th.bulkmanagerselect input {
+ .cms table.grid-field__table tr.bulkManagerOptions th.bulkmanagerselect input {
margin-left: 0; }
-.cms table.ss-gridfield-table tr.bulkManagerOptions .title {
+.cms table.grid-field__table tr.bulkManagerOptions .title {
margin: 0 0 2px 2px; }
-.cms table.ss-gridfield-table tr.bulkManagerOptions .dropdown {
+.cms table.grid-field__table tr.bulkManagerOptions .dropdown {
display: inline-block;
border: none;
box-shadow: none;
@@ -12,17 +14,17 @@
margin: 0;
color: #000;
vertical-align: top; }
-.cms table.ss-gridfield-table tr.bulkManagerOptions .doBulkActionButton .ui-button-text {
+.cms table.grid-field__table tr.bulkManagerOptions .doBulkActionButton .ui-button-text {
padding: 6px 0 5px 2.1em; }
- .cms table.ss-gridfield-table tr.bulkManagerOptions .doBulkActionButton .ui-button-text .ui-button-text {
+ .cms table.grid-field__table tr.bulkManagerOptions .doBulkActionButton .ui-button-text .ui-button-text {
padding: 0; }
-.cms table.ss-gridfield-table tr.bulkManagerOptions .doBulkActionButton .loading .ui-icon {
+.cms table.grid-field__table tr.bulkManagerOptions .doBulkActionButton .loading .ui-icon {
background: transparent url(../../framework/images/network-save.gif) no-repeat 0 0; }
-.cms table.ss-gridfield-table tbody .col-bulkSelect {
+.cms table.grid-field__table tbody .col-bulkSelect {
width: 25px;
padding: 0 10px;
text-align: center; }
-.cms table.ss-gridfield-table tbody td a.tempDisabledEditLink {
+.cms table.grid-field__table tbody td a.tempDisabledEditLink {
background: url("../../framework/admin/images/btn-icon/document--pencil.png") no-repeat 2px 0px;
display: inline-block;
width: 20px;
@@ -32,3 +34,5 @@
vertical-align: middle;
background-position: 2px 0px;
background-repeat: no-repeat no-repeat; }
+
+/*# sourceMappingURL=GridFieldBulkManager.css.map */
diff --git a/bulkManager/css/GridFieldBulkManager.css.map b/bulkManager/css/GridFieldBulkManager.css.map
new file mode 100644
index 0000000..6bb71bf
--- /dev/null
+++ b/bulkManager/css/GridFieldBulkManager.css.map
@@ -0,0 +1,7 @@
+{
+"version": 3,
+"mappings": "AAII,wEAAsB;EAClB,YAAY,EAAE,IAAI;AAGtB,uEACA;EACE,UAAU,EAAE,MAAM;EAElB,6EACA;IACE,WAAW,EAAE,CAAC;AAIlB,yDACA;EACE,MAAM,EAAE,WAAW;AAGrB,4DACA;EACE,OAAO,EAAE,YAAY;EACrB,MAAM,EAAE,IAAI;EACZ,UAAU,EAAE,IAAI;EAEhB,OAAO,EAAE,CAAC;EACV,MAAM,EAAE,CAAC;EAET,KAAK,EAAE,IAAI;EACX,cAAc,EAAE,GAAG;AAKnB,sFACA;EACE,OAAO,EAAE,eAAe;EAExB,sGACA;IACE,OAAO,EAAE,CAAC;AAId,wFACA;EACE,UAAU,EAAE,sEAAsE;AAOtF,kDACA;EACE,KAAK,EAAE,IAAI;EACX,OAAO,EAAE,MAAM;EACf,UAAU,EAAE,MAAM;AAGpB,4DACA;EACE,UAAU,EAAE,mFAAmF;EAC/F,OAAO,EAAE,YAAY;EACrB,KAAK,EAAE,IAAI;EACX,MAAM,EAAE,IAAI;EACZ,WAAW,EAAE,QAAQ;EACrB,QAAQ,EAAE,MAAM;EAChB,cAAc,EAAE,MAAM;EACtB,mBAAmB,EAAE,OAAO;EAC5B,iBAAiB,EAAE,mBAAmB",
+"sources": ["GridFieldBulkManager.scss"],
+"names": [],
+"file": "GridFieldBulkManager.css"
+}
\ No newline at end of file
diff --git a/bulkManager/css/GridFieldBulkManager.scss b/bulkManager/css/GridFieldBulkManager.scss
index e13fd58..671177a 100644
--- a/bulkManager/css/GridFieldBulkManager.scss
+++ b/bulkManager/css/GridFieldBulkManager.scss
@@ -1,7 +1,11 @@
-.cms table.ss-gridfield-table
+.cms table.grid-field__table
{
tr.bulkManagerOptions
{
+ th.bulkmanagerheading {
+ padding-left: 40px;
+ }
+
th.bulkmanagerselect
{
text-align: center;
@@ -17,7 +21,7 @@
margin: 0 0 2px 2px;
}
- .dropdown
+ .dropdown
{
display: inline-block;
border: none;
@@ -71,4 +75,4 @@
background-repeat: no-repeat no-repeat;
}
}
-}
\ No newline at end of file
+}
diff --git a/bulkManager/javascript/GridFieldBulkManager.js b/bulkManager/javascript/GridFieldBulkManager.js
index 14329b8..edf16e3 100644
--- a/bulkManager/javascript/GridFieldBulkManager.js
+++ b/bulkManager/javascript/GridFieldBulkManager.js
@@ -1,5 +1,5 @@
-(function($) {
- $.entwine('ss', function($) {
+(function($) {
+ $.entwine('ss', function($) {
$.entwine('colymba', function($) {
@@ -34,14 +34,14 @@
onunmatch: function(){}
});
-
+
/**
* Bulkselect table cell behaviours
*/
$('td.col-bulkSelect').entwine({
onmatch: function(){
},
- onunmatch: function(){
+ onunmatch: function(){
},
onmouseover: function(){
//disable default row click behaviour -> avoid navigation to edit form when clicking the checkbox
@@ -59,20 +59,20 @@
}
});
-
+
/**
* Individual select checkbox behaviour
*/
$('td.col-bulkSelect input').entwine({
onmatch: function(){
},
- onunmatch: function(){
+ onunmatch: function(){
},
onclick: function(e) {
- $(this).parents('.ss-gridfield-table').find('input.bulkSelectAll').prop('checked', '');
+ $(this).parents('.grid-field__table').find('input.bulkSelectAll').prop('checked', '');
}
});
-
+
/**
* Bulkselect checkbox behaviours
@@ -80,35 +80,35 @@
$('input.bulkSelectAll').entwine({
onmatch: function(){
},
- onunmatch: function(){
+ onunmatch: function(){
},
onclick: function()
{
var state = $(this).prop('checked');
- $(this).parents('.ss-gridfield-table')
+ $(this).parents('.grid-field__table')
.find('td.col-bulkSelect input')
.prop('checked', state)
.trigger('change');
},
getSelectRecordsID: function()
{
- return $(this).parents('.ss-gridfield-table')
+ return $(this).parents('.grid-field__table')
.find('td.col-bulkSelect input:checked')
- .map(function() {
+ .map(function() {
return parseInt( $(this).data('record') )
})
.get();
}
});
-
+
/**
* Bulk action dropdown behaviours
*/
$('select.bulkActionName').entwine({
onmatch: function(){
},
- onunmatch: function(){
+ onunmatch: function(){
},
onchange: function(e)
{
@@ -136,10 +136,10 @@
else{
$btn.removeClass('ss-ui-action-destructive');
}
-
- }
+
+ }
});
-
+
/**
* bulk action button behaviours
@@ -147,7 +147,7 @@
$('.doBulkActionButton').entwine({
onmatch: function(){
},
- onunmatch: function(){
+ onunmatch: function(){
},
getActionURL: function(action, url)
{
@@ -176,13 +176,13 @@
var $parent = $(this).parents('.bulkManagerOptions'),
action = $parent.find('select.bulkActionName').val(),
ids = $(this).parents('.bulkManagerOptions').find('input.bulkSelectAll:first').getSelectRecordsID()
- ;
+ ;
- this.doBulkAction(action, ids);
+ this.doBulkAction(action, ids);
},
doBulkAction: function(action, ids, callbackFunction, callbackContext)
- {
+ {
var $parent = $(this).parents('.bulkManagerOptions'),
$btn = $parent.find('a.doBulkActionButton'),
@@ -190,7 +190,7 @@
url = this.getActionURL(action, $(this).data('url')),
data = { records: ids }
;
-
+
if ( ids.length <= 0 )
{
alert( ss.i18n._t('GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT') );
@@ -207,10 +207,10 @@
callbackFunction.call(callbackContext, false);
}
return false;
- }
- }
+ }
+ }
- $btn.addClass('loading');
+ $btn.addClass('loading');
if ( config[action]['isAjax'] )
{
@@ -219,7 +219,7 @@
data: data,
type: "POST",
context: $(this)
- }).done(function(data, textStatus, jqXHR) {
+ }).done(function(data, textStatus, jqXHR) {
$btn.removeClass('loading');
if ( callbackFunction && callbackContext )
{
@@ -239,7 +239,7 @@
}
});
-
- });
+
+ });
});
}(jQuery));
diff --git a/bulkManager/templates/BulkManagerButtons.ss b/bulkManager/templates/BulkManagerButtons.ss
index 7102b79..ac8f897 100644
--- a/bulkManager/templates/BulkManagerButtons.ss
+++ b/bulkManager/templates/BulkManagerButtons.ss
@@ -1,15 +1,25 @@
-
-
- <% _t('GRIDFIELD_BULK_MANAGER.COMPONENT_TITLE', 'Modify one or more entry at a time.') %>
-
- $Menu
-
- $Button.Label
-
-
- |
-
-
- |
-
\ No newline at end of file
+
+
+ <% _t('GRIDFIELD_BULK_MANAGER.COMPONENT_TITLE', 'Modify one or more entry at a time.') %>
+
+
+ |
+
diff --git a/bulkUpload/BULK_UPLOAD.md b/bulkUpload/BULK_UPLOAD.md
index 65dced9..20b9c9c 100644
--- a/bulkUpload/BULK_UPLOAD.md
+++ b/bulkUpload/BULK_UPLOAD.md
@@ -4,20 +4,26 @@ A component for uploading images and/or files in bulk into `DataObject` managed
## Usage 1
Simplest usage, add the component to your `GridFieldConfig` as below. The component will find the first `Image` or `File` has_one relation to use on the managed `DataObject`.
- $config->addComponent(new GridFieldBulkUpload());
+```php
+$config->addComponent(new \Colymba\BulkUpload\BulkUploader());
+```
## Usage 2
You can specify which `Image` or `File` field to use and a specific `DataObject` class name to use.
$fileRelationName (string, optional): The name of the `Image` or `File` has_one field to use (If your relation is set has 'MyImage' => 'Image', the parameter should be 'MyImage')
$recordClassName (string, optional): The class name of the `DataObject` to create (Usefull if for example your `GridField` holds `DataObject`s of different classes, like when used with the `GridFieldAddNewMultiClass` component.)
- $config->addComponent(new GridFieldBulkUpload($fileRelationName, $recordClassName));
+```php
+$config->addComponent(new \Colymba\BulkUpload\BulkUploader($fileRelationName, $recordClassName));
+```
## Configuration
### Component configuration
The component's option can be configurated through the `setConfig` functions like this:
- $config->getComponentByType('GridFieldBulkUpload')->setConfig($reference, $value);
+```php
+$config->getComponentByType('Colymba\\BulkUpload\\BulkUploader')->setConfig($reference, $value);
+```
The available configuration options are:
* 'fileRelationName' : sets the name of the `Image` or `File` has_one field to use (i.e. 'MyImage')
@@ -30,12 +36,14 @@ The underlying `UploadField` can be configured via a set of APIs:
For example, to set the upload folder, which is set by calling `setFolderName` on the `UploadField`, and setting the upload method as sequential, you would use the following:
- $config->getComponentByType('GridFieldBulkUpload')
- ->setUfSetup('setFolderName', 'myFolder')
- ->setUfConfig('sequentialUploads', true);
+```php
+$config->getComponentByType('Colymba\\BulkUpload\\BulkUploader')
+ ->setUfSetup('setFolderName', 'myFolder')
+ ->setUfConfig('sequentialUploads', true);
+```
Please see the [`UploadField` api](http://api.silverstripe.org/master/class-UploadField.html) and the [`Upload` api](http://api.silverstripe.org/master/class-Upload.html) for more info.
## Bulk Editing
-To get a quick edit shortcut to all the newly upload files, please also add the `GridFieldBulkManager` component to your `GridFieldConfig`.
+To get a quick edit shortcut to all the newly upload files, please also add the `Colymba\BulkManager\BulkManager` component to your `GridFieldConfig`.
diff --git a/bulkUpload/code/BulkUploadField.php b/bulkUpload/code/BulkUploadField.php
index b9d98b0..15ca462 100644
--- a/bulkUpload/code/BulkUploadField.php
+++ b/bulkUpload/code/BulkUploadField.php
@@ -1,4 +1,10 @@
gridfield = $gridfield;
parent::__construct($parent, $folderName);
}
+ /**
+ * {@inheritDoc}
+ */
public function Link($action = null)
{
return Controller::join_links($this->gridfield->Link(), 'bulkupload/', $action);
diff --git a/bulkUpload/code/GridFieldBulkUpload.php b/bulkUpload/code/BulkUploader.php
similarity index 80%
rename from bulkUpload/code/GridFieldBulkUpload.php
rename to bulkUpload/code/BulkUploader.php
index f5d732a..69faff1 100644
--- a/bulkUpload/code/GridFieldBulkUpload.php
+++ b/bulkUpload/code/BulkUploader.php
@@ -1,10 +1,24 @@
null,
- 'recordClassName' => null
+ 'fileRelationName' => null,
+ 'recordClassName' => null
);
/**
@@ -24,7 +38,7 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
* These options are passed on directly to the UploadField
* via {@link UploadField::setConfig()} api.
*
- * Defaults are: *
+ * Defaults are:
* 'sequentialUploads' => false : process uploads 1 after the other rather than all at once
* 'canAttachExisting' => true : displays "From files" button in the UploadField
* 'canPreviewFolder' => true : displays the upload location in the UploadField
@@ -33,8 +47,8 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
*/
protected $ufConfig = array(
'sequentialUploads' => false,
- 'canAttachExisting' => true,
- 'canPreviewFolder' => true,
+ 'canAttachExisting' => true,
+ 'canPreviewFolder' => true,
);
/**
@@ -47,7 +61,7 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
* @var array
*/
protected $ufSetup = array(
- 'setFolderName' => 'bulkUpload',
+ 'setFolderName' => 'bulkUpload',
);
/**
@@ -60,13 +74,14 @@ class GridFieldBulkUpload implements GridField_HTMLProvider, GridField_URLHandle
* @var array
*/
protected $ufValidatorSetup = array(
- 'setAllowedMaxFileSize' => null,
+ 'setAllowedMaxFileSize' => null,
);
/**
* Component constructor.
*
* @param string $fileRelationName
+ * @param string $recordClassName
*/
public function __construct($fileRelationName = null, $recordClassName = null)
{
@@ -92,7 +107,7 @@ public function __construct($fileRelationName = null, $recordClassName = null)
public function setConfig($reference, $value)
{
if (in_array($reference, array('folderName', 'maxFileSize', 'sequentialUploads', 'canAttachExisting', 'canPreviewFolder'))) {
- Deprecation::notice('2.1.0', "GridFieldBulkUpload 'setConfig()' doesn't support '$reference' anymore. Please use 'setUfConfig()', 'setUfSetup()' or 'setUfValidatorSetup()' instead.");
+ Deprecation::notice('2.1.0', "BulkUploader 'setConfig()' doesn't support '$reference' anymore. Please use 'setUfConfig()', 'setUfSetup()' or 'setUfValidatorSetup()' instead.");
if ($reference === 'folderName') {
$this->setUfSetup('setFolderName', $value);
@@ -228,6 +243,7 @@ public function getRecordClassName($gridField)
* Get the first has_one Image/File relation from the GridField managed DataObject
* i.e. 'MyImage' => 'Image' will return 'MyImage'.
*
+ * @param GridField $gridField
* @return string Name of the $has_one relation
*/
public function getDefaultFileRelationName($gridField)
@@ -237,7 +253,10 @@ public function getDefaultFileRelationName($gridField)
$imageField = null;
foreach ($hasOneFields as $field => $type) {
- if ($type === 'Image' || $type === 'File' || is_subclass_of($type, 'File')) {
+ if ($type === 'SilverStripe\\Assets\\Image'
+ || $type === 'SilverStripe\\Assets\\File'
+ || is_subclass_of($type, 'SilverStripe\\Assets\\File')
+ ) {
$imageField = $field;
break;
}
@@ -250,6 +269,7 @@ public function getDefaultFileRelationName($gridField)
* Returns the name of the Image/File field name from the managed record
* Either as set in the component config or the default one.
*
+ * @param GridField $gridField
* @return string
*/
public function getFileRelationName($gridField)
@@ -264,6 +284,7 @@ public function getFileRelationName($gridField)
* i.e. 'MyImage' => 'Image' will return 'Image'
* i.e. 'MyImage' => 'File' will return 'File'.
*
+ * @param GridField $gridField
* @return string file relation className
*/
public function getFileRelationClassName($gridField)
@@ -275,7 +296,7 @@ public function getFileRelationClassName($gridField)
if ($fieldName) {
return $hasOneFields[$fieldName];
} else {
- return 'File';
+ return 'SilverStripe\\Assets\\File';
}
}
@@ -299,7 +320,7 @@ public function bulkUploadField($gridField)
->setRecord(DataObject::create()) // avoid UploadField to get auto-config from the Page (e.g fix allowedMaxFileNumber)
- ->setTemplate('GridFieldBulkUploadField')
+ ->setTemplate('BulkUploadField')
->setDownloadTemplateName('colymba-bulkuploaddownloadtemplate')
->setConfig('url', $gridField->Link('bulkupload/upload'))
@@ -308,20 +329,20 @@ public function bulkUploadField($gridField)
->setConfig('urlFileExists', $gridField->Link('bulkupload/fileexists'))
;
- //set UploadField config
- foreach ($this->ufConfig as $key => $val) {
- $uploadField->setConfig($key, $val);
- }
+ //set UploadField config
+ foreach ($this->ufConfig as $key => $val) {
+ $uploadField->setConfig($key, $val);
+ }
- //UploadField setup
- foreach ($this->ufSetup as $fn => $param) {
- $uploadField->{$fn}($param);
- }
+ //UploadField setup
+ foreach ($this->ufSetup as $fn => $param) {
+ $uploadField->{$fn}($param);
+ }
- //UploadField Validator setup
- foreach ($this->ufValidatorSetup as $fn => $param) {
- $uploadField->getValidator()->{$fn}($param);
- }
+ //UploadField Validator setup
+ foreach ($this->ufValidatorSetup as $fn => $param) {
+ $uploadField->getValidator()->{$fn}($param);
+ }
return $uploadField;
}
@@ -345,7 +366,7 @@ public function getHTMLFragments($gridField)
}
// check BulkManager exists
- $bulkManager = $gridField->getConfig()->getComponentsByType('GridFieldBulkManager');
+ $bulkManager = $gridField->getConfig()->getComponentsByType('Colymba\\BulkManager\\BulkManager');
// upload management buttons
$finishButton = FormAction::create('Finish', _t('GRIDFIELD_BULK_UPLOAD.FINISH_BTN_LABEL', 'Finish'))
@@ -369,10 +390,10 @@ public function getHTMLFragments($gridField)
$bulkManager_actions = $bulkManager_config['actions'];
if (array_key_exists('bulkedit', $bulkManager_actions)) {
$editAllButton = FormAction::create('EditAll', _t('GRIDFIELD_BULK_UPLOAD.EDIT_ALL_BTN_LABEL', 'Edit all'))
- ->addExtraClass('bulkUploadEditButton')
- ->setAttribute('data-icon', 'pencil')
- ->setAttribute('data-url', $gridField->Link('bulkupload/edit'))
- ->setUseButtonTag(true);
+ ->addExtraClass('bulkUploadEditButton')
+ ->setAttribute('data-icon', 'pencil')
+ ->setAttribute('data-url', $gridField->Link('bulkupload/edit'))
+ ->setUseButtonTag(true);
} else {
$editAllButton = '';
}
@@ -389,17 +410,17 @@ public function getHTMLFragments($gridField)
$uploadField->ClearErrorButton = $clearErrorButton;
$data = ArrayData::create(array(
- 'Colspan' => count($gridField->getColumns()),
- 'UploadField' => $uploadField->Field(), // call ->Field() to get requirements in right order
+ 'Colspan' => count($gridField->getColumns()),
+ 'UploadField' => $uploadField->Field(), // call ->Field() to get requirements in right order
));
- Requirements::css(BULKEDITTOOLS_UPLOAD_PATH.'/css/GridFieldBulkUpload.css');
- Requirements::javascript(BULKEDITTOOLS_UPLOAD_PATH.'/javascript/GridFieldBulkUpload.js');
- Requirements::javascript(BULKEDITTOOLS_UPLOAD_PATH.'/javascript/GridFieldBulkUpload_downloadtemplate.js');
- Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH.'/lang/js');
+ Requirements::css(BULKEDITTOOLS_UPLOAD_PATH . '/css/GridFieldBulkUpload.css');
+ Requirements::javascript(BULKEDITTOOLS_UPLOAD_PATH . '/javascript/GridFieldBulkUpload.js');
+ Requirements::javascript(BULKEDITTOOLS_UPLOAD_PATH . '/javascript/GridFieldBulkUpload_downloadtemplate.js');
+ Requirements::add_i18n_javascript(BULKEDITTOOLS_PATH . '/lang/js');
return array(
- 'header' => $data->renderWith('GridFieldBulkUpload'),
+ 'header' => $data->renderWith('Colymba\\BulkUpload\\BulkUploader'),
);
}
@@ -425,14 +446,14 @@ public function getURLHandlers($gridField)
* Pass control over to the RequestHandler.
*
* @param GridField $gridField
- * @param SS_HTTPRequest $request
+ * @param HTTPRequest $request
*
* @return mixed
*/
public function handleBulkUpload($gridField, $request)
{
- $controller = $gridField->getForm()->Controller();
- $handler = new GridFieldBulkUpload_Request($gridField, $this, $controller);
+ $controller = $gridField->getForm()->getController();
+ $handler = new BulkUploaderRequest($gridField, $this, $controller);
return $handler->handleRequest($request, DataModel::inst());
}
diff --git a/bulkUpload/code/GridFieldBulkUpload_Request.php b/bulkUpload/code/BulkUploaderRequest.php
similarity index 83%
rename from bulkUpload/code/GridFieldBulkUpload_Request.php
rename to bulkUpload/code/BulkUploaderRequest.php
index 1e584a4..a02fe43 100644
--- a/bulkUpload/code/GridFieldBulkUpload_Request.php
+++ b/bulkUpload/code/BulkUploaderRequest.php
@@ -1,10 +1,23 @@
component->getRecordClassName($this->gridField);
@@ -114,7 +127,7 @@ public function upload(SS_HTTPRequest $request)
// JS Template Data
$responseData = $this->newRecordJSTemplateData($record, $uploadResponse);
- $response = new SS_HTTPResponse(Convert::raw2json(array($responseData)));
+ $response = new HTTPResponse(Convert::raw2json(array($responseData)));
$this->contentTypeNegotiation($response);
return $response;
@@ -133,16 +146,19 @@ protected function newRecordJSTemplateData(DataObject &$record, &$uploadResponse
{
// fetch uploadedFile record and sort out previewURL
// update $uploadResponse datas in case changes happened onAfterWrite()
- $uploadedFile = DataObject::get_by_id($this->component->getFileRelationClassName($this->gridField), $uploadResponse['id']);
+ $uploadedFile = DataObject::get_by_id(
+ $this->component->getFileRelationClassName($this->gridField),
+ $uploadResponse['id']
+ );
if ($uploadedFile) {
$uploadResponse['name'] = $uploadedFile->Name;
$uploadResponse['url'] = $uploadedFile->getURL();
if ($uploadedFile instanceof Image) {
- $uploadResponse['thumbnail_url'] = $uploadedFile->CroppedImage(30, 30)->getURL();
+ $uploadResponse['thumbnail_url'] = $uploadedFile->Fill(30, 30)->getURL();
} else {
- $uploadResponse['thumbnail_url'] = $uploadedFile->Icon();
+ $uploadResponse['thumbnail_url'] = $uploadedFile->IconTag();
}
// check if our new record has a Title, if not create one automatically
@@ -173,8 +189,10 @@ protected function newRecordJSTemplateData(DataObject &$record, &$uploadResponse
* Used by select dialog.
*
* @link UploadField->getRelationAutosetClass()
+ * @param string $default
+ * @return string
*/
- public function getRelationAutosetClass($default = 'File')
+ public function getRelationAutosetClass($default = 'SilverStripe\\Assets\\File')
{
$uploadField = $this->getUploadField();
@@ -186,6 +204,7 @@ public function getRelationAutosetClass($default = 'File')
* Used by select dialog.
*
* @link UploadField->getAllowedMaxFileNumber()
+ * @return int|null
*/
public function getAllowedMaxFileNumber()
{
@@ -198,11 +217,11 @@ public function getAllowedMaxFileNumber()
* Retrieve Files to be attached
* and generated DataObjects for each one.
*
- * @param SS_HTTPRequest $request
+ * @param HTTPRequest $request
*
- * @return SS_HTTPResponse
+ * @return HTTPResponse
*/
- public function attach(SS_HTTPRequest $request)
+ public function attach(HTTPRequest $request)
{
$uploadField = $this->getUploadField();
$attachResponses = $uploadField->attach($request);
@@ -231,7 +250,7 @@ public function attach(SS_HTTPRequest $request)
array_push($return, $responseData);
}
- $response = new SS_HTTPResponse(Convert::raw2json($return));
+ $response = new HTTPResponse(Convert::raw2json($return));
$this->contentTypeNegotiation($response);
return $response;
@@ -242,7 +261,7 @@ public function attach(SS_HTTPRequest $request)
*
* @link UploadField->select()
*/
- public function select(SS_HTTPRequest $request)
+ public function select(HTTPRequest $request)
{
$uploadField = $this->getUploadField();
@@ -256,7 +275,7 @@ public function select(SS_HTTPRequest $request)
*
* @link UploadField->fileexists()
*/
- public function fileexists(SS_HTTPRequest $request)
+ public function fileexists(HTTPRequest $request)
{
$uploadField = $this->getUploadField();
@@ -278,11 +297,15 @@ public function Link($action = null)
* e.g. IE needs text/plain for iframe transport
* https://github.com/blueimp/jQuery-File-Upload/issues/1795.
*
- * @param SS_HTTPResponse $response HTTP Response to set content-type on
+ * @param HTTPResponse $response HTTP Response to set content-type on
*/
protected function contentTypeNegotiation(&$response)
{
- if (isset($_SERVER['HTTP_ACCEPT']) && ((strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) || $_SERVER['HTTP_ACCEPT'] === '*/*')) {
+ if (isset($_SERVER['HTTP_ACCEPT'])
+ && ((strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false)
+ || $_SERVER['HTTP_ACCEPT'] === '*/*'
+ )
+ ) {
$response->addHeader('Content-Type', 'application/json');
} else {
$response->addHeader('Content-Type', 'text/plain');
diff --git a/bulkUpload/code/GridFieldBulkImageUpload.php b/bulkUpload/code/GridFieldBulkImageUpload.php
index 4e01af7..9bd91a7 100644
--- a/bulkUpload/code/GridFieldBulkImageUpload.php
+++ b/bulkUpload/code/GridFieldBulkImageUpload.php
@@ -1,24 +1,33 @@
=3.1"
- }
+ "name": "colymba/gridfield-bulk-editing-tools",
+ "type": "silverstripe-module",
+ "description": "SilverStripe 3 GridField component to upload images and edit records in bulk",
+ "homepage": "https://github.com/colymba/GridFieldBulkEditingTools",
+ "keywords": ["silverstripe", "bulk upload", "image upload", "gridfield bulk upload"],
+ "license": "BSD Simplified",
+ "authors": [
+ {
+ "name": "Thierry Francois",
+ "homepage": "http://colymba.com"
+ },
+ {
+ "name": "GitHub contributors",
+ "homepage": "https://github.com/colymba/GridFieldBulkEditingTools/contributors"
+ }
+ ],
+ "require": {
+ "silverstripe/framework": "^4.0@dev"
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Colymba\\BulkManager\\": "bulkManager/code/",
+ "Colymba\\BulkUpload\\": "bulkUpload/code/"
+ }
+ }
}