diff --git a/.gitignore b/.gitignore index 9034277..4a02812 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,7 @@ .transifexrc **/css/bourbon **/.sass-cache -node_modules/ \ No newline at end of file +node_modules/ +vendor/ +public/ +composer.lock diff --git a/_config/config.yml b/_config/config.yml new file mode 100644 index 0000000..a587c82 --- /dev/null +++ b/_config/config.yml @@ -0,0 +1,3 @@ +SilverStripe\Admin\LeftAndMain: + extra_requirements_javascript: + - "colymba/gridfield-bulk-editing-tools: client/dist/js/main.js" diff --git a/client/dist/js/main.js b/client/dist/js/main.js index 57f53a3..2dc6023 100644 --- a/client/dist/js/main.js +++ b/client/dist/js/main.js @@ -1 +1 @@ -!function(){"use strict";var e={157:function(e,t,i){var s;((s=i(311))&&s.__esModule?s:{default:s}).default.entwine("ss",(e=>{window.bulkTools={gridfieldRefresh(e,t){t.isError||(t.isDestructive?this.removeGridFieldRows(e,t.records.success):this.updateGridFieldRows(e,t.records.success),this.failedGridFieldRows(e,t.records.failed))},getGridFieldRow(e,t){return e.find(`.ss-gridfield-item[data-id="${t.id}"][data-class="${t.class}"]`)},cleanGridFieldRow(e){return e.removeClass("bt-deleted bt-failed bt-updated").removeAttr("bt-error")},removeGridFieldRows(e,t){t.forEach((function(t){this.getGridFieldRow(e,t).addClass("bt-deleted").fadeOut(2e3)}),this),e.entwine(".").entwine("ss").delay(2e3).reload()},failedGridFieldRows(e,t){t.forEach((function(t){this.getGridFieldRow(e,t).addClass("bt-failed").attr("bt-error",t.message)}),this)},updateGridFieldRows(t,i){t.find(".ss-gridfield-item.ss-gridfield-no-items").remove(),i.forEach((function(i){const s=this.getGridFieldRow(t,i),d=e(i.row).addClass("bt-updated");1===s.length?s.replaceWith(d):t.find(".ss-gridfield-items").prepend(d)}),this)}}}))},572:function(e,t,i){var s=n(i(311)),d=n(i(754));function n(e){return e&&e.__esModule?e:{default:e}}s.default.entwine("colymba",(e=>{e(".bulkManagerOptions").entwine({onmatch(){const t=this.parents("thead"),i=t.find("tr"),s=t.find([".filter-header",".sortable-header"].join(",")),d=i.index(this);let n=i.length-1;s.each(((e,t)=>{const s=i.index(t);sn&&i.eq(n).insertAfter(e(this))}}),e("td.col-bulkSelect").entwine({onmouseover(){e(this).parents(".ss-gridfield-item").find(".edit-link").removeClass("edit-link").addClass("tempDisabledEditLink")},onmouseout(){e(this).parents(".ss-gridfield-item").find(".tempDisabledEditLink").addClass("edit-link").removeClass("tempDisabledEditLink")},onclick(t){const i=e(t.target).find("input");e(i).prop("checked")?e(i).prop("checked",!1):e(i).prop("checked",!0)}}),e("td.col-bulkSelect input").entwine({onmatch(){},onunmatch(){},onclick(){e(this).parents(".grid-field__table").find("input.bulkSelectAll").prop("checked","")}}),e("input.bulkSelectAll").entwine({onclick(){const t=e(this).prop("checked");e(this).parents(".grid-field__table").find("td.col-bulkSelect input").prop("checked",t).trigger("change")},getSelectRecordsID(){return e(this).parents(".grid-field__table").find("td.col-bulkSelect input:checked").map((function(){return parseInt(e(this).data("record"),10)})).get()}}),e("select.bulkActionName").entwine({onchange(){const t=e(this).val(),i=e(this).parents(".bulkManagerOptions").find(".doBulkActionButton"),s=i.data("config");if(e.each(s,((e,s)=>{e!==t&&i.removeClass(s.buttonClasses)})),t){if(i.removeClass("disabled"),i.addClass(s[t].buttonClasses).addClass("btn-outline-secondary"),s[t].icon){const e=i.find("img");e.length?e.attr("src",s[t].icon):i.prepend(``)}else i.find("img").remove();s[t].destructive?i.addClass("btn-outline-danger"):i.removeClass("btn-outline-danger")}else i.addClass("disabled")}}),e(".doBulkActionButton").entwine({getActionURL(e,t){const i=(new Date).getTime();let s=t.split("?"),d="";return e&&(d=`/${e}`),s=s[1]?`${s[0]+d}?${s[1]}&cacheBuster=${i}`:`${s[0]+d}?cacheBuster=${i}`,s},onclick(){const t=e(this).parents(".bulkManagerOptions").find("select.bulkActionName").val(),i=e(this).parents(".bulkManagerOptions").find("input.bulkSelectAll:first").getSelectRecordsID();this.doBulkAction(t,i)},doBulkAction(t,i){const{bulkTools:s}=window,n=e(this).parents(".bulkManagerOptions"),a=n.find("a.doBulkActionButton"),r=n.find(".message"),l=a.data("config");let o=this.getActionURL(t,e(this).data("url"));const c={records:i};if(i.length<=0)return alert(d.default._t("GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT")),!1;if(l[t].destructive&&!confirm(d.default._t("GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION")))return!1;if(a.addClass("loading"),r.removeClass("static show error warning"),l[t].xhr)e.ajax({url:o,data:c,type:"POST",context:e(this)}).always((function(t){let i=t;a.removeClass("loading"),t.responseText&&(i=JSON.parse(t.responseText)),r.html(i.message),i.isError?r.addClass("static error"):i.isWarning?r.addClass("show warning"):r.addClass("show"),s.gridfieldRefresh(e(this).parents(".ss-gridfield"),i)}));else{o=`${o}&${`records[]=${i.join("&records[]=")}`}`,window.location.href=o}return!0}})}))},453:function(e,t,i){var s;((s=i(311))&&s.__esModule?s:{default:s}).default.entwine("colymba",(e=>{e("#bulkEditToggle").entwine({onclick(){const t=this.parents("form").find(".ss-toggle .ui-accordion-header");let i=this.data("state");i=i&&"close"!==i?"close":"open",t.each((function(){const t=e(this);"open"!==i||t.hasClass("ui-state-active")||t.click(),"close"===i&&t.hasClass("ui-state-active")&&t.click()})),this.data("state",i)}}),e(".bulkEditingFieldHolder").entwine({onchange(){this.removeClass("updated"),this.hasClass("hasUpdate")||this.addClass("hasUpdate")}})}))},545:function(e,t,i){var s=n(i(311)),d=n(i(648));function n(e){return e&&e.__esModule?e:{default:e}}const{bulkTools:a}=window,r=e=>()=>(t,i)=>{let{type:d,payload:n}=i;switch(d){case"UPLOADFIELD_ADD_FILE":return-1!==n.fieldId.indexOf("_BU")&&n.file.id&&(e=>{const t=(0,s.default)(`#${e.fieldId}`),i=t.parents(".ss-gridfield"),d=t.data("schema");s.default.ajax(d.data.attachFileEndpoint.url,{method:d.data.attachFileEndpoint.method,data:{fileID:e.file.id}}).done((e=>{a.gridfieldRefresh(i,e)}))})(n),e(t,{type:d,payload:n});case"UPLOADFIELD_UPLOAD_SUCCESS":return-1!==n.fieldId.indexOf("_BU")&&(e=>{const t=(0,s.default)(`#${e.fieldId}`).parents(".ss-gridfield");a.gridfieldRefresh(t,e.json.bulkTools)})(n),e(t,{type:d,payload:n});default:return e(t,{type:d,payload:n})}};document.addEventListener("DOMContentLoaded",(()=>{d.default.transform("bulkUploaderTransformation",(e=>{e.reducer("assetAdmin",r)}))}))},648:function(e){e.exports=Injector},754:function(e){e.exports=i18n},311:function(e){e.exports=jQuery}},t={};function i(s){var d=t[s];if(void 0!==d)return d.exports;var n=t[s]={exports:{}};return e[s](n,n.exports,i),n.exports}i(157),i(572),i(453),i(545)}(); \ No newline at end of file +!function(){"use strict";var e={157:function(e,t,i){var s;((s=i(311))&&s.__esModule?s:{default:s}).default.entwine("ss",(e=>{window.bulkTools={gridfieldRefresh(e,t){t.isError||(t.isDestructive?this.removeGridFieldRows(e,t.records.success):this.updateGridFieldRows(e,t.records.success),this.failedGridFieldRows(e,t.records.failed))},getGridFieldRow(e,t){return e.find(`.ss-gridfield-item[data-id="${t.id}"][data-class="${t.class}"]`)},cleanGridFieldRow(e){return e.removeClass("bt-deleted bt-failed bt-updated").removeAttr("bt-error")},removeGridFieldRows(e,t){t.forEach((function(t){this.getGridFieldRow(e,t).addClass("bt-deleted").fadeOut(2e3)}),this),e.entwine(".").entwine("ss").delay(2e3).reload()},failedGridFieldRows(e,t){t.forEach((function(t){this.getGridFieldRow(e,t).addClass("bt-failed").attr("bt-error",t.message)}),this)},updateGridFieldRows(t,i){t.find(".ss-gridfield-item.ss-gridfield-no-items").remove(),i.forEach((function(i){const s=this.getGridFieldRow(t,i),d=e(i.row).addClass("bt-updated");1===s.length?s.replaceWith(d):t.find(".ss-gridfield-items").prepend(d)}),this)}}}))},572:function(e,t,i){var s=n(i(311)),d=n(i(754));function n(e){return e&&e.__esModule?e:{default:e}}s.default.entwine("colymba",(e=>{e(".bulkManagerOptions").entwine({onmatch(){const t=this.parents("thead"),i=t.find("tr"),s=t.find([".filter-header",".sortable-header"].join(",")),d=i.index(this);let n=i.length-1;s.each(((e,t)=>{const s=i.index(t);sn&&i.eq(n).insertAfter(e(this))}}),e("td.col-bulkSelect").entwine({onmouseover(){e(this).parents(".ss-gridfield-item").find(".edit-link").removeClass("edit-link").addClass("tempDisabledEditLink")},onmouseout(){e(this).parents(".ss-gridfield-item").find(".tempDisabledEditLink").addClass("edit-link").removeClass("tempDisabledEditLink")},onclick(t){const i=e(t.target).find("input");e(i).prop("checked")?e(i).prop("checked",!1):e(i).prop("checked",!0)}}),e("td.col-bulkSelect input").entwine({onmatch(){},onunmatch(){},onclick(){e(this).parents(".grid-field__table").find("input.bulkSelectAll").prop("checked","")}}),e("input.bulkSelectAll").entwine({onclick(){const t=e(this).prop("checked");e(this).parents(".grid-field__table").find("td.col-bulkSelect input").prop("checked",t).trigger("change")},getSelectRecordsID(){return e(this).parents(".grid-field__table").find("td.col-bulkSelect input:checked").map((function(){return parseInt(e(this).data("record"),10)})).get()}}),e("select.bulkActionName").entwine({onchange(){const t=e(this).val(),i=e(this).parents(".bulkManagerOptions").find(".doBulkActionButton"),s=i.data("config");if(e.each(s,((e,s)=>{e!==t&&i.removeClass(s.buttonClasses)})),t){if(i.removeClass("disabled"),i.addClass(s[t].buttonClasses).addClass("btn-outline-secondary"),s[t].icon){const e=i.find("img");e.length?e.attr("src",s[t].icon):i.prepend(``)}else i.find("img").remove();s[t].destructive?i.addClass("btn-outline-danger"):i.removeClass("btn-outline-danger")}else i.addClass("disabled")}}),e(".doBulkActionButton").entwine({getActionURL(e,t){const i=(new Date).getTime();let s=t.split("?"),d="";return e&&(d=`/${e}`),s=s[1]?`${s[0]+d}?${s[1]}&cacheBuster=${i}`:`${s[0]+d}?cacheBuster=${i}`,s},onclick(){const t=e(this).parents(".bulkManagerOptions").find("select.bulkActionName").val(),i=e(this).parents(".bulkManagerOptions").find("input.bulkSelectAll:first").getSelectRecordsID();this.doBulkAction(t,i)},doBulkAction(t,i){const{bulkTools:s}=window,n=e(this).parents(".bulkManagerOptions"),a=n.find("a.doBulkActionButton"),r=n.find(".message"),l=a.data("config");let o=this.getActionURL(t,e(this).data("url"));const c={records:i};if(i.length<=0)return alert(d.default._t("GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT")),!1;if(l[t].destructive&&!confirm(d.default._t("GRIDFIELD_BULK_MANAGER.CONFIRM_DESTRUCTIVE_ACTION")))return!1;if(a.addClass("loading"),r.removeClass("static show error warning"),l[t].xhr)e.ajax({url:o,data:c,type:"POST",context:e(this)}).always((function(t){let i=t;a.removeClass("loading"),t.responseText&&(i=JSON.parse(t.responseText)),r.html(i.message),i.isError?r.addClass("static error"):i.isWarning?r.addClass("show warning"):r.addClass("show"),s.gridfieldRefresh(e(this).parents(".ss-gridfield"),i)}));else{o=`${o}&${`records[]=${i.join("&records[]=")}`}`,window.location.href=o}return!0}})}))},453:function(e,t,i){var s;((s=i(311))&&s.__esModule?s:{default:s}).default.entwine("colymba",(e=>{e("#bulkEditToggle").entwine({onclick(){const t=this.parents("form").find(".ss-toggle .ui-accordion-header");let i=this.data("state");i=i&&"close"!==i?"close":"open",t.each((function(){const t=e(this);"open"!==i||t.hasClass("ui-state-active")||t.click(),"close"===i&&t.hasClass("ui-state-active")&&t.click()})),this.data("state",i)}}),e(".bulkEditingFieldHolder").entwine({onchange(){this.removeClass("updated"),this.hasClass("hasUpdate")||this.addClass("hasUpdate")}})}))},545:function(e,t,i){var s=n(i(311)),d=n(i(648));function n(e){return e&&e.__esModule?e:{default:e}}const{bulkTools:a}=window,r=e=>()=>(t,i)=>{let{type:d,payload:n}=i;switch(d){case"UPLOADFIELD_ADD_FILE":return-1!==n.fieldId.indexOf("_BU")&&n.file.id&&(e=>{const t=(0,s.default)(`#${e.fieldId}`),i=t.parents(".ss-gridfield"),d=t.data("schema");s.default.ajax(d.data.attachFileEndpoint.url,{method:d.data.attachFileEndpoint.method,data:{fileID:e.file.id}}).done((e=>{a.gridfieldRefresh(i,e)}))})(n),e(t,{type:d,payload:n});case"UPLOADFIELD_UPLOAD_SUCCESS":return-1!==n.fieldId.indexOf("_BU")&&(e=>{const t=(0,s.default)(`#${e.fieldId}`).parents(".ss-gridfield");a.gridfieldRefresh(t,e.json.bulkTools)})(n),e(t,{type:d,payload:n});default:return e(t,{type:d,payload:n})}};document.addEventListener("DOMContentLoaded",(()=>{d.default.transform("bulkUploaderTransformation",(e=>{e.reducer("assetAdmin",r)}))}))},648:function(e){e.exports=Injector},754:function(e){e.exports=i18n},311:function(e){e.exports=jQuery}},t={};function i(s){var d=t[s];if(void 0!==d)return d.exports;var n=t[s]={exports:{}};return e[s](n,n.exports,i),n.exports}i(157),i(572),i(453),i(545)}(); diff --git a/client/src/js/manager.js b/client/src/js/manager.js index 06e3957..ae6bec3 100644 --- a/client/src/js/manager.js +++ b/client/src/js/manager.js @@ -1,18 +1,18 @@ /* global window, alert, confirm */ -import jQuery from 'jquery'; -import i18n from 'i18n'; +import jQuery from "jquery"; +import i18n from "i18n"; -jQuery.entwine('colymba', ($) => { +jQuery.entwine("colymba", ($) => { /** * Makes sure the component is above the headers */ - $('.bulkManagerOptions').entwine({ + $(".bulkManagerOptions").entwine({ onmatch() { - const $parent = this.parents('thead'); - const $tr = $parent.find('tr'); + const $parent = this.parents("thead"); + const $tr = $parent.find("tr"); - const targets = ['.filter-header', '.sortable-header']; - const $target = $parent.find(targets.join(',')); + const targets = [".filter-header", ".sortable-header"]; + const $target = $parent.find(targets.join(",")); const index = $tr.index(this); let newIndex = $tr.length - 1; @@ -30,77 +30,84 @@ jQuery.entwine('colymba', ($) => { }, }); - /** * Bulkselect table cell behaviours */ - $('td.col-bulkSelect').entwine({ + $("td.col-bulkSelect").entwine({ onmouseover() { // disable default row click behaviour -> avoid navigation to edit form when // clicking the checkbox - $(this).parents('.ss-gridfield-item').find('.edit-link').removeClass('edit-link') - .addClass('tempDisabledEditLink'); + $(this) + .parents(".ss-gridfield-item") + .find(".edit-link") + .removeClass("edit-link") + .addClass("tempDisabledEditLink"); }, onmouseout() { // re-enable default row click behaviour - $(this).parents('.ss-gridfield-item').find('.tempDisabledEditLink').addClass('edit-link') - .removeClass('tempDisabledEditLink'); + $(this) + .parents(".ss-gridfield-item") + .find(".tempDisabledEditLink") + .addClass("edit-link") + .removeClass("tempDisabledEditLink"); }, onclick(e) { // check/uncheck checkbox when clicking cell - const cb = $(e.target).find('input'); - if (!$(cb).prop('checked')) { - $(cb).prop('checked', true); + const cb = $(e.target).find("input"); + if (!$(cb).prop("checked")) { + $(cb).prop("checked", true); } else { - $(cb).prop('checked', false); + $(cb).prop("checked", false); } - } + }, }); /** * Individual select checkbox behaviour */ - $('td.col-bulkSelect input').entwine({ - onmatch() { - }, - onunmatch() { - }, + $("td.col-bulkSelect input").entwine({ + onmatch() {}, + onunmatch() {}, onclick() { - $(this).parents('.grid-field__table').find('input.bulkSelectAll').prop('checked', ''); - } + $(this) + .parents(".grid-field__table") + .find("input.bulkSelectAll") + .prop("checked", ""); + }, }); /** * Bulkselect checkbox behaviours */ - $('input.bulkSelectAll').entwine({ + $("input.bulkSelectAll").entwine({ onclick() { - const state = $(this).prop('checked'); - $(this).parents('.grid-field__table') - .find('td.col-bulkSelect input') - .prop('checked', state) - .trigger('change'); + const state = $(this).prop("checked"); + $(this) + .parents(".grid-field__table") + .find("td.col-bulkSelect input") + .prop("checked", state) + .trigger("change"); }, getSelectRecordsID() { - return $(this).parents('.grid-field__table') - .find('td.col-bulkSelect input:checked') + return $(this) + .parents(".grid-field__table") + .find("td.col-bulkSelect input:checked") .map(function () { - return parseInt($(this).data('record'), 10); + return parseInt($(this).data("record"), 10); }) .get(); - } + }, }); - /** * Bulk action dropdown behaviours */ - $('select.bulkActionName').entwine({ + $("select.bulkActionName").entwine({ onchange() { const value = $(this).val(); - const $parent = $(this).parents('.bulkManagerOptions'); - const $btn = $parent.find('.doBulkActionButton'); - const config = $btn.data('config'); + const $parent = $(this).parents(".bulkManagerOptions"); + const $btn = $parent.find(".doBulkActionButton"); + const config = $btn.data("config"); $.each(config, (configKey, configData) => { if (configKey !== value) { @@ -109,45 +116,45 @@ jQuery.entwine('colymba', ($) => { }); if (!value) { - $btn.addClass('disabled'); + $btn.addClass("disabled"); 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) { - const $img = $btn.find('img'); + const $img = $btn.find("img"); if ($img.length) { - $img.attr('src', config[value].icon); + $img.attr("src", config[value].icon); } else { $btn.prepend(``); } } else { - $btn.find('img').remove(); + $btn.find("img").remove(); } - if (config[value].destructive) { - $btn.addClass('btn-outline-danger'); + $btn.addClass("btn-outline-danger"); } else { - $btn.removeClass('btn-outline-danger'); + $btn.removeClass("btn-outline-danger"); } - } + }, }); - /** * bulk action button behaviours */ - $('.doBulkActionButton').entwine({ + $(".doBulkActionButton").entwine({ getActionURL(action, url) { const cacheBuster = new Date().getTime(); - let newUrl = url.split('?'); + let newUrl = url.split("?"); - let newAction = ''; + let newAction = ""; if (action) { newAction = `/${action}`; } @@ -160,9 +167,12 @@ jQuery.entwine('colymba', ($) => { return newUrl; }, onclick() { - const $parent = $(this).parents('.bulkManagerOptions'); - const action = $parent.find('select.bulkActionName').val(); - const ids = $(this).parents('.bulkManagerOptions').find('input.bulkSelectAll:first').getSelectRecordsID(); + const $parent = $(this).parents(".bulkManagerOptions"); + const action = $parent.find("select.bulkActionName").val(); + const ids = $(this) + .parents(".bulkManagerOptions") + .find("input.bulkSelectAll:first") + .getSelectRecordsID(); this.doBulkAction(action, ids); }, @@ -170,38 +180,40 @@ jQuery.entwine('colymba', ($) => { doBulkAction(action, ids) { const { bulkTools } = window; - const $parent = $(this).parents('.bulkManagerOptions'); - const $btn = $parent.find('a.doBulkActionButton'); - const $msg = $parent.find('.message'); + const $parent = $(this).parents(".bulkManagerOptions"); + const $btn = $parent.find("a.doBulkActionButton"); + const $msg = $parent.find(".message"); - const config = $btn.data('config'); - let url = this.getActionURL(action, $(this).data('url')); + const config = $btn.data("config"); + let url = this.getActionURL(action, $(this).data("url")); const inputData = { records: ids }; if (ids.length <= 0) { - alert(i18n._t('GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT')); + alert(i18n._t("GRIDFIELD_BULK_MANAGER.BULKACTION_EMPTY_SELECT")); return false; } // if ( $btn.hasClass('ss-ui-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; } } - $btn.addClass('loading'); - $msg.removeClass('static show error warning'); + $btn.addClass("loading"); + $msg.removeClass("static show error warning"); if (config[action].xhr) { $.ajax({ url, data: inputData, - type: 'POST', - context: $(this) + type: "POST", + context: $(this), }).always(function (data) { let returnData = data; - $btn.removeClass('loading'); + $btn.removeClass("loading"); // if request fail, return a +4xx status code, extract json response if (data.responseText) { @@ -211,23 +223,26 @@ jQuery.entwine('colymba', ($) => { $msg.html(returnData.message); if (returnData.isError) { - $msg.addClass('static error'); + $msg.addClass("static error"); } else if (returnData.isWarning) { - $msg.addClass('show warning'); + $msg.addClass("show warning"); } else { - $msg.addClass('show'); + $msg.addClass("show"); } - bulkTools.gridfieldRefresh($(this).parents('.ss-gridfield'), returnData); + bulkTools.gridfieldRefresh( + $(this).parents(".ss-gridfield"), + returnData, + ); }); } else { - const records = `records[]=${ids.join('&records[]=')}`; + const records = `records[]=${ids.join("&records[]=")}`; url = `${url}&${records}`; window.location.href = url; } return true; - } + }, }); }); diff --git a/client/src/js/managerBulkEditingForm.js b/client/src/js/managerBulkEditingForm.js index 5be7856..f21895b 100644 --- a/client/src/js/managerBulkEditingForm.js +++ b/client/src/js/managerBulkEditingForm.js @@ -1,49 +1,50 @@ /* global window */ -import jQuery from 'jquery'; +import jQuery from "jquery"; -jQuery.entwine('colymba', ($) => { +jQuery.entwine("colymba", ($) => { /** * Toggle all accordion forms * open or closed */ - $('#bulkEditToggle').entwine({ + $("#bulkEditToggle").entwine({ onclick() { - const toggleFields = this.parents('form').find('.ss-toggle .ui-accordion-header'); - let state = this.data('state'); + const toggleFields = this.parents("form").find( + ".ss-toggle .ui-accordion-header", + ); + let state = this.data("state"); - if (!state || state === 'close') { - state = 'open'; + if (!state || state === "close") { + state = "open"; } else { - state = 'close'; + state = "close"; } toggleFields.each(function () { const $this = $(this); - if (state === 'open' && !$this.hasClass('ui-state-active')) { + if (state === "open" && !$this.hasClass("ui-state-active")) { $this.click(); } - if (state === 'close' && $this.hasClass('ui-state-active')) { + if (state === "close" && $this.hasClass("ui-state-active")) { $this.click(); } }); - this.data('state', state); - } + this.data("state", state); + }, }); - /** * Contains each rocrds editing fields, * tracks changes and updates... */ - $('.bulkEditingFieldHolder').entwine({ + $(".bulkEditingFieldHolder").entwine({ onchange() { - this.removeClass('updated'); - if (!this.hasClass('hasUpdate')) { - this.addClass('hasUpdate'); + this.removeClass("updated"); + if (!this.hasClass("hasUpdate")) { + this.addClass("hasUpdate"); } - } + }, }); }); diff --git a/composer.json b/composer.json index 70eb9ce..bfe2e77 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,12 @@ "type": "silverstripe-vendormodule", "description": "SilverStripe GridField component to upload images/files and edit records in bulk", "homepage": "https://github.com/colymba/GridFieldBulkEditingTools", - "keywords": ["silverstripe", "bulk upload", "image upload", "gridfield bulk upload"], + "keywords": [ + "silverstripe", + "bulk upload", + "image upload", + "gridfield bulk upload" + ], "license": "BSD-3-Clause", "authors": [ { @@ -16,8 +21,7 @@ } ], "require": { - "silverstripe/framework": "^5", - "silverstripe/asset-admin": "^2" + "silverstripe/framework": "^5 || ^4" }, "extra": { "branch-alias": { @@ -34,5 +38,11 @@ "Colymba\\BulkManager\\": "src/BulkManager/", "Colymba\\BulkUpload\\": "src/BulkUploader/" } + }, + "config": { + "allow-plugins": { + "composer/installers": true, + "silverstripe/vendor-plugin": true + } } } diff --git a/docs/en/BULK_MANAGER.md b/docs/en/BULK_MANAGER.md index 3838016..89a7115 100644 --- a/docs/en/BULK_MANAGER.md +++ b/docs/en/BULK_MANAGER.md @@ -1,7 +1,9 @@ # 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 + Simply add component to your `GridFieldConfig` ```php @@ -9,6 +11,7 @@ $config->addComponent(new \Colymba\BulkManager\BulkManager()); ``` ## Configuration + The component's options can be configurated individually or in bulk through the 'config' functions like this: ```php @@ -16,13 +19,17 @@ $config->getComponentByType('Colymba\\BulkManager\\BulkManager')->setConfig($ref ``` ### $config overview + 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 + You can remove or add individual action or replace them all via `addBulkAction()` and `removeBulkAction()` ### Adding a custom action + To add a custom bulk action to the list use: ```php @@ -32,9 +39,11 @@ $config ``` #### Custom action handler + 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. #### 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. diff --git a/src/BulkManager/BulkAction/ArchiveHandler.php b/src/BulkManager/BulkAction/ArchiveHandler.php index 32b4b9d..f712477 100644 --- a/src/BulkManager/BulkAction/ArchiveHandler.php +++ b/src/BulkManager/BulkAction/ArchiveHandler.php @@ -19,7 +19,7 @@ class ArchiveHandler extends Handler /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name - * + * * @var string */ private static $url_segment = 'archive'; @@ -42,14 +42,14 @@ class ArchiveHandler extends Handler /** * Front-end label for this handler's action - * + * * @var string */ protected $label = 'Archive'; /** * Front-end icon path for this handler's action. - * + * * @var string */ protected $icon = ''; @@ -57,22 +57,22 @@ class ArchiveHandler extends Handler /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash - * + * * @var string */ protected $buttonClasses = 'font-icon-trash'; - + /** * Whether this handler should be called via an XHR from the front-end - * + * * @var boolean */ protected $xhr = true; - + /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. - * + * * @var boolean */ protected $destructive = true; @@ -100,13 +100,11 @@ class ArchiveHandler extends Handler $response = new HTTPBulkToolsResponse(true, $this->gridField); try { - foreach ($records as $record) - { + foreach ($records as $record) { $done = $record->doArchive(); - if ($done) - { + if ($done) { $response->addSuccessRecord($record); - }else{ + } else { $response->addFailedRecord($record, $done); } } diff --git a/src/BulkManager/BulkAction/DeleteHandler.php b/src/BulkManager/BulkAction/DeleteHandler.php index 4771f63..aa8c172 100644 --- a/src/BulkManager/BulkAction/DeleteHandler.php +++ b/src/BulkManager/BulkAction/DeleteHandler.php @@ -19,7 +19,7 @@ class DeleteHandler extends Handler /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name - * + * * @var string */ private static $url_segment = 'delete'; @@ -42,14 +42,14 @@ class DeleteHandler extends Handler /** * Front-end label for this handler's action - * + * * @var string */ protected $label = 'Delete'; /** * Front-end icon path for this handler's action. - * + * * @var string */ protected $icon = ''; @@ -57,22 +57,22 @@ class DeleteHandler extends Handler /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash - * + * * @var string */ protected $buttonClasses = 'font-icon-trash'; - + /** * Whether this handler should be called via an XHR from the front-end - * + * * @var boolean */ protected $xhr = true; - + /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. - * + * * @var boolean */ protected $destructive = true; diff --git a/src/BulkManager/BulkAction/EditHandler.php b/src/BulkManager/BulkAction/EditHandler.php index 9cefc8a..75d7273 100644 --- a/src/BulkManager/BulkAction/EditHandler.php +++ b/src/BulkManager/BulkAction/EditHandler.php @@ -25,7 +25,7 @@ class EditHandler extends Handler /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name - * + * * @var string */ private static $url_segment = 'edit'; @@ -54,14 +54,14 @@ class EditHandler extends Handler /** * Front-end label for this handler's action - * + * * @var string */ protected $label = 'Edit'; /** * Front-end icon path for this handler's action. - * + * * @var string */ protected $icon = ''; @@ -69,22 +69,22 @@ class EditHandler extends Handler /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash - * + * * @var string */ protected $buttonClasses = 'font-icon-edit'; - + /** * Whether this handler should be called via an XHR from the front-end - * + * * @var boolean */ protected $xhr = false; - + /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. - * + * * @var boolean */ protected $destructive = false; @@ -108,7 +108,7 @@ class EditHandler extends Handler */ public function Link($action = null) { - return Controller::join_links(parent::Link(), $this->stat('url_segment'), $action); + return Controller::join_links(parent::Link(), self::$url_segment, $action); } /** @@ -130,7 +130,7 @@ class EditHandler extends Handler FormAction::create('doSave', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.SAVE_BTN_LABEL', 'Save all')) ->setAttribute('id', 'bulkEditingSaveBtn') ->addExtraClass('btn btn-success') - ->setAttribute('data-icon', 'accept') + ->setAttribute('data-icon', '! ') ->setUseButtonTag(true) ); @@ -138,10 +138,10 @@ class EditHandler extends Handler FormAction::create('Cancel', _t('GRIDFIELD_BULKMANAGER_EDIT_HANDLER.CANCEL_BTN_LABEL', 'Cancel')) ->setAttribute('id', 'bulkEditingUpdateCancelBtn') ->addExtraClass('btn btn-danger cms-panel-link') - ->setAttribute('data-icon', 'decline') + ->setAttribute('data-icon', 'P ') ->setAttribute('href', $one_level_up->Link) ->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(); @@ -164,7 +164,7 @@ class EditHandler extends Handler ); $header = LiteralField::create( 'bulkEditHeader', - '

'.$headerText.'

' + '

' . $headerText . '

' ); $recordsFieldList->push($header); @@ -184,9 +184,9 @@ class EditHandler extends Handler $record->getTitle(), $recordEditingFields ) - ->setHeadingLevel(4) - ->setAttribute('data-id', $id) - ->addExtraClass('bulkEditingFieldHolder'); + ->setHeadingLevel(4) + ->setAttribute('data-id', $id) + ->addExtraClass('bulkEditingFieldHolder'); $recordsFieldList->push($toggleField); } @@ -206,7 +206,7 @@ class EditHandler extends Handler //and add record ids GET var $bulkEditForm->setAttribute( 'action', - $this->Link('bulkEditForm?records[]='.implode('&', $recordList)) + $this->Link('bulkEditForm?records[]=' . implode('&', $recordList)) ); return $bulkEditForm; diff --git a/src/BulkManager/BulkAction/Handler.php b/src/BulkManager/BulkAction/Handler.php index 69be806..71a7bb8 100644 --- a/src/BulkManager/BulkAction/Handler.php +++ b/src/BulkManager/BulkAction/Handler.php @@ -21,7 +21,7 @@ class Handler extends RequestHandler /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name - * + * * @var string */ private static $url_segment = null; @@ -42,14 +42,14 @@ class Handler extends RequestHandler /** * Front-end label for this handler's action - * + * * @var string */ protected $label = 'Action'; /** * Front-end icon path for this handler's action. - * + * * @var string */ protected $icon = ''; @@ -57,22 +57,22 @@ class Handler extends RequestHandler /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash - * + * * @var string */ protected $buttonClasses = ''; - + /** * Whether this handler should be called via an XHR from the front-end - * + * * @var boolean */ protected $xhr = true; - + /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. - * + * * @var boolean */ protected $destructive = false; @@ -108,7 +108,7 @@ class Handler extends RequestHandler /** * Set if hanlder performs destructive actions - * + * * @param boolean destructive If true, a warning will be shown on the front-end * @return RequestHandler */ @@ -117,10 +117,10 @@ class Handler extends RequestHandler $this->destructive = $destructive; return $this; } - + /** * True if the hanlder performs destructive actions - * + * * @return boolean */ public function getDestructive() @@ -130,11 +130,11 @@ class Handler extends RequestHandler /** * Set if handler is called via XHR - * + * * @param boolean xhr If true the handler will be called via an XHR from front-end * @return RequestHandler */ - + public function setXhr($xhr) { $this->xhr = $xhr; diff --git a/src/BulkManager/BulkAction/PublishHandler.php b/src/BulkManager/BulkAction/PublishHandler.php index 0afd41e..6ef3965 100644 --- a/src/BulkManager/BulkAction/PublishHandler.php +++ b/src/BulkManager/BulkAction/PublishHandler.php @@ -19,7 +19,7 @@ class PublishHandler extends Handler /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name - * + * * @var string */ private static $url_segment = 'publish'; @@ -42,14 +42,14 @@ class PublishHandler extends Handler /** * Front-end label for this handler's action - * + * * @var string */ protected $label = 'Publish'; /** * Front-end icon path for this handler's action. - * + * * @var string */ protected $icon = ''; @@ -57,22 +57,22 @@ class PublishHandler extends Handler /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash - * + * * @var string */ protected $buttonClasses = 'font-icon-rocket'; - + /** * Whether this handler should be called via an XHR from the front-end - * + * * @var boolean */ protected $xhr = true; - + /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. - * + * * @var boolean */ protected $destructive = false; @@ -100,13 +100,11 @@ class PublishHandler extends Handler $response = new HTTPBulkToolsResponse(false, $this->gridField); try { - foreach ($records as $record) - { + foreach ($records as $record) { $done = $record->publishRecursive(); - if ($done) - { + if ($done) { $response->addSuccessRecord($record); - }else{ + } else { $response->addFailedRecord($record, $done); } } @@ -123,7 +121,7 @@ class PublishHandler extends Handler $response->setStatusCode(500); $response->setMessage($ex->getMessage()); } - + return $response; } } diff --git a/src/BulkManager/BulkAction/UnPublishHandler.php b/src/BulkManager/BulkAction/UnPublishHandler.php index 7bdec81..84d2851 100644 --- a/src/BulkManager/BulkAction/UnPublishHandler.php +++ b/src/BulkManager/BulkAction/UnPublishHandler.php @@ -19,7 +19,7 @@ class UnPublishHandler extends Handler /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name - * + * * @var string */ private static $url_segment = 'unpublish'; @@ -42,14 +42,14 @@ class UnPublishHandler extends Handler /** * Front-end label for this handler's action - * + * * @var string */ protected $label = 'UnPublish'; /** * Front-end icon path for this handler's action. - * + * * @var string */ protected $icon = ''; @@ -57,22 +57,22 @@ class UnPublishHandler extends Handler /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash - * + * * @var string */ protected $buttonClasses = ''; - + /** * Whether this handler should be called via an XHR from the front-end - * + * * @var boolean */ protected $xhr = true; - + /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. - * + * * @var boolean */ protected $destructive = false; @@ -98,15 +98,13 @@ class UnPublishHandler extends Handler { $records = $this->getRecords(); $response = new HTTPBulkToolsResponse(false, $this->gridField); - + try { - foreach ($records as $record) - { + foreach ($records as $record) { $done = $record->doUnpublish(); - if ($done) - { + if ($done) { $response->addSuccessRecord($record); - }else{ + } else { $response->addFailedRecord($record, $done); } } diff --git a/src/BulkManager/BulkAction/UnlinkHandler.php b/src/BulkManager/BulkAction/UnlinkHandler.php index 0dc8f45..d1e929f 100644 --- a/src/BulkManager/BulkAction/UnlinkHandler.php +++ b/src/BulkManager/BulkAction/UnlinkHandler.php @@ -19,7 +19,7 @@ class UnlinkHandler extends Handler /** * URL segment used to call this handler * If none given, @BulkManager will fallback to the Unqualified class name - * + * * @var string */ private static $url_segment = 'unlink'; @@ -42,14 +42,14 @@ class UnlinkHandler extends Handler /** * Front-end label for this handler's action - * + * * @var string */ protected $label = 'Unlink'; /** * Front-end icon path for this handler's action. - * + * * @var string */ protected $icon = ''; @@ -57,22 +57,22 @@ class UnlinkHandler extends Handler /** * Extra classes to add to the bulk action button for this handler * Can also be used to set the button font-icon e.g. font-icon-trash - * + * * @var string */ protected $buttonClasses = 'font-icon-link-broken'; - + /** * Whether this handler should be called via an XHR from the front-end - * + * * @var boolean */ protected $xhr = true; - + /** * Set to true is this handler will destroy any data. * A warning and confirmation will be shown on the front-end. - * + * * @var boolean */ protected $destructive = false; diff --git a/src/BulkManager/BulkManager.php b/src/BulkManager/BulkManager.php index e62538c..ae54a24 100644 --- a/src/BulkManager/BulkManager.php +++ b/src/BulkManager/BulkManager.php @@ -129,8 +129,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G $handler = Injector::inst()->get($handlerClassName); $urlSegment = $handler->config()->get('url_segment'); - if (!$urlSegment) - { + if (!$urlSegment) { $rc = new ReflectionClass($handlerClassName); $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); } - foreach ($this->config['actions'] as $url => $class) - { - if ($handlerClassName === $class || $urlSegment === $url) - { + foreach ($this->config['actions'] as $url => $class) { + if ($handlerClassName === $class || $urlSegment === $url) { unset($this->config['actions'][$url]); return $this; } @@ -290,7 +287,7 @@ class BulkManager implements GridField_HTMLProvider, GridField_ColumnProvider, G ->addExtraClass('bulkActionName no-change-track form-group--no-label') ->setAttribute('id', '') ->setEmptyString(_t('SilverStripe\Admin\LeftAndMain.DropdownBatchActionsDefault', 'Choose an action...')); - + $templateData = array( 'Menu' => $dropDownActionsList->FieldHolder(), diff --git a/src/BulkTools/HTTPBulkToolsResponse.php b/src/BulkTools/HTTPBulkToolsResponse.php index 6c6c930..97c6bd8 100644 --- a/src/BulkTools/HTTPBulkToolsResponse.php +++ b/src/BulkTools/HTTPBulkToolsResponse.php @@ -123,7 +123,7 @@ class HTTPBulkToolsResponse extends HTTPResponse */ public function addHeader($header, $value) { - if($header === "content-type") { + if ($header === "content-type") { return $this; } return parent::addHeader($header, $value); @@ -139,7 +139,7 @@ class HTTPBulkToolsResponse extends HTTPResponse */ public function removeHeader($header) { - if($header === "content-type") { + if ($header === "content-type") { return $this; } return parent::removeHeader($header); @@ -333,7 +333,7 @@ class HTTPBulkToolsResponse extends HTTPResponse ); foreach ($this->successRecords as $record) { - $data = array('id' => $record->ID, 'class' => str_replace('\\', '\\\\', $record->ClassName)); + $data = array('id' => $record->ID, 'class' => str_replace('\\', '\\\\', $record->ClassName ?? '')); if (!$this->removesRows) { $data['row'] = $this->getRecordGridfieldRow($record); } diff --git a/src/BulkUploader/BulkUploadHandler.php b/src/BulkUploader/BulkUploadHandler.php index 37cee9a..be807dd 100644 --- a/src/BulkUploader/BulkUploadHandler.php +++ b/src/BulkUploader/BulkUploadHandler.php @@ -70,7 +70,7 @@ class BulkUploadHandler extends RequestHandler * Add file ID to the Dataobject * Add DataObject to Gridfield list * Publish DataObject if enabled - * + * * @param integer $fileID The newly uploaded/attached file ID * * @return DataObject The new DataObject @@ -86,7 +86,7 @@ class BulkUploadHandler extends RequestHandler $fileRelationName = $this->component->getFileRelationName($this->gridField); $record->{"{$fileRelationName}ID"} = $fileID; $record->write(); //HasManyList call write on record but not ManyManyList, so we call it here again - + $this->gridField->list->add($record); if ( @@ -111,9 +111,8 @@ class BulkUploadHandler extends RequestHandler { $assetAdmin = AssetAdmin::singleton(); $uploadResponse = $assetAdmin->apiCreateFile($request); - - if ($uploadResponse->getStatusCode() == 200) - { + + if ($uploadResponse->getStatusCode() == 200) { $responseData = Convert::json2array($uploadResponse->getBody()); $responseData = array_shift($responseData); @@ -121,7 +120,7 @@ class BulkUploadHandler extends RequestHandler $bulkToolsResponse = new HTTPBulkToolsResponse(false, $this->gridField); $bulkToolsResponse->addSuccessRecord($record); - + $responseData['bulkTools'] = json_decode($bulkToolsResponse->getBody() ?? ''); $uploadResponse->setBody(json_encode(array($responseData))); } diff --git a/src/BulkUploader/BulkUploader.php b/src/BulkUploader/BulkUploader.php index 2097c11..5f05cae 100644 --- a/src/BulkUploader/BulkUploader.php +++ b/src/BulkUploader/BulkUploader.php @@ -183,7 +183,8 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler $imageField = null; foreach ($hasOneFields as $field => $type) { - if ($type === 'SilverStripe\\Assets\\Image' + if ( + $type === 'SilverStripe\\Assets\\Image' || $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, '') ->setForm($gridField->getForm()) ->setRecord(DataObject::create()) // avoid UploadField to get auto-config from the Page (e.g fix allowedMaxFileNumber) - ; + ; //UploadField setup foreach ($this->ufSetup as $fn => $param) { @@ -293,8 +294,8 @@ class BulkUploader implements GridField_HTMLProvider, GridField_URLHandler 'Colspan' => (count($gridField->getColumns() ?? [])), 'UploadField' => $uploadField->Field() // call ->Field() to get requirements in right order )); - - Requirements::javascript('colymba/gridfield-bulk-editing-tools:client/dist/js/main.js'); + //This one is no longer needed since the javascript is now loaded at the top of the cms + //Requirements::javascript('colymba/gridfield-bulk-editing-tools:client/dist/js/main.js'); Requirements::css('colymba/gridfield-bulk-editing-tools:client/dist/styles/main.css'); Requirements::add_i18n_javascript('colymba/gridfield-bulk-editing-tools:client/lang');