first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -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();
});
});
}
}

View File

@@ -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);
}
}

View File

@@ -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();
});
});
}
}

View File

@@ -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);
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,105 @@
/**
* 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 BulkActionSelectCheckboxExtension
*/
export default class BulkActionCheckboxExtension {
/**
* Extend grid with bulk action checkboxes handling functionality
*
* @param {Grid} grid
*/
extend(grid) {
this.handleBulkActionCheckboxSelect(grid);
this.handleBulkActionSelectAllCheckbox(grid);
}
/**
* Handles "Select all" button in the grid
*
* @param {Grid} grid
*
* @private
*/
handleBulkActionSelectAllCheckbox(grid) {
grid.getContainer().on('change', '.js-bulk-action-select-all', (e) => {
const $checkbox = $(e.currentTarget);
const isChecked = $checkbox.is(':checked');
if (isChecked) {
this.enableBulkActionsBtn(grid);
} else {
this.disableBulkActionsBtn(grid);
}
grid.getContainer().find('.js-bulk-action-checkbox').prop('checked', isChecked);
});
}
/**
* Handles each bulk action checkbox select in the grid
*
* @param {Grid} grid
*
* @private
*/
handleBulkActionCheckboxSelect(grid) {
grid.getContainer().on('change', '.js-bulk-action-checkbox', () => {
const checkedRowsCount = grid.getContainer().find('.js-bulk-action-checkbox:checked').length;
if (checkedRowsCount > 0) {
this.enableBulkActionsBtn(grid);
} else {
this.disableBulkActionsBtn(grid);
}
});
}
/**
* Enable bulk actions button
*
* @param {Grid} grid
*
* @private
*/
enableBulkActionsBtn(grid) {
grid.getContainer().find('.js-bulk-actions-btn').prop('disabled', false);
}
/**
* Disable bulk actions button
*
* @param {Grid} grid
*
* @private
*/
disableBulkActionsBtn(grid) {
grid.getContainer().find('.js-bulk-actions-btn').prop('disabled', true);
}
}

View File

@@ -0,0 +1,86 @@
/**
* 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 Router from '../../router';
const {$} = window;
/**
* Class BulkOpenTabsExtension
*/
export default class BulkOpenTabsExtension {
constructor() {
this.router = new Router();
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid with bulk action open tabs
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-bulk-action-btn.open_tabs', (event) => {
this.openTabs(event, grid);
});
}
/**
* Handle bulk action opening tabs
*
* @param {Event} event
* @param {Grid} grid
*
* @private
*/
openTabs(event, grid) {
const $submitBtn = $(event.currentTarget);
const route = $submitBtn.data('route');
const routeParamName = $submitBtn.data('routeParamName');
const tabsBlockedMessage = $submitBtn.data('tabsBlockedMessage');
const $checkboxes = grid.getContainer().find('.js-bulk-action-checkbox:checked');
let allTabsOpened = true;
$checkboxes.each((i, element) => {
const $checkbox = $(element);
const routeParams = {};
routeParams[routeParamName] = $checkbox.val();
const handle = window.open(this.router.generate(route, routeParams));
if (handle) {
handle.blur();
window.focus();
} else {
allTabsOpened = false;
}
if (!allTabsOpened) {
alert(tabsBlockedMessage);
}
});
}
}

View File

@@ -0,0 +1,104 @@
/**
* 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;
/**
* This extension enables submit functionality of the choice fields in grid.
*
* Usage of the extension:
*
* const myGrid = new Grid('myGrid');
* myGrid.addExtension(new ChoiceExtension());
*
*/
export default class ChoiceExtension {
constructor() {
this.locks = [];
}
extend(grid) {
const $choiceOptionsContainer = grid.getContainer().find('table.table .js-choice-options');
$choiceOptionsContainer.find('.js-dropdown-item').on('click', (e) => {
e.preventDefault();
const $button = $(e.currentTarget);
const $parent = $button.closest('.js-choice-options');
const url = $parent.data('url');
this.submitForm(url, $button);
});
}
/**
* Submits the form.
* @param {string} url
* @param {jQuery} $button
* @private
*/
submitForm(url, $button) {
const selectedStatusId = $button.data('value');
if (this.isLocked(url)) {
return;
}
const $form = $('<form>', {
action: url,
method: 'POST',
}).append(
$('<input>', {
name: 'value',
value: selectedStatusId,
type: 'hidden',
}));
$form.appendTo('body');
$form.submit();
this.lock(url);
}
/**
* Checks if current url is being used at the moment.
*
* @param url
* @return {boolean}
*
* @private
*/
isLocked(url) {
return this.locks.includes(url);
}
/**
* Locks the current url so it cant be used twice to execute same request
* @param url
* @private
*/
lock(url) {
this.locks.push(url);
}
}

View File

@@ -0,0 +1,69 @@
/**
* 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 ReloadListExtension extends grid with "Column toggling" feature
*/
export default class ColumnTogglingExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
const $table = grid.getContainer().find('table.table');
$table.find('.ps-togglable-row').on('click', (e) => {
e.preventDefault();
this.toggleValue($(e.delegateTarget));
});
}
/**
* @param {jQuery} row
* @private
*/
toggleValue(row) {
const toggleUrl = row.data('toggleUrl');
this.submitAsForm(toggleUrl);
}
/**
* Submits request url as form
*
* @param {string} toggleUrl
* @private
*/
submitAsForm(toggleUrl) {
const $form = $('<form>', {
action: toggleUrl,
method: 'POST',
}).appendTo('body');
$form.submit();
}
}

View File

@@ -0,0 +1,166 @@
/**
* 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 'tablednd/dist/jquery.tablednd.min';
const {$} = window;
/**
* Class CategoryPositionExtension extends Grid with reorderable category positions
*/
export default class CategoryPositionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
this.grid = grid;
this.addIdsToGridTableRows();
grid.getContainer().find('.js-grid-table').tableDnD({
dragHandle: '.js-drag-handle',
onDragClass: 'dragging-row',
onDragStart: () => {
this.originalPositions = decodeURIComponent($.tableDnD.serialize());
},
onDrop: (table, row) => this.handleCategoryPositionChange(row),
});
}
/**
* When position is changed handle update
*
* @param {HTMLElement} row
*
* @private
*/
handleCategoryPositionChange(row) {
const positions = decodeURIComponent($.tableDnD.serialize());
const way = (this.originalPositions.indexOf(row.id) < positions.indexOf(row.id)) ? 1 : 0;
const $categoryPositionContainer = $(row).find(`.js-${this.grid.getId()}-position:first`);
const categoryId = $categoryPositionContainer.data('id');
const categoryParentId = $categoryPositionContainer.data('id-parent');
const positionUpdateUrl = $categoryPositionContainer.data('position-update-url');
let params = positions.replace(new RegExp(`${this.grid.getId()}_grid_table`, 'g'), 'positions');
const queryParams = {
id_category_parent: categoryParentId,
id_category_to_move: categoryId,
way,
};
if (positions.indexOf('_0&') !== -1) {
queryParams.found_first = 1;
}
params += `&${$.param(queryParams)}`;
this.updateCategoryPosition(positionUpdateUrl, params);
}
/**
* Add ID's to Grid table rows to make tableDnD.onDrop() function work.
*
* @private
*/
addIdsToGridTableRows() {
this.grid.getContainer()
.find('.js-grid-table')
.find(`.js-${this.grid.getId()}-position`)
.each((index, positionWrapper) => {
const $positionWrapper = $(positionWrapper);
const categoryId = $positionWrapper.data('id');
const categoryParentId = $positionWrapper.data('id-parent');
const position = $positionWrapper.data('position');
const id = `tr_${categoryParentId}_${categoryId}_${position}`;
$positionWrapper.closest('tr').attr('id', id);
});
}
/**
* Update categories listing with new positions
*
* @private
*/
updateCategoryIdsAndPositions() {
this.grid.getContainer()
.find('.js-grid-table')
.find(`.js-${this.grid.getId()}-position`)
.each((index, positionWrapper) => {
const $positionWrapper = $(positionWrapper);
const $row = $positionWrapper.closest('tr');
const offset = $positionWrapper.data('pagination-offset');
const newPosition = offset > 0 ? index + offset : index;
const oldId = $row.attr('id');
$row.attr('id', oldId.replace(/_[0-9]$/g, `_${newPosition}`));
$positionWrapper.find('.js-position').text(newPosition + 1);
$positionWrapper.data('position', newPosition);
});
}
/**
* Process categories positions update
*
* @param {String} url
* @param {String} params
*
* @private
*/
updateCategoryPosition(url, params) {
$.post({
url,
headers: {
'cache-control': 'no-cache',
},
data: params,
dataType: 'json',
}).then((response) => {
if (response.success) {
window.showSuccessMessage(response.message);
} else {
window.showErrorMessage(response.message);
}
this.updateCategoryIdsAndPositions();
});
}
}

View File

@@ -0,0 +1,97 @@
/**
* 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 AsyncToggleColumnExtension submits toggle action using AJAX
*/
export default class AsyncToggleColumnExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid
.getContainer()
.find('.js-grid-table')
.on('click', '.ps-togglable-row', (event) => {
const $button = $(event.currentTarget);
if (!$button.hasClass('ps-switch')) {
event.preventDefault();
}
$.post({
url: $button.data('toggle-url'),
})
.then((response) => {
if (response.status) {
window.showSuccessMessage(response.message);
this.toggleButtonDisplay($button);
return;
}
window.showErrorMessage(response.message);
})
.catch((error) => {
const response = error.responseJSON;
window.showErrorMessage(response.message);
});
});
}
/**
* Toggle button display from enabled to disabled and other way around
*
* @param {jQuery} $button
*
* @private
*/
toggleButtonDisplay($button) {
const isActive = $button.hasClass('grid-toggler-icon-valid');
const classToAdd = isActive ? 'grid-toggler-icon-not-valid' : 'grid-toggler-icon-valid';
const classToRemove = isActive ? 'grid-toggler-icon-valid' : 'grid-toggler-icon-not-valid';
const icon = isActive ? 'clear' : 'check';
$button.removeClass(classToRemove);
$button.addClass(classToAdd);
if ($button.hasClass('material-icons')) {
$button.text(icon);
}
}
}

View File

@@ -0,0 +1,120 @@
/**
* 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 ExportToSqlManagerExtension extends grid with exporting query to SQL Manager
*/
export default class ExportToSqlManagerExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getHeaderContainer().on('click', '.js-common_show_query-grid-action', () => this.onShowSqlQueryClick(grid));
grid.getHeaderContainer().on(
'click',
'.js-common_export_sql_manager-grid-action',
() => this.onExportSqlManagerClick(grid),
);
}
/**
* Invoked when clicking on the "show sql query" toolbar button
*
* @param {Grid} grid
*
* @private
*/
onShowSqlQueryClick(grid) {
const $sqlManagerForm = $(`#${grid.getId()}_common_show_query_modal_form`);
this.fillExportForm($sqlManagerForm, grid);
const $modal = $(`#${grid.getId()}_grid_common_show_query_modal`);
$modal.modal('show');
$modal.on('click', '.btn-sql-submit', () => $sqlManagerForm.submit());
}
/**
* Invoked when clicking on the "export to the sql query" toolbar button
*
* @param {Grid} grid
*
* @private
*/
onExportSqlManagerClick(grid) {
const $sqlManagerForm = $(`#${grid.getId()}_common_show_query_modal_form`);
this.fillExportForm($sqlManagerForm, grid);
$sqlManagerForm.submit();
}
/**
* Fill export form with SQL and it's name
*
* @param {jQuery} $sqlManagerForm
* @param {Grid} grid
*
* @private
*/
fillExportForm($sqlManagerForm, grid) {
const query = grid.getContainer().find('.js-grid-table').data('query');
$sqlManagerForm.find('textarea[name="sql"]').val(query);
$sqlManagerForm.find('input[name="name"]').val(this.getNameFromBreadcrumb());
}
/**
* Get export name from page's breadcrumb
*
* @return {String}
*
* @private
*/
getNameFromBreadcrumb() {
const $breadcrumbs = $('.header-toolbar').find('.breadcrumb-item');
let name = '';
$breadcrumbs.each((i, item) => {
const $breadcrumb = $(item);
const breadcrumbTitle = $breadcrumb.find('a').length > 0
? $breadcrumb.find('a').text()
: $breadcrumb.text();
if (name.length > 0) {
name = name.concat(' > ');
}
name = name.concat(breadcrumbTitle);
});
return name;
}
}

View File

@@ -0,0 +1,44 @@
/**
* 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 resetSearch from '@app/utils/reset_search';
const {$} = window;
/**
* Class FiltersResetExtension extends grid with filters resetting
*/
export default class FiltersResetExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-reset-search', (event) => {
resetSearch($(event.currentTarget).data('url'), $(event.currentTarget).data('redirect'));
});
}
}

View File

@@ -0,0 +1,44 @@
/**
* 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)
*/
/**
* Responsible for grid filters search and reset button availability when filter inputs changes.
*/
export default class FiltersSubmitButtonEnablerExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
const $filtersRow = grid.getContainer().find('.column-filters');
$filtersRow.find('.grid-search-button').prop('disabled', true);
$filtersRow.find('input:not(.js-bulk-action-select-all), select').on('input dp.change', () => {
$filtersRow.find('.grid-search-button').prop('disabled', false);
$filtersRow.find('.js-grid-reset-button').prop('hidden', false);
});
}
}

View File

@@ -0,0 +1,95 @@
/**
* 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 LinkRowActionExtension handles link row actions
*/
export default class LinkRowActionExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
this.initRowLinks(grid);
this.initConfirmableActions(grid);
}
/**
* Extend grid
*
* @param {Grid} grid
*/
initConfirmableActions(grid) {
grid.getContainer().on('click', '.js-link-row-action', (event) => {
const confirmMessage = $(event.currentTarget).data('confirm-message');
if (confirmMessage.length && !window.confirm(confirmMessage)) {
event.preventDefault();
}
});
}
/**
* Add a click event on rows that matches the first link action (if present)
*
* @param {Grid} grid
*/
initRowLinks(grid) {
$('tr', grid.getContainer()).each(function initEachRow() {
const $parentRow = $(this);
$('.js-link-row-action[data-clickable-row=1]:first', $parentRow).each(function propagateFirstLinkAction() {
const $rowAction = $(this);
const $parentCell = $rowAction.closest('td');
const clickableCells = $('td.clickable', $parentRow).not($parentCell);
let isDragging = false;
clickableCells.addClass('cursor-pointer').mousedown(() => {
$(window).mousemove(() => {
isDragging = true;
$(window).unbind('mousemove');
});
});
clickableCells.mouseup(() => {
const wasDragging = isDragging;
isDragging = false;
$(window).unbind('mousemove');
if (!wasDragging) {
const confirmMessage = $rowAction.data('confirm-message');
if (!confirmMessage.length || window.confirm(confirmMessage)) {
document.location = $rowAction.attr('href');
}
}
});
});
});
}
}

View File

@@ -0,0 +1,73 @@
/**
* 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;
/**
* Allows submitting form inside modals.
* Form must be inside modal, see example structure below:
*
* <div class="modal" id="uniqueModalId">
* <form data-bulk-inputs-id="bulkInputs">
* <div class="d-none">
* <div id="bulkInputs" data-prototype="<input type="hidden" name="__name__"/>"></div>
* </div>
* </form>
* </div>
*
* Note that "data-prototype" is required to add checked items to the form. "__name__"
* will be replaced with value of bulk checkbox.
*/
export default class ModalFormSubmitExtension {
extend(grid) {
grid.getContainer().on('click', '.js-bulk-modal-form-submit-btn', (event) => {
const modalId = $(event.target).data('modal-id');
const $modal = $(`#${modalId}`);
$modal.modal('show');
$modal.find('.js-submit-modal-form-btn').on('click', () => {
const $form = $modal.find('form');
const $bulkInputsBlock = $form.find(`#${$form.data('bulk-inputs-id')}`);
const $checkboxes = grid.getContainer().find('.js-bulk-action-checkbox:checked');
$checkboxes.each((i, element) => {
const $checkbox = $(element);
const input = $bulkInputsBlock
.data('prototype')
.replace(/__name__/g, $checkbox.val());
const $input = $($.parseHTML(input)[0]);
$input.val($checkbox.val());
$form.append($input);
});
$form.submit();
});
});
}
}

View File

@@ -0,0 +1,204 @@
/**
* 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 'tablednd/dist/jquery.tablednd.min';
const {$} = window;
/**
* Class PositionExtension extends Grid with reorderable positions
*/
export default class PositionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
this.grid = grid;
this.addIdsToGridTableRows();
grid.getContainer().find('.js-grid-table').tableDnD({
onDragClass: 'position-row-while-drag',
dragHandle: '.js-drag-handle',
onDrop: (table, row) => this.handlePositionChange(row),
});
grid.getContainer().find('.js-drag-handle').hover(
function () {
$(this).closest('tr').addClass('hover');
},
function () {
$(this).closest('tr').removeClass('hover');
},
);
}
/**
* When position is changed handle update
*
* @param {HTMLElement} row
*
* @private
*/
handlePositionChange(row) {
const $rowPositionContainer = $(row).find(`.js-${this.grid.getId()}-position:first`);
const updateUrl = $rowPositionContainer.data('update-url');
const method = $rowPositionContainer.data('update-method');
const positions = this.getRowsPositions();
const params = {positions};
this.updatePosition(updateUrl, params, method);
}
/**
* Returns the current table positions
* @returns {Array}
* @private
*/
getRowsPositions() {
const tableData = JSON.parse($.tableDnD.jsonize());
const rowsData = tableData[`${this.grid.getId()}_grid_table`];
const completeRowsData = [];
let trData;
// retrieve dragAndDropOffset offset to have all needed data
// for positions mapping evolution over time
for (let i = 0; i < rowsData.length; i += 1) {
trData = this.grid.getContainer()
.find(`#${rowsData[i]}`);
completeRowsData.push({
rowMarker: rowsData[i],
offset: trData.data('dragAndDropOffset'),
});
}
return this.computeMappingBetweenOldAndNewPositions(completeRowsData);
}
/**
* Add ID's to Grid table rows to make tableDnD.onDrop() function work.
*
* @private
*/
addIdsToGridTableRows() {
let counter = 0;
this.grid.getContainer()
.find(`.js-grid-table .js-${this.grid.getId()}-position`)
.each((index, positionWrapper) => {
const $positionWrapper = $(positionWrapper);
const rowId = $positionWrapper.data('id');
const position = $positionWrapper.data('position');
const id = `row_${rowId}_${position}`;
$positionWrapper.closest('tr').attr('id', id);
$positionWrapper.closest('td').addClass('js-drag-handle');
$positionWrapper.closest('tr').data('dragAndDropOffset', counter);
counter += 1;
});
}
/**
* Process rows positions update
*
* @param {String} url
* @param {Object} params
* @param {String} method
*
* @private
*/
updatePosition(url, params, method) {
const isGetOrPostMethod = ['GET', 'POST'].includes(method);
const $form = $('<form>', {
action: url,
method: isGetOrPostMethod ? method : 'POST',
}).appendTo('body');
const positionsNb = params.positions.length;
let position;
for (let i = 0; i < positionsNb; i += 1) {
position = params.positions[i];
$form.append(
$('<input>', {
type: 'hidden',
name: `positions[${i}][rowId]`,
value: position.rowId,
}),
$('<input>', {
type: 'hidden',
name: `positions[${i}][oldPosition]`,
value: position.oldPosition,
}),
$('<input>', {
type: 'hidden',
name: `positions[${i}][newPosition]`,
value: position.newPosition,
}),
);
}
// This _method param is used by Symfony to simulate DELETE and PUT methods
if (!isGetOrPostMethod) {
$form.append($('<input>', {
type: 'hidden',
name: '_method',
value: method,
}));
}
$form.submit();
}
/**
* Rows have been reordered. This function
* finds, for each row ID: the old position, the new position
*
* @returns {Array}
* @private
*/
computeMappingBetweenOldAndNewPositions(rowsData) {
const regex = /^row_(\d+)_(\d+)$/;
const mapping = Array(rowsData.length).fill().map(Object);
for (let i = 0; i < rowsData.length; i += 1) {
const [, rowId, oldPosition] = regex.exec(rowsData[i].rowMarker);
mapping[i].rowId = rowId;
mapping[i].oldPosition = parseInt(oldPosition, 10);
// This row will have as a new position the old position of the current one
mapping[rowsData[i].offset].newPosition = mapping[i].oldPosition;
}
return mapping;
}
}

View File

@@ -0,0 +1,230 @@
/**
* 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;
/**
* Extends grid with preview functionality.
*/
export default class PreviewExtension {
constructor(previewCustomization) {
this.locks = [];
this.expandSelector = '.js-expand';
this.collapseSelector = '.js-collapse';
this.previewOpenClass = 'preview-open';
this.previewToggleSelector = '.preview-toggle';
this.previewCustomization = previewCustomization;
}
/**
* Extends provided grid with preview functionality
*
* @param grid
*/
extend(grid) {
this.$gridContainer = $(grid.getContainer);
this.$gridContainer.find('tbody tr').on('mouseover mouseleave', (event) => this.handleIconHovering(event));
this.$gridContainer.find(this.previewToggleSelector).on('click', (event) => this.togglePreview(event));
}
/**
* Shows/hides preview toggling icons
*
* @param event
* @private
*/
handleIconHovering(event) {
const $previewToggle = $(event.currentTarget).find(this.previewToggleSelector);
if (event.type === 'mouseover' && !$(event.currentTarget).hasClass(this.previewOpenClass)) {
this.showExpandIcon($previewToggle);
} else {
this.hideExpandIcon($previewToggle);
}
}
/**
* Shows/hides preview
*
* @param event
* @private
*/
togglePreview(event) {
const $previewToggle = $(event.currentTarget);
const $columnRow = $previewToggle.closest('tr');
if ($columnRow.hasClass(this.previewOpenClass)) {
$columnRow.next('.preview-row').remove();
$columnRow.removeClass(this.previewOpenClass);
this.showExpandIcon($columnRow);
this.hideCollapseIcon($columnRow);
return;
}
this.closeOpenedPreviews();
const dataUrl = $(event.currentTarget).data('preview-data-url');
if (this.isLocked(dataUrl)) {
return;
}
// Prevents loading preview multiple times.
// Uses "dataUrl" as lock key.
this.lock(dataUrl);
$.ajax({
url: dataUrl,
method: 'GET',
dataType: 'json',
complete: () => {
this.unlock(dataUrl);
},
}).then((response) => {
this.renderPreviewContent($columnRow, response.preview);
}).catch((e) => {
window.showErrorMessage(e.responseJSON.message);
});
}
/**
* Renders preview content
*
* @param $columnRow
* @param content
*
* @private
*/
renderPreviewContent($columnRow, content) {
const rowColumnCount = $columnRow.find('td').length;
const $previewTemplate = $(`
<tr class="preview-row">
<td colspan="${rowColumnCount}">${content}</td>
</tr>
`);
$columnRow.addClass(this.previewOpenClass);
this.showCollapseIcon($columnRow);
this.hideExpandIcon($columnRow);
if (typeof this.previewCustomization === 'function') {
this.previewCustomization($previewTemplate);
}
$columnRow.after($previewTemplate);
}
/**
* Shows preview expanding icon
*
* @param parent
* @private
*/
showExpandIcon(parent) {
parent.find(this.expandSelector).removeClass('d-none');
}
/**
* Hides preview expanding icon
*
* @param parent
* @private
*/
hideExpandIcon(parent) {
parent.find(this.expandSelector).addClass('d-none');
}
/**
* Shows preview collapsing icon
*
* @param parent
* @private
*/
showCollapseIcon(parent) {
parent.find(this.collapseSelector).removeClass('d-none');
}
/**
* Hides preview collapsing icon
*
* @param parent
* @private
*/
hideCollapseIcon(parent) {
parent.find(this.collapseSelector).addClass('d-none');
}
isLocked(key) {
return this.locks.indexOf(key) !== -1;
}
lock(key) {
if (this.isLocked(key)) {
return;
}
this.locks.push(key);
}
unlock(key) {
const index = this.locks.indexOf(key);
if (index === -1) {
return;
}
this.locks.splice(index, 1);
}
/**
* Close all previews that are open.
*
* @private
*/
closeOpenedPreviews() {
const $rows = this.$gridContainer.find('.grid-table tbody').find('tr:not(.preview-row)');
$.each($rows, (i, row) => {
const $row = $(row);
if (!$row.hasClass(this.previewOpenClass)) {
return;
}
const $previewRow = $row.next();
if (!$previewRow.hasClass('preview-row')) {
return;
}
$previewRow.remove();
$row.removeClass(this.previewOpenClass);
this.hideCollapseIcon($row);
});
}
}

View File

@@ -0,0 +1,40 @@
/**
* 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)
*/
/**
* Class ReloadListExtension extends grid with "List reload" action
*/
export default class ReloadListExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getHeaderContainer().on('click', '.js-common_refresh_list-grid-action', () => {
window.location.reload();
});
}
}

View File

@@ -0,0 +1,42 @@
/**
* 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 TableSorting from '@app/utils/table-sorting';
/**
* Class ReloadListExtension extends grid with "List reload" action
*/
export default class SortingExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
const $sortableTable = grid.getContainer().find('table.table');
new TableSorting($sortableTable).attach();
}
}

View File

@@ -0,0 +1,109 @@
/**
* 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;
/**
* Handles submit of grid actions
*/
export default class SubmitBulkActionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid with bulk action submitting
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-bulk-action-submit-btn', (event) => {
this.submit(event, grid);
});
}
/**
* Handle bulk action submitting
*
* @param {Event} event
* @param {Grid} grid
*
* @private
*/
submit(event, grid) {
const $submitBtn = $(event.currentTarget);
const confirmMessage = $submitBtn.data('confirm-message');
const confirmTitle = $submitBtn.data('confirmTitle');
if (confirmMessage !== undefined && confirmMessage.length > 0) {
if (confirmTitle !== undefined) {
this.showConfirmModal($submitBtn, grid, confirmMessage, confirmTitle);
} else if (window.confirm(confirmMessage)) {
this.postForm($submitBtn, grid);
}
} else {
this.postForm($submitBtn, grid);
}
}
/**
* @param {jQuery} $submitBtn
* @param {Grid} grid
* @param {string} confirmMessage
* @param {string} confirmTitle
*/
showConfirmModal($submitBtn, grid, confirmMessage, confirmTitle) {
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, grid));
modal.show();
}
/**
* @param {jQuery} $submitBtn
* @param {Grid} grid
*/
postForm($submitBtn, grid) {
const $form = $(`#${grid.getId()}_filter_form`);
$form.attr('action', $submitBtn.data('form-url'));
$form.attr('method', $submitBtn.data('form-method'));
$form.submit();
}
}

View File

@@ -0,0 +1,68 @@
/**
* 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 SubmitGridActionExtension handles grid action submits
*/
export default class SubmitGridActionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
extend(grid) {
grid.getHeaderContainer().on('click', '.js-grid-action-submit-btn', (event) => {
this.handleSubmit(event, grid);
});
}
/**
* Handle grid action submit.
* It uses grid form to submit actions.
*
* @param {Event} event
* @param {Grid} grid
*
* @private
*/
handleSubmit(event, grid) {
const $submitBtn = $(event.currentTarget);
const confirmMessage = $submitBtn.data('confirm-message');
if (typeof confirmMessage !== 'undefined' && confirmMessage.length > 0 && !window.confirm(confirmMessage)) {
return;
}
const $form = $(`#${grid.getId()}_filter_form`);
$form.attr('action', $submitBtn.data('url'));
$form.attr('method', $submitBtn.data('method'));
$form.find(`input[name="${grid.getId()}[_token]"]`).val($submitBtn.data('csrf'));
$form.submit();
}
}

View File

@@ -0,0 +1,77 @@
/**
* 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 is responsible for handling Grid events
*/
export default class Grid {
/**
* Grid id
*
* @param {string} id
*/
constructor(id) {
this.id = id;
this.$container = $(`#${this.id}_grid`);
}
/**
* Get grid id
*
* @returns {string}
*/
getId() {
return this.id;
}
/**
* Get grid container
*
* @returns {jQuery}
*/
getContainer() {
return this.$container;
}
/**
* Get grid header container
*
* @returns {jQuery}
*/
getHeaderContainer() {
return this.$container.closest('.js-grid-panel').find('.js-grid-header');
}
/**
* Extend grid with external extensions
*
* @param {object} extension
*/
addExtension(extension) {
extension.extend(this);
}
}