first commit

This commit is contained in:
2024-11-11 18:46:54 +01:00
commit a630d17338
25634 changed files with 4923715 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
const $ = window.$;
$(() => {
const backupGrid = new Grid('backup');
backupGrid.addExtension(new BulkActionCheckboxExtension());
backupGrid.addExtension(new SubmitBulkExtension());
backupGrid.addExtension(new LinkRowActionExtension());
backupGrid.addExtension(new SubmitRowActionExtension());
});

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 SpecificPriceFormHandler from './specific-price-form-handler';
const $ = window.$;
$(() => {
new SpecificPriceFormHandler();
});

View File

@@ -0,0 +1,497 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
class SpecificPriceFormHandler {
constructor() {
this.prefixCreateForm = 'form_step2_specific_price_';
this.prefixEditForm = 'form_modal_';
this.editModalIsOpen = false;
this.$createPriceFormDefaultValues = new Object();
this.storePriceFormDefaultValues();
this.loadAndDisplayExistingSpecificPricesList();
this.configureAddPriceFormBehavior();
this.configureEditPriceModalBehavior();
this.configureDeletePriceButtonsBehavior();
this.configureMultipleModalsBehavior();
}
/**
* @private
*/
loadAndDisplayExistingSpecificPricesList() {
var listContainer = $('#js-specific-price-list');
var url = listContainer.data('listingUrl').replace(/list\/\d+/, 'list/' + this.getProductId());
$.ajax({
type: 'GET',
url: url,
})
.done(specificPrices => {
var tbody = listContainer.find('tbody');
tbody.find('tr').remove();
if (specificPrices.length > 0) {
listContainer.removeClass('hide');
} else {
listContainer.addClass('hide');
}
var specificPricesList = this.renderSpecificPricesListingAsHtml(specificPrices);
tbody.append(specificPricesList);
});
}
/**
* @param array specificPrices
*
* @returns string
*
* @private
*/
renderSpecificPricesListingAsHtml(specificPrices) {
var specificPricesList = '';
var self = this;
$.each(specificPrices, (index, specificPrice) => {
var deleteUrl = $('#js-specific-price-list').attr('data-action-delete').replace(/delete\/\d+/, 'delete/' + specificPrice.id_specific_price);
var row = self.renderSpecificPriceRow(specificPrice, deleteUrl);
specificPricesList = specificPricesList + row;
});
return specificPricesList;
}
/**
* @param Object specificPrice
* @param string deleteUrl
*
* @returns string
*
* @private
*/
renderSpecificPriceRow(specificPrice, deleteUrl) {
var specificPriceId = specificPrice.id_specific_price;
var row = '<tr>' +
'<td>' + specificPrice.rule_name + '</td>' +
'<td>' + specificPrice.attributes_name + '</td>' +
'<td>' + specificPrice.currency + '</td>' +
'<td>' + specificPrice.country + '</td>' +
'<td>' + specificPrice.group + '</td>' +
'<td>' + specificPrice.customer + '</td>' +
'<td>' + specificPrice.fixed_price + '</td>' +
'<td>' + specificPrice.impact + '</td>' +
'<td>' + specificPrice.period + '</td>' +
'<td>' + specificPrice.from_quantity + '</td>' +
'<td>' + (specificPrice.can_delete ? '<a href="' + deleteUrl + '" class="js-delete delete btn tooltip-link delete pl-0 pr-0"><i class="material-icons">delete</i></a>' : '') + '</td>' +
'<td>' + (specificPrice.can_edit ? '<a href="#" data-specific-price-id="' + specificPriceId + '" class="js-edit edit btn tooltip-link delete pl-0 pr-0"><i class="material-icons">edit</i></a>' : '') + '</td>' +
'</tr>';
return row;
}
/**
* @private
*/
configureAddPriceFormBehavior() {
const usePrefixForCreate = true;
var selectorPrefix = this.getPrefixSelector(usePrefixForCreate);
$('#specific_price_form .js-cancel').click(() => {
this.resetCreatePriceFormDefaultValues();
$('#specific_price_form').collapse('hide');
});
$('#specific_price_form .js-save').on('click', () => this.submitCreatePriceForm());
$('#js-open-create-specific-price-form').on('click', () => this.loadAndFillOptionsForSelectCombinationInput(usePrefixForCreate));
$(selectorPrefix + 'leave_bprice').on('click', () => this.enableSpecificPriceFieldIfEligible(usePrefixForCreate));
$(selectorPrefix + 'sp_reduction_type').on('change', () => this.enableSpecificPriceTaxFieldIfEligible(usePrefixForCreate));
}
/**
* @private
*/
configureEditPriceFormInsideModalBehavior() {
const usePrefixForCreate = false;
var selectorPrefix = this.getPrefixSelector(usePrefixForCreate);
$('#form_modal_cancel').click(() => this.closeEditPriceModalAndRemoveForm());
$('#form_modal_close').click(() => this.closeEditPriceModalAndRemoveForm());
$('#form_modal_save').click(() => this.submitEditPriceForm());
this.loadAndFillOptionsForSelectCombinationInput(usePrefixForCreate);
$(selectorPrefix + 'leave_bprice').on('click', () => this.enableSpecificPriceFieldIfEligible(usePrefixForCreate));
$(selectorPrefix + 'sp_reduction_type').on('change', () => this.enableSpecificPriceTaxFieldIfEligible(usePrefixForCreate));
this.reinitializeDatePickers();
this.initializeLeaveBPriceField(usePrefixForCreate);
this.enableSpecificPriceTaxFieldIfEligible(usePrefixForCreate);
}
/**
* @private
*/
reinitializeDatePickers() {
$('.datepicker input').datetimepicker({format: 'YYYY-MM-DD'});
}
/**
* @param boolean usePrefixForCreate
*
* @private
*/
initializeLeaveBPriceField(usePrefixForCreate) {
var selectorPrefix = this.getPrefixSelector(usePrefixForCreate);
if ($(selectorPrefix + 'sp_price').val() != '') {
$(selectorPrefix + 'sp_price').prop('disabled', false);
$(selectorPrefix + 'leave_bprice').prop('checked', false);
}
}
/**
* @private
*/
configureEditPriceModalBehavior() {
$(document).on('click', '#js-specific-price-list .js-edit', (event) => {
event.preventDefault();
var specificPriceId = $(event.currentTarget).data('specificPriceId');
this.openEditPriceModalAndLoadForm(specificPriceId);
});
}
/**
* @private
*/
configureDeletePriceButtonsBehavior() {
$(document).on('click', '#js-specific-price-list .js-delete', (event) => {
event.preventDefault();
this.deleteSpecificPrice(event.currentTarget);
});
}
/**
* @see https://vijayasankarn.wordpress.com/2017/02/24/quick-fix-scrolling-and-focus-when-multiple-bootstrap-modals-are-open/
*/
configureMultipleModalsBehavior() {
$('.modal').on('hidden.bs.modal', () => {
if (this.editModalIsOpen) {
$('body').addClass('modal-open');
}
});
}
/**
* @private
*/
submitCreatePriceForm() {
const url = $('#specific_price_form').attr('data-action');
const data = $('#specific_price_form input, #specific_price_form select, #form_id_product').serialize();
$('#specific_price_form .js-save').attr('disabled', 'disabled');
$.ajax({
type: 'POST',
url: url,
data: data,
})
.done(response => {
showSuccessMessage(translate_javascripts['Form update success']);
this.resetCreatePriceFormDefaultValues();
$('#specific_price_form').collapse('hide');
this.loadAndDisplayExistingSpecificPricesList();
$('#specific_price_form .js-save').removeAttr('disabled');
})
.fail(errors => {
showErrorMessage(errors.responseJSON);
$('#specific_price_form .js-save').removeAttr('disabled');
});
}
/**
* @private
*/
submitEditPriceForm() {
const baseUrl = $('#edit-specific-price-modal-form').attr('data-action');
const specificPriceId = $('#edit-specific-price-modal-form').data('specificPriceId');
const url = baseUrl.replace(/update\/\d+/, 'update/' + specificPriceId);
const data = $('#edit-specific-price-modal-form input, #edit-specific-price-modal-form select, #form_id_product').serialize();
$('#edit-specific-price-modal-form .js-save').attr('disabled', 'disabled');
$.ajax({
type: 'POST',
url: url,
data: data,
})
.done(response => {
showSuccessMessage(translate_javascripts['Form update success']);
this.closeEditPriceModalAndRemoveForm();
this.loadAndDisplayExistingSpecificPricesList();
$('#edit-specific-price-modal-form .js-save').removeAttr('disabled');
})
.fail(errors => {
showErrorMessage(errors.responseJSON);
$('#edit-specific-price-modal-form .js-save').removeAttr('disabled');
});
}
/**
* @param string clickedLink selector
*
* @private
*/
deleteSpecificPrice(clickedLink) {
modalConfirmation.create(translate_javascripts['This will delete the specific price. Do you wish to proceed?'], null, {
onContinue: () => {
var url = $(clickedLink).attr('href');
$(clickedLink).attr('disabled', 'disabled');
$.ajax({
type: 'GET',
url: url,
})
.done(response => {
this.loadAndDisplayExistingSpecificPricesList();
showSuccessMessage(response);
$(clickedLink).removeAttr('disabled');
})
.fail(errors => {
showErrorMessage(errors.responseJSON);
$(clickedLink).removeAttr('disabled');
});
}
}).show();
}
/**
* Store 'add specific price' form values
* for future usage
*
* @private
*/
storePriceFormDefaultValues() {
var storage = this.$createPriceFormDefaultValues;
$('#specific_price_form').find('select,input').each((index, value) => {
storage[$(value).attr('id')] = $(value).val();
});
$('#specific_price_form').find('input:checkbox').each((index, value) => {
storage[$(value).attr('id')] = $(value).prop('checked');
});
this.$createPriceFormDefaultValues = storage;
}
/**
* @param boolean usePrefixForCreate
*
* @private
*/
loadAndFillOptionsForSelectCombinationInput(usePrefixForCreate) {
var selectorPrefix = this.getPrefixSelector(usePrefixForCreate);
var inputField = $(selectorPrefix + 'sp_id_product_attribute');
var url = inputField.attr('data-action').replace(/product-combinations\/\d+/, 'product-combinations/' + this.getProductId());
$.ajax({
type: 'GET',
url: url,
})
.done(combinations => {
/** remove all options except first one */
inputField.find('option:gt(0)').remove();
$.each(combinations, (index, combination) => {
inputField.append('<option value="' + combination.id + '">' + combination.name + '</option>');
});
if (inputField.data('selectedAttribute') != '0') {
inputField.val(inputField.data('selectedAttribute')).trigger('change');
}
});
}
/**
* @param boolean usePrefixForCreate
*
* @private
*/
enableSpecificPriceTaxFieldIfEligible(usePrefixForCreate) {
var selectorPrefix = this.getPrefixSelector(usePrefixForCreate);
if ($(selectorPrefix + 'sp_reduction_type').val() === 'percentage') {
$(selectorPrefix + 'sp_reduction_tax').hide();
} else {
$(selectorPrefix + 'sp_reduction_tax').show();
}
}
/**
* Reset 'add specific price' form values
* using previously stored default values
*
* @private
*/
resetCreatePriceFormDefaultValues() {
var previouslyStoredValues = this.$createPriceFormDefaultValues;
$('#specific_price_form').find('input').each((index, value) => {
$(value).val(previouslyStoredValues[$(value).attr('id')]);
});
$('#specific_price_form').find('select').each((index, value) => {
$(value).val(previouslyStoredValues[$(value).attr('id')]).change();
});
$('#specific_price_form').find('input:checkbox').each((index, value) => {
$(value).prop("checked", true);
});
}
/**
* @param boolean usePrefixForCreate
*
* @private
*/
enableSpecificPriceFieldIfEligible(usePrefixForCreate) {
var selectorPrefix = this.getPrefixSelector(usePrefixForCreate);
$(selectorPrefix + 'sp_price').prop('disabled', $(selectorPrefix + 'leave_bprice').is(':checked')).val('');
}
/**
* Open 'edit specific price' form into a modal
*
* @param integer specificPriceId
*
* @private
*/
openEditPriceModalAndLoadForm(specificPriceId) {
const url = $('#js-specific-price-list').data('actionEdit').replace(/form\/\d+/, 'form/' + specificPriceId);
$('#edit-specific-price-modal').modal("show");
this.editModalIsOpen = true;
$.ajax({
type: 'GET',
url: url,
})
.done(response => {
this.insertEditSpecificPriceFormIntoModal(response);
$('#edit-specific-price-modal-form').data('specificPriceId', specificPriceId);
this.configureEditPriceFormInsideModalBehavior();
})
.fail(errors => {
showErrorMessage(errors.responseJSON);
});
}
/**
* @private
*/
closeEditPriceModalAndRemoveForm() {
$('#edit-specific-price-modal').modal("hide");
this.editModalIsOpen = false;
var formLocationHolder = $('#edit-specific-price-modal-form');
formLocationHolder.empty();
}
/**
* @param string form: HTML 'edit specific price' form
*
* @private
*/
insertEditSpecificPriceFormIntoModal(form) {
var formLocationHolder = $('#edit-specific-price-modal-form');
formLocationHolder.empty();
formLocationHolder.append(form);
}
/**
* Get product ID for current Catalog Product page
*
* @returns integer
*
* @private
*/
getProductId() {
return $('#form_id_product').val();
}
/**
* @param boolean usePrefixForCreate
*
* @returns string
*
* @private
*/
getPrefixSelector(usePrefixForCreate) {
if (usePrefixForCreate == true) {
return '#' + this.prefixCreateForm;
} else {
return '#' + this.prefixEditForm;
}
}
}
export default SpecificPriceFormHandler;

View File

@@ -0,0 +1,117 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import ReloadListExtension from '../../components/grid/extension/reload-list-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
import CategoryPositionExtension from '../../components/grid/extension/column/catalog/category-position-extension';
import AsyncToggleColumnExtension from '../../components/grid/extension/column/common/async-toggle-column-extension';
import DeleteCategoryRowActionExtension from '../../components/grid/extension/action/row/category/delete-category-row-action-extension';
import DeleteCategoriesBulkActionExtension from '../../components/grid/extension/action/bulk/category/delete-categories-bulk-action-extension';
import TranslatableInput from '../../components/translatable-input';
import ChoiceTable from '../../components/choice-table';
import textToLinkRewriteCopier from '../../components/text-to-link-rewrite-copier';
import ChoiceTree from '../../components/form/choice-tree';
import FormSubmitButton from '../../components/form-submit-button';
import TaggableField from '../../components/taggable-field';
import ShowcaseCard from '../../components/showcase-card/showcase-card';
import ShowcaseCardCloseExtension from '../../components/showcase-card/extension/showcase-card-close-extension';
import TextWithRecommendedLengthCounter from '../../components/form/text-with-recommended-length-counter';
import TranslatableField from '../../components/translatable-field';
import TinyMCEEditor from '../../components/tinymce-editor';
import Serp from '../../app/utils/serp/index';
const $ = window.$;
$(() => {
const categoriesGrid = new Grid('category');
categoriesGrid.addExtension(new FiltersResetExtension());
categoriesGrid.addExtension(new SortingExtension());
categoriesGrid.addExtension(new CategoryPositionExtension());
categoriesGrid.addExtension(new ExportToSqlManagerExtension());
categoriesGrid.addExtension(new ReloadListExtension());
categoriesGrid.addExtension(new BulkActionCheckboxExtension());
categoriesGrid.addExtension(new SubmitBulkExtension());
categoriesGrid.addExtension(new SubmitRowActionExtension());
categoriesGrid.addExtension(new LinkRowActionExtension());
categoriesGrid.addExtension(new AsyncToggleColumnExtension());
categoriesGrid.addExtension(new DeleteCategoryRowActionExtension());
categoriesGrid.addExtension(new DeleteCategoriesBulkActionExtension());
const showcaseCard = new ShowcaseCard('categoriesShowcaseCard');
showcaseCard.addExtension(new ShowcaseCardCloseExtension());
new TranslatableField();
new TinyMCEEditor();
const translatorInput = new TranslatableInput();
new ChoiceTable();
new TextWithRecommendedLengthCounter();
textToLinkRewriteCopier({
sourceElementSelector: 'input[name^="category[name]"]',
destinationElementSelector: `${translatorInput.localeInputSelector}:not(.d-none) input[name^="category[link_rewrite]"]`,
});
textToLinkRewriteCopier({
sourceElementSelector: 'input[name^="root_category[name]"]',
destinationElementSelector: `${translatorInput.localeInputSelector}:not(.d-none) input[name^="root_category[link_rewrite]"]`,
});
new Serp(
{
container: '#serp-app',
defaultTitle: 'input[name^="category[name]"]',
watchedTitle: 'input[name^="category[meta_title]"]',
defaultDescription: 'textarea[name^="category[description]"]',
watchedDescription: 'textarea[name^="category[meta_description]"]',
watchedMetaUrl: 'input[name^="category[link_rewrite]"]',
multiLanguageInput: `${translatorInput.localeInputSelector}:not(.d-none)`,
multiLanguageItem: translatorInput.localeItemSelector,
},
$('#serp-app').data('category-url'),
);
new FormSubmitButton();
new TaggableField({
tokenFieldSelector: 'input.js-taggable-field',
options: {
createTokensOnBlur: true,
},
});
new ChoiceTree('#category_id_parent');
new ChoiceTree('#category_shop_association').enableAutoCheckChildren();
new ChoiceTree('#root_category_id_parent');
new ChoiceTree('#root_category_shop_association').enableAutoCheckChildren();
});

View File

@@ -0,0 +1,74 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 PreviewOpener from '../../../components/form/preview-opener';
import ChoiceTree from '../../../components/form/choice-tree';
import TaggableField from '../../../components/taggable-field';
import TranslatableInput from '../../../components/translatable-input';
import textToLinkRewriteCopier from '../../../components/text-to-link-rewrite-copier';
import TranslatableField from '../../../components/translatable-field';
import TinyMCEEditor from '../../../components/tinymce-editor';
import Serp from '../../../app/utils/serp/index';
const $ = window.$;
$(() => {
new ChoiceTree('#cms_page_page_category_id');
const translatorInput = new TranslatableInput();
new Serp(
{
container: '#serp-app',
defaultTitle: 'input[name^="cms_page[title]"]',
watchedTitle: 'input[name^="cms_page[meta_title]"]',
defaultDescription: 'input[name^="cms_page[description]"]',
watchedDescription: 'input[name^="cms_page[meta_description]"]',
watchedMetaUrl: 'input[name^="cms_page[friendly_url]"]',
multiLanguageInput: `${translatorInput.localeInputSelector}:not(.d-none)`,
multiLanguageItem: translatorInput.localeItemSelector
},
$('#serp-app').data('cms-url')
);
new TranslatableField();
new TinyMCEEditor();
new TaggableField({
tokenFieldSelector: 'input.js-taggable-field',
options: {
createTokensOnBlur: true
}
});
new PreviewOpener('.js-preview-url');
textToLinkRewriteCopier({
sourceElementSelector: 'input.js-copier-source-title',
destinationElementSelector: `${translatorInput.localeInputSelector}:not(.d-none) input.js-copier-destination-friendly-url`
});
new ChoiceTree('#cms_page_shop_association').enableAutoCheckChildren();
});

View File

@@ -0,0 +1,94 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import ColumnTogglingExtension from '../../components/grid/extension/column-toggling-extension';
import PositionExtension from '../../components/grid/extension/position-extension';
import ChoiceTree from '../../components/form/choice-tree';
import TranslatableInput from '../../components/translatable-input';
import textToLinkRewriteCopier from '../../components/text-to-link-rewrite-copier';
import TaggableField from '../../components/taggable-field';
import ShowcaseCard from '../../components/showcase-card/showcase-card';
import ShowcaseCardCloseExtension from '../../components/showcase-card/extension/showcase-card-close-extension';
const $ = window.$;
$(() => {
const cmsCategory = new Grid('cms_page_category');
cmsCategory.addExtension(new ReloadListActionExtension());
cmsCategory.addExtension(new ExportToSqlManagerExtension());
cmsCategory.addExtension(new FiltersResetExtension());
cmsCategory.addExtension(new SortingExtension());
cmsCategory.addExtension(new LinkRowActionExtension());
cmsCategory.addExtension(new SubmitBulkExtension());
cmsCategory.addExtension(new BulkActionCheckboxExtension());
cmsCategory.addExtension(new SubmitRowActionExtension());
cmsCategory.addExtension(new ColumnTogglingExtension());
cmsCategory.addExtension(new PositionExtension());
const translatorInput = new TranslatableInput();
textToLinkRewriteCopier({
sourceElementSelector: 'input[name^="cms_page_category[name]"]',
destinationElementSelector: `${translatorInput.localeInputSelector}:not(.d-none) input[name^="cms_page_category[friendly_url]"]`,
});
new ChoiceTree('#cms_page_category_parent_category');
const shopChoiceTree = new ChoiceTree('#cms_page_category_shop_association');
shopChoiceTree.enableAutoCheckChildren();
new TaggableField({
tokenFieldSelector: 'input[name^="cms_page_category[meta_keywords]"]',
options: {
createTokensOnBlur: true,
},
});
const cmsGrid = new Grid('cms_page');
cmsGrid.addExtension(new ReloadListActionExtension());
cmsGrid.addExtension(new ExportToSqlManagerExtension());
cmsGrid.addExtension(new FiltersResetExtension());
cmsGrid.addExtension(new SortingExtension());
cmsGrid.addExtension(new ColumnTogglingExtension());
cmsGrid.addExtension(new BulkActionCheckboxExtension());
cmsGrid.addExtension(new SubmitBulkExtension());
cmsGrid.addExtension(new SubmitRowActionExtension());
cmsGrid.addExtension(new PositionExtension());
cmsGrid.addExtension(new LinkRowActionExtension());
const helperBlock = new ShowcaseCard('cms-pages-showcase-card');
helperBlock.addExtension(new ShowcaseCardCloseExtension());
});

View File

@@ -0,0 +1,60 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
import SubmitGridExtension from '../../components/grid/extension/submit-grid-action-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import TranslatableInput from '../../components/translatable-input';
import ChoiceTree from '../../components/form/choice-tree';
/**
* Responsible for actions in Contacts listing page.
*/
export default class ContactsPage {
constructor() {
const contactGrid = new Grid('contact');
contactGrid.addExtension(new ReloadListActionExtension());
contactGrid.addExtension(new ExportToSqlManagerExtension());
contactGrid.addExtension(new FiltersResetExtension());
contactGrid.addExtension(new SortingExtension());
contactGrid.addExtension(new LinkRowActionExtension());
contactGrid.addExtension(new SubmitGridExtension());
contactGrid.addExtension(new SubmitBulkExtension());
contactGrid.addExtension(new BulkActionCheckboxExtension());
contactGrid.addExtension(new SubmitRowActionExtension());
new TranslatableInput();
new ChoiceTree('#contact_shop_association').enableAutoCheckChildren();
}
}

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ContactsPage from './ContactsPage';
const $ = window.$;
$(() => {
new ContactsPage;
});

View File

@@ -0,0 +1,82 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* This class triggers events required for turning on or off exchange rates scheduler an displaying the right text
* below the switch.
*/
export default class ExchangeRatesUpdateScheduler {
constructor() {
this._initEvents();
return {};
}
_initEvents() {
$(document).on('change', '.js-live-exchange-rate', (event) => this._initLiveExchangeRate(event));
}
/**
* @param {Object} event
*
* @private
*/
_initLiveExchangeRate(event) {
const $liveExchangeRatesSwitch = $(event.currentTarget);
const $form = $liveExchangeRatesSwitch.closest('form');
const formItems = $form.serialize();
$.ajax({
type: 'POST',
url: $liveExchangeRatesSwitch.attr('data-url'),
data: formItems,
})
.then((response) => {
if (!response.status) {
showErrorMessage(response.message);
this._changeTextByCurrentSwitchValue($liveExchangeRatesSwitch.val());
return;
}
showSuccessMessage(response.message);
this._changeTextByCurrentSwitchValue($liveExchangeRatesSwitch.val());
}
).fail((response) => {
if (typeof response.responseJSON !== 'undefined') {
showErrorMessage(response.responseJSON.message);
this._changeTextByCurrentSwitchValue($liveExchangeRatesSwitch.val());
}
});
}
_changeTextByCurrentSwitchValue(switchValue) {
const valueParsed = parseInt(switchValue);
$('.js-exchange-rate-text-when-disabled').toggleClass('d-none', 0 !== valueParsed);
$('.js-exchange-rate-text-when-enabled').toggleClass('d-none', 1 !== valueParsed);
}
}

View File

@@ -0,0 +1,51 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ColumnTogglingExtension from '../../components/grid/extension/column-toggling-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import ChoiceTree from '../../components/form/choice-tree';
import ExchangeRatesUpdateScheduler from './ExchangeRatesUpdateScheduler';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
$(() => {
const currency = new Grid('currency');
currency.addExtension(new SortingExtension());
currency.addExtension(new FiltersResetExtension());
currency.addExtension(new ReloadListActionExtension());
currency.addExtension(new ColumnTogglingExtension());
currency.addExtension(new SubmitRowActionExtension());
currency.addExtension(new LinkRowActionExtension());
const choiceTree = new ChoiceTree('#currency_shop_association');
choiceTree.enableAutoCheckChildren();
new ExchangeRatesUpdateScheduler();
});

View File

@@ -0,0 +1,73 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import SubmitGridExtension from '../../components/grid/extension/submit-grid-action-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
import LinkableItem from '../../components/linkable-item';
import ChoiceTable from '../../components/choice-table';
import ColumnTogglingExtension from '../../components/grid/extension/column-toggling-extension';
import DeleteCustomersBulkActionExtension
from '../../components/grid/extension/action/bulk/customer/delete-customers-bulk-action-extension';
import DeleteCustomerRowActionExtension
from '../../components/grid/extension/action/row/customer/delete-customer-row-action-extension';
import ShowcaseCard from '../../components/showcase-card/showcase-card';
import ShowcaseCardCloseExtension from '../../components/showcase-card/extension/showcase-card-close-extension';
const $ = window.$;
$(() => {
const customerGrid = new Grid('customer');
customerGrid.addExtension(new ReloadListActionExtension());
customerGrid.addExtension(new ExportToSqlManagerExtension());
customerGrid.addExtension(new FiltersResetExtension());
customerGrid.addExtension(new SortingExtension());
customerGrid.addExtension(new BulkActionCheckboxExtension());
customerGrid.addExtension(new SubmitBulkExtension());
customerGrid.addExtension(new SubmitGridExtension());
customerGrid.addExtension(new LinkRowActionExtension());
customerGrid.addExtension(new ColumnTogglingExtension());
customerGrid.addExtension(new DeleteCustomersBulkActionExtension());
customerGrid.addExtension(new DeleteCustomerRowActionExtension());
const showcaseCard = new ShowcaseCard('customersShowcaseCard');
showcaseCard.addExtension(new ShowcaseCardCloseExtension());
// needed for "Group access" input in Add/Edit customer forms
new ChoiceTable();
// in customer view page
// there are a lot of tables
// where you click any row
// and it redirects user to related page
new LinkableItem();
});

View File

@@ -0,0 +1,171 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Class is responsible for managing test email sending
*/
class EmailSendingTest {
constructor() {
this.$successAlert = $('.js-test-email-success');
this.$errorAlert = $('.js-test-email-errors');
this.$loader = $('.js-test-email-loader');
this.$sendEmailBtn = $('.js-send-test-email-btn');
this.$sendEmailBtn.on('click', (event) => {
this._handle(event);
});
}
/**
* Handle test email sending
*
* @param {Event} event
*
* @private
*/
_handle(event) {
// fill test email sending form with configured values
$('#test_email_sending_mail_method').val($('input[name="form[email_config][mail_method]"]:checked').val());
$('#test_email_sending_smtp_server').val($('#form_smtp_config_server').val());
$('#test_email_sending_smtp_username').val($('#form_smtp_config_username').val());
$('#test_email_sending_smtp_password').val($('#form_smtp_config_password').val());
$('#test_email_sending_smtp_port').val($('#form_smtp_config_port').val());
$('#test_email_sending_smtp_encryption').val($('#form_smtp_config_encryption').val());
const $testEmailSendingForm = $(event.currentTarget).closest('form');
this._resetMessages();
this._hideSendEmailButton();
this._showLoader();
$.post({
url: $testEmailSendingForm.attr('action'),
data: $testEmailSendingForm.serialize(),
}).then((response) => {
this._hideLoader();
this._showSendEmailButton();
if (0 !== response.errors.length) {
this._showErrors(response.errors);
return;
}
this._showSuccess();
});
}
/**
* Make sure that additional content (alerts, loader) is not visible
*
* @private
*/
_resetMessages() {
this._hideSuccess();
this._hideErrors();
}
/**
* Show success message
*
* @private
*/
_showSuccess() {
this.$successAlert.removeClass('d-none');
}
/**
* Hide success message
*
* @private
*/
_hideSuccess() {
this.$successAlert.addClass('d-none');
}
/**
* Show loader during AJAX call
*
* @private
*/
_showLoader() {
this.$loader.removeClass('d-none');
}
/**
* Hide loader
*
* @private
*/
_hideLoader() {
this.$loader.addClass('d-none');
}
/**
* Show errors
*
* @param {Array} errors
*
* @private
*/
_showErrors(errors) {
errors.forEach((error) => {
this.$errorAlert.append('<p>' + error + '</p>');
});
this.$errorAlert.removeClass('d-none');
}
/**
* Hide errors
*
* @private
*/
_hideErrors() {
this.$errorAlert.addClass('d-none').empty();
}
/**
* Show send email button
*
* @private
*/
_showSendEmailButton() {
this.$sendEmailBtn.removeClass('d-none');
}
/**
* Hide send email button
*
* @private
*/
_hideSendEmailButton() {
this.$sendEmailBtn.addClass('d-none');
}
}
export default EmailSendingTest;

View File

@@ -0,0 +1,54 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 EmailSendingTest from './email-sending-test';
import SmtpConfigurationToggler from './smtp-configuration-toggler';
import Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import SubmitGridExtension from '../../components/grid/extension/submit-grid-action-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
$(() => {
const emailLogsGrid = new Grid('email_logs');
emailLogsGrid.addExtension(new ReloadListActionExtension());
emailLogsGrid.addExtension(new ExportToSqlManagerExtension());
emailLogsGrid.addExtension(new FiltersResetExtension());
emailLogsGrid.addExtension(new SortingExtension());
emailLogsGrid.addExtension(new BulkActionCheckboxExtension());
emailLogsGrid.addExtension(new SubmitBulkExtension());
emailLogsGrid.addExtension(new SubmitGridExtension());
emailLogsGrid.addExtension(new LinkRowActionExtension());
new EmailSendingTest();
new SmtpConfigurationToggler();
});

View File

@@ -0,0 +1,70 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Class SmtpConfigurationToggler is responsible for showing/hiding SMTP configuration form
*/
class SmtpConfigurationToggler {
constructor() {
$('.js-email-method').on('change', 'input[type="radio"]', (event) => {
const mailMethod = $(event.currentTarget).val();
this._getSmtpMailMethodOption() == mailMethod ? this._showSmtpConfiguration() : this._hideSmtpConfiguration();
});
}
/**
* Show SMTP configuration form
*
* @private
*/
_showSmtpConfiguration() {
$('.js-smtp-configuration').removeClass('d-none');
}
/**
* Hide SMTP configuration
*
* @private
*/
_hideSmtpConfiguration() {
$('.js-smtp-configuration').addClass('d-none');
}
/**
* Get SMTP mail option value
*
* @private
*
* @returns {String}
*/
_getSmtpMailMethodOption() {
return $('.js-email-method').data('smtp-mail-method');
}
}
export default SmtpConfigurationToggler;

View File

@@ -0,0 +1,172 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ChoiceTree from "../../components/form/choice-tree";
import AddonsConnector from "../../components/addons-connector";
import ChangePasswordControl from "../../components/form/change-password-control";
import employeeFormMap from "./employee-form-map";
/**
* Class responsible for javascript actions in employee add/edit page.
*/
export default class EmployeeForm {
constructor() {
this.shopChoiceTreeSelector = employeeFormMap.shopChoiceTree;
this.shopChoiceTree = new ChoiceTree(this.shopChoiceTreeSelector);
this.employeeProfileSelector = employeeFormMap.profileSelect;
this.tabsDropdownSelector = employeeFormMap.defaultPageSelect;
this.shopChoiceTree.enableAutoCheckChildren();
new AddonsConnector(
employeeFormMap.addonsConnectForm,
employeeFormMap.addonsLoginButton
);
new ChangePasswordControl(
employeeFormMap.changePasswordInputsBlock,
employeeFormMap.showChangePasswordBlockButton,
employeeFormMap.hideChangePasswordBlockButton,
employeeFormMap.generatePasswordButton,
employeeFormMap.oldPasswordInput,
employeeFormMap.newPasswordInput,
employeeFormMap.confirmNewPasswordInput,
employeeFormMap.generatedPasswordDisplayInput,
employeeFormMap.passwordStrengthFeedbackContainer
);
this._initEvents();
this._toggleShopTree();
return {};
}
/**
* Initialize page's events.
*
* @private
*/
_initEvents() {
const $employeeProfilesDropdown = $(this.employeeProfileSelector);
const getTabsUrl = $employeeProfilesDropdown.data('get-tabs-url');
$(document).on('change', this.employeeProfileSelector, () => this._toggleShopTree());
// Reload tabs dropdown when employee profile is changed.
$(document).on('change', this.employeeProfileSelector, (event) => {
$.get(
getTabsUrl,
{
profileId: $(event.currentTarget).val()
},
(tabs) => {
this._reloadTabsDropdown(tabs);
},
'json'
);
});
}
/**
* Reload tabs dropdown with new content.
*
* @param {Object} accessibleTabs
*
* @private
*/
_reloadTabsDropdown(accessibleTabs) {
const $tabsDropdown = $(this.tabsDropdownSelector);
$tabsDropdown.empty();
for (let key in accessibleTabs) {
if (accessibleTabs[key]['children'].length > 0 && accessibleTabs[key]['name']) {
// If tab has children - create an option group and put children inside.
const $optgroup = this._createOptionGroup(accessibleTabs[key]['name']);
for (let childKey in accessibleTabs[key]['children']) {
if (accessibleTabs[key]['children'][childKey]['name']) {
$optgroup.append(
this._createOption(
accessibleTabs[key]['children'][childKey]['name'],
accessibleTabs[key]['children'][childKey]['id_tab'])
);
}
}
$tabsDropdown.append($optgroup);
} else if (accessibleTabs[key]['name']) {
// If tab doesn't have children - create an option.
$tabsDropdown.append(
this._createOption(
accessibleTabs[key]['name'],
accessibleTabs[key]['id_tab']
)
);
}
}
}
/**
* Hide shop choice tree if superadmin profile is selected, show it otherwise.
*
* @private
*/
_toggleShopTree() {
const $employeeProfileDropdown = $(this.employeeProfileSelector);
const superAdminProfileId = $employeeProfileDropdown.data('admin-profile');
$(this.shopChoiceTreeSelector)
.closest('.form-group')
.toggleClass('d-none', $employeeProfileDropdown.val() == superAdminProfileId)
;
}
/**
* Creates an <optgroup> element
*
* @param {String} name
*
* @returns {jQuery}
*
* @private
*/
_createOptionGroup(name) {
return $(`<optgroup label="${name}">`);
}
/**
* Creates an <option> element.
*
* @param {String} name
* @param {String} value
*
* @returns {jQuery}
*
* @private
*/
_createOption(name, value) {
return $(`<option value="${value}">${name}</option>`);
}
}

View File

@@ -0,0 +1,46 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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
*/
/**
* Defines all selectors that are used in employee add/edit form.
*/
export default {
shopChoiceTree: '#employee_shop_association',
profileSelect: '#employee_profile',
defaultPageSelect: '#employee_default_page',
addonsConnectForm: '#addons-connect-form',
addonsLoginButton: '#addons_login_btn',
// selectors related to "change password" form control
changePasswordInputsBlock: '.js-change-password-block',
showChangePasswordBlockButton: '.js-change-password',
hideChangePasswordBlockButton: '.js-change-password-cancel',
generatePasswordButton: '#employee_change_password_generate_password_button',
oldPasswordInput: '#employee_change_password_old_password',
newPasswordInput: '#employee_change_password_new_password_first',
confirmNewPasswordInput: '#employee_change_password_new_password_second',
generatedPasswordDisplayInput: '#employee_change_password_generated_password',
passwordStrengthFeedbackContainer: '.js-password-strength-feedback',
}

View File

@@ -0,0 +1,30 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 EmployeeForm from "./EmployeeForm";
$(() => {
new EmployeeForm();
});

View File

@@ -0,0 +1,56 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitBulkActionExtension from '../../components/grid/extension/submit-bulk-action-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import ColumnTogglingExtension from '../../components/grid/extension/column-toggling-extension';
import ShowcaseCard from '../../components/showcase-card/showcase-card';
import ShowcaseCardCloseExtension from '../../components/showcase-card/extension/showcase-card-close-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
$(() => {
const employeeGrid = new Grid('employee');
employeeGrid.addExtension(new ReloadListActionExtension());
employeeGrid.addExtension(new ExportToSqlManagerExtension());
employeeGrid.addExtension(new FiltersResetExtension());
employeeGrid.addExtension(new SortingExtension());
employeeGrid.addExtension(new BulkActionCheckboxExtension());
employeeGrid.addExtension(new SubmitBulkActionExtension());
employeeGrid.addExtension(new SubmitRowActionExtension());
employeeGrid.addExtension(new ColumnTogglingExtension());
employeeGrid.addExtension(new LinkRowActionExtension());
const showcaseCard = new ShowcaseCard('employeesShowcaseCard');
showcaseCard.addExtension(new ShowcaseCardCloseExtension());
});

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ChoiceTable from '../../components/choice-table';
const $ = window.$;
$(() => {
new ChoiceTable();
});

View File

@@ -0,0 +1,88 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
export default class EntityFieldsValidator {
/**
* Validates entity fields
*
* @returns {boolean}
*/
static validate() {
$('.js-validation-error').addClass('d-none');
return this._checkDuplicateSelectedValues() && this._checkRequiredFields();
}
/**
* Checks if there are no duplicate selected values.
*
* @returns {boolean}
* @private
*/
static _checkDuplicateSelectedValues() {
const uniqueFields = [];
let valid = true;
$('.js-entity-field select').each(function () {
let value = $(this).val();
if (value === 'no') {
return;
}
if ($.inArray(value, uniqueFields) !== -1) {
valid = false;
$('.js-duplicate-columns-warning').removeClass('d-none');
return;
}
uniqueFields.push(value);
});
return valid;
}
/**
* Checks if all required fields are selected.
*
* @returns {boolean}
* @private
*/
static _checkRequiredFields() {
let requiredImportFields = $('.js-import-data-table').data('required-fields');
for (let key in requiredImportFields) {
if (0 === $(`option[value="${requiredImportFields[key]}"]:selected`).length) {
$('.js-missing-column-warning').removeClass('d-none');
$('.js-missing-column').text($(`option[value="${requiredImportFields[key]}"]:first`).text());
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,100 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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
*/
/**
* Class ImportBatchSizeCalculator calculates the import batch size.
* Import batch size is the maximum number of records that
* the import should handle in one batch.
*/
export default class ImportBatchSizeCalculator {
constructor() {
// Target execution time in milliseconds.
this._targetExecutionTime = 5000;
// Maximum batch size increase multiplier.
this._maxAcceleration = 4;
// Minimum and maximum import batch sizes.
this._minBatchSize = 5;
this._maxBatchSize = 100;
}
/**
* Marks the start of the import operation.
* Must be executed before starting the import,
* to be able to calculate the import batch size later on.
*/
markImportStart() {
this._importStartTime = new Date().getTime();
}
/**
* Marks the end of the import operation.
* Must be executed after the import operation finishes,
* to be able to calculate the import batch size later on.
*/
markImportEnd() {
this._actualExecutionTime = new Date().getTime() - this._importStartTime;
}
/**
* Calculates how much the import execution time can be increased to still be acceptable.
*
* @returns {number}
* @private
*/
_calculateAcceleration() {
return Math.min(this._maxAcceleration, this._targetExecutionTime / this._actualExecutionTime);
}
/**
* Calculates the recommended import batch size.
*
* @param {number} currentBatchSize current import batch size
* @param {number} maxBatchSize greater than zero, the batch size that shouldn't be exceeded
*
* @returns {number} recommended import batch size
*/
calculateBatchSize(currentBatchSize, maxBatchSize = 0) {
if (!this._importStartTime) {
throw 'Import start is not marked.';
}
if (!this._actualExecutionTime) {
throw 'Import end is not marked.';
}
let candidates = [
this._maxBatchSize,
Math.max(this._minBatchSize, Math.floor(currentBatchSize * this._calculateAcceleration()))
];
if (maxBatchSize > 0) {
candidates.push(maxBatchSize);
}
return Math.min(...candidates);
}
}

View File

@@ -0,0 +1,69 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ImportMatchConfiguration from './ImportMatchConfiguration';
import ImportDataTable from './ImportDataTable';
import EntityFieldsValidator from './EntityFieldsValidator';
import Importer from './Importer';
export default class ImportDataPage {
constructor() {
new ImportMatchConfiguration();
new ImportDataTable();
this.importer = new Importer();
$(document).on('click', '.js-process-import', (e) => this.importHandler(e));
$(document).on('click', '.js-abort-import', () => this.importer.requestCancelImport());
$(document).on('click', '.js-close-modal', () => this.importer.progressModal.hide());
$(document).on('click', '.js-continue-import', () => this.importer.continueImport());
}
/**
* Import process event handler
*/
importHandler(e) {
e.preventDefault();
if (!EntityFieldsValidator.validate()) {
return;
}
let configuration = {};
// Collect the configuration from the form into an array.
$('.import-data-configuration-form').find(
'#skip, select[name^=type_value], #csv, #iso_lang, #entity,' +
'#truncate, #match_ref, #regenerate, #forceIDs, #sendemail,' +
'#separator, #multiple_value_separator'
).each((index, $input) => {
configuration[$($input).attr('name')] = $($input).val();
});
this.importer.import(
$('.js-import-process-button').data('import_url'),
configuration
);
}
}

View File

@@ -0,0 +1,173 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 $importDataTable = $('.js-import-data-table');
/**
* Pagination directions - forward and backward.
*/
const FORWARD = 'forward';
const BACKWARD = 'backward';
export default class ImportDataTable {
constructor() {
this.numberOfColumnsPerPage = this._getNumberOfVisibleColumns();
this.totalNumberOfColumns = this._getTotalNumberOfColumns();
$('.js-import-next-page').on('click', () => this.importNextPageHandler());
$('.js-import-previous-page').on('click', () => this.importPreviousPageHandler());
}
/**
* Handle the next page action in import data table.
*/
importNextPageHandler() {
this._importPaginationHandler(FORWARD);
}
/**
* Handle the previous page action in import data table.
*/
importPreviousPageHandler() {
this._importPaginationHandler(BACKWARD);
}
/**
* Handle the forward and back buttons actions in the import table.
*
* @param {string} direction
* @private
*/
_importPaginationHandler(direction) {
const $currentPageElements = $importDataTable.find('th:visible,td:visible');
const $oppositePaginationButton = direction === FORWARD ? $('.js-import-next-page') : $('.js-import-previous-page');
let lastVisibleColumnFound = false;
let numberOfVisibleColumns = 0;
let $tableColumns = $importDataTable.find('th');
if (direction === BACKWARD) {
// If going backward - reverse the table columns array and use the same logic as forward
$tableColumns = $($tableColumns.toArray().reverse());
}
for (let index in $tableColumns) {
if (isNaN(index)) {
// Reached the last column - hide the opposite pagination button
this._hide($oppositePaginationButton);
break;
}
// Searching for last visible column
if ($($tableColumns[index]).is(':visible')) {
lastVisibleColumnFound = true;
continue;
}
// If last visible column was found - show the column after it
if (lastVisibleColumnFound) {
// If going backward, the column index must be counted from the last element
let showColumnIndex = direction === BACKWARD ? this.totalNumberOfColumns - 1 - index : index;
this._showTableColumnByIndex(showColumnIndex);
numberOfVisibleColumns++;
// If number of visible columns per page is already reached - break the loop
if (numberOfVisibleColumns >= this.numberOfColumnsPerPage) {
this._hide($oppositePaginationButton);
break;
}
}
}
// Hide all the columns from previous page
this._hide($currentPageElements);
// If the first column in the table is not visible - show the "previous" pagination arrow
if (!$importDataTable.find('th:first').is(':visible')) {
this._show($('.js-import-previous-page'));
}
// If the last column in the table is not visible - show the "next" pagination arrow
if (!$importDataTable.find('th:last').is(':visible')) {
this._show($('.js-import-next-page'));
}
}
/**
* Gets the number of currently visible columns in the import data table.
*
* @returns {number}
* @private
*/
_getNumberOfVisibleColumns() {
return $importDataTable.find('th:visible').length;
}
/**
* Gets the total number of columns in the import data table.
*
* @returns {number}
* @private
*/
_getTotalNumberOfColumns() {
return $importDataTable.find('th').length;
}
/**
* Hide the elements.
*
* @param $elements
* @private
*/
_hide($elements) {
$elements.addClass('d-none');
}
/**
* Show the elements.
*
* @param $elements
* @private
*/
_show($elements) {
$elements.removeClass('d-none');
}
/**
* Shows a column from import data table by given index
*
* @param columnIndex
* @private
*/
_showTableColumnByIndex(columnIndex) {
// Increasing the index because nth-child calculates from 1 and index starts from 0
columnIndex++;
this._show($importDataTable.find('th:nth-child(' + columnIndex + ')'));
this._show($importDataTable.find('tbody > tr').find('td:nth-child(' + columnIndex + ')'));
}
}

View File

@@ -0,0 +1,178 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Class is responsible for import match configuration
* in Advanced parameters -> Import -> step 2 form.
*/
export default class ImportMatchConfiguration
{
/**
* Initializes all the processes related with import matches.
*/
constructor() {
this.loadEvents();
}
/**
* Loads all events for data match configuration.
*/
loadEvents() {
$(document).on('click', '.js-save-import-match', (event) => this.save(event));
$(document).on('click', '.js-load-import-match', (event) => this.load(event));
$(document).on('click', '.js-delete-import-match', (event) => this.delete(event));
}
/**
* Save the import match configuration.
*/
save(event) {
event.preventDefault();
const ajaxUrl = $('.js-save-import-match').attr('data-url');
const formData = $('.import-data-configuration-form').serialize();
$.ajax({
type: 'POST',
url: ajaxUrl,
data: formData,
}).then(response => {
if (typeof response.errors !== 'undefined' && response.errors.length) {
this._showErrorPopUp(response.errors);
} else if (response.matches.length > 0){
let $dataMatchesDropdown = this.matchesDropdown;
for (let key in response.matches) {
let $existingMatch = $dataMatchesDropdown.find(`option[value=${response.matches[key].id_import_match}]`);
// If match already exists with same id - do nothing
if ($existingMatch.length > 0) {
continue;
}
// Append the new option to the matches dropdown
this._appendOptionToDropdown(
$dataMatchesDropdown,
response.matches[key].name,
response.matches[key].id_import_match
);
}
}
});
}
/**
* Load the import match.
*/
load(event) {
event.preventDefault();
const ajaxUrl = $('.js-load-import-match').attr('data-url');
$.ajax({
type: 'GET',
url: ajaxUrl,
data: {
import_match_id: this.matchesDropdown.val()
},
}).then(response => {
if (response) {
this.rowsSkipInput.val(response.skip);
let entityFields = response.match.split('|');
for (let i in entityFields) {
$(`#type_value_${i}`).val(entityFields[i]);
}
}
});
}
/**
* Delete the import match.
*/
delete(event) {
event.preventDefault();
const ajaxUrl = $('.js-delete-import-match').attr('data-url');
const $dataMatchesDropdown = this.matchesDropdown;
const selectedMatchId = $dataMatchesDropdown.val();
$.ajax({
type: 'DELETE',
url: ajaxUrl,
data: {
import_match_id: selectedMatchId
},
}).then(() => {
// Delete the match option from matches dropdown
$dataMatchesDropdown.find(`option[value=${selectedMatchId}]`).remove();
});
}
/**
* Appends a new option to given dropdown.
*
* @param {jQuery} $dropdown
* @param {String} optionText
* @param {String} optionValue
* @private
*/
_appendOptionToDropdown($dropdown, optionText, optionValue) {
const $newOption = $('<option>');
$newOption.attr('value', optionValue);
$newOption.text(optionText);
$dropdown.append($newOption);
}
/**
* Shows error messages in the native error pop-up.
*
* @param {Array} errors
* @private
*/
_showErrorPopUp(errors) {
alert(errors);
}
/**
* Get the matches dropdown.
*
* @returns {*|HTMLElement}
*/
get matchesDropdown() {
return $('#matches');
}
/**
* Get the "rows to skip" input.
*
* @returns {*|HTMLElement}
*/
get rowsSkipInput() {
return $('#skip');
}
}

View File

@@ -0,0 +1,319 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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
*/
export default class ImportProgressModal {
/**
* Show the import progress modal window.
*/
show() {
this.progressModal.modal('show');
}
/**
* Hide the import progress modal window.
*/
hide() {
this.progressModal.modal('hide');
}
/**
* Updates the import progressbar.
*
* @param {number} completed number of completed items.
* @param {number} total number of items in total.
*/
updateProgress(completed, total) {
completed = parseInt(completed);
total = parseInt(total);
let $progressBar = this.progressBar,
percentage = completed / total * 100;
$progressBar.css('width', `${percentage}%`);
$progressBar.find('> span').text(`${completed}/${total}`);
}
/**
* Updates the progress bar label.
*
* @param {String} label if not provided - will use the default label
*/
updateProgressLabel(label) {
this.progressLabel.text(label);
}
/**
* Sets the progress label to "importing"
*/
setImportingProgressLabel() {
this.updateProgressLabel(this.progressModal.find('.modal-body').data('importing-label'));
}
/**
* Sets the progress label to "imported"
*/
setImportedProgressLabel() {
this.updateProgressLabel(this.progressModal.find('.modal-body').data('imported-label'));
}
/**
* Shows information messages in the import modal.
*
* @param {Array} messages
*/
showInfoMessages(messages) {
this._showMessages(this.infoMessageBlock, messages);
}
/**
* Shows warning messages in the import modal.
*
* @param {Array} messages
*/
showWarningMessages(messages) {
this._showMessages(this.warningMessageBlock, messages);
}
/**
* Shows error messages in the import modal.
*
* @param {Array} messages
*/
showErrorMessages(messages) {
this._showMessages(this.errorMessageBlock, messages);
}
/**
* Shows the import success message.
*/
showSuccessMessage() {
this.successMessageBlock.removeClass('d-none');
}
/**
* Shows the post size limit warning message.
*
* @param {number} postSizeValue to be shown in the warning
*/
showPostLimitMessage(postSizeValue) {
this.postLimitMessage.find('#post_limit_value').text(postSizeValue);
this.postLimitMessage.removeClass('d-none');
}
/**
* Show messages in given message block.
*
* @param {jQuery} $messageBlock
* @param {Array} messages
* @private
*/
_showMessages($messageBlock, messages) {
let showMessagesBlock = false;
for (let key in messages) {
// Indicate that the messages block should be displayed
showMessagesBlock = true;
let message = $('<div>');
message.text(messages[key]);
message.addClass('message');
$messageBlock.append(message);
}
if (showMessagesBlock) {
$messageBlock.removeClass('d-none');
}
}
/**
* Show the "Ignore warnings and continue" button.
*/
showContinueImportButton() {
this.continueImportButton.removeClass('d-none')
}
/**
* Hide the "Ignore warnings and continue" button.
*/
hideContinueImportButton() {
this.continueImportButton.addClass('d-none');
}
/**
* Show the "Abort import" button.
*/
showAbortImportButton() {
this.abortImportButton.removeClass('d-none');
}
/**
* Hide the "Abort import" button.
*/
hideAbortImportButton() {
this.abortImportButton.addClass('d-none');
}
/**
* Show the "Close" button of the modal.
*/
showCloseModalButton() {
this.closeModalButton.removeClass('d-none');
}
/**
* Hide the "Close" button.
*/
hideCloseModalButton() {
this.closeModalButton.addClass('d-none');
}
/**
* Clears all warning messages from the modal.
*/
clearWarningMessages() {
this.warningMessageBlock.addClass('d-none').find('.message').remove();
}
/**
* Reset the modal - resets progress bar and removes messages.
*/
reset() {
// Reset the progress bar
this.updateProgress(0, 0);
this.updateProgressLabel(this.progressLabel.attr('default-value'));
// Hide action buttons
this.continueImportButton.addClass('d-none');
this.abortImportButton.addClass('d-none');
this.closeModalButton.addClass('d-none');
// Remove messages
this.successMessageBlock.addClass('d-none');
this.infoMessageBlock.addClass('d-none').find('.message').remove();
this.errorMessageBlock.addClass('d-none').find('.message').remove();
this.postLimitMessage.addClass('d-none');
this.clearWarningMessages();
}
/**
* Gets import progress modal.
*
* @returns {jQuery}
*/
get progressModal() {
return $('#import_progress_modal');
}
/**
* Gets import progress bar.
*
* @returns {jQuery}
*/
get progressBar() {
return this.progressModal.find('.progress-bar');
}
/**
* Gets information messages block.
*
* @returns {jQuery|HTMLElement}
*/
get infoMessageBlock() {
return $('.js-import-info');
}
/**
* Gets error messages block.
*
* @returns {jQuery|HTMLElement}
*/
get errorMessageBlock() {
return $('.js-import-errors');
}
/**
* Gets warning messages block.
*
* @returns {jQuery|HTMLElement}
*/
get warningMessageBlock() {
return $('.js-import-warnings');
}
/**
* Gets success messages block.
*
* @returns {jQuery|HTMLElement}
*/
get successMessageBlock() {
return $('.js-import-success');
}
/**
* Gets post limit message.
*
* @returns {jQuery|HTMLElement}
*/
get postLimitMessage() {
return $('.js-post-limit-warning');
}
/**
* Gets "Ignore warnings and continue" button.
*
* @returns {jQuery|HTMLElement}
*/
get continueImportButton() {
return $('.js-continue-import');
}
/**
* Gets "Abort import" button.
*
* @returns {jQuery|HTMLElement}
*/
get abortImportButton() {
return $('.js-abort-import');
}
/**
* Gets "Close" button of the modal.
*
* @returns {jQuery|HTMLElement}
*/
get closeModalButton() {
return $('.js-close-modal');
}
/**
* Gets progress bar label.
*
* @returns {jQuery|HTMLElement}
*/
get progressLabel() {
return $('#import_progress_bar').find('.progress-details-text');
}
}

View File

@@ -0,0 +1,302 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ImportProgressModal from './ImportProgressModal';
import ImportBatchSizeCalculator from './ImportBatchSizeCalculator';
import PostSizeChecker from './PostSizeChecker';
export default class Importer {
constructor() {
this.configuration = {};
this.progressModal = new ImportProgressModal;
this.batchSizeCalculator = new ImportBatchSizeCalculator;
this.postSizeChecker = new PostSizeChecker();
// Default number of rows in one batch of the import.
this.defaultBatchSize = 5;
}
/**
* Process the import.
*
* @param {String} importUrl url of the controller, processing the import.
* @param {Object} configuration import configuration.
*/
import(importUrl, configuration) {
this._mergeConfiguration(configuration);
this.importUrl = importUrl;
// Total number of rows to be imported.
this.totalRowsCount = 0;
// Flags that mark that there were warnings or errors during import.
this.hasWarnings = false;
this.hasErrors = false;
// Resetting the import progress modal and showing it.
this.progressModal.reset();
this.progressModal.show();
// Starting the import with default batch size, which is adjusted for next iterations.
this._ajaxImport(0, this.defaultBatchSize);
}
/**
* Process the ajax import request.
*
* @param {number} offset row number, from which the import job will start processing data.
* @param {number} batchSize batch size of this import job.
* @param {boolean} validateOnly whether the data should be only validated, if false - the data will be imported.
* @param {Object} recurringVariables variables which are recurring between import batch jobs.
* @private
*/
_ajaxImport(offset, batchSize, validateOnly = true, recurringVariables = {}) {
this._mergeConfiguration({
offset: offset,
limit: batchSize,
validateOnly: validateOnly ? 1 : 0,
crossStepsVars: JSON.stringify(recurringVariables)
});
this._onImportStart();
$.post({
url: this.importUrl,
dataType: 'json',
data: this.configuration,
success: (response) => {
if (this._importCancelRequested) {
this._cancelImport();
return false;
}
let hasErrors = response.errors && response.errors.length,
hasWarnings = response.warnings && response.warnings.length,
hasNotices = response.notices && response.notices.length;
if (response.totalCount !== undefined && response.totalCount) {
// The total rows count is retrieved only in the first batch response.
this.totalRowsCount = response.totalCount;
}
// Update import progress.
this.progressModal.updateProgress(response.doneCount, this.totalRowsCount);
if (!validateOnly) {
// Set the progress label to "Importing".
this.progressModal.setImportingProgressLabel();
}
// Information messages are not shown during validation.
if (!validateOnly && hasNotices) {
this.progressModal.showInfoMessages(response.notices);
}
if (hasErrors) {
this.hasErrors = true;
this.progressModal.showErrorMessages(response.errors);
// If there are errors and it's not validation step - stop the import.
// If it's validation step - we will show all errors once it finishes.
if (!validateOnly) {
this._onImportStop();
return false;
}
} else if (hasWarnings) {
this.hasWarnings = true;
this.progressModal.showWarningMessages(response.warnings);
}
if (!response.isFinished) {
// Marking the end of import operation.
this.batchSizeCalculator.markImportEnd();
// Calculate next import batch size and offset.
let nextOffset = offset + batchSize;
let nextBatchSize = this.batchSizeCalculator.calculateBatchSize(batchSize, this.totalRowsCount);
// Showing a warning if post size limit is about to be reached.
if (this.postSizeChecker.isReachingPostSizeLimit(response.postSizeLimit, response.nextPostSize)) {
this.progressModal.showPostLimitMessage(
this.postSizeChecker.getRequiredPostSizeInMegabytes(response.nextPostSize)
);
}
// Run the import again for the next batch.
return this._ajaxImport(
nextOffset,
nextBatchSize,
validateOnly,
response.crossStepsVariables
);
}
// All import batches are finished successfully.
// If it was only validating the import data until this point,
// we have to run the data import now.
if (validateOnly) {
// If errors occurred during validation - stop the import.
if (this.hasErrors) {
this._onImportStop();
return false;
}
if (this.hasWarnings) {
// Show the button to ignore warnings.
this.progressModal.showContinueImportButton();
this._onImportStop();
return false;
}
// Update the progress bar to 100%.
this.progressModal.updateProgress(this.totalRowsCount, this.totalRowsCount);
// Continue with the data import.
return this._ajaxImport(0, this.defaultBatchSize, false);
}
// Import is completely finished.
this._onImportFinish();
},
error: (XMLHttpRequest, textStatus, errorCode) => {
if (textStatus === 'parsererror') {
textStatus = 'Technical error: Unexpected response returned by server. Import stopped.';
}
this._onImportStop();
this.progressModal.showErrorMessages([textStatus]);
}
});
}
/**
* Continue the import when it was stopped.
*/
continueImport() {
if (!this.configuration) {
throw 'Missing import configuration. Make sure the import had started before continuing.';
}
this.progressModal.hideContinueImportButton();
this.progressModal.hideCloseModalButton();
this.progressModal.clearWarningMessages();
this._ajaxImport(0, this.defaultBatchSize, false);
}
/**
* Set the import configuration.
*
* @param importConfiguration
*/
set configuration(importConfiguration) {
this._importConfiguration = importConfiguration;
}
/**
* Get the import configuration.
*
* @returns {*}
*/
get configuration() {
return this._importConfiguration;
}
/**
* Set progress modal.
*
* @param {ImportProgressModal} modal
*/
set progressModal(modal) {
this._modal = modal;
}
/**
* Get progress modal.
*
* @returns {ImportProgressModal}
*/
get progressModal() {
return this._modal;
}
/**
* Request import cancellation.
* Import operation will be cancelled at next iteration when requested.
*/
requestCancelImport() {
this._importCancelRequested = true;
}
/**
* Merge given configuration into current import configuration.
*
* @param {Object} configuration
* @private
*/
_mergeConfiguration(configuration) {
for (let key in configuration) {
this._importConfiguration[key] = configuration[key];
}
}
/**
* Cancel the import process.
* @private
*/
_cancelImport() {
this.progressModal.hide();
this._importCancelRequested = false;
}
/**
* Additional actions when import is stopped.
* @private
*/
_onImportStop() {
this.progressModal.showCloseModalButton();
this.progressModal.hideAbortImportButton();
}
/**
* Additional actions when import is finished.
* @private
*/
_onImportFinish() {
this._onImportStop();
this.progressModal.showSuccessMessage();
this.progressModal.setImportedProgressLabel();
this.progressModal.updateProgress(this.totalRowsCount, this.totalRowsCount);
}
/**
* Additional actions when import is starting.
* @private
*/
_onImportStart() {
// Marking the start of import operation.
this.batchSizeCalculator.markImportStart();
this.progressModal.showAbortImportButton();
}
}

View File

@@ -0,0 +1,54 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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
*/
export default class PostSizeChecker {
constructor() {
// How close can we get to the post size limit. 0.9 means 90%.
this.postSizeLimitThreshold = 0.9;
}
/**
* Check if given postSizeLimit is reaching the required post size
*
* @param {number} postSizeLimit
* @param {number} requiredPostSize
*
* @returns {boolean}
*/
isReachingPostSizeLimit(postSizeLimit, requiredPostSize) {
return requiredPostSize >= postSizeLimit * this.postSizeLimitThreshold;
}
/**
* Get required post size in megabytes.
*
* @param {number} requiredPostSize
*
* @returns {number}
*/
getRequiredPostSizeInMegabytes(requiredPostSize) {
return parseInt(requiredPostSize / (1024 * 1024));
}
}

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ImportDataPage from './ImportDataPage';
const $ = window.$;
$(() => {
new ImportDataPage();
});

View File

@@ -0,0 +1,203 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 entityCategories = 0;
const entityProducts = 1;
const entityCombinations = 2;
const entityCustomers = 3;
const entityAddresses = 4;
const entityBrands = 5;
const entitySuppliers = 6;
const entityAlias = 7;
const entityStoreContacts = 8;
export default class FormFieldToggle {
constructor() {
$('.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();
this.toggleEntityAlert(selectedEntity);
this.toggleFields(selectedEntity, entityName);
this.loadAvailableFields(selectedEntity);
}
/**
* Toggle alert warning for selected import entity
*
* @param {int} selectedEntity
*/
toggleEntityAlert(selectedEntity) {
let $alert = $('.js-entity-alert');
if ([entityCategories, entityProducts].includes(selectedEntity)) {
$alert.show();
} else {
$alert.hide();
}
}
/**
* Toggle available options for selected entity
*
* @param {int} selectedEntity
* @param {string} entityName
*/
toggleFields(selectedEntity, entityName) {
const $truncateFormGroup = $('.js-truncate-form-group');
const $matchRefFormGroup = $('.js-match-ref-form-group');
const $regenerateFormGroup = $('.js-regenerate-form-group');
const $forceIdsFormGroup = $('.js-force-ids-form-group');
const $entityNamePlaceholder = $('.js-entity-name');
if (entityStoreContacts === selectedEntity) {
$truncateFormGroup.hide();
} else {
$truncateFormGroup.show();
}
if ([entityProducts, entityCombinations].includes(selectedEntity)) {
$matchRefFormGroup.show();
} else {
$matchRefFormGroup.hide();
}
if ([
entityCategories,
entityProducts,
entityBrands,
entitySuppliers,
entityStoreContacts
].includes(selectedEntity)
) {
$regenerateFormGroup.show();
} else {
$regenerateFormGroup.hide();
}
if ([
entityCategories,
entityProducts,
entityCustomers,
entityAddresses,
entityBrands,
entitySuppliers,
entityStoreContacts,
entityAlias
].includes(selectedEntity)
) {
$forceIdsFormGroup.show();
} else {
$forceIdsFormGroup.hide();
}
$entityNamePlaceholder.html(entityName);
}
/**
* Load available fields for given entity
*
* @param {int} entity
*/
loadAvailableFields(entity) {
const $availableFields = $('.js-available-fields');
$.ajax({
url: $availableFields.data('url'),
data: {
entity: entity
},
dataType: 'json',
}).then(response => {
this._removeAvailableFields($availableFields);
for (let i = 0; i < response.length; i++) {
this._appendAvailableField(
$availableFields,
response[i].label + (response[i].required ? '*' : ''),
response[i].description
);
}
$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) {
let $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) {
let $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);
}
}

View File

@@ -0,0 +1,268 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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";
const $ = window.$;
export default class ImportPage {
constructor() {
new FormFieldToggle();
$('.js-from-files-history-btn').on('click', () => this.showFilesHistoryHandler());
$('.js-close-files-history-block-btn').on('click', () => this.closeFilesHistoryHandler());
$('#fileHistoryTable').on('click', '.js-use-file-btn', (event) => this.useFileFromFilesHistory(event));
$('.js-change-import-file-btn').on('click', () => this.changeImportFileHandler());
$('.js-import-file').on('change', () => this.uploadFile());
this.toggleSelectedFile();
this.handleSubmit();
}
/**
* Handle submit and add confirm box in case the toggle button about
* deleting all entities before import is checked
*/
handleSubmit() {
$('.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())}?`);
}
});
}
/**
* Check if selected file names exists and if so, then display it
*/
toggleSelectedFile() {
let selectFilename = $('#csv').val();
if (selectFilename.length > 0) {
this.showImportFileAlert(selectFilename);
this.hideFileUploadBlock();
}
}
changeImportFileHandler() {
this.hideImportFileAlert();
this.showFileUploadBlock();
}
/**
* Show files history event handler
*/
showFilesHistoryHandler() {
this.showFilesHistory();
this.hideFileUploadBlock();
}
/**
* Close files history event handler
*/
closeFilesHistoryHandler() {
this.closeFilesHistory();
this.showFileUploadBlock();
}
/**
* Show files history block
*/
showFilesHistory() {
$('.js-files-history-block').removeClass('d-none');
}
/**
* Hide files history block
*/
closeFilesHistory() {
$('.js-files-history-block').addClass('d-none');
}
/**
* Prefill hidden file input with selected file name from history
*/
useFileFromFilesHistory(event) {
let filename = $(event.target).closest('.btn-group').data('file');
$('.js-import-file-input').val(filename);
this.showImportFileAlert(filename);
this.closeFilesHistory();
}
/**
* Show alert with imported file name
*/
showImportFileAlert(filename) {
$('.js-import-file-alert').removeClass('d-none');
$('.js-import-file').text(filename);
}
/**
* Hides selected import file alert
*/
hideImportFileAlert() {
$('.js-import-file-alert').addClass('d-none');
}
/**
* Hides import file upload block
*/
hideFileUploadBlock() {
$('.js-file-upload-form-group').addClass('d-none');
}
/**
* Hides import file upload block
*/
showFileUploadBlock() {
$('.js-file-upload-form-group').removeClass('d-none');
}
/**
* Make file history button clickable
*/
enableFilesHistoryBtn() {
$('.js-from-files-history-btn').removeAttr('disabled');
}
/**
* Show error message if file uploading failed
*
* @param {string} fileName
* @param {integer} fileSize
* @param {string} message
*/
showImportFileError(fileName, fileSize, message) {
const $alert = $('.js-import-file-error');
const fileData = fileName + ' (' + this.humanizeSize(fileSize) + ')';
$alert.find('.js-file-data').text(fileData);
$alert.find('.js-error-message').text(message);
$alert.removeClass('d-none');
}
/**
* Hide file uploading error
*/
hideImportFileError() {
const $alert = $('.js-import-file-error');
$alert.addClass('d-none');
}
/**
* Show file size in human readable format
*
* @param {int} bytes
*
* @returns {string}
*/
humanizeSize(bytes) {
if (typeof bytes !== 'number') {
return '';
}
if (bytes >= 1000000000) {
return (bytes / 1000000000).toFixed(2) + ' GB';
}
if (bytes >= 1000000) {
return (bytes / 1000000).toFixed(2) + ' MB';
}
return (bytes / 1000).toFixed(2) + ' KB';
}
/**
* Upload selected import file
*/
uploadFile() {
this.hideImportFileError();
const $input = $('#file');
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;
}
const data = new FormData();
data.append('file', uploadedFile);
$.ajax({
type: 'POST',
url: $('.js-import-form').data('file-upload-url'),
data: data,
cache: false,
contentType: false,
processData: false,
}).then(response => {
if (response.error) {
this.showImportFileError(uploadedFile.name, uploadedFile.size, response.error);
return;
}
let filename = response.file.name;
$('.js-import-file-input').val(filename);
this.showImportFileAlert(filename);
this.hideFileUploadBlock();
this.addFileToHistoryTable(filename);
this.enableFilesHistoryBtn();
});
}
/**
* Renders new row in files history table
*
* @param {string} filename
*/
addFileToHistoryTable(filename) {
const $table = $('#fileHistoryTable');
let baseDeleteUrl = $table.data('delete-file-url');
let deleteUrl = baseDeleteUrl + '&filename=' + encodeURIComponent(filename);
let baseDownloadUrl = $table.data('download-file-url');
let downloadUrl = baseDownloadUrl + '&filename=' + encodeURIComponent(filename);
let $template = $table.find('tr:first').clone();
$template.removeClass('d-none');
$template.find('td:first').text(filename);
$template.find('.btn-group').attr('data-file', filename);
$template.find('.js-delete-file-btn').attr('href', deleteUrl);
$template.find('.js-download-file-btn').attr('href', downloadUrl);
$table.find('tbody').append($template);
let filesNumber = $table.find('tr').length - 1;
$('.js-files-history-number').text(filesNumber);
}
}

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
$(() => {
new ImportPage();
});

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 PositionsListHandler from './positions-list-handler';
const $ = window.$;
$(() => {
new PositionsListHandler();
});

View File

@@ -0,0 +1,289 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
class PositionsListHandler {
constructor() {
if ($("#position-filters").length === 0) {
return;
}
const self = this;
self.$panelSelection = $("#modules-position-selection-panel");
self.$panelSelectionSingleSelection = $("#modules-position-single-selection");
self.$panelSelectionMultipleSelection = $("#modules-position-multiple-selection");
self.$panelSelectionOriginalY = self.$panelSelection.offset().top;
self.$showModules = $("#show-modules");
self.$modulesList = $('.modules-position-checkbox');
self.$hookPosition = $("#hook-position");
self.$hookSearch = $("#hook-search");
self.$modulePositionsForm = $('#module-positions-form');
self.$moduleUnhookButton = $('#unhook-button-position-bottom');
self.$moduleButtonsUpdate = $('.module-buttons-update .btn');
self.handleList();
self.handleSortable();
$('input[name="form[general][enable_tos]"]').on('change', () => self.handle());
}
/**
* Handle all events for Design -> Positions List
*/
handleList() {
const self = this;
$(window).on('scroll', () => {
const $scrollTop = $(window).scrollTop();
self.$panelSelection.css(
'top',
$scrollTop < 20 ? 0 : $scrollTop - self.$panelSelectionOriginalY
);
});
self.$modulesList.on('change', function () {
const $checkedCount = self.$modulesList.filter(':checked').length;
if ($checkedCount === 0) {
self.$moduleUnhookButton.hide();
self.$panelSelection.hide();
self.$panelSelectionSingleSelection.hide();
self.$panelSelectionMultipleSelection.hide();
} else if ($checkedCount === 1) {
self.$moduleUnhookButton.show();
self.$panelSelection.show();
self.$panelSelectionSingleSelection.show();
self.$panelSelectionMultipleSelection.hide();
} else {
self.$moduleUnhookButton.show();
self.$panelSelection.show();
self.$panelSelectionSingleSelection.hide();
self.$panelSelectionMultipleSelection.show();
$('#modules-position-selection-count').html($checkedCount);
}
});
self.$panelSelection.find('button').click(() => {
$('button[name="unhookform"]').trigger('click');
});
self.$hooksList = [];
$('section.hook-panel .hook-name').each(function () {
const $this = $(this);
self.$hooksList.push({
'title': $this.html(),
'element': $this,
'container': $this.parents('.hook-panel')
});
});
self.$showModules.select2();
self.$showModules.on('change', () => {
self.modulesPositionFilterHooks();
});
self.$hookPosition.on('change', () => {
self.modulesPositionFilterHooks();
});
self.$hookSearch.on('input', () => {
self.modulesPositionFilterHooks();
});
self.$hookSearch.on('keypress', (e) => {
const keyCode = e.keyCode || e.which;
return keyCode !== 13;
});
$('.hook-checker').on('click', function() {
$(`.hook${$(this).data('hook-id')}`).prop('checked', $(this).prop('checked'));
});
self.$modulesList.on('click', function() {
$(`#Ghook${$(this).data('hook-id')}`).prop(
'checked',
$(`.hook${$(this).data('hook-id')}:not(:checked)`).length === 0
);
});
self.$moduleButtonsUpdate.on('click', function() {
const $btn = $(this);
const $current = $btn.closest('.module-item');
let $destination;
if ($btn.data('way')) {
$destination = $current.next('.module-item');
} else {
$destination = $current.prev('.module-item');
}
if ($destination.length === 0) {
return false;
}
if ($btn.data('way')) {
$current.insertAfter($destination);
} else {
$current.insertBefore($destination);
}
self.updatePositions(
{
hookId: $btn.data('hook-id'),
moduleId: $btn.data('module-id'),
way: $btn.data('way'),
positions: [],
},
$btn.closest('ul')
);
return false;
});
}
/**
* Handle sortable events
*/
handleSortable() {
const self = this;
$('.sortable').sortable({
forcePlaceholderSize: true,
start: function(e, ui) {
$(this).data('previous-index', ui.item.index());
},
update: function($event, ui) {
const [ hookId, moduleId ] = ui.item.attr('id').split('_');
const $data = {
hookId,
moduleId,
way: ($(this).data('previous-index') < ui.item.index()) ? 1 : 0,
positions: [],
};
self.updatePositions(
$data,
$($event.target)
);
},
});
}
updatePositions($data, $list) {
const self = this;
$.each($list.children(), function(index, element) {
$data.positions.push($(element).attr('id'));
});
$.ajax({
type: 'POST',
headers: {'cache-control': 'no-cache'},
url: self.$modulePositionsForm.data('update-url'),
data: $data,
success: () => {
let start = 0;
$.each($list.children(), function(index, element) {
console.log($(element).find('.index-position'));
$(element).find('.index-position').html(++start);
});
window.showSuccessMessage(window.update_success_msg);
}
});
}
/**
* Filter hooks / modules search and everything
* about hooks positions.
*/
modulesPositionFilterHooks() {
const self = this;
const $hookName = self.$hookSearch.val();
const $moduleId = self.$showModules.val();
const $regex = new RegExp(`(${$hookName})`, 'gi');
for (let $id = 0; $id < self.$hooksList.length; $id++) {
self.$hooksList[$id].container.toggle($hookName === '' && $moduleId === 'all');
self.$hooksList[$id].element.html(self.$hooksList[$id].title);
self.$hooksList[$id].container.find('.module-item').removeClass('highlight');
}
// Have select a hook name or a module id
if ($hookName !== '' || $moduleId !== 'all') {
// Prepare set of matched elements
let $hooksToShowFromModule = $();
let $hooksToShowFromHookName = $();
let $currentHooks;
let $start;
for (let $id = 0; $id < self.$hooksList.length; $id++) {
// Prepare highlight when one module is selected
if ($moduleId !== 'all') {
$currentHooks = self.$hooksList[$id].container.find(`.module-position-${$moduleId}`);
if ($currentHooks.length > 0) {
$hooksToShowFromModule = $hooksToShowFromModule.add(self.$hooksList[$id].container);
$currentHooks.addClass('highlight');
}
}
// Prepare highlight when there is a hook name
if ($hookName !== '') {
$start = self.$hooksList[$id].title.toLowerCase().search($hookName.toLowerCase());
if ($start !== -1) {
$hooksToShowFromHookName = $hooksToShowFromHookName.add(self.$hooksList[$id].container);
self.$hooksList[$id].element.html(
self.$hooksList[$id].title.replace(
$regex,
'<span class="highlight">$1</span>'
)
);
}
}
}
// Nothing selected
if ($moduleId === 'all' && $hookName !== '') {
$hooksToShowFromHookName.show();
} else if ($hookName === '' && $moduleId !== 'all') { // Have no hook bug have a module
$hooksToShowFromModule.show();
} else { // Both selected
$hooksToShowFromHookName.filter($hooksToShowFromModule).show();
}
}
if (!self.$hookPosition.prop('checked')) {
for (let $id = 0; $id < self.$hooksList.length; $id++) {
if (self.$hooksList[$id].container.is('.hook-position')) {
self.$hooksList[$id].container.hide();
}
}
}
};
}
export default PositionsListHandler;

View File

@@ -0,0 +1,34 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 initDatePickers from '../../app/utils/datepicker';
import TranslatableInput from '../../components/translatable-input';
const $ = window.$;
$(() => {
initDatePickers();
new TranslatableInput();
});

View File

@@ -0,0 +1,55 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import ChoiceTree from "../../components/form/choice-tree";
import ColumnTogglingExtension from "../../components/grid/extension/column-toggling-extension";
const $ = window.$;
$(document).ready(() => {
const grid = new Grid('language');
grid.addExtension(new ReloadListActionExtension());
grid.addExtension(new ExportToSqlManagerExtension());
grid.addExtension(new FiltersResetExtension());
grid.addExtension(new SortingExtension());
grid.addExtension(new LinkRowActionExtension());
grid.addExtension(new SubmitBulkExtension());
grid.addExtension(new SubmitRowActionExtension());
grid.addExtension(new BulkActionCheckboxExtension());
grid.addExtension(new ColumnTogglingExtension());
// needed for shop association input in form
new ChoiceTree('#language_shop_association').enableAutoCheckChildren();
});

View File

@@ -0,0 +1,33 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
$(() => {
// show warning message when currency is changed
$('#form_configuration_default_currency').on('change', function () {
alert($(this).data('warning-message'));
});
});

View File

@@ -0,0 +1,43 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import SubmitGridActionExtension from '../../components/grid/extension/submit-grid-action-extension';
const $ = global.$;
$(() => {
const grid = new Grid('logs');
grid.addExtension(new ReloadListActionExtension());
grid.addExtension(new ExportToSqlManagerExtension());
grid.addExtension(new FiltersResetExtension());
grid.addExtension(new SortingExtension());
grid.addExtension(new SubmitGridActionExtension());
});

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 TinyMCEEditor from '../../components/tinymce-editor';
const $ = window.$;
$(() => {
new TinyMCEEditor();
});

View File

@@ -0,0 +1,71 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 TranslatableInput from '../../components/translatable-input';
import TaggableField from '../../components/taggable-field';
import FormSubmitButton from '../../components/form-submit-button';
import Grid from '../../components/grid/grid';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ColumnTogglingExtension from '../../components/grid/extension/column-toggling-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import ChoiceTree from '../../components/form/choice-tree';
import TranslatableField from '../../components/translatable-field';
import TinyMCEEditor from '../../components/tinymce-editor';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
$(() => {
['manufacturer', 'manufacturer_address'].forEach((gridName) => {
const grid = new Grid(gridName);
grid.addExtension(new ExportToSqlManagerExtension());
grid.addExtension(new ReloadListActionExtension());
grid.addExtension(new SortingExtension());
grid.addExtension(new FiltersResetExtension());
grid.addExtension(new ColumnTogglingExtension());
grid.addExtension(new SubmitRowActionExtension());
grid.addExtension(new SubmitBulkExtension());
grid.addExtension(new BulkActionCheckboxExtension());
grid.addExtension(new LinkRowActionExtension());
});
new TranslatableInput();
new TranslatableField();
new TinyMCEEditor();
new TaggableField({
tokenFieldSelector: 'input.js-taggable-field',
options: {
createTokensOnBlur: true,
},
});
new FormSubmitButton();
new ChoiceTree('#manufacturer_shop_association').enableAutoCheckChildren();
});

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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
*/
export default {
manufacturerAddressCountrySelect: '#manufacturer_address_id_country',
manufacturerAddressStateSelect: '#manufacturer_address_id_state',
manufacturerAddressStateBlock: '.js-manufacturer-address-state',
manufacturerAddressDniInput: '#manufacturer_address_dni',
manufacturerAddressDniInputLabel: 'label[for="manufacturer_address_dni"]',
};

View File

@@ -0,0 +1,43 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 CountryStateSelectionToggler from '../../components/country-state-selection-toggler';
import ManufacturerAddressMap from './manufacturer-address-map';
import CountryDniRequiredToggler from '../../components/country-dni-required-toggler';
const $ = window.$;
$(document).ready(() => {
new CountryStateSelectionToggler(
ManufacturerAddressMap.manufacturerAddressCountrySelect,
ManufacturerAddressMap.manufacturerAddressStateSelect,
ManufacturerAddressMap.manufacturerAddressStateBlock
);
new CountryDniRequiredToggler(
ManufacturerAddressMap.manufacturerAddressCountrySelect,
ManufacturerAddressMap.manufacturerAddressDniInput,
ManufacturerAddressMap.manufacturerAddressDniInputLabel
);
});

View File

@@ -0,0 +1,68 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
import SubmitGridExtension from '../../components/grid/extension/submit-grid-action-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import ShowcaseCard from '../../components/showcase-card/showcase-card';
import ShowcaseCardCloseExtension from '../../components/showcase-card/extension/showcase-card-close-extension';
import TaggableField from '../../components/taggable-field';
import TranslatableInput from '../../components/translatable-input';
import MetaPageNameOptionHandler from './meta-page-name-option-handler';
const $ = window.$;
$(() => {
const meta = new Grid('meta');
meta.addExtension(new ReloadListActionExtension());
meta.addExtension(new ExportToSqlManagerExtension());
meta.addExtension(new FiltersResetExtension());
meta.addExtension(new SortingExtension());
meta.addExtension(new LinkRowActionExtension());
meta.addExtension(new SubmitGridExtension());
meta.addExtension(new SubmitBulkExtension());
meta.addExtension(new SubmitRowActionExtension());
meta.addExtension(new BulkActionCheckboxExtension());
const helperBlock = new ShowcaseCard('seo-urls-showcase-card');
helperBlock.addExtension(new ShowcaseCardCloseExtension());
new TaggableField({
tokenFieldSelector: 'input.js-taggable-field',
options: {
createTokensOnBlur: true,
},
});
new TranslatableInput();
new MetaPageNameOptionHandler();
});

View File

@@ -0,0 +1,62 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Class MetaPageNameOptionHandler is responsible for checking the index page condition - if index page is selected it
* does not allow to enter url rewrite field by disabling that input. In another cases url rewrite field is mandatory to
* enter.
*/
export default class MetaPageNameOptionHandler {
constructor() {
const pageNameSelector = '.js-meta-page-name';
const currentPage = $(pageNameSelector).val();
this.setUrlRewriteDisabledStatusByCurrentPage(currentPage);
$(document).on('change', pageNameSelector, event => this.changePageNameEvent(event));
}
/**
* An event which is being called after the selector is being updated.
* @param {object} event
* @private
*/
changePageNameEvent(event) {
const $this = $(event.currentTarget);
const currentPage = $this.val();
this.setUrlRewriteDisabledStatusByCurrentPage(currentPage);
}
/**
* Sets url rewrite form field to disabled or enabled according to current page value.
* @param {string} currentPage
* @private
*/
setUrlRewriteDisabledStatusByCurrentPage(currentPage) {
$('.js-url-rewrite input').prop('disabled', currentPage === 'index');
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,36 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ModuleCard from '../../components/module-card';
import AdminModuleController from './controller';
import ModuleLoader from './loader';
const $ = window.$;
$(() => {
const moduleCardController = new ModuleCard();
new ModuleLoader();
new AdminModuleController(moduleCardController);
});

View File

@@ -0,0 +1,80 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Module Admin Page Loader.
* @constructor
*/
class ModuleLoader {
constructor() {
ModuleLoader.handleImport();
ModuleLoader.handleEvents();
}
static handleImport() {
const moduleImport = $('#module-import');
moduleImport.click(() => {
moduleImport.addClass('onclick', 250, validate);
});
function validate() {
setTimeout(
() => {
moduleImport.removeClass('onclick');
moduleImport.addClass('validate', 450, callback);
},
2250
);
}
function callback() {
setTimeout(
() => {
moduleImport.removeClass('validate');
},
1250
);
}
}
static handleEvents() {
$('body').on(
'click',
'a.module-read-more-grid-btn, a.module-read-more-list-btn',
(event) => {
event.preventDefault();
const modulePoppin = $(event.target).data('target');
$.get(event.target.href, (data) => {
$(modulePoppin).html(data);
$(modulePoppin).modal();
});
}
);
}
}
export default ModuleLoader;

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 TermsAndConditionsOptionHandler from './terms-and-conditions-option-handler';
const $ = window.$;
$(() => {
new TermsAndConditionsOptionHandler();
});

View File

@@ -0,0 +1,53 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
class TermsAndConditionsOptionHandler {
constructor() {
this.handle();
$('input[name="form[general][enable_tos]"]').on('change', () => this.handle());
}
handle() {
const tosEnabledVal = $('input[name="form[general][enable_tos]"]:checked').val();
const isTosEnabled = parseInt(tosEnabledVal);
this.handleTermsAndConditionsCmsSelect(isTosEnabled);
}
/**
* If terms and conditions option is disabled, then terms and conditions
* cms select must be disabled.
*
* @param {int} isTosEnabled
*/
handleTermsAndConditionsCmsSelect(isTosEnabled) {
$('#form_general_tos_cms_id').prop('disabled', !isTosEnabled);
}
}
export default TermsAndConditionsOptionHandler;

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 TranslatableInput from '../../../components/translatable-input';
const $ = window.$;
$(() => {
new TranslatableInput();
});

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 MultipleChoiceTable from '../../components/multiple-choice-table';
const $ = window.$;
$(() => {
new MultipleChoiceTable();
});

View File

@@ -0,0 +1,53 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
class CatalogModeOptionHandler {
constructor(pageMap) {
this.pageMap = Object.assign({
catalogModeField: 'input[name="form[general][catalog_mode]"]',
selectedCatalogModeField: 'input[name="form[general][catalog_mode]"]:checked',
catalogModeOptions: '.catalog-mode-option'
}, pageMap);
this.handle(0);
$(this.pageMap.catalogModeField).on('change', () => this.handle(600));
}
handle(fadeLength) {
const catalogModeVal = $(this.pageMap.selectedCatalogModeField).val();
const catalogModeEnabled = parseInt(catalogModeVal);
let catalogOptions = $(this.pageMap.catalogModeOptions);
if (catalogModeEnabled) {
catalogOptions.show(fadeLength);
} else {
catalogOptions.hide(fadeLength / 2);
}
}
}
export default CatalogModeOptionHandler;

View File

@@ -0,0 +1,37 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 TranslatableInput from '../../components/translatable-input';
import StockManagementOptionHandler from './stock-management-option-handler';
import CatalogModeOptionHandler from './catalog-mode-option-handler';
import * as pageMap from './product-preferences-page-map';
const $ = window.$;
$(() => {
new TranslatableInput();
new StockManagementOptionHandler();
new CatalogModeOptionHandler(pageMap);
});

View File

@@ -0,0 +1,30 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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
*/
export default {
catalogModeField: 'input[name="form[general][catalog_mode]"]',
selectedCatalogModeField: 'input[name="form[general][catalog_mode]"]:checked',
catalogModeOptions: '.catalog-mode-option'
};

View File

@@ -0,0 +1,80 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
class StockManagementOptionHandler {
constructor() {
this.handle();
$('input[name="form[stock][stock_management]"]').on('change', () => this.handle());
}
handle() {
const stockManagementVal = $('input[name="form[stock][stock_management]"]:checked').val();
const isStockManagementEnabled = parseInt(stockManagementVal);
this.handleAllowOrderingOutOfStockOption(isStockManagementEnabled);
this.handleDisplayAvailableQuantitiesOption(isStockManagementEnabled);
}
/**
* If stock managament is disabled
* then 'Allow ordering of out-of-stock products' option must be Yes and disabled
* otherwise it should be enabled
*
* @param {int} isStockManagementEnabled
*/
handleAllowOrderingOutOfStockOption(isStockManagementEnabled) {
const allowOrderingOosRadios = $('input[name="form[stock][allow_ordering_oos]"]');
if (isStockManagementEnabled) {
allowOrderingOosRadios.removeAttr('disabled');
} else {
allowOrderingOosRadios.val([1]);
allowOrderingOosRadios.attr('disabled', 'disabled');
}
}
/**
* If stock managament is disabled
* then 'Display available quantities on the product page' option must be No and disabled
* otherwise it should be enabled
*
* @param {int} isStockManagementEnabled
*/
handleDisplayAvailableQuantitiesOption(isStockManagementEnabled) {
const displayQuantitiesRadio = $('input[name="form[page][display_quantities]"]');
if (isStockManagementEnabled) {
displayQuantitiesRadio.removeAttr('disabled');
} else {
displayQuantitiesRadio.val([0]);
displayQuantitiesRadio.attr('disabled', 'disabled');
}
}
}
export default StockManagementOptionHandler;

View File

@@ -0,0 +1,57 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from "../../components/grid/extension/reload-list-extension";
import ExportToSqlManagerExtension from "../../components/grid/extension/export-to-sql-manager-extension";
import FiltersResetExtension from "../../components/grid/extension/filters-reset-extension";
import SortingExtension from "../../components/grid/extension/sorting-extension";
import LinkRowActionExtension from "../../components/grid/extension/link-row-action-extension";
import SubmitGridExtension from "../../components/grid/extension/submit-grid-action-extension";
import SubmitBulkExtension from "../../components/grid/extension/submit-bulk-action-extension";
import BulkActionCheckboxExtension from "../../components/grid/extension/bulk-action-checkbox-extension";
import SubmitRowActionExtension from "../../components/grid/extension/action/row/submit-row-action-extension";
import TranslatableInput from "../../components/translatable-input";
/**
* Responsible for actions in Profiles listing page.
*/
export default class ProfilesPage {
constructor() {
const profilesGrid = new Grid('profile');
profilesGrid.addExtension(new ReloadListActionExtension());
profilesGrid.addExtension(new ExportToSqlManagerExtension());
profilesGrid.addExtension(new FiltersResetExtension());
profilesGrid.addExtension(new SortingExtension());
profilesGrid.addExtension(new LinkRowActionExtension());
profilesGrid.addExtension(new SubmitGridExtension());
profilesGrid.addExtension(new SubmitBulkExtension());
profilesGrid.addExtension(new BulkActionCheckboxExtension());
profilesGrid.addExtension(new SubmitRowActionExtension());
new TranslatableInput();
}
}

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ProfilesPage from "./ProfilesPage";
const $ = window.$;
$(() => {
new ProfilesPage;
});

View File

@@ -0,0 +1,127 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import SubmitGridExtension from '../../components/grid/extension/submit-grid-action-extension';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
class SqlManagerPage {
constructor() {
const requestSqlGrid = new Grid('sql_request');
requestSqlGrid.addExtension(new ReloadListActionExtension());
requestSqlGrid.addExtension(new ExportToSqlManagerExtension());
requestSqlGrid.addExtension(new FiltersResetExtension());
requestSqlGrid.addExtension(new SortingExtension());
requestSqlGrid.addExtension(new LinkRowActionExtension());
requestSqlGrid.addExtension(new SubmitGridExtension());
requestSqlGrid.addExtension(new SubmitBulkExtension());
requestSqlGrid.addExtension(new BulkActionCheckboxExtension());
$(document).on('change', '.js-db-tables-select', () => this.reloadDbTableColumns());
$(document).on('click', '.js-add-db-table-to-query-btn', (event) => this.addDbTableToQuery(event));
$(document).on('click', '.js-add-db-table-column-to-query-btn', (event) => this.addDbTableColumnToQuery(event));
}
/**
* Reload database table columns
*/
reloadDbTableColumns() {
const $selectedOption = $('.js-db-tables-select').find('option:selected');
const $table = $('.js-table-columns');
$.ajax($selectedOption.data('table-columns-url'))
.then((response) => {
$('.js-table-alert').addClass('d-none');
const columns = response.columns;
$table.removeClass('d-none');
$table.find('tbody').empty();
columns.forEach((column) => {
const $row = $('<tr>')
.append($('<td>').html(column.name))
.append($('<td>').html(column.type))
.append($('<td>').addClass('text-right')
.append($('<button>')
.addClass('btn btn-sm btn-outline-secondary js-add-db-table-column-to-query-btn')
.attr('data-column', column.name)
.html($table.data('action-btn'))
)
);
$table.find('tbody').append($row);
});
});
}
/**
* Add selected database table name to SQL query input
*
* @param event
*/
addDbTableToQuery(event) {
const $selectedOption = $('.js-db-tables-select').find('option:selected');
if ($selectedOption.length === 0) {
alert($(event.target).data('choose-table-message'));
return;
}
this.addToQuery($selectedOption.val());
}
/**
* Add table column to SQL query input
*
* @param event
*/
addDbTableColumnToQuery(event) {
this.addToQuery($(event.target).data('column'));
}
/**
* Add data to SQL query input
*
* @param {String} data
*/
addToQuery(data) {
const $queryInput = $('#sql_request_sql');
$queryInput.val($queryInput.val() + ' ' + data);
}
}
$(document).ready(() => {
new SqlManagerPage();
});

View File

@@ -0,0 +1,52 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from "../../components/grid/grid";
import SortingExtension from "../../components/grid/extension/sorting-extension";
import FiltersResetExtension from "../../components/grid/extension/filters-reset-extension";
import SubmitGridActionExtension from "../../components/grid/extension/submit-grid-action-extension";
import ColumnTogglingExtension from "../../components/grid/extension/column-toggling-extension";
import SubmitRowActionExtension from "../../components/grid/extension/action/row/submit-row-action-extension";
import BulkActionCheckboxExtension from "../../components/grid/extension/bulk-action-checkbox-extension";
import SubmitBulkActionExtension from "../../components/grid/extension/submit-bulk-action-extension";
import ReloadListExtension from "../../components/grid/extension/reload-list-extension";
import ExportToSqlManagerExtension from "../../components/grid/extension/export-to-sql-manager-extension";
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
$(() => {
const supplierGrid = new Grid('supplier');
supplierGrid.addExtension(new SortingExtension());
supplierGrid.addExtension(new SubmitGridActionExtension());
supplierGrid.addExtension(new FiltersResetExtension());
supplierGrid.addExtension(new ColumnTogglingExtension());
supplierGrid.addExtension(new SubmitRowActionExtension());
supplierGrid.addExtension(new BulkActionCheckboxExtension());
supplierGrid.addExtension(new SubmitBulkActionExtension());
supplierGrid.addExtension(new ReloadListExtension());
supplierGrid.addExtension(new ExportToSqlManagerExtension());
supplierGrid.addExtension(new LinkRowActionExtension());
});

View File

@@ -0,0 +1,49 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Responsible for 'display tax in cart' option presentation.
*/
export default class DisplayInCartOptionHandler {
constructor() {
this._handle();
$('.js-enable-tax').on('change', () => this._handle());
}
/**
* If tax is disabled, then display tax in shopping cart option must be disabled.
*
* @private
*/
_handle() {
const enabledVal = $('.js-enable-tax:checked').val();
const isTaxEnabled = parseInt(enabledVal, 10);
$('.js-display-in-cart').prop('disabled', !isTaxEnabled);
}
}

View File

@@ -0,0 +1,55 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from '../../components/grid/grid';
import SortingExtension from '../../components/grid/extension/sorting-extension';
import FiltersResetExtension from '../../components/grid/extension/filters-reset-extension';
import ReloadListActionExtension from '../../components/grid/extension/reload-list-extension';
import ColumnTogglingExtension from '../../components/grid/extension/column-toggling-extension';
import SubmitRowActionExtension from '../../components/grid/extension/action/row/submit-row-action-extension';
import SubmitBulkExtension from '../../components/grid/extension/submit-bulk-action-extension';
import BulkActionCheckboxExtension from '../../components/grid/extension/bulk-action-checkbox-extension';
import ExportToSqlManagerExtension from '../../components/grid/extension/export-to-sql-manager-extension';
import DisplayInCartOptionHandler from './display-in-cart-option-handler';
import TranslatableInput from '../../components/translatable-input';
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
$(() => {
const taxGrid = new Grid('tax');
taxGrid.addExtension(new ExportToSqlManagerExtension());
taxGrid.addExtension(new ReloadListActionExtension());
taxGrid.addExtension(new SortingExtension());
taxGrid.addExtension(new FiltersResetExtension());
taxGrid.addExtension(new ColumnTogglingExtension());
taxGrid.addExtension(new SubmitRowActionExtension());
taxGrid.addExtension(new SubmitBulkExtension());
taxGrid.addExtension(new BulkActionCheckboxExtension());
taxGrid.addExtension(new LinkRowActionExtension());
new DisplayInCartOptionHandler();
new TranslatableInput();
});

View File

@@ -0,0 +1,66 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* This handler displays delete theme modal and handles the submit action.
*/
export default class DeleteThemeHandler {
constructor() {
$(document).on('click', '.js-display-delete-theme-modal', e => this._displayDeleteThemeModal(e));
}
/**
* Displays modal with its own event handling.
*
* @param e
* @private
*/
_displayDeleteThemeModal(e) {
const $modal = $('#delete_theme_modal');
$modal.modal('show');
this._submitForm($modal, e);
}
/**
* Submits form by adding click event listener for modal and calling original form event.
*
* @param $modal
* @param originalButtonEvent
*
* @private
*/
_submitForm($modal, originalButtonEvent) {
const $formButton = $(originalButtonEvent.currentTarget);
$modal.on('click', '.js-submit-delete-theme', () => {
const $form = $formButton.closest('form');
$form.submit();
});
}
}

View File

@@ -0,0 +1,37 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 ResetThemeLayoutsHandler from './reset-theme-layouts-handler';
import UseThemeHandler from './use-theme-handler';
import MultiStoreRestrictionField from '../../components/multi-store-restriction-field/multi-store-restriction-field';
import DeleteThemeHandler from './delete-theme-handler';
const $ = window.$;
$(() => {
new ResetThemeLayoutsHandler();
new MultiStoreRestrictionField();
new UseThemeHandler();
new DeleteThemeHandler();
});

View File

@@ -0,0 +1,58 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Handles "Reset to defaults" action submitting on button click.
*/
export default class ResetThemeLayoutsHandler {
constructor() {
$(document).on('click', '.js-reset-theme-layouts-btn', (e) => this._handleResetting(e));
return {};
}
/**
* @param {Event} event
*
* @private
*/
_handleResetting(event) {
const $btn = $(event.currentTarget);
const $form = $('<form>', {
'action': $btn.data('submit-url'),
'method': 'POST'
}).append($('<input>', {
'name': 'token',
'value': $btn.data('csrf-token'),
'type': 'hidden'
}));
$form.appendTo('body');
$form.submit();
}
}

View File

@@ -0,0 +1,66 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* This handler displays use theme modal and handles the submit form logic.
*/
export default class UseThemeHandler {
constructor() {
$(document).on('click', '.js-display-use-theme-modal', e => this._displayUseThemeModal(e));
}
/**
* Displays modal with its own event handling.
*
* @param e
* @private
*/
_displayUseThemeModal(e) {
const $modal = $('#use_theme_modal');
$modal.modal('show');
this._submitForm($modal, e);
}
/**
* Submits form by adding click event listener for modal and calling original form event.
*
* @param $modal
* @param originalButtonEvent
*
* @private
*/
_submitForm($modal, originalButtonEvent) {
const $formButton = $(originalButtonEvent.currentTarget);
$modal.on('click', '.js-submit-use-theme', () => {
const $form = $formButton.closest('form');
$form.submit();
});
}
}

View File

@@ -0,0 +1,161 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* Back office translations type
*
* @type {string}
*/
const back = 'back';
/**
* Modules translations type
* @type {string}
*/
const themes = 'themes';
/**
* Modules translations type
* @type {string}
*/
const modules = 'modules';
/**
* Mails translations type
* @type {string}
*/
const mails = 'mails';
/**
* Other translations type
* @type {string}
*/
const others = 'others';
/**
* Email body translations type
* @type {string}
*/
const emailContentBody = 'body';
export default class FormFieldToggle {
constructor() {
$('.js-translation-type').on('change', this.toggleFields.bind(this));
$('.js-email-content-type').on('change', this.toggleEmailFields.bind(this));
this.toggleFields();
}
/**
* Toggle dependant translations fields, based on selected translation type
*/
toggleFields() {
let selectedOption = $('.js-translation-type').val();
let $modulesFormGroup = $('.js-module-form-group');
let $emailFormGroup = $('.js-email-form-group');
let $themesFormGroup = $('.js-theme-form-group');
let $themesSelect = $themesFormGroup.find('select');
let $noThemeOption = $themesSelect.find('.js-no-theme');
let $firstThemeOption = $themesSelect.find('option:not(.js-no-theme):first');
switch (selectedOption) {
case back:
case others:
this._hide($modulesFormGroup, $emailFormGroup, $themesFormGroup);
break;
case themes:
if ($noThemeOption.is(':selected')) {
$themesSelect.val($firstThemeOption.val());
}
this._hide($modulesFormGroup, $emailFormGroup, $noThemeOption);
this._show($themesFormGroup);
break;
case modules:
this._hide($emailFormGroup, $themesFormGroup);
this._show($modulesFormGroup);
break;
case mails:
this._hide($modulesFormGroup, $themesFormGroup);
this._show($emailFormGroup);
break;
}
this.toggleEmailFields();
}
/**
* Toggles fields, which are related to email translations
*/
toggleEmailFields() {
if ($('.js-translation-type').val() !== mails) {
return;
}
let selectedEmailContentType = $('.js-email-form-group').find('select').val();
let $themesFormGroup = $('.js-theme-form-group');
let $noThemeOption = $themesFormGroup.find('.js-no-theme');
if (selectedEmailContentType === emailContentBody) {
$noThemeOption.prop('selected', true);
this._show($noThemeOption, $themesFormGroup);
} else {
this._hide($noThemeOption, $themesFormGroup);
}
}
/**
* Make all given selectors hidden
*
* @param $selectors
* @private
*/
_hide(...$selectors) {
for (let key in $selectors) {
$selectors[key].addClass('d-none');
$selectors[key].find('select').prop('disabled', 'disabled');
}
}
/**
* Make all given selectors visible
*
* @param $selectors
* @private
*/
_show(...$selectors) {
for (let key in $selectors) {
$selectors[key].removeClass('d-none');
$selectors[key].find('select').prop('disabled', false);
}
}
}

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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";
export default class TranslationSettingsPage {
constructor() {
new FormFieldToggle();
}
}

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 TranslationSettingsPage from './TranslationSettingsPage';
const $ = window.$;
$(() => {
new TranslationSettingsPage();
});

View File

@@ -0,0 +1,67 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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 Grid from "../../components/grid/grid";
import FiltersResetExtension from "../../components/grid/extension/filters-reset-extension";
import ReloadListActionExtension from "../../components/grid/extension/reload-list-extension";
import ExportToSqlManagerExtension from "../../components/grid/extension/export-to-sql-manager-extension";
import BulkActionCheckboxExtension from "../../components/grid/extension/bulk-action-checkbox-extension";
import SubmitBulkActionExtension from "../../components/grid/extension/submit-bulk-action-extension";
import SortingExtension from "../../components/grid/extension/sorting-extension";
import SubmitRowActionExtension from "../../components/grid/extension/action/row/submit-row-action-extension";
import ColumnTogglingExtension from "../../components/grid/extension/column-toggling-extension";
import ChoiceTree from "../../components/form/choice-tree";
import GeneratableInput from "../../components/generatable-input";
import MultipleChoiceTable from "../../components/multiple-choice-table";
import PermissionsRowSelector from "./permissions-row-selector";
import LinkRowActionExtension from '../../components/grid/extension/link-row-action-extension';
const $ = window.$;
$(() => {
const webserviceGrid = new Grid('webservice_key');
webserviceGrid.addExtension(new ReloadListActionExtension());
webserviceGrid.addExtension(new ExportToSqlManagerExtension());
webserviceGrid.addExtension(new FiltersResetExtension());
webserviceGrid.addExtension(new ColumnTogglingExtension());
webserviceGrid.addExtension(new SortingExtension());
webserviceGrid.addExtension(new SubmitBulkActionExtension());
webserviceGrid.addExtension(new SubmitRowActionExtension());
webserviceGrid.addExtension(new BulkActionCheckboxExtension());
webserviceGrid.addExtension(new LinkRowActionExtension());
// needed for shop association input in form
new ChoiceTree('#webservice_key_shop_association').enableAutoCheckChildren();
// needed for permissions input in form
new MultipleChoiceTable();
// needed for key input in form
const generatableInput = new GeneratableInput();
generatableInput.attachOn('.js-generator-btn');
new PermissionsRowSelector();
});

View File

@@ -0,0 +1,49 @@
/**
* 2007-2019 PrestaShop and Contributors
*
* 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 https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 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.$;
/**
* In Add/Edit page of Webservice key there is permissions table input (permissons as columns / resources as rows).
* There is "All" column and once resource is checked under this column
* every other permission column should be auto-selected for that resource.
*/
export default class PermissionsRowSelector {
constructor() {
// when checkbox in "All" column is checked
$('input[id^="webservice_key_permissions_all"]').on('change', (event) => {
const $checkedBox = $(event.currentTarget);
const isChecked = $checkedBox.is(':checked');
// for each input in same row we need to toggle its value
$checkedBox.closest('tr').find(`input:not(input[id="${$checkedBox.attr('id')}"])`).each((i, input) => {
$(input).prop('checked', isChecked);
});
});
return {};
}
}