first commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
const {$} = window;
|
||||
|
||||
/**
|
||||
* This 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) {
|
||||
window.showErrorMessage(response.message);
|
||||
this.changeTextByCurrentSwitchValue($liveExchangeRatesSwitch.val());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
window.showSuccessMessage(response.message);
|
||||
this.changeTextByCurrentSwitchValue($liveExchangeRatesSwitch.val());
|
||||
},
|
||||
).fail((response) => {
|
||||
if (typeof response.responseJSON !== 'undefined') {
|
||||
window.showErrorMessage(response.responseJSON.message);
|
||||
this.changeTextByCurrentSwitchValue($liveExchangeRatesSwitch.val());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
changeTextByCurrentSwitchValue(switchValue) {
|
||||
const valueParsed = parseInt(switchValue, 10);
|
||||
$('.js-exchange-rate-text-when-disabled').toggleClass('d-none', valueParsed !== 0);
|
||||
$('.js-exchange-rate-text-when-enabled').toggleClass('d-none', valueParsed !== 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<!--**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*-->
|
||||
<template>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<h4>{{ $t('step.symbol') }}</h4>
|
||||
<input
|
||||
type="text"
|
||||
v-model="customSymbol"
|
||||
>
|
||||
</div>
|
||||
<div class="col-8 border-left">
|
||||
<h4>{{ $t('step.format') }}</h4>
|
||||
<div class="row">
|
||||
<div
|
||||
class="ps-radio col-6"
|
||||
v-for="(pattern, transformation) in availableFormats"
|
||||
:key="transformation"
|
||||
:id="transformation"
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
:checked="transformation === customTransformation"
|
||||
:value="transformation"
|
||||
>
|
||||
<label @click.prevent.stop="customTransformation = transformation">
|
||||
{{ displayPattern(pattern) }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {NumberFormatter} from '@app/cldr';
|
||||
|
||||
export default {
|
||||
name: 'CurrencyFormatForm',
|
||||
data: () => ({
|
||||
value: {
|
||||
symbol: '',
|
||||
transformation: '',
|
||||
},
|
||||
}),
|
||||
props: {
|
||||
language: {
|
||||
type: Object,
|
||||
required: true,
|
||||
default: () => {},
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
availableFormats() {
|
||||
return this.language.transformations;
|
||||
},
|
||||
customSymbol: {
|
||||
get() {
|
||||
return this.value.symbol;
|
||||
},
|
||||
set(symbol) {
|
||||
this.value.symbol = symbol;
|
||||
this.$emit('input', this.value);
|
||||
},
|
||||
},
|
||||
customTransformation: {
|
||||
get() {
|
||||
return this.value.transformation;
|
||||
},
|
||||
set(transformation) {
|
||||
this.value.transformation = transformation;
|
||||
this.$emit('input', this.value);
|
||||
},
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
displayPattern(pattern) {
|
||||
const patterns = pattern.split(';');
|
||||
const priceSpecification = {...this.language.priceSpecification};
|
||||
priceSpecification.positivePattern = patterns[0];
|
||||
priceSpecification.negativePattern = patterns.length > 1 ? patterns[1] : `-${pattern}`;
|
||||
priceSpecification.currencySymbol = this.customSymbol;
|
||||
|
||||
const currencyFormatter = NumberFormatter.build(priceSpecification);
|
||||
|
||||
return currencyFormatter.format(14251999.42);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.customSymbol = this.language.priceSpecification.currencySymbol;
|
||||
const currencyPattern = this.language.priceSpecification.positivePattern;
|
||||
|
||||
// Detect which transformation matches the language pattern
|
||||
/* eslint-disable-next-line no-restricted-syntax,guard-for-in */
|
||||
for (const transformation in this.language.transformations) {
|
||||
const transformationPatterns = this.language.transformations[transformation].split(';');
|
||||
|
||||
if (transformationPatterns[0] === currencyPattern) {
|
||||
this.customTransformation = transformation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,112 @@
|
||||
<!--**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*-->
|
||||
<template>
|
||||
<div
|
||||
:id="id"
|
||||
class="card-block row"
|
||||
>
|
||||
<div class="col-sm">
|
||||
<language-list
|
||||
v-if="languagesCount"
|
||||
:languages="languages"
|
||||
@selectLanguage="selectLanguage"
|
||||
@resetLanguage="resetLanguage"
|
||||
/>
|
||||
|
||||
<currency-modal
|
||||
:language="selectedLanguage"
|
||||
@close="closeModal"
|
||||
@applyCustomization="applyCustomization"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {showGrowl} from '@app/utils/growl';
|
||||
import LanguageList from './LanguageList';
|
||||
import CurrencyModal from './CurrencyModal';
|
||||
|
||||
export default {
|
||||
name: 'CurrencyFormatter',
|
||||
data: () => ({selectedLanguage: null}),
|
||||
props: {
|
||||
id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
languages: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
currencyData: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
components: {LanguageList, CurrencyModal},
|
||||
computed: {
|
||||
languagesCount() {
|
||||
return this.languages.length;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
closeModal() {
|
||||
this.selectedLanguage = null;
|
||||
},
|
||||
selectLanguage(language) {
|
||||
this.selectedLanguage = language;
|
||||
},
|
||||
resetLanguage(language) {
|
||||
const patterns = language.currencyPattern.split(';');
|
||||
language.priceSpecification.positivePattern = patterns[0];
|
||||
language.priceSpecification.negativePattern = patterns.length > 1 ? patterns[1] : `-${patterns[0]}`;
|
||||
language.priceSpecification.currencySymbol = language.currencySymbol;
|
||||
|
||||
this.currencyData.transformations[language.id] = '';
|
||||
this.currencyData.symbols[language.id] = language.currencySymbol;
|
||||
|
||||
showGrowl('success', this.$t('list.reset.success'));
|
||||
},
|
||||
applyCustomization(customData) {
|
||||
const selectedPattern = this.selectedLanguage.transformations[
|
||||
customData.transformation
|
||||
];
|
||||
const patterns = selectedPattern.split(';');
|
||||
|
||||
this.selectedLanguage.priceSpecification.currencySymbol = customData.symbol;
|
||||
this.selectedLanguage.priceSpecification.positivePattern = patterns[0];
|
||||
// eslint-disable-next-line
|
||||
this.selectedLanguage.priceSpecification.negativePattern =
|
||||
patterns.length > 1 ? patterns[1] : `-${patterns[0]}`;
|
||||
|
||||
this.currencyData.transformations[this.selectedLanguage.id] = customData.transformation;
|
||||
this.currencyData.symbols[this.selectedLanguage.id] = customData.symbol;
|
||||
|
||||
this.closeModal();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,81 @@
|
||||
<!--**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*-->
|
||||
<template>
|
||||
<modal
|
||||
confirmation
|
||||
:modal-title="modalTitle"
|
||||
@close="$emit('close')"
|
||||
@confirm="$emit('applyCustomization', customData)"
|
||||
v-if="language !== null"
|
||||
>
|
||||
<template slot="body">
|
||||
<currency-format-form
|
||||
:language="language"
|
||||
@input="customData = $event"
|
||||
/>
|
||||
</template>
|
||||
</modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Modal from '@vue/components/Modal';
|
||||
import CurrencyFormatForm from './CurrencyFormatForm';
|
||||
|
||||
export default {
|
||||
name: 'CurrencyModal',
|
||||
data: () => ({
|
||||
customData: null,
|
||||
}),
|
||||
components: {
|
||||
CurrencyFormatForm,
|
||||
Modal,
|
||||
},
|
||||
props: {
|
||||
language: {
|
||||
type: Object,
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
modalTitle() {
|
||||
return this.$t('modal.title') + (this.language !== null ? ` + ${this.language.name}` : '');
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import '~@scss/config/_settings.scss';
|
||||
|
||||
.modal-header .close {
|
||||
font-size: 1.2rem;
|
||||
color: $gray-medium;
|
||||
opacity: 1;
|
||||
}
|
||||
.modal-content {
|
||||
border-radius: 0
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,111 @@
|
||||
<!--**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*-->
|
||||
<template>
|
||||
<table class="grid-table js-grid-table table">
|
||||
<thead class="thead-default">
|
||||
<tr class="column-headers">
|
||||
<th scope="col">
|
||||
{{ $t('list.language') }}
|
||||
</th>
|
||||
<th scope="col">
|
||||
{{ $t('list.example') }}
|
||||
</th>
|
||||
<th scope="col">
|
||||
<div class="text-right">
|
||||
{{ $t('list.edit') }}
|
||||
</div>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<div class="grid-actions-header-text">
|
||||
{{ $t('list.reset') }}
|
||||
</div>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="language in languages"
|
||||
:key="language.id"
|
||||
>
|
||||
<td>
|
||||
{{ language.name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ displayFormat(language) }}
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group-action text-right">
|
||||
<div class="btn-group">
|
||||
<button
|
||||
type="button"
|
||||
class="btn"
|
||||
@click.prevent.stop="$emit('selectLanguage', language)"
|
||||
>
|
||||
<i class="material-icons">edit</i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="btn-group-action text-right">
|
||||
<div class="btn-group">
|
||||
<button
|
||||
type="button"
|
||||
class="btn"
|
||||
@click.prevent.stop="$emit('resetLanguage', language)"
|
||||
>
|
||||
<i class="material-icons">refresh</i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {NumberFormatter} from '@app/cldr';
|
||||
|
||||
export default {
|
||||
name: 'LanguageList',
|
||||
props: {
|
||||
languages: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
displayFormat(language) {
|
||||
const currencyFormatter = NumberFormatter.build(language.priceSpecification);
|
||||
|
||||
return this.$t('list.example.format', {
|
||||
'%price%': currencyFormatter.format(14251999.42),
|
||||
'%discount%': currencyFormatter.format(-566.268),
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Defines all selectors that are used in currency add/edit form.
|
||||
*/
|
||||
export default {
|
||||
currencyForm: '#currency_form',
|
||||
currencyFormFooter: '#currency_form .card .card-footer',
|
||||
currencySelector: '#currency_selected_iso_code',
|
||||
isUnofficialCheckbox: '#currency_unofficial',
|
||||
namesInput: (langId) => `#currency_names_${langId}`,
|
||||
symbolsInput: (langId) => `#currency_symbols_${langId}`,
|
||||
transformationsInput: (langId) => `#currency_transformations_${langId}`,
|
||||
isoCodeInput: '#currency_iso_code',
|
||||
exchangeRateInput: '#currency_exchange_rate',
|
||||
resetDefaultSettingsInput: '#currency_reset_default_settings',
|
||||
loadingDataModal: '#currency_loading_data_modal',
|
||||
precisionInput: '#currency_precision',
|
||||
shopAssociationTree: '#currency_shop_association',
|
||||
currencyFormatter: '#currency_formatter',
|
||||
};
|
||||
@@ -0,0 +1,270 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
import Vue from 'vue';
|
||||
import VueI18n from 'vue-i18n';
|
||||
import VueResource from 'vue-resource';
|
||||
import {showGrowl} from '@app/utils/growl';
|
||||
import ConfirmModal from '@components/modal';
|
||||
import ReplaceFormatter from '@vue/plugins/vue-i18n/replace-formatter';
|
||||
import CurrencyFormatter from './components/CurrencyFormatter.vue';
|
||||
|
||||
Vue.use(VueResource);
|
||||
Vue.use(VueI18n);
|
||||
|
||||
export default class CurrencyForm {
|
||||
/**
|
||||
* @param {object} currencyFormMap - Page map
|
||||
*/
|
||||
constructor(currencyFormMap) {
|
||||
this.map = currencyFormMap;
|
||||
this.$currencyForm = $(this.map.currencyForm);
|
||||
this.$currencyFormFooter = $(this.map.currencyFormFooter);
|
||||
this.apiReferenceUrl = this.$currencyForm.data('reference-url');
|
||||
this.referenceCurrencyResource = Vue.resource(this.apiReferenceUrl);
|
||||
this.originalLanguages = this.$currencyForm.data('languages');
|
||||
this.translations = this.$currencyForm.data('translations');
|
||||
this.$currencySelector = $(this.map.currencySelector);
|
||||
this.$isUnofficialCheckbox = $(this.map.isUnofficialCheckbox);
|
||||
this.$isoCodeInput = $(this.map.isoCodeInput);
|
||||
this.$exchangeRateInput = $(this.map.exchangeRateInput);
|
||||
this.$precisionInput = $(this.map.precisionInput);
|
||||
this.$resetDefaultSettingsButton = $(this.map.resetDefaultSettingsInput);
|
||||
this.$loadingDataModal = $(this.map.loadingDataModal);
|
||||
this.currencyFormatterId = this.map.currencyFormatter.replace('#', '');
|
||||
this.hideModal = true;
|
||||
this.$loadingDataModal.on('shown.bs.modal', () => {
|
||||
if (this.hideModal) {
|
||||
this.$loadingDataModal.modal('hide');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init() {
|
||||
this.initListeners();
|
||||
this.initFields();
|
||||
this.initState();
|
||||
this.initCurrencyFormatter();
|
||||
}
|
||||
|
||||
initState() {
|
||||
this.state = {
|
||||
currencyData: this.getCurrencyDataFromForm(),
|
||||
languages: [...this.originalLanguages],
|
||||
};
|
||||
}
|
||||
|
||||
initCurrencyFormatter() {
|
||||
// Customizer only present when languages data are present (for installed currencies only)
|
||||
if (!this.originalLanguages.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
const i18n = new VueI18n({
|
||||
locale: 'en',
|
||||
formatter: new ReplaceFormatter(),
|
||||
messages: {en: this.translations},
|
||||
});
|
||||
|
||||
$(`<div id="${this.currencyFormatterId}"></div>`).insertBefore(this.$currencyFormFooter);
|
||||
this.currencyFormatter = new Vue({
|
||||
el: this.map.currencyFormatter,
|
||||
i18n,
|
||||
components: {CurrencyFormatter},
|
||||
data: this.state,
|
||||
template: `<currency-formatter
|
||||
id="${this.currencyFormatterId}"
|
||||
:languages="languages"
|
||||
:currencyData="currencyData">
|
||||
</currency-formatter>`,
|
||||
});
|
||||
|
||||
this.currencyFormatter.$watch('currencyData', () => {
|
||||
// We use the state value directly since the object is shared with the Vue component and already updated
|
||||
this.fillCurrencyCustomData(this.state.currencyData);
|
||||
}, {deep: true, immediate: true});
|
||||
}
|
||||
|
||||
initListeners() {
|
||||
this.$currencySelector.change(this.onCurrencySelectorChange.bind(this));
|
||||
this.$isUnofficialCheckbox.change(this.onIsUnofficialCheckboxChange.bind(this));
|
||||
this.$resetDefaultSettingsButton.click(this.onResetDefaultSettingsClick.bind(this));
|
||||
}
|
||||
|
||||
initFields() {
|
||||
if (!this.isUnofficialCurrency()) {
|
||||
this.$isUnofficialCheckbox.prop('checked', false);
|
||||
this.$isoCodeInput.prop('readonly', true);
|
||||
} else {
|
||||
this.$currencySelector.val('');
|
||||
this.$isoCodeInput.prop('readonly', false);
|
||||
}
|
||||
}
|
||||
|
||||
onCurrencySelectorChange() {
|
||||
const selectedISOCode = this.$currencySelector.val();
|
||||
|
||||
if (selectedISOCode !== '') {
|
||||
this.$isUnofficialCheckbox.prop('checked', false);
|
||||
this.$isoCodeInput.prop('readonly', true);
|
||||
this.resetCurrencyData(selectedISOCode);
|
||||
} else {
|
||||
this.$isUnofficialCheckbox.prop('checked', true);
|
||||
this.$isoCodeInput.prop('readonly', false);
|
||||
}
|
||||
}
|
||||
|
||||
isUnofficialCurrency() {
|
||||
if (this.$isUnofficialCheckbox.prop('type') === 'hidden') {
|
||||
return this.$isUnofficialCheckbox.attr('value') === '1';
|
||||
}
|
||||
|
||||
return this.$isUnofficialCheckbox.prop('checked');
|
||||
}
|
||||
|
||||
onIsUnofficialCheckboxChange() {
|
||||
if (this.isUnofficialCurrency()) {
|
||||
this.$currencySelector.val('');
|
||||
this.$isoCodeInput.prop('readonly', false);
|
||||
} else {
|
||||
this.$isoCodeInput.prop('readonly', true);
|
||||
}
|
||||
}
|
||||
|
||||
async onResetDefaultSettingsClick() {
|
||||
await this.resetCurrencyData(this.$isoCodeInput.val());
|
||||
}
|
||||
|
||||
showResetDefaultSettingsConfirmModal() {
|
||||
const confirmTitle = this.translations['modal.restore.title'];
|
||||
const confirmMessage = this.translations['modal.restore.body'];
|
||||
const confirmButtonLabel = this.translations['modal.restore.apply'];
|
||||
const closeButtonLabel = this.translations['modal.restore.cancel'];
|
||||
|
||||
const modal = new ConfirmModal({
|
||||
id: 'currency_restore_default_settings',
|
||||
confirmTitle,
|
||||
confirmMessage,
|
||||
confirmButtonLabel,
|
||||
closeButtonLabel,
|
||||
}, () => this.onResetDefaultSettingsClick());
|
||||
|
||||
modal.show();
|
||||
}
|
||||
|
||||
async resetCurrencyData(selectedISOCode) {
|
||||
this.$loadingDataModal.modal('show');
|
||||
this.$resetDefaultSettingsButton.addClass('spinner');
|
||||
|
||||
this.state.currencyData = await this.fetchCurrency(selectedISOCode);
|
||||
this.fillCurrencyData(this.state.currencyData);
|
||||
|
||||
// Reset languages
|
||||
this.originalLanguages.forEach((language) => {
|
||||
// Use language data (which contain the reference) to reset
|
||||
// price specification data (which contain the custom values)
|
||||
const patterns = language.currencyPattern.split(';');
|
||||
language.priceSpecification.positivePattern = patterns[0];
|
||||
language.priceSpecification.negativePattern = patterns.length > 1 ? patterns[1] : `-${patterns[0]}`;
|
||||
language.priceSpecification.currencySymbol = language.currencySymbol;
|
||||
});
|
||||
this.state.languages = [...this.originalLanguages];
|
||||
|
||||
this.hideModal = true;
|
||||
this.$loadingDataModal.modal('hide');
|
||||
this.$resetDefaultSettingsButton.removeClass('spinner');
|
||||
}
|
||||
|
||||
async fetchCurrency(currencyIsoCode) {
|
||||
let currencyData = null;
|
||||
|
||||
if (currencyIsoCode) {
|
||||
await this.referenceCurrencyResource.get({id: currencyIsoCode}).then((response) => {
|
||||
currencyData = response.body;
|
||||
}, (errorResponse) => {
|
||||
if (errorResponse.body && errorResponse.body.error) {
|
||||
showGrowl('error', errorResponse.body.error, 3000);
|
||||
} else {
|
||||
showGrowl('error', `Can not find CLDR data for currency ${currencyIsoCode}`, 3000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (currencyData && currencyData.transformations === undefined) {
|
||||
currencyData.transformations = {};
|
||||
Object.keys(currencyData.symbols).forEach((langId) => {
|
||||
currencyData.transformations[langId] = '';
|
||||
});
|
||||
}
|
||||
|
||||
return currencyData;
|
||||
}
|
||||
|
||||
fillCurrencyData(currencyData) {
|
||||
if (!currencyData) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.keys(currencyData.symbols).forEach((langId) => {
|
||||
const langNameSelector = this.map.namesInput(langId);
|
||||
$(langNameSelector).val(currencyData.names[langId]);
|
||||
});
|
||||
|
||||
this.fillCurrencyCustomData(currencyData);
|
||||
this.$isoCodeInput.val(currencyData.isoCode);
|
||||
this.$exchangeRateInput.val(currencyData.exchangeRate);
|
||||
this.$precisionInput.val(currencyData.precision);
|
||||
}
|
||||
|
||||
fillCurrencyCustomData(currencyData) {
|
||||
Object.keys(currencyData.symbols).forEach((langId) => {
|
||||
const langSymbolSelector = this.map.symbolsInput(langId);
|
||||
$(langSymbolSelector).val(currencyData.symbols[langId]);
|
||||
});
|
||||
|
||||
Object.keys(currencyData.transformations).forEach((langId) => {
|
||||
const langTransformationSelector = this.map.transformationsInput(langId);
|
||||
$(langTransformationSelector).val(currencyData.transformations[langId]);
|
||||
});
|
||||
}
|
||||
|
||||
getCurrencyDataFromForm() {
|
||||
const currencyData = {
|
||||
names: {},
|
||||
symbols: {},
|
||||
transformations: {},
|
||||
isoCode: this.$isoCodeInput.val(),
|
||||
exchangeRate: this.$exchangeRateInput.val(),
|
||||
precision: this.$precisionInput.val(),
|
||||
};
|
||||
|
||||
this.originalLanguages.forEach((lang) => {
|
||||
currencyData.names[lang.id] = $(this.map.namesInput(lang.id)).val();
|
||||
currencyData.symbols[lang.id] = $(this.map.symbolsInput(lang.id)).val();
|
||||
currencyData.transformations[lang.id] = $(this.map.transformationsInput(lang.id)).val();
|
||||
});
|
||||
|
||||
return currencyData;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
import currencyFormMap from './currency-form-map';
|
||||
import CurrencyForm from './currency-form';
|
||||
|
||||
const {$} = window;
|
||||
|
||||
$(() => {
|
||||
window.prestashop.component.initComponents(
|
||||
[
|
||||
'TranslatableInput',
|
||||
],
|
||||
);
|
||||
const choiceTree = new window.prestashop.component.ChoiceTree(currencyFormMap.shopAssociationTree);
|
||||
choiceTree.enableAutoCheckChildren();
|
||||
const currencyForm = new CurrencyForm(currencyFormMap);
|
||||
currencyForm.init();
|
||||
});
|
||||
56
admin-kalsport/themes/new-theme/js/pages/currency/index.js
Normal file
56
admin-kalsport/themes/new-theme/js/pages/currency/index.js
Normal file
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
import 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 ExportToSqlManagerExtension from '@components/grid/extension/export-to-sql-manager-extension';
|
||||
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 ExchangeRatesUpdateScheduler from '@pages/currency/ExchangeRatesUpdateScheduler';
|
||||
import FiltersSubmitButtonEnablerExtension from '@components/grid/extension/filters-submit-button-enabler-extension';
|
||||
import LinkRowActionExtension from '@components/grid/extension/link-row-action-extension';
|
||||
|
||||
const {$} = window;
|
||||
|
||||
$(() => {
|
||||
const currency = new Grid('currency');
|
||||
|
||||
currency.addExtension(new BulkActionCheckboxExtension());
|
||||
currency.addExtension(new SubmitBulkExtension());
|
||||
currency.addExtension(new ExportToSqlManagerExtension());
|
||||
currency.addExtension(new SortingExtension());
|
||||
currency.addExtension(new FiltersResetExtension());
|
||||
currency.addExtension(new ReloadListActionExtension());
|
||||
currency.addExtension(new ColumnTogglingExtension());
|
||||
currency.addExtension(new SubmitRowActionExtension());
|
||||
currency.addExtension(new FiltersSubmitButtonEnablerExtension());
|
||||
currency.addExtension(new LinkRowActionExtension());
|
||||
|
||||
new ExchangeRatesUpdateScheduler();
|
||||
});
|
||||
Reference in New Issue
Block a user