update
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
const {$} = window;
|
||||
|
||||
/**
|
||||
* Class DeleteCategoriesBulkActionExtension handles submitting of row action
|
||||
*/
|
||||
export default class DeleteCategoriesBulkActionExtension {
|
||||
constructor() {
|
||||
return {
|
||||
extend: (grid) => this.extend(grid),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend grid
|
||||
*
|
||||
* @param {Grid} grid
|
||||
*/
|
||||
extend(grid) {
|
||||
grid.getContainer().on('click', '.js-delete-categories-bulk-action', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const submitUrl = $(event.currentTarget).data('categories-delete-url');
|
||||
|
||||
const $deleteCategoriesModal = $(`#${grid.getId()}_grid_delete_categories_modal`);
|
||||
$deleteCategoriesModal.modal('show');
|
||||
|
||||
$deleteCategoriesModal.on('click', '.js-submit-delete-categories', () => {
|
||||
const $checkboxes = grid.getContainer().find('.js-bulk-action-checkbox:checked');
|
||||
const $categoriesToDeleteInputBlock = $('#delete_categories_categories_to_delete');
|
||||
|
||||
$checkboxes.each((i, element) => {
|
||||
const $checkbox = $(element);
|
||||
|
||||
const categoryInput = $categoriesToDeleteInputBlock
|
||||
.data('prototype')
|
||||
.replace(/__name__/g, $checkbox.val());
|
||||
|
||||
const $input = $($.parseHTML(categoryInput)[0]);
|
||||
$input.val($checkbox.val());
|
||||
|
||||
$categoriesToDeleteInputBlock.append($input);
|
||||
});
|
||||
|
||||
const $form = $deleteCategoriesModal.find('form');
|
||||
|
||||
$form.attr('action', submitUrl);
|
||||
$form.submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
const {$} = window;
|
||||
|
||||
/**
|
||||
* Handles bulk delete for "Customers" grid.
|
||||
*/
|
||||
export default class DeleteCustomersBulkActionExtension {
|
||||
constructor() {
|
||||
return {
|
||||
extend: (grid) => this.extend(grid),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend grid
|
||||
*
|
||||
* @param {Grid} grid
|
||||
*/
|
||||
extend(grid) {
|
||||
grid.getContainer().on('click', '.js-delete-customers-bulk-action', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const submitUrl = $(event.currentTarget).data('customers-delete-url');
|
||||
|
||||
const $modal = $(`#${grid.getId()}_grid_delete_customers_modal`);
|
||||
$modal.modal('show');
|
||||
|
||||
$modal.on('click', '.js-submit-delete-customers', () => {
|
||||
const $selectedCustomerCheckboxes = grid.getContainer().find('.js-bulk-action-checkbox:checked');
|
||||
|
||||
$selectedCustomerCheckboxes.each((i, checkbox) => {
|
||||
const $input = $(checkbox);
|
||||
|
||||
this.addCustomerToDeleteCollectionInput($input.val());
|
||||
});
|
||||
|
||||
const $form = $modal.find('form');
|
||||
|
||||
$form.attr('action', submitUrl);
|
||||
$form.submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create input with customer id and add it to delete collection input
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
addCustomerToDeleteCollectionInput(customerId) {
|
||||
const $customersInput = $('#delete_customers_customers_to_delete');
|
||||
|
||||
const customerInput = $customersInput
|
||||
.data('prototype')
|
||||
.replace(/__name__/g, customerId);
|
||||
const $item = $($.parseHTML(customerInput)[0]);
|
||||
$item.val(customerId);
|
||||
|
||||
$customersInput.append($item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
const {$} = window;
|
||||
|
||||
/**
|
||||
* Class CategoryDeleteRowActionExtension handles submitting of row action
|
||||
*/
|
||||
export default class DeleteCategoryRowActionExtension {
|
||||
constructor() {
|
||||
return {
|
||||
extend: (grid) => this.extend(grid),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend grid
|
||||
*
|
||||
* @param {Grid} grid
|
||||
*/
|
||||
extend(grid) {
|
||||
grid.getContainer().on('click', '.js-delete-category-row-action', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const $deleteCategoriesModal = $(`#${grid.getId()}_grid_delete_categories_modal`);
|
||||
$deleteCategoriesModal.modal('show');
|
||||
|
||||
$deleteCategoriesModal.on('click', '.js-submit-delete-categories', () => {
|
||||
const $button = $(event.currentTarget);
|
||||
const categoryId = $button.data('category-id');
|
||||
|
||||
const $categoriesToDeleteInputBlock = $('#delete_categories_categories_to_delete');
|
||||
|
||||
const categoryInput = $categoriesToDeleteInputBlock
|
||||
.data('prototype')
|
||||
.replace(/__name__/g, $categoriesToDeleteInputBlock.children().length);
|
||||
|
||||
const $item = $($.parseHTML(categoryInput)[0]);
|
||||
$item.val(categoryId);
|
||||
|
||||
$categoriesToDeleteInputBlock.append($item);
|
||||
|
||||
const $form = $deleteCategoriesModal.find('form');
|
||||
|
||||
$form.attr('action', $button.data('category-delete-url'));
|
||||
$form.submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
const {$} = window;
|
||||
|
||||
/**
|
||||
* Class DeleteCustomerRowActionExtension handles submitting of row action
|
||||
*/
|
||||
export default class DeleteCustomerRowActionExtension {
|
||||
constructor() {
|
||||
return {
|
||||
extend: (grid) => this.extend(grid),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Extend grid
|
||||
*
|
||||
* @param {Grid} grid
|
||||
*/
|
||||
extend(grid) {
|
||||
grid.getContainer().on('click', '.js-delete-customer-row-action', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const $deleteCustomersModal = $(`#${grid.getId()}_grid_delete_customers_modal`);
|
||||
$deleteCustomersModal.modal('show');
|
||||
|
||||
$deleteCustomersModal.on('click', '.js-submit-delete-customers', () => {
|
||||
const $button = $(event.currentTarget);
|
||||
const customerId = $button.data('customer-id');
|
||||
|
||||
this.addCustomerInput(customerId);
|
||||
|
||||
const $form = $deleteCustomersModal.find('form');
|
||||
|
||||
$form.attr('action', $button.data('customer-delete-url'));
|
||||
$form.submit();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds input for selected customer to delete form
|
||||
*
|
||||
* @param {integer} customerId
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
addCustomerInput(customerId) {
|
||||
const $customersToDeleteInputBlock = $('#delete_customers_customers_to_delete');
|
||||
|
||||
const customerInput = $customersToDeleteInputBlock
|
||||
.data('prototype')
|
||||
.replace(/__name__/g, $customersToDeleteInputBlock.children().length);
|
||||
|
||||
const $item = $($.parseHTML(customerInput)[0]);
|
||||
$item.val(customerId);
|
||||
|
||||
$customersToDeleteInputBlock.append($item);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
import ConfirmModal from '@components/modal';
|
||||
|
||||
const {$} = window;
|
||||
|
||||
/**
|
||||
* Class SubmitRowActionExtension handles submitting of row action
|
||||
*/
|
||||
export default class SubmitRowActionExtension {
|
||||
/**
|
||||
* Extend grid
|
||||
*
|
||||
* @param {Grid} grid
|
||||
*/
|
||||
extend(grid) {
|
||||
grid.getContainer().on('click', '.js-submit-row-action', (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
const $button = $(event.currentTarget);
|
||||
const confirmMessage = $button.data('confirmMessage');
|
||||
const confirmTitle = $button.data('title');
|
||||
|
||||
const method = $button.data('method');
|
||||
|
||||
if (confirmTitle) {
|
||||
this.showConfirmModal($button, grid, confirmMessage, confirmTitle, method);
|
||||
} else {
|
||||
if (confirmMessage.length && !window.confirm(confirmMessage)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.postForm($button, method);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
postForm($button, method) {
|
||||
const isGetOrPostMethod = ['GET', 'POST'].includes(method);
|
||||
|
||||
const $form = $('<form>', {
|
||||
action: $button.data('url'),
|
||||
method: isGetOrPostMethod ? method : 'POST',
|
||||
}).appendTo('body');
|
||||
|
||||
if (!isGetOrPostMethod) {
|
||||
$form.append($('<input>', {
|
||||
type: '_hidden',
|
||||
name: '_method',
|
||||
value: method,
|
||||
}));
|
||||
}
|
||||
|
||||
$form.submit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {jQuery} $submitBtn
|
||||
* @param {Grid} grid
|
||||
* @param {string} confirmMessage
|
||||
* @param {string} confirmTitle
|
||||
* @param {string} method
|
||||
*/
|
||||
showConfirmModal($submitBtn, grid, confirmMessage, confirmTitle, method) {
|
||||
const confirmButtonLabel = $submitBtn.data('confirmButtonLabel');
|
||||
const closeButtonLabel = $submitBtn.data('closeButtonLabel');
|
||||
const confirmButtonClass = $submitBtn.data('confirmButtonClass');
|
||||
|
||||
const modal = new ConfirmModal({
|
||||
id: `${grid.getId()}-grid-confirm-modal`,
|
||||
confirmTitle,
|
||||
confirmMessage,
|
||||
confirmButtonLabel,
|
||||
closeButtonLabel,
|
||||
confirmButtonClass,
|
||||
}, () => this.postForm($submitBtn, method));
|
||||
|
||||
modal.show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user