Initial commit

This commit is contained in:
2019-11-20 07:44:43 +01:00
commit 5bf49c4a81
41188 changed files with 5459177 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
/**
* ChoiceTable is responsible for managing common actions in choice table form type
*/
export default class ChoiceTable {
/**
* Init constructor
*/
constructor() {
$(document).on('change', '.js-choice-table-select-all', (e) => {
this.handleSelectAll(e);
});
}
/**
* Check/uncheck all boxes in table
*
* @param {Event} event
*/
handleSelectAll(event) {
const $selectAllCheckboxes = $(event.target);
const isSelectAllChecked = $selectAllCheckboxes.is(':checked');
$selectAllCheckboxes.closest('table').find('tbody input:checkbox').prop('checked', isSelectAllChecked);
}
}

View File

@@ -0,0 +1,67 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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('confirm-message');
if (confirmMessage.length && !confirm(confirmMessage)) {
return;
}
const method = $button.data('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();
});
}
}

View File

@@ -0,0 +1,104 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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,70 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = global.$;
/**
* 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,116 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
/**
* Class ExportToSqlManagerExtension extends grid with exporting query to SQL Manager
*/
export default class ExportToSqlManagerExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-common_show_query-grid-action', () => this._onShowSqlQueryClick(grid));
grid.getContainer().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 = 0 < $breadcrumb.find('a').length ?
$breadcrumb.find('a').text() :
$breadcrumb.text();
if (0 < name.length) {
name = name.concat(' > ');
}
name = name.concat(breadcrumbTitle);
});
return name;
}
}

View File

@@ -0,0 +1,45 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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,46 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
/**
* Class LinkRowActionExtension handles link row actions
*/
export default class LinkRowActionExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-link-row-action', (event) => {
const confirmMessage = $(event.currentTarget).data('confirm-message');
if (confirmMessage.length && !confirm(confirmMessage)) {
event.preventDefault();
}
});
}
}

View File

@@ -0,0 +1,175 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
import tableDnD from "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 paginationOffset = parseInt($rowPositionContainer.data('pagination-offset'), 10);
const positions = this._getRowsPositions(paginationOffset);
const params = {positions};
this._updatePosition(updateUrl, params, method);
}
/**
* Returns the current table positions
* @returns {Array}
* @private
*/
_getRowsPositions(paginationOffset) {
const tableData = JSON.parse($.tableDnD.jsonize());
const rowsData = tableData[this.grid.getId()+'_grid_table'];
const regex = /^row_(\d+)_(\d+)$/;
const rowsNb = rowsData.length;
const positions = [];
let rowData, i;
for (i = 0; i < rowsNb; ++i) {
rowData = regex.exec(rowsData[i]);
positions.push({
rowId: rowData[1],
newPosition: paginationOffset + i,
oldPosition: parseInt(rowData[2], 10),
});
}
return positions;
}
/**
* Add ID's to Grid table rows to make tableDnD.onDrop() function work.
*
* @private
*/
_addIdsToGridTableRows() {
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');
});
}
/**
* 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) {
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();
}
}

View File

@@ -0,0 +1,40 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class ReloadListExtension extends grid with "List reload" action
*/
export default class ReloadListExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-common_refresh_list-grid-action', () => {
location.reload();
});
}
}

View File

@@ -0,0 +1,42 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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,71 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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');
if (typeof confirmMessage !== "undefined" && 0 < confirmMessage.length && !confirm(confirmMessage)) {
return;
}
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 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
/**
* Class SubmitGridActionExtension handles grid action submits
*/
export default class SubmitGridActionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid)
};
}
extend(grid) {
grid.getContainer().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" && 0 < confirmMessage.length && !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,68 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
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;
}
/**
* Extend grid with external extensions
*
* @param {object} extension
*/
addExtension(extension) {
extension.extend(this);
}
}

View File

@@ -0,0 +1,303 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
var BOEvent = {
on: function(eventName, callback, context) {
document.addEventListener(eventName, function(event) {
if (typeof context !== 'undefined') {
callback.call(context, event);
} else {
callback(event);
}
});
},
emitEvent: function(eventName, eventType) {
var _event = document.createEvent(eventType);
// true values stand for: can bubble, and is cancellable
_event.initEvent(eventName, true, true);
document.dispatchEvent(_event);
}
};
/**
* Class is responsible for handling Module Card behavior
*
* This is a port of admin-dev/themes/default/js/bundle/module/module_card.js
*/
export default class ModuleCard {
constructor() {
/* Selectors for module action links (uninstall, reset, etc...) to add a confirm popin */
this.moduleActionMenuLinkSelector = 'button.module_action_menu_';
this.moduleActionMenuInstallLinkSelector = 'button.module_action_menu_install';
this.moduleActionMenuEnableLinkSelector = 'button.module_action_menu_enable';
this.moduleActionMenuUninstallLinkSelector = 'button.module_action_menu_uninstall';
this.moduleActionMenuDisableLinkSelector = 'button.module_action_menu_disable';
this.moduleActionMenuEnableMobileLinkSelector = 'button.module_action_menu_enable_mobile';
this.moduleActionMenuDisableMobileLinkSelector = 'button.module_action_menu_disable_mobile';
this.moduleActionMenuResetLinkSelector = 'button.module_action_menu_reset';
this.moduleActionMenuUpdateLinkSelector = 'button.module_action_menu_upgrade';
this.moduleItemListSelector = '.module-item-list';
this.moduleItemGridSelector = '.module-item-grid';
this.moduleItemActionsSelector = '.module-actions';
/* Selectors only for modal buttons */
this.moduleActionModalDisableLinkSelector = 'a.module_action_modal_disable';
this.moduleActionModalResetLinkSelector = 'a.module_action_modal_reset';
this.moduleActionModalUninstallLinkSelector = 'a.module_action_modal_uninstall';
this.forceDeletionOption = '#force_deletion';
this.initActionButtons();
}
initActionButtons() {
const self = this;
$(document).on('click', this.forceDeletionOption, function () {
const btn = $(self.moduleActionModalUninstallLinkSelector, $("div.module-item-list[data-tech-name='" + $(this).attr("data-tech-name") + "']"));
if ($(this).prop('checked') === true) {
btn.attr('data-deletion', 'true');
} else {
btn.removeAttr('data-deletion');
}
});
$(document).on('click', this.moduleActionMenuInstallLinkSelector, function () {
if ($("#modal-prestatrust").length) {
$("#modal-prestatrust").modal('hide');
}
return self._dispatchPreEvent('install', this) && self._confirmAction('install', this) && self._requestToController('install', $(this));
});
$(document).on('click', this.moduleActionMenuEnableLinkSelector, function () {
return self._dispatchPreEvent('enable', this) && self._confirmAction('enable', this) && self._requestToController('enable', $(this));
});
$(document).on('click', this.moduleActionMenuUninstallLinkSelector, function () {
return self._dispatchPreEvent('uninstall', this) && self._confirmAction('uninstall', this) && self._requestToController('uninstall', $(this));
});
$(document).on('click', this.moduleActionMenuDisableLinkSelector, function () {
return self._dispatchPreEvent('disable', this) && self._confirmAction('disable', this) && self._requestToController('disable', $(this));
});
$(document).on('click', this.moduleActionMenuEnableMobileLinkSelector, function () {
return self._dispatchPreEvent('enable_mobile', this) && self._confirmAction('enable_mobile', this) && self._requestToController('enable_mobile', $(this));
});
$(document).on('click', this.moduleActionMenuDisableMobileLinkSelector, function () {
return self._dispatchPreEvent('disable_mobile', this) && self._confirmAction('disable_mobile', this) && self._requestToController('disable_mobile', $(this));
});
$(document).on('click', this.moduleActionMenuResetLinkSelector, function () {
return self._dispatchPreEvent('reset', this) && self._confirmAction('reset', this) && self._requestToController('reset', $(this));
});
$(document).on('click', this.moduleActionMenuUpdateLinkSelector, function () {
return self._dispatchPreEvent('update', this) && self._confirmAction('update', this) && self._requestToController('update', $(this));
});
$(document).on('click', this.moduleActionModalDisableLinkSelector, function () {
return self._requestToController('disable', $(self.moduleActionMenuDisableLinkSelector, $("div.module-item-list[data-tech-name='" + $(this).attr("data-tech-name") + "']")));
});
$(document).on('click', this.moduleActionModalResetLinkSelector, function () {
return self._requestToController('reset', $(self.moduleActionMenuResetLinkSelector, $("div.module-item-list[data-tech-name='" + $(this).attr("data-tech-name") + "']")));
});
$(document).on('click', this.moduleActionModalUninstallLinkSelector, function (e) {
$(e.target).parents('.modal').on('hidden.bs.modal', function(event) {
return self._requestToController(
'uninstall',
$(
self.moduleActionMenuUninstallLinkSelector,
$("div.module-item-list[data-tech-name='" + $(e.target).attr("data-tech-name") + "']")
),
$(e.target).attr("data-deletion")
);
}.bind(e));
});
};
_getModuleItemSelector() {
if ($(this.moduleItemListSelector).length) {
return this.moduleItemListSelector;
} else {
return this.moduleItemGridSelector;
}
};
_confirmAction(action, element) {
var modal = $('#' + $(element).data('confirm_modal'));
if (modal.length != 1) {
return true;
}
modal.first().modal('show');
return false; // do not allow a.href to reload the page. The confirm modal dialog will do it async if needed.
};
/**
* Update the content of a modal asking a confirmation for PrestaTrust and open it
*
* @param {array} result containing module data
* @return {void}
*/
_confirmPrestaTrust(result) {
var that = this;
var modal = this._replacePrestaTrustPlaceholders(result);
modal.find(".pstrust-install").off('click').on('click', function() {
// Find related form, update it and submit it
var install_button = $(that.moduleActionMenuInstallLinkSelector, '.module-item[data-tech-name="' + result.module.attributes.name + '"]');
var form = install_button.parent("form");
$('<input>').attr({
type: 'hidden',
value: '1',
name: 'actionParams[confirmPrestaTrust]'
}).appendTo(form);
install_button.click();
modal.modal('hide');
});
modal.modal();
};
_replacePrestaTrustPlaceholders(result) {
var modal = $("#modal-prestatrust");
var module = result.module.attributes;
if (result.confirmation_subject !== 'PrestaTrust' || !modal.length) {
return;
}
var alertClass = module.prestatrust.status ? 'success' : 'warning';
if (module.prestatrust.check_list.property) {
modal.find("#pstrust-btn-property-ok").show();
modal.find("#pstrust-btn-property-nok").hide();
} else {
modal.find("#pstrust-btn-property-ok").hide();
modal.find("#pstrust-btn-property-nok").show();
modal.find("#pstrust-buy").attr("href", module.url).toggle(module.url !== null);
}
modal.find("#pstrust-img").attr({src: module.img, alt: module.name});
modal.find("#pstrust-name").text(module.displayName);
modal.find("#pstrust-author").text(module.author);
modal.find("#pstrust-label").attr("class", "text-" + alertClass).text(module.prestatrust.status ? 'OK' : 'KO');
modal.find("#pstrust-message").attr("class", "alert alert-"+alertClass);
modal.find("#pstrust-message > p").text(module.prestatrust.message);
return modal;
}
_dispatchPreEvent(action, element) {
var event = jQuery.Event('module_card_action_event');
$(element).trigger(event, [action]);
if (event.isPropagationStopped() !== false || event.isImmediatePropagationStopped() !== false) {
return false; // if all handlers have not been called, then stop propagation of the click event.
}
return (event.result !== false); // explicit false must be set from handlers to stop propagation of the click event.
};
_requestToController(action, element, forceDeletion, disableCacheClear, callback) {
var self = this;
var jqElementObj = element.closest(this.moduleItemActionsSelector);
var form = element.closest("form");
var spinnerObj = $("<button class=\"btn-primary-reverse onclick unbind spinner \"></button>");
var url = "//" + window.location.host + form.attr("action");
var actionParams = form.serializeArray();
if (forceDeletion === "true" || forceDeletion === true) {
actionParams.push({name: "actionParams[deletion]", value: true});
}
if (disableCacheClear === "true" || disableCacheClear === true) {
actionParams.push({name: "actionParams[cacheClearEnabled]", value: 0});
}
$.ajax({
url: url,
dataType: 'json',
method: 'POST',
data: actionParams,
beforeSend: function () {
jqElementObj.hide();
jqElementObj.after(spinnerObj);
}
}).done(function (result) {
if (typeof result === undefined) {
$.growl.error({message: "No answer received from server"});
} else {
var moduleTechName = Object.keys(result)[0];
if (result[moduleTechName].status === false) {
if (typeof result[moduleTechName].confirmation_subject !== 'undefined') {
self._confirmPrestaTrust(result[moduleTechName]);
}
$.growl.error({message: result[moduleTechName].msg});
} else {
$.growl.notice({message: result[moduleTechName].msg});
var alteredSelector = self._getModuleItemSelector().replace('.', '');
var mainElement = null;
if (action == "uninstall") {
mainElement = jqElementObj.closest('.' + alteredSelector);
mainElement.remove();
BOEvent.emitEvent("Module Uninstalled", "CustomEvent");
} else if (action == "disable") {
mainElement = jqElementObj.closest('.' + alteredSelector);
mainElement.addClass(alteredSelector + '-isNotActive');
mainElement.attr('data-active', '0');
BOEvent.emitEvent("Module Disabled", "CustomEvent");
} else if (action == "enable") {
mainElement = jqElementObj.closest('.' + alteredSelector);
mainElement.removeClass(alteredSelector + '-isNotActive');
mainElement.attr('data-active', '1');
BOEvent.emitEvent("Module Enabled", "CustomEvent");
}
jqElementObj.replaceWith(result[moduleTechName].action_menu_html);
}
}
}).fail(function() {
const moduleItem = jqElementObj.closest('module-item-list');
const techName = moduleItem.data('techName');
$.growl.error({message: "Could not perform action "+action+" for module "+techName});
}).always(function () {
jqElementObj.fadeIn();
spinnerObj.remove();
if (callback) {
callback();
}
});
return false;
};
}

View File

@@ -0,0 +1,57 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
/**
* MultipleChoiceTable is responsible for managing common actions in multiple choice table form type
*/
export default class MultipleChoiceTable {
/**
* Init constructor
*/
constructor() {
$(document).on('click', '.js-multiple-choice-table-select-column', (e) => this.handleSelectColumn(e));
}
/**
* Check/uncheck all boxes in column
*
* @param {Event} event
*/
handleSelectColumn(event) {
event.preventDefault();
const $selectColumnBtn = $(event.target);
const checked = $selectColumnBtn.data('column-checked');
$selectColumnBtn.data('column-checked', !checked);
const $table = $selectColumnBtn.closest('table');
$table
.find('tbody tr td:nth-child(' + $selectColumnBtn.data('column-num') + ') input[type=checkbox]')
.prop('checked', !checked);
}
}

View File

@@ -0,0 +1,59 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
/**
* Class ShowcaseCardCloseExtension is responsible for providing helper block closing behavior
*/
export default class ShowcaseCardCloseExtension {
/**
* Extend helper block.
*
* @param {ShowcaseCard} helperBlock
*/
extend(helperBlock) {
const container = helperBlock.getContainer();
container.on('click', '.js-remove-helper-block', (evt) => {
container.remove();
const $btn = $(evt.target);
const url = $btn.data('closeUrl');
const cardName = $btn.data('cardName');
if (url) {
// notify the card was closed
$.post(
url,
{
close: 1,
name: cardName
}
);
}
});
}
}

View File

@@ -0,0 +1,60 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
/**
* Class ShowcaseCard is responsible for handling events related with showcase card.
*/
export default class ShowcaseCard {
/**
* Showcase card id.
*
* @param {string} id
*/
constructor(id) {
this.id = id;
this.$container = $('#' + this.id);
}
/**
* Get showcase card container.
*
* @returns {jQuery}
*/
getContainer() {
return this.$container;
}
/**
* Extend showcase card with external extensions.
*
* @param {object} extension
*/
addExtension(extension) {
extension.extend(this);
}
}

View File

@@ -0,0 +1,55 @@
/**
* 2007-2018 PrestaShop
*
* 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.txt.
* 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 http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2018 PrestaShop SA
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
const $ = window.$;
class TranslatableInput {
constructor(options) {
options = options || {};
this.localeItemSelector = options.localeItemSelector || '.js-locale-item';
this.localeButtonSelector = options.localeButtonSelector || '.js-locale-btn';
this.localeInputSelector = options.localeInputSelector || 'input.js-locale-input';
$('body').on('click', this.localeItemSelector, this.toggleInputs.bind(this));
}
/**
* Toggle all translatable inputs in form in which locale was changed
*
* @param {Event} event
*/
toggleInputs(event) {
const localeItem = $(event.target);
const form = localeItem.closest('form');
const selectedLocale = localeItem.data('locale');
form.find(this.localeButtonSelector).text(selectedLocale);
form.find(this.localeInputSelector).addClass('d-none');
form.find(this.localeInputSelector+'.js-locale-' + selectedLocale).removeClass('d-none');
}
}
export default TranslatableInput;