update
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
/**
|
||||
* 2007-2018 PrestaShop
|
||||
* 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.txt.
|
||||
* 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
|
||||
@@ -15,15 +16,14 @@
|
||||
*
|
||||
* 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.
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2018 PrestaShop SA
|
||||
* @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)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
const $ = window.$;
|
||||
const {$} = window;
|
||||
|
||||
const entityCategories = 0;
|
||||
const entityProducts = 1;
|
||||
@@ -37,15 +37,15 @@ const entityStoreContacts = 8;
|
||||
|
||||
export default class FormFieldToggle {
|
||||
constructor() {
|
||||
$('.js-entity-select').on('change', this.toggleForm.bind(this));
|
||||
$('.js-entity-select').on('change', () => this.toggleForm());
|
||||
|
||||
this.toggleForm();
|
||||
}
|
||||
|
||||
toggleForm() {
|
||||
let selectedOption = $('#entity').find('option:selected');
|
||||
let selectedEntity = parseInt(selectedOption.val());
|
||||
let entityName = selectedOption.text().toLowerCase();
|
||||
const selectedOption = $('#entity').find('option:selected');
|
||||
const selectedEntity = parseInt(selectedOption.val(), 10);
|
||||
const entityName = selectedOption.text().toLowerCase();
|
||||
|
||||
this.toggleEntityAlert(selectedEntity);
|
||||
this.toggleFields(selectedEntity, entityName);
|
||||
@@ -58,7 +58,7 @@ export default class FormFieldToggle {
|
||||
* @param {int} selectedEntity
|
||||
*/
|
||||
toggleEntityAlert(selectedEntity) {
|
||||
let $alert = $('.js-entity-alert');
|
||||
const $alert = $('.js-entity-alert');
|
||||
|
||||
if ([entityCategories, entityProducts].includes(selectedEntity)) {
|
||||
$alert.show();
|
||||
@@ -97,7 +97,7 @@ export default class FormFieldToggle {
|
||||
entityProducts,
|
||||
entityBrands,
|
||||
entitySuppliers,
|
||||
entityStoreContacts
|
||||
entityStoreContacts,
|
||||
].includes(selectedEntity)
|
||||
) {
|
||||
$regenerateFormGroup.show();
|
||||
@@ -113,7 +113,7 @@ export default class FormFieldToggle {
|
||||
entityBrands,
|
||||
entitySuppliers,
|
||||
entityStoreContacts,
|
||||
entityAlias
|
||||
entityAlias,
|
||||
].includes(selectedEntity)
|
||||
) {
|
||||
$forceIdsFormGroup.show();
|
||||
@@ -130,26 +130,74 @@ export default class FormFieldToggle {
|
||||
* @param {int} entity
|
||||
*/
|
||||
loadAvailableFields(entity) {
|
||||
const url = -1 === window.location.href.indexOf('index.php') ? '../../../ajax.php' : '../../../../ajax.php';
|
||||
const $availableFields = $('.js-available-fields');
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
url: $availableFields.data('url'),
|
||||
data: {
|
||||
getAvailableFields: 1,
|
||||
entity: entity
|
||||
entity,
|
||||
},
|
||||
dataType: 'json',
|
||||
}).then(response => {
|
||||
let fields = '';
|
||||
let $availableFields = $('.js-available-fields');
|
||||
$availableFields.empty();
|
||||
}).then((response) => {
|
||||
this.removeAvailableFields($availableFields);
|
||||
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
fields += response[i].field;
|
||||
for (let i = 0; i < response.length; i += 1) {
|
||||
this.appendAvailableField(
|
||||
$availableFields,
|
||||
response[i].label + (response[i].required ? '*' : ''),
|
||||
response[i].description,
|
||||
);
|
||||
}
|
||||
|
||||
$availableFields.html(fields);
|
||||
$availableFields.find('[data-toggle="popover"]').popover();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove available fields content from given container.
|
||||
*
|
||||
* @param {jQuery} $container
|
||||
* @private
|
||||
*/
|
||||
removeAvailableFields($container) {
|
||||
$container.find('[data-toggle="popover"]').popover('hide');
|
||||
$container.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a help box to given field.
|
||||
*
|
||||
* @param {jQuery} $field
|
||||
* @param {String} helpBoxContent
|
||||
* @private
|
||||
*/
|
||||
appendHelpBox($field, helpBoxContent) {
|
||||
const $helpBox = $('.js-available-field-popover-template').clone();
|
||||
|
||||
$helpBox.attr('data-content', helpBoxContent);
|
||||
$helpBox.removeClass('js-available-field-popover-template d-none');
|
||||
$field.append($helpBox);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append available field to given container.
|
||||
*
|
||||
* @param {jQuery} $appendTo field will be appended to this container.
|
||||
* @param {String} fieldText
|
||||
* @param {String} helpBoxContent
|
||||
* @private
|
||||
*/
|
||||
appendAvailableField($appendTo, fieldText, helpBoxContent) {
|
||||
const $field = $('.js-available-field-template').clone();
|
||||
|
||||
$field.text(fieldText);
|
||||
|
||||
if (helpBoxContent) {
|
||||
// Append help box next to the field
|
||||
this.appendHelpBox($field, helpBoxContent);
|
||||
}
|
||||
|
||||
$field.removeClass('js-available-field-template d-none');
|
||||
$field.appendTo($appendTo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/**
|
||||
* 2007-2018 PrestaShop
|
||||
* 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.txt.
|
||||
* 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
|
||||
@@ -15,17 +16,16 @@
|
||||
*
|
||||
* 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.
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2018 PrestaShop SA
|
||||
* @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)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
import FormFieldToggle from "./FormFieldToggle";
|
||||
import FormFieldToggle from './FormFieldToggle';
|
||||
|
||||
const $ = window.$;
|
||||
const {$} = window;
|
||||
|
||||
export default class ImportPage {
|
||||
constructor() {
|
||||
@@ -46,11 +46,15 @@ export default class ImportPage {
|
||||
* deleting all entities before import is checked
|
||||
*/
|
||||
handleSubmit() {
|
||||
$('.js-import-form').on('submit', function() {
|
||||
$('.js-import-form').on('submit', function () {
|
||||
const $this = $(this);
|
||||
|
||||
if ($this.find('input[name="truncate"]:checked').val() === '1') {
|
||||
return confirm(`${$this.data('delete-confirm-message')} ${$.trim($('#entity > option:selected').text().toLowerCase())}?`);
|
||||
/* eslint-disable-next-line max-len */
|
||||
return window.confirm(`${$this.data('delete-confirm-message')} ${$.trim($('#entity > option:selected').text().toLowerCase())}?`);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -58,7 +62,8 @@ export default class ImportPage {
|
||||
* Check if selected file names exists and if so, then display it
|
||||
*/
|
||||
toggleSelectedFile() {
|
||||
let selectFilename = $('#csv').val();
|
||||
const selectFilename = $('#csv').val();
|
||||
|
||||
if (selectFilename.length > 0) {
|
||||
this.showImportFileAlert(selectFilename);
|
||||
this.hideFileUploadBlock();
|
||||
@@ -104,7 +109,7 @@ export default class ImportPage {
|
||||
* Prefill hidden file input with selected file name from history
|
||||
*/
|
||||
useFileFromFilesHistory(event) {
|
||||
let filename = $(event.target).closest('.btn-group').data('file');
|
||||
const filename = $(event.target).closest('.btn-group').data('file');
|
||||
|
||||
$('.js-import-file-input').val(filename);
|
||||
|
||||
@@ -158,10 +163,10 @@ export default class ImportPage {
|
||||
showImportFileError(fileName, fileSize, message) {
|
||||
const $alert = $('.js-import-file-error');
|
||||
|
||||
const fileData = fileName + ' (' + this.humanizeSize(fileSize) + ')';
|
||||
const fileData = `${fileName} (${this.humanizeSize(fileSize)})`;
|
||||
|
||||
$alert.find('.js-file-data').html(fileData);
|
||||
$alert.find('.js-error-message').html(message);
|
||||
$alert.find('.js-file-data').text(fileData);
|
||||
$alert.find('.js-error-message').text(message);
|
||||
$alert.removeClass('d-none');
|
||||
}
|
||||
|
||||
@@ -186,14 +191,14 @@ export default class ImportPage {
|
||||
}
|
||||
|
||||
if (bytes >= 1000000000) {
|
||||
return (bytes / 1000000000).toFixed(2) + ' GB';
|
||||
return `${(bytes / 1000000000).toFixed(2)} GB`;
|
||||
}
|
||||
|
||||
if (bytes >= 1000000) {
|
||||
return (bytes / 1000000).toFixed(2) + ' MB';
|
||||
return `${(bytes / 1000000).toFixed(2)} MB`;
|
||||
}
|
||||
|
||||
return (bytes / 1000).toFixed(2) + ' KB';
|
||||
return `${(bytes / 1000).toFixed(2)} KB`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,6 +211,7 @@ export default class ImportPage {
|
||||
const uploadedFile = $input.prop('files')[0];
|
||||
|
||||
const maxUploadSize = $input.data('max-file-upload-size');
|
||||
|
||||
if (maxUploadSize < uploadedFile.size) {
|
||||
this.showImportFileError(uploadedFile.name, uploadedFile.size, 'File is too large');
|
||||
return;
|
||||
@@ -217,17 +223,17 @@ export default class ImportPage {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: $('.js-import-form').data('file-upload-url'),
|
||||
data: data,
|
||||
data,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
}).then(response => {
|
||||
}).then((response) => {
|
||||
if (response.error) {
|
||||
this.showImportFileError(uploadedFile.name, uploadedFile.size, response.error);
|
||||
return;
|
||||
}
|
||||
|
||||
let filename = response.file.name;
|
||||
const filename = response.file.name;
|
||||
|
||||
$('.js-import-file-input').val(filename);
|
||||
|
||||
@@ -246,13 +252,13 @@ export default class ImportPage {
|
||||
addFileToHistoryTable(filename) {
|
||||
const $table = $('#fileHistoryTable');
|
||||
|
||||
let baseDeleteUrl = $table.data('delete-file-url');
|
||||
let deleteUrl = baseDeleteUrl + '&filename=' + encodeURIComponent(filename);
|
||||
const baseDeleteUrl = $table.data('delete-file-url');
|
||||
const deleteUrl = `${baseDeleteUrl}&filename=${encodeURIComponent(filename)}`;
|
||||
|
||||
let baseDownloadUrl = $table.data('download-file-url');
|
||||
let downloadUrl = baseDownloadUrl + '&filename=' + encodeURIComponent(filename);
|
||||
const baseDownloadUrl = $table.data('download-file-url');
|
||||
const downloadUrl = `${baseDownloadUrl}&filename=${encodeURIComponent(filename)}`;
|
||||
|
||||
let $template = $table.find('tr:first').clone();
|
||||
const $template = $table.find('tr:first').clone();
|
||||
|
||||
$template.removeClass('d-none');
|
||||
$template.find('td:first').text(filename);
|
||||
@@ -262,7 +268,7 @@ export default class ImportPage {
|
||||
|
||||
$table.find('tbody').append($template);
|
||||
|
||||
let filesNumber = $table.find('tr').length - 1;
|
||||
const filesNumber = $table.find('tr').length - 1;
|
||||
$('.js-files-history-number').text(filesNumber);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/**
|
||||
* 2007-2018 PrestaShop
|
||||
* 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.txt.
|
||||
* 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
|
||||
@@ -15,17 +16,16 @@
|
||||
*
|
||||
* 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.
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2018 PrestaShop SA
|
||||
* @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)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
import ImportPage from './ImportPage';
|
||||
|
||||
const $ = window.$;
|
||||
const {$} = window;
|
||||
|
||||
$(() => {
|
||||
new ImportPage();
|
||||
|
||||
Reference in New Issue
Block a user