Updated to SS5 and reverted original namespacing
This commit is contained in:
parent
a208bee685
commit
4fbab0d232
18
.upgrade.yml
18
.upgrade.yml
|
@ -1,10 +1,10 @@
|
||||||
mappings:
|
mappings:
|
||||||
GridFieldBulkActionDeleteHandler: Violet88\BulkManager\BulkAction\DeleteHandler
|
GridFieldBulkActionDeleteHandler: Colymba\BulkManager\BulkAction\DeleteHandler
|
||||||
GridFieldBulkActionEditHandler: Violet88\BulkManager\BulkAction\EditHandler
|
GridFieldBulkActionEditHandler: Colymba\BulkManager\BulkAction\EditHandler
|
||||||
GridFieldBulkActionHandler: Violet88\BulkManager\BulkAction\Handler
|
GridFieldBulkActionHandler: Colymba\BulkManager\BulkAction\Handler
|
||||||
GridFieldBulkActionUnlinkHandler: Violet88\BulkManager\BulkAction\UnlinkHandler
|
GridFieldBulkActionUnlinkHandler: Colymba\BulkManager\BulkAction\UnlinkHandler
|
||||||
GridFieldBulkManager: Violet88\BulkManager\BulkManager
|
GridFieldBulkManager: Colymba\BulkManager\BulkManager
|
||||||
BulkUploadField: Violet88\BulkUpload\BulkUploadField
|
BulkUploadField: Colymba\BulkUpload\BulkUploadField
|
||||||
GridFieldBulkImageUpload: Violet88\BulkUpload\GridFieldBulkImageUpload
|
GridFieldBulkImageUpload: Colymba\BulkUpload\GridFieldBulkImageUpload
|
||||||
GridFieldBulkUpload: Violet88\BulkUpload\BulkUploader
|
GridFieldBulkUpload: Colymba\BulkUpload\BulkUploader
|
||||||
GridFieldBulkUpload_Request: Violet88\BulkUpload\BulkUploadHandler
|
GridFieldBulkUpload_Request: Colymba\BulkUpload\BulkUploadHandler
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
SilverStripe\Admin\LeftAndMain:
|
SilverStripe\Admin\LeftAndMain:
|
||||||
extra_requirements_javascript:
|
extra_requirements_javascript:
|
||||||
- 'violet88/gridfield-bulk-editing-tools: client/dist/js/main.js'
|
- "colymba/gridfield-bulk-editing-tools: client/dist/js/main.js"
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
/* global window, alert, confirm */
|
/* global window, alert, confirm */
|
||||||
import jQuery from 'jquery';
|
import jQuery from "jquery";
|
||||||
import i18n from 'i18n';
|
import i18n from "i18n";
|
||||||
|
|
||||||
jQuery.entwine('violet88', ($) => {
|
jQuery.entwine("colymba", ($) => {
|
||||||
/**
|
/**
|
||||||
* Makes sure the component is above the headers
|
* Makes sure the component is above the headers
|
||||||
*/
|
*/
|
||||||
$('.bulkManagerOptions').entwine({
|
$(".bulkManagerOptions").entwine({
|
||||||
onmatch() {
|
onmatch() {
|
||||||
const $parent = this.parents('thead');
|
const $parent = this.parents("thead");
|
||||||
const $tr = $parent.find('tr');
|
const $tr = $parent.find("tr");
|
||||||
|
|
||||||
const targets = ['.filter-header', '.sortable-header'];
|
const targets = [".filter-header", ".sortable-header"];
|
||||||
const $target = $parent.find(targets.join(','));
|
const $target = $parent.find(targets.join(","));
|
||||||
|
|
||||||
const index = $tr.index(this);
|
const index = $tr.index(this);
|
||||||
let newIndex = $tr.length - 1;
|
let newIndex = $tr.length - 1;
|
||||||
|
@ -30,77 +30,84 @@ jQuery.entwine('violet88', ($) => {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulkselect table cell behaviours
|
* Bulkselect table cell behaviours
|
||||||
*/
|
*/
|
||||||
$('td.col-bulkSelect').entwine({
|
$("td.col-bulkSelect").entwine({
|
||||||
onmouseover() {
|
onmouseover() {
|
||||||
// disable default row click behaviour -> avoid navigation to edit form when
|
// disable default row click behaviour -> avoid navigation to edit form when
|
||||||
// clicking the checkbox
|
// clicking the checkbox
|
||||||
$(this).parents('.ss-gridfield-item').find('.edit-link').removeClass('edit-link')
|
$(this)
|
||||||
.addClass('tempDisabledEditLink');
|
.parents(".ss-gridfield-item")
|
||||||
|
.find(".edit-link")
|
||||||
|
.removeClass("edit-link")
|
||||||
|
.addClass("tempDisabledEditLink");
|
||||||
},
|
},
|
||||||
onmouseout() {
|
onmouseout() {
|
||||||
// re-enable default row click behaviour
|
// re-enable default row click behaviour
|
||||||
$(this).parents('.ss-gridfield-item').find('.tempDisabledEditLink').addClass('edit-link')
|
$(this)
|
||||||
.removeClass('tempDisabledEditLink');
|
.parents(".ss-gridfield-item")
|
||||||
|
.find(".tempDisabledEditLink")
|
||||||
|
.addClass("edit-link")
|
||||||
|
.removeClass("tempDisabledEditLink");
|
||||||
},
|
},
|
||||||
onclick(e) {
|
onclick(e) {
|
||||||
// check/uncheck checkbox when clicking cell
|
// check/uncheck checkbox when clicking cell
|
||||||
const cb = $(e.target).find('input');
|
const cb = $(e.target).find("input");
|
||||||
if (!$(cb).prop('checked')) {
|
if (!$(cb).prop("checked")) {
|
||||||
$(cb).prop('checked', true);
|
$(cb).prop("checked", true);
|
||||||
} else {
|
} else {
|
||||||
$(cb).prop('checked', false);
|
$(cb).prop("checked", false);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Individual select checkbox behaviour
|
* Individual select checkbox behaviour
|
||||||
*/
|
*/
|
||||||
$('td.col-bulkSelect input').entwine({
|
$("td.col-bulkSelect input").entwine({
|
||||||
onmatch() {
|
onmatch() {},
|
||||||
},
|
onunmatch() {},
|
||||||
onunmatch() {
|
|
||||||
},
|
|
||||||
onclick() {
|
onclick() {
|
||||||
$(this).parents('.grid-field__table').find('input.bulkSelectAll').prop('checked', '');
|
$(this)
|
||||||
}
|
.parents(".grid-field__table")
|
||||||
|
.find("input.bulkSelectAll")
|
||||||
|
.prop("checked", "");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulkselect checkbox behaviours
|
* Bulkselect checkbox behaviours
|
||||||
*/
|
*/
|
||||||
$('input.bulkSelectAll').entwine({
|
$("input.bulkSelectAll").entwine({
|
||||||
onclick() {
|
onclick() {
|
||||||
const state = $(this).prop('checked');
|
const state = $(this).prop("checked");
|
||||||
$(this).parents('.grid-field__table')
|
$(this)
|
||||||
.find('td.col-bulkSelect input')
|
.parents(".grid-field__table")
|
||||||
.prop('checked', state)
|
.find("td.col-bulkSelect input")
|
||||||
.trigger('change');
|
.prop("checked", state)
|
||||||
|
.trigger("change");
|
||||||
},
|
},
|
||||||
getSelectRecordsID() {
|
getSelectRecordsID() {
|
||||||
return $(this).parents('.grid-field__table')
|
return $(this)
|
||||||
.find('td.col-bulkSelect input:checked')
|
.parents(".grid-field__table")
|
||||||
|
.find("td.col-bulkSelect input:checked")
|
||||||
.map(function () {
|
.map(function () {
|
||||||
return parseInt($(this).data('record'), 10);
|
return parseInt($(this).data("record"), 10);
|
||||||
})
|
})
|
||||||
.get();
|
.get();
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bulk action dropdown behaviours
|
* Bulk action dropdown behaviours
|
||||||
*/
|
*/
|
||||||
$('select.bulkActionName').entwine({
|
$("select.bulkActionName").entwine({
|
||||||
onchange() {
|
onchange() {
|
||||||
const value = $(this).val();
|
const value = $(this).val();
|
||||||
const $parent = $(this).parents('.bulkManagerOptions');
|
const $parent = $(this).parents(".bulkManagerOptions");
|
||||||
const $btn = $parent.find('.doBulkActionButton');
|
const $btn = $parent.find(".doBulkActionButton");
|
||||||
const config = $btn.data('config');
|
const config = $btn.data("config");
|
||||||
|
|
||||||
$.each(config, (configKey, configData) => {
|
$.each(config, (configKey, configData) => {
|
||||||
if (configKey !== value) {
|
if (configKey !== value) {
|
||||||
|
@ -109,45 +116,45 @@ jQuery.entwine('violet88', ($) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
$btn.addClass('disabled');
|
$btn.addClass("disabled");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$btn.removeClass('disabled');
|
$btn.removeClass("disabled");
|
||||||
|
|
||||||
$btn.addClass(config[value].buttonClasses).addClass('btn-outline-secondary');
|
$btn
|
||||||
|
.addClass(config[value].buttonClasses)
|
||||||
|
.addClass("btn-outline-secondary");
|
||||||
|
|
||||||
if (config[value].icon) {
|
if (config[value].icon) {
|
||||||
const $img = $btn.find('img');
|
const $img = $btn.find("img");
|
||||||
|
|
||||||
if ($img.length) {
|
if ($img.length) {
|
||||||
$img.attr('src', config[value].icon);
|
$img.attr("src", config[value].icon);
|
||||||
} else {
|
} else {
|
||||||
$btn.prepend(`<img src="${config[value].icon}" alt="" />`);
|
$btn.prepend(`<img src="${config[value].icon}" alt="" />`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$btn.find('img').remove();
|
$btn.find("img").remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (config[value].destructive) {
|
if (config[value].destructive) {
|
||||||
$btn.addClass('btn-outline-danger');
|
$btn.addClass("btn-outline-danger");
|
||||||
} else {
|
} else {
|
||||||
$btn.removeClass('btn-outline-danger');
|
$btn.removeClass("btn-outline-danger");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bulk action button behaviours
|
* bulk action button behaviours
|
||||||
*/
|
*/
|
||||||
$('.doBulkActionButton').entwine({
|
$(".doBulkActionButton").entwine({
|
||||||
getActionURL(action, url) {
|
getActionURL(action, url) {
|
||||||
const cacheBuster = new Date().getTime();
|
const cacheBuster = new Date().getTime();
|
||||||
let newUrl = url.split('?');
|
let newUrl = url.split("?");
|
||||||
|
|
||||||
let newAction = '';
|
let newAction = "";
|
||||||
if (action) {
|
if (action) {
|
||||||
newAction = `/${action}`;
|
newAction = `/${action}`;
|
||||||
}
|
}
|
||||||
|
@ -160,9 +167,12 @@ jQuery.entwine('violet88', ($) => {
|
||||||
return newUrl;
|
return newUrl;
|
||||||
},
|
},
|
||||||
onclick() {
|
onclick() {
|
||||||
const $parent = $(this).parents('.bulkManagerOptions');
|
const $parent = $(this).parents(".bulkManagerOptions");
|
||||||
const action = $parent.find('select.bulkActionName').val();
|
const action = $parent.find("select.bulkActionName").val();
|
||||||
const ids = $(this).parents('.bulkManagerOptions').find('input.bulkSelectAll:first').getSelectRecordsID();
|
const ids = $(this)
|
||||||
|
.parents(".bulkManagerOptions")
|
||||||
|
.find("input.bulkSelectAll:first")
|
||||||
|
.getSelectRecordsID();
|
||||||
|
|
||||||
this.doBulkAction(action, ids);
|
this.doBulkAction(action, ids);
|
||||||
},
|
},
|
||||||
|
@ -170,38 +180,40 @@ jQuery.entwine('violet88', ($) => {
|
||||||
doBulkAction(action, ids) {
|
doBulkAction(action, ids) {
|
||||||
const { bulkTools } = window;
|
const { bulkTools } = window;
|
||||||
|
|
||||||
const $parent = $(this).parents('.bulkManagerOptions');
|
const $parent = $(this).parents(".bulkManagerOptions");
|
||||||
const $btn = $parent.find('a.doBulkActionButton');
|
const $btn = $parent.find("a.doBulkActionButton");
|
||||||
const $msg = $parent.find('.message');
|
const $msg = $parent.find(".message");
|
||||||
|
|
||||||
const config = $btn.data('config');
|
const config = $btn.data("config");
|
||||||
let url = this.getActionURL(action, $(this).data('url'));
|
let url = this.getActionURL(action, $(this).data("url"));
|
||||||
const inputData = { records: ids };
|
const inputData = { records: ids };
|
||||||
|
|
||||||
if (ids.length <= 0) {
|
if (ids.length <= 0) {
|
||||||
alert(i18n._t('GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT'));
|
alert(i18n._t("GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ( $btn.hasClass('ss-ui-action-destructive') )
|
// if ( $btn.hasClass('ss-ui-action-destructive') )
|
||||||
if (config[action].destructive) {
|
if (config[action].destructive) {
|
||||||
if (!confirm(i18n._t('GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION'))) {
|
if (
|
||||||
|
!confirm(i18n._t("GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION"))
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$btn.addClass('loading');
|
$btn.addClass("loading");
|
||||||
$msg.removeClass('static show error warning');
|
$msg.removeClass("static show error warning");
|
||||||
|
|
||||||
if (config[action].xhr) {
|
if (config[action].xhr) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url,
|
url,
|
||||||
data: inputData,
|
data: inputData,
|
||||||
type: 'POST',
|
type: "POST",
|
||||||
context: $(this)
|
context: $(this),
|
||||||
}).always(function (data) {
|
}).always(function (data) {
|
||||||
let returnData = data;
|
let returnData = data;
|
||||||
$btn.removeClass('loading');
|
$btn.removeClass("loading");
|
||||||
|
|
||||||
// if request fail, return a +4xx status code, extract json response
|
// if request fail, return a +4xx status code, extract json response
|
||||||
if (data.responseText) {
|
if (data.responseText) {
|
||||||
|
@ -211,23 +223,26 @@ jQuery.entwine('violet88', ($) => {
|
||||||
$msg.html(returnData.message);
|
$msg.html(returnData.message);
|
||||||
|
|
||||||
if (returnData.isError) {
|
if (returnData.isError) {
|
||||||
$msg.addClass('static error');
|
$msg.addClass("static error");
|
||||||
} else if (returnData.isWarning) {
|
} else if (returnData.isWarning) {
|
||||||
$msg.addClass('show warning');
|
$msg.addClass("show warning");
|
||||||
} else {
|
} else {
|
||||||
$msg.addClass('show');
|
$msg.addClass("show");
|
||||||
}
|
}
|
||||||
|
|
||||||
bulkTools.gridfieldRefresh($(this).parents('.ss-gridfield'), returnData);
|
bulkTools.gridfieldRefresh(
|
||||||
|
$(this).parents(".ss-gridfield"),
|
||||||
|
returnData,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const records = `records[]=${ids.join('&records[]=')}`;
|
const records = `records[]=${ids.join("&records[]=")}`;
|
||||||
url = `${url}&${records}`;
|
url = `${url}&${records}`;
|
||||||
|
|
||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,49 +1,50 @@
|
||||||
/* global window */
|
/* global window */
|
||||||
import jQuery from 'jquery';
|
import jQuery from "jquery";
|
||||||
|
|
||||||
jQuery.entwine('violet88', ($) => {
|
jQuery.entwine("colymba", ($) => {
|
||||||
/**
|
/**
|
||||||
* Toggle all accordion forms
|
* Toggle all accordion forms
|
||||||
* open or closed
|
* open or closed
|
||||||
*/
|
*/
|
||||||
$('#bulkEditToggle').entwine({
|
$("#bulkEditToggle").entwine({
|
||||||
onclick() {
|
onclick() {
|
||||||
const toggleFields = this.parents('form').find('.ss-toggle .ui-accordion-header');
|
const toggleFields = this.parents("form").find(
|
||||||
let state = this.data('state');
|
".ss-toggle .ui-accordion-header",
|
||||||
|
);
|
||||||
|
let state = this.data("state");
|
||||||
|
|
||||||
if (!state || state === 'close') {
|
if (!state || state === "close") {
|
||||||
state = 'open';
|
state = "open";
|
||||||
} else {
|
} else {
|
||||||
state = 'close';
|
state = "close";
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFields.each(function () {
|
toggleFields.each(function () {
|
||||||
const $this = $(this);
|
const $this = $(this);
|
||||||
|
|
||||||
if (state === 'open' && !$this.hasClass('ui-state-active')) {
|
if (state === "open" && !$this.hasClass("ui-state-active")) {
|
||||||
$this.click();
|
$this.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state === 'close' && $this.hasClass('ui-state-active')) {
|
if (state === "close" && $this.hasClass("ui-state-active")) {
|
||||||
$this.click();
|
$this.click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.data('state', state);
|
this.data("state", state);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains each rocrds editing fields,
|
* Contains each rocrds editing fields,
|
||||||
* tracks changes and updates...
|
* tracks changes and updates...
|
||||||
*/
|
*/
|
||||||
$('.bulkEditingFieldHolder').entwine({
|
$(".bulkEditingFieldHolder").entwine({
|
||||||
onchange() {
|
onchange() {
|
||||||
this.removeClass('updated');
|
this.removeClass("updated");
|
||||||
if (!this.hasClass('hasUpdate')) {
|
if (!this.hasClass("hasUpdate")) {
|
||||||
this.addClass('hasUpdate');
|
this.addClass("hasUpdate");
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "violet88/gridfield-bulk-editing-tools",
|
"name": "colymba/gridfield-bulk-editing-tools",
|
||||||
"type": "silverstripe-vendormodule",
|
"type": "silverstripe-vendormodule",
|
||||||
"description": "SilverStripe GridField component to upload images/files and edit records in bulk",
|
"description": "SilverStripe GridField component to upload images/files and edit records in bulk",
|
||||||
"homepage": "https://github.com/colymba/GridFieldBulkEditingTools",
|
"homepage": "https://github.com/colymba/GridFieldBulkEditingTools",
|
||||||
|
@ -35,9 +35,9 @@
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Violet88\\BulkTools\\": "src/BulkTools/",
|
"Colymba\\BulkTools\\": "src/BulkTools/",
|
||||||
"Violet88\\BulkManager\\": "src/BulkManager/",
|
"Colymba\\BulkManager\\": "src/BulkManager/",
|
||||||
"Violet88\\BulkUpload\\": "src/BulkUploader/"
|
"Colymba\\BulkUpload\\": "src/BulkUploader/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
# Bulk Manager
|
# Bulk Manager
|
||||||
Perform actions on multiple records straight from the GridField. Comes with *unlink*, *delete* and bulk *editing*. You can also easily create/add your own.
|
|
||||||
|
Perform actions on multiple records straight from the GridField. Comes with _unlink_, _delete_ and bulk _editing_. You can also easily create/add your own.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Simply add component to your `GridFieldConfig`
|
Simply add component to your `GridFieldConfig`
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
@ -9,32 +11,39 @@ $config->addComponent(new \Colymba\BulkManager\BulkManager());
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
The component's options can be configurated individually or in bulk through the 'config' functions like this:
|
The component's options can be configurated individually or in bulk through the 'config' functions like this:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$config->getComponentByType('Violet88\\BulkManager\\BulkManager')->setConfig($reference, $value);
|
$config->getComponentByType('Colymba\\BulkManager\\BulkManager')->setConfig($reference, $value);
|
||||||
```
|
```
|
||||||
|
|
||||||
### $config overview
|
### $config overview
|
||||||
|
|
||||||
The available configuration options are:
|
The available configuration options are:
|
||||||
* 'editableFields' : array of string referencing specific CMS fields available for editing
|
|
||||||
|
- 'editableFields' : array of string referencing specific CMS fields available for editing
|
||||||
|
|
||||||
## Custom actions
|
## Custom actions
|
||||||
|
|
||||||
You can remove or add individual action or replace them all via `addBulkAction()` and `removeBulkAction()`
|
You can remove or add individual action or replace them all via `addBulkAction()` and `removeBulkAction()`
|
||||||
|
|
||||||
### Adding a custom action
|
### Adding a custom action
|
||||||
|
|
||||||
To add a custom bulk action to the list use:
|
To add a custom bulk action to the list use:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$config
|
$config
|
||||||
->getComponentByType('Violet88\\BulkManager\\BulkManager')
|
->getComponentByType('Colymba\\BulkManager\\BulkManager')
|
||||||
->addBulkAction('Namespace\\ClassName')
|
->addBulkAction('Namespace\\ClassName')
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Custom action handler
|
#### Custom action handler
|
||||||
When creating your own bulk action `RequestHandler`, you should extend `Violet88\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.
|
|
||||||
|
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 the handler's `$url_segment`, from which the handler will be called and its relating `$allowed_actions` and `$url_handlers`. See `Handler`, `DeleteHandler` and `UnlinkHandler` for examples.
|
Make sure to define the handler's `$url_segment`, from which the handler will be called and its relating `$allowed_actions` and `$url_handlers`. See `Handler`, `DeleteHandler` and `UnlinkHandler` for examples.
|
||||||
|
|
||||||
#### Front-end config
|
#### Front-end config
|
||||||
|
|
||||||
Bulk action handler's front-end configuration is set via class properties `label`, `icon`, `buttonClasses`, `xhr` and `destructive`. See `Handler`, `DeleteHandler` and `UnlinkHandler` for reference and examples.
|
Bulk action handler's front-end configuration is set via class properties `label`, `icon`, `buttonClasses`, `xhr` and `destructive`. See `Handler`, `DeleteHandler` and `UnlinkHandler` for reference and examples.
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager\BulkAction;
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
use Violet88\BulkManager\BulkAction\Handler;
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
use Violet88\BulkTools\HTTPBulkToolsResponse;
|
use Colymba\BulkTools\HTTPBulkToolsResponse;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
@ -100,13 +100,11 @@ class ArchiveHandler extends Handler
|
||||||
$response = new HTTPBulkToolsResponse(true, $this->gridField);
|
$response = new HTTPBulkToolsResponse(true, $this->gridField);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($records as $record)
|
foreach ($records as $record) {
|
||||||
{
|
|
||||||
$done = $record->doArchive();
|
$done = $record->doArchive();
|
||||||
if ($done)
|
if ($done) {
|
||||||
{
|
|
||||||
$response->addSuccessRecord($record);
|
$response->addSuccessRecord($record);
|
||||||
}else{
|
} else {
|
||||||
$response->addFailedRecord($record, $done);
|
$response->addFailedRecord($record, $done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager\BulkAction;
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
use Violet88\BulkManager\BulkAction\Handler;
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
use Violet88\BulkTools\HTTPBulkToolsResponse;
|
use Colymba\BulkTools\HTTPBulkToolsResponse;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager\BulkAction;
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
use Violet88\BulkManager\BulkAction\Handler;
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
@ -141,7 +141,7 @@ class EditHandler extends Handler
|
||||||
->setAttribute('data-icon', 'decline')
|
->setAttribute('data-icon', 'decline')
|
||||||
->setAttribute('href', $one_level_up->Link)
|
->setAttribute('href', $one_level_up->Link)
|
||||||
->setUseButtonTag(true)
|
->setUseButtonTag(true)
|
||||||
->setAttribute('src', '')//changes type to image so isn't hooked by default actions handlers
|
->setAttribute('src', '') //changes type to image so isn't hooked by default actions handlers
|
||||||
);
|
);
|
||||||
|
|
||||||
$recordList = $this->getRecordIDList();
|
$recordList = $this->getRecordIDList();
|
||||||
|
@ -164,7 +164,7 @@ class EditHandler extends Handler
|
||||||
);
|
);
|
||||||
$header = LiteralField::create(
|
$header = LiteralField::create(
|
||||||
'bulkEditHeader',
|
'bulkEditHeader',
|
||||||
'<h1 id="bulkEditHeader">'.$headerText.'</h1>'
|
'<h1 id="bulkEditHeader">' . $headerText . '</h1>'
|
||||||
);
|
);
|
||||||
$recordsFieldList->push($header);
|
$recordsFieldList->push($header);
|
||||||
|
|
||||||
|
@ -184,9 +184,9 @@ class EditHandler extends Handler
|
||||||
$record->getTitle(),
|
$record->getTitle(),
|
||||||
$recordEditingFields
|
$recordEditingFields
|
||||||
)
|
)
|
||||||
->setHeadingLevel(4)
|
->setHeadingLevel(4)
|
||||||
->setAttribute('data-id', $id)
|
->setAttribute('data-id', $id)
|
||||||
->addExtraClass('bulkEditingFieldHolder');
|
->addExtraClass('bulkEditingFieldHolder');
|
||||||
|
|
||||||
$recordsFieldList->push($toggleField);
|
$recordsFieldList->push($toggleField);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ class EditHandler extends Handler
|
||||||
//and add record ids GET var
|
//and add record ids GET var
|
||||||
$bulkEditForm->setAttribute(
|
$bulkEditForm->setAttribute(
|
||||||
'action',
|
'action',
|
||||||
$this->Link('bulkEditForm?records[]='.implode('&', $recordList))
|
$this->Link('bulkEditForm?records[]=' . implode('&', $recordList))
|
||||||
);
|
);
|
||||||
|
|
||||||
return $bulkEditForm;
|
return $bulkEditForm;
|
||||||
|
@ -368,9 +368,9 @@ class EditHandler extends Handler
|
||||||
$form->addExtraClass('center cms-content');
|
$form->addExtraClass('center cms-content');
|
||||||
$form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
|
$form->setAttribute('data-pjax-fragment', 'CurrentForm Content');
|
||||||
|
|
||||||
Requirements::javascript('violet88/gridfield-bulk-editing-tools:client/dist/js/main.js');
|
Requirements::javascript('colymba/gridfield-bulk-editing-tools:client/dist/js/main.js');
|
||||||
Requirements::css('violet88/gridfield-bulk-editing-tools:client/dist/styles/main.css');
|
Requirements::css('colymba/gridfield-bulk-editing-tools:client/dist/styles/main.css');
|
||||||
Requirements::add_i18n_javascript('violet88/gridfield-bulk-editing-tools:lang');
|
Requirements::add_i18n_javascript('colymba/gridfield-bulk-editing-tools:lang');
|
||||||
|
|
||||||
if ($this->request->isAjax()) {
|
if ($this->request->isAjax()) {
|
||||||
$response = new HTTPResponse(
|
$response = new HTTPResponse(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager\BulkAction;
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\RequestHandler;
|
use SilverStripe\Control\RequestHandler;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager\BulkAction;
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
use Violet88\BulkManager\BulkAction\Handler;
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
use Violet88\BulkTools\HTTPBulkToolsResponse;
|
use Colymba\BulkTools\HTTPBulkToolsResponse;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
@ -100,13 +100,11 @@ class PublishHandler extends Handler
|
||||||
$response = new HTTPBulkToolsResponse(false, $this->gridField);
|
$response = new HTTPBulkToolsResponse(false, $this->gridField);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($records as $record)
|
foreach ($records as $record) {
|
||||||
{
|
|
||||||
$done = $record->publishRecursive();
|
$done = $record->publishRecursive();
|
||||||
if ($done)
|
if ($done) {
|
||||||
{
|
|
||||||
$response->addSuccessRecord($record);
|
$response->addSuccessRecord($record);
|
||||||
}else{
|
} else {
|
||||||
$response->addFailedRecord($record, $done);
|
$response->addFailedRecord($record, $done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager\BulkAction;
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
use Violet88\BulkManager\BulkAction\Handler;
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
use Violet88\BulkTools\HTTPBulkToolsResponse;
|
use Colymba\BulkTools\HTTPBulkToolsResponse;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
@ -100,13 +100,11 @@ class UnPublishHandler extends Handler
|
||||||
$response = new HTTPBulkToolsResponse(false, $this->gridField);
|
$response = new HTTPBulkToolsResponse(false, $this->gridField);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
foreach ($records as $record)
|
foreach ($records as $record) {
|
||||||
{
|
|
||||||
$done = $record->doUnpublish();
|
$done = $record->doUnpublish();
|
||||||
if ($done)
|
if ($done) {
|
||||||
{
|
|
||||||
$response->addSuccessRecord($record);
|
$response->addSuccessRecord($record);
|
||||||
}else{
|
} else {
|
||||||
$response->addFailedRecord($record, $done);
|
$response->addFailedRecord($record, $done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager\BulkAction;
|
namespace Colymba\BulkManager\BulkAction;
|
||||||
|
|
||||||
use Violet88\BulkManager\BulkAction\Handler;
|
use Colymba\BulkManager\BulkAction\Handler;
|
||||||
use Violet88\BulkTools\HTTPBulkToolsResponse;
|
use Colymba\BulkTools\HTTPBulkToolsResponse;
|
||||||
use SilverStripe\Core\Convert;
|
use SilverStripe\Core\Convert;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkManager;
|
namespace Colymba\BulkManager;
|
||||||
|
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
@ -129,8 +129,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
|
||||||
|
|
||||||
$handler = Injector::inst()->get($handlerClassName);
|
$handler = Injector::inst()->get($handlerClassName);
|
||||||
$urlSegment = $handler->config()->get('url_segment');
|
$urlSegment = $handler->config()->get('url_segment');
|
||||||
if (!$urlSegment)
|
if (!$urlSegment) {
|
||||||
{
|
|
||||||
$rc = new ReflectionClass($handlerClassName);
|
$rc = new ReflectionClass($handlerClassName);
|
||||||
$urlSegment = $rc->getShortName();
|
$urlSegment = $rc->getShortName();
|
||||||
}
|
}
|
||||||
|
@ -154,10 +153,8 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
|
||||||
user_error("Provide either a class name or URL segment", E_USER_ERROR);
|
user_error("Provide either a class name or URL segment", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->config['actions'] as $url => $class)
|
foreach ($this->config['actions'] as $url => $class) {
|
||||||
{
|
if ($handlerClassName === $class || $urlSegment === $url) {
|
||||||
if ($handlerClassName === $class || $urlSegment === $url)
|
|
||||||
{
|
|
||||||
unset($this->config['actions'][$url]);
|
unset($this->config['actions'][$url]);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -263,9 +260,9 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
|
||||||
*/
|
*/
|
||||||
public function getHTMLFragments($gridField)
|
public function getHTMLFragments($gridField)
|
||||||
{
|
{
|
||||||
Requirements::javascript('violet88/gridfield-bulk-editing-tools:client/dist/js/main.js');
|
Requirements::javascript('colymba/gridfield-bulk-editing-tools:client/dist/js/main.js');
|
||||||
Requirements::css('violet88/gridfield-bulk-editing-tools:client/dist/styles/main.css');
|
Requirements::css('colymba/gridfield-bulk-editing-tools:client/dist/styles/main.css');
|
||||||
Requirements::add_i18n_javascript('violet88/gridfield-bulk-editing-tools:client/lang');
|
Requirements::add_i18n_javascript('colymba/gridfield-bulk-editing-tools:client/lang');
|
||||||
|
|
||||||
if (!count($this->config['actions'] ?? [])) {
|
if (!count($this->config['actions'] ?? [])) {
|
||||||
user_error('Trying to use BulkManager without any bulk action.', E_USER_ERROR);
|
user_error('Trying to use BulkManager without any bulk action.', E_USER_ERROR);
|
||||||
|
@ -308,7 +305,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G
|
||||||
$templateData = new ArrayData($templateData);
|
$templateData = new ArrayData($templateData);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'header' => $templateData->renderWith('Violet88\\BulkManager\\BulkManagerButtons'),
|
'header' => $templateData->renderWith('Colymba\\BulkManager\\BulkManagerButtons'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkTools;
|
namespace Colymba\BulkTools;
|
||||||
|
|
||||||
use SilverStripe\Control\HTTPResponse;
|
use SilverStripe\Control\HTTPResponse;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkUpload;
|
namespace Colymba\BulkUpload;
|
||||||
|
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
//use SilverStripe\Forms\UploadField;
|
//use SilverStripe\Forms\UploadField;
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkUpload;
|
namespace Colymba\BulkUpload;
|
||||||
|
|
||||||
use Violet88\BulkTools\HTTPBulkToolsResponse;
|
use Colymba\BulkTools\HTTPBulkToolsResponse;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
use SilverStripe\Control\RequestHandler;
|
use SilverStripe\Control\RequestHandler;
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
|
@ -112,8 +112,7 @@ class BulkUploadHandler extends RequestHandler
|
||||||
$assetAdmin = AssetAdmin::singleton();
|
$assetAdmin = AssetAdmin::singleton();
|
||||||
$uploadResponse = $assetAdmin->apiCreateFile($request);
|
$uploadResponse = $assetAdmin->apiCreateFile($request);
|
||||||
|
|
||||||
if ($uploadResponse->getStatusCode() == 200)
|
if ($uploadResponse->getStatusCode() == 200) {
|
||||||
{
|
|
||||||
$responseData = Convert::json2array($uploadResponse->getBody());
|
$responseData = Convert::json2array($uploadResponse->getBody());
|
||||||
$responseData = array_shift($responseData);
|
$responseData = array_shift($responseData);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Violet88\BulkUpload;
|
namespace Colymba\BulkUpload;
|
||||||
|
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\View\ArrayData;
|
use SilverStripe\View\ArrayData;
|
||||||
|
@ -183,7 +183,8 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||||
|
|
||||||
$imageField = null;
|
$imageField = null;
|
||||||
foreach ($hasOneFields as $field => $type) {
|
foreach ($hasOneFields as $field => $type) {
|
||||||
if ($type === 'SilverStripe\\Assets\\Image'
|
if (
|
||||||
|
$type === 'SilverStripe\\Assets\\Image'
|
||||||
|| $type === 'SilverStripe\\Assets\\File'
|
|| $type === 'SilverStripe\\Assets\\File'
|
||||||
|| is_subclass_of($type, 'SilverStripe\\Assets\\File')
|
|| is_subclass_of($type, 'SilverStripe\\Assets\\File')
|
||||||
) {
|
) {
|
||||||
|
@ -245,7 +246,7 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||||
$uploadField = BulkUploadField::create($gridField, $fieldName, '')
|
$uploadField = BulkUploadField::create($gridField, $fieldName, '')
|
||||||
->setForm($gridField->getForm())
|
->setForm($gridField->getForm())
|
||||||
->setRecord(DataObject::create()) // avoid UploadField to get auto-config from the Page (e.g fix allowedMaxFileNumber)
|
->setRecord(DataObject::create()) // avoid UploadField to get auto-config from the Page (e.g fix allowedMaxFileNumber)
|
||||||
;
|
;
|
||||||
|
|
||||||
//UploadField setup
|
//UploadField setup
|
||||||
foreach ($this->ufSetup as $fn => $param) {
|
foreach ($this->ufSetup as $fn => $param) {
|
||||||
|
@ -294,12 +295,12 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler
|
||||||
'UploadField' => $uploadField->Field() // call ->Field() to get requirements in right order
|
'UploadField' => $uploadField->Field() // call ->Field() to get requirements in right order
|
||||||
));
|
));
|
||||||
//This one is no longer needed since the javascript is now loaded at the top of the cms
|
//This one is no longer needed since the javascript is now loaded at the top of the cms
|
||||||
//Requirements::javascript('violet88/gridfield-bulk-editing-tools:client/dist/js/main.js');
|
//Requirements::javascript('colymba/gridfield-bulk-editing-tools:client/dist/js/main.js');
|
||||||
Requirements::css('violet88/gridfield-bulk-editing-tools:client/dist/styles/main.css');
|
Requirements::css('colymba/gridfield-bulk-editing-tools:client/dist/styles/main.css');
|
||||||
Requirements::add_i18n_javascript('violet88/gridfield-bulk-editing-tools:client/lang');
|
Requirements::add_i18n_javascript('colymba/gridfield-bulk-editing-tools:client/lang');
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'before' => $data->renderWith('Violet88\\BulkUpload\\BulkUploader'),
|
'before' => $data->renderWith('Colymba\\BulkUpload\\BulkUploader'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue