Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
{
"presets": ["env"]
}

View File

@@ -0,0 +1,24 @@
/**
* 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
*/

View File

@@ -0,0 +1,27 @@
/**
* 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
*/
.modal-content {
padding: 1%;
}

View File

@@ -0,0 +1,127 @@
#right-sidebar {
background: white;
float: right;
position: fixed;
display: block;
top: 136px;
bottom: 0px;
z-index: 1000;
overflow: auto;
right: -3em;
padding: 0 3em 0 0;
box-shadow: 0 0 12px rgba(0,0,0,0.8);
}
/*right sidebar is untested */
.sidebar.sidebar-right.sidebar-xs-show {
right: 0;
-webkit-transform: translate(0,0);
-ms-transform: translate(0,0);
-o-transform: translate(0,0);
-moz-transform: translate(0,0);
transform: translate(0,0);
}
@media (min-width: 768px) {
/*right sidebar is untested */
.sidebar.sidebar-right.sidebar-sm-show {
right: 0;
-webkit-transform: translate(0,0);
-ms-transform: translate(0,0);
-o-transform: translate(0,0);
-moz-transform: translate(0,0);
transform: translate(0,0);
}
}
@media (min-width: 992px) {
.sidebar.sidebar-right.sidebar-md-show {
right: 0;
-webkit-transform: translate(0,0);
-ms-transform: translate(0,0);
-o-transform: translate(0,0);
-moz-transform: translate(0,0);
transform: translate(0,0);
}
}
@media (min-width: 1170px) {
.sidebar.sidebar-right.sidebar-lg-show {
right: 0;
-webkit-transform: translate(0,0);
-moz-transform: translate(0,0);
-ms-transform: translate(0,0);
-o-transform: translate(0,0);
transform: translate(0,0);
}
}
/* animation class - optional: without it the sidebar would just pop in and out*/
.sidebar-animate {
-webkit-transition: -webkit-transform 300ms ease;
-moz-transition: -moz-transform 300ms ease;
-o-transition: transform 300ms ease;
transition: transform 300ms ease;
}
.sidebar.sidebar-right {
-webkit-transform: translate(100%,0);
-moz-transform: translate(100%,0);
-ms-transform: translate(100%,0);
-o-transform: translate(100%,0);
transform: translate(100%,0);
}
.sidebar.sidebar-right.sidebar-open {
-webkit-transform: translate(0,0);
-moz-transform: translate(0,0);
-ms-transform: translate(0,0);
-o-transform: translate(0,0);
transform: translate(0,0);
}
#right-sidebar .quicknav-container {
height: 100%;
}
.sidebar.sidebar-right .quicknav-fixed-bottom {
bottom: 0;
margin-bottom: 0;
position: fixed;
left: 0;
right: 3em;
height: 50px;
}
.sidebar.sidebar-right .quicknav-fixed-bottom ul.pagination {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.sidebar.sidebar-right .quicknav-fixed-bottom input {
outline-style: none;
text-align: center;
}
.sidebar.sidebar-right .quicknav-header {
background: #363A41;
color: #fff;
padding: 1.2em;
height: 50px;
}
.sidebar.sidebar-right .quicknav-header h2{
color: #fff;
margin-bottom: 0;
}
.sidebar.sidebar-right .quicknav-scroller {
overflow: auto;
height: calc(100% - 50px - 50px);
}
.sidebar.sidebar-right .quicknav-scroller table {
margin-bottom: 0;
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 50 KiB

View File

@@ -0,0 +1,42 @@
{
"extends": "airbnb-base",
"env": {
"browser": true
},
"plugins": [
"import",
"html"
],
"settings": {
"import/resolver": {
"webpack": {
"config": "../../webpack.config.js"
}
}
},
"rules": {
"import/extensions": [
"error",
"always",
{
"js": "never",
"vue": "never"
}
],
"no-param-reassign": [
"error",
{
"props": false
}
],
"no-underscore-dangle": "off",
"no-trailing-spaces": [
"error",
{
"skipBlankLines": true
}
],
"class-methods-use-this": "off",
"no-unused-vars": "warn"
}
}

View File

@@ -0,0 +1,32 @@
/**
* 2007-2019 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class LocalizationException {
constructor(message) {
this.message = message;
this.name = 'LocalizationException';
}
}
export default LocalizationException;

View File

@@ -0,0 +1,35 @@
/**
* 2007-2019 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
import NumberFormatter from './number-formatter';
import NumberSymbol from './number-symbol';
import PriceSpecification from './specifications/price';
import NumberSpecification from './specifications/number';
export {
PriceSpecification,
NumberSpecification,
NumberFormatter,
NumberSymbol,
};

View File

@@ -0,0 +1,319 @@
/**
* 2007-2019 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* These placeholders are used in CLDR number formatting templates.
* They are meant to be replaced by the correct localized symbols in the number formatting process.
*/
import NumberSymbol from './number-symbol';
import PriceSpecification from './specifications/price';
import NumberSpecification from './specifications/number';
const escapeRE = require('lodash.escaperegexp');
const CURRENCY_SYMBOL_PLACEHOLDER = '¤';
const DECIMAL_SEPARATOR_PLACEHOLDER = '.';
const GROUP_SEPARATOR_PLACEHOLDER = ',';
const MINUS_SIGN_PLACEHOLDER = '-';
const PERCENT_SYMBOL_PLACEHOLDER = '%';
const PLUS_SIGN_PLACEHOLDER = '+';
class NumberFormatter {
/**
* @param NumberSpecification specification Number specification to be used
* (can be a number spec, a price spec, a percentage spec)
*/
constructor(specification) {
this.numberSpecification = specification;
}
/**
* Formats the passed number according to specifications.
*
* @param int|float|string number The number to format
* @param NumberSpecification specification Number specification to be used
* (can be a number spec, a price spec, a percentage spec)
*
* @return string The formatted number
* You should use this this value for display, without modifying it
*/
format(number, specification) {
if (specification !== undefined) {
this.numberSpecification = specification;
}
/*
* We need to work on the absolute value first.
* Then the CLDR pattern will add the sign if relevant (at the end).
*/
const num = Math.abs(number).toFixed(this.numberSpecification.getMaxFractionDigits());
let [majorDigits, minorDigits] = this.extractMajorMinorDigits(num);
majorDigits = this.splitMajorGroups(majorDigits);
minorDigits = this.adjustMinorDigitsZeroes(minorDigits);
// Assemble the final number
let formattedNumber = majorDigits;
if (minorDigits) {
formattedNumber += DECIMAL_SEPARATOR_PLACEHOLDER + minorDigits;
}
// Get the good CLDR formatting pattern. Sign is important here !
const pattern = this.getCldrPattern(majorDigits < 0);
formattedNumber = this.addPlaceholders(formattedNumber, pattern);
formattedNumber = this.replaceSymbols(formattedNumber);
formattedNumber = this.performSpecificReplacements(formattedNumber);
return formattedNumber;
}
/**
* Get number's major and minor digits.
*
* Major digits are the "integer" part (before decimal separator),
* minor digits are the fractional part
* Result will be an array of exactly 2 items: [majorDigits, minorDigits]
*
* Usage example:
* list(majorDigits, minorDigits) = this.getMajorMinorDigits(decimalNumber);
*
* @param DecimalNumber number
*
* @return string[]
*/
extractMajorMinorDigits(number) {
// Get the number's major and minor digits.
const result = number.toString().split('.');
const majorDigits = result[0];
const minorDigits = (result[1] === undefined) ? '' : result[1];
return [majorDigits, minorDigits];
}
/**
* Splits major digits into groups.
*
* e.g.: Given the major digits "1234567", and major group size
* configured to 3 digits, the result would be "1 234 567"
*
* @param string majorDigits The major digits to be grouped
*
* @return string The grouped major digits
*/
splitMajorGroups(digit) {
if (!this.numberSpecification.isGroupingUsed()) {
return digit;
}
// Reverse the major digits, since they are grouped from the right.
const majorDigits = digit.split('').reverse();
// Group the major digits.
let groups = [];
groups.push(majorDigits.splice(0, this.numberSpecification.getPrimaryGroupSize()));
while (majorDigits.length) {
groups.push(majorDigits.splice(0, this.numberSpecification.getSecondaryGroupSize()));
}
// Reverse back the digits and the groups
groups = groups.reverse();
const newGroups = [];
groups.forEach((group) => {
newGroups.push(group.reverse().join(''));
});
// Reconstruct the major digits.
return newGroups.join(GROUP_SEPARATOR_PLACEHOLDER);
}
/**
* Adds or remove trailing zeroes, depending on specified min and max fraction digits numbers.
*
* @param string minorDigits Digits to be adjusted with (trimmed or padded) zeroes
*
* @return string The adjusted minor digits
*/
adjustMinorDigitsZeroes(minorDigits) {
let digit = minorDigits;
if (digit.length > this.numberSpecification.getMaxFractionDigits()) {
// Strip any trailing zeroes.
digit = digit.replace(/0+$/, '');
}
if (digit.length < this.numberSpecification.getMinFractionDigits()) {
// Re-add needed zeroes
digit = digit.padEnd(
this.numberSpecification.getMinFractionDigits(),
'0',
);
}
return digit;
}
/**
* Get the CLDR formatting pattern.
*
* @see http://cldr.unicode.org/translation/number-patterns
*
* @param bool isNegative If true, the negative pattern
* will be returned instead of the positive one
*
* @return string The CLDR formatting pattern
*/
getCldrPattern(isNegative) {
if (isNegative) {
return this.numberSpecification.getNegativePattern();
}
return this.numberSpecification.getPositivePattern();
}
/**
* Replace placeholder number symbols with relevant numbering system's symbols.
*
* @param string number
* The number to process
*
* @return string
* The number with replaced symbols
*/
replaceSymbols(number) {
const symbols = this.numberSpecification.getSymbol();
const map = {};
map[DECIMAL_SEPARATOR_PLACEHOLDER] = symbols.getDecimal();
map[GROUP_SEPARATOR_PLACEHOLDER] = symbols.getGroup();
map[MINUS_SIGN_PLACEHOLDER] = symbols.getMinusSign();
map[PERCENT_SYMBOL_PLACEHOLDER] = symbols.getPercentSign();
map[PLUS_SIGN_PLACEHOLDER] = symbols.getPlusSign();
return this.strtr(number, map);
}
/**
* strtr() for JavaScript
* Translate characters or replace substrings
*
* @param str
* String to parse
* @param pairs
* Hash of ('from' => 'to', ...).
*
* @return string
*/
strtr(str, pairs) {
const substrs = Object.keys(pairs).map(escapeRE);
return str.split(RegExp(`(${substrs.join('|')})`))
.map(part => pairs[part] || part)
.join('');
}
/**
* Add missing placeholders to the number using the passed CLDR pattern.
*
* Missing placeholders can be the percent sign, currency symbol, etc.
*
* e.g. with a currency CLDR pattern:
* - Passed number (partially formatted): 1,234.567
* - Returned number: 1,234.567 ¤
* ("¤" symbol is the currency symbol placeholder)
*
* @see http://cldr.unicode.org/translation/number-patterns
*
* @param formattedNumber
* Number to process
* @param pattern
* CLDR formatting pattern to use
*
* @return string
*/
addPlaceholders(formattedNumber, pattern) {
/*
* Regex groups explanation:
* # : literal "#" character. Once.
* (,#+)* : any other "#" characters group, separated by ",". Zero to infinity times.
* 0 : literal "0" character. Once.
* (\.[0#]+)* : any combination of "0" and "#" characters groups, separated by '.'.
* Zero to infinity times.
*/
return pattern.replace(/#?(,#+)*0(\.[0#]+)*/, formattedNumber);
}
/**
* Perform some more specific replacements.
*
* Specific replacements are needed when number specification is extended.
* For instance, prices have an extended number specification in order to
* add currency symbol to the formatted number.
*
* @param string formattedNumber
*
* @return mixed
*/
performSpecificReplacements(formattedNumber) {
if (this.numberSpecification instanceof PriceSpecification) {
return formattedNumber
.split(CURRENCY_SYMBOL_PLACEHOLDER)
.join(this.numberSpecification.getCurrencySymbol());
}
return formattedNumber;
}
static build(specifications) {
const symbol = new NumberSymbol(...specifications.symbol);
let specification;
if (specifications.currencySymbol) {
specification = new PriceSpecification(
specifications.positivePattern,
specifications.negativePattern,
symbol,
parseInt(specifications.maxFractionDigits, 10),
parseInt(specifications.minFractionDigits, 10),
specifications.groupingUsed,
specifications.primaryGroupSize,
specifications.secondaryGroupSize,
specifications.currencySymbol,
specifications.currencyCode,
);
} else {
specification = new NumberSpecification(
specifications.positivePattern,
specifications.negativePattern,
symbol,
parseInt(specifications.maxFractionDigits, 10),
parseInt(specifications.minFractionDigits, 10),
specifications.groupingUsed,
specifications.primaryGroupSize,
specifications.secondaryGroupSize,
);
}
return new NumberFormatter(specification);
}
}
export default NumberFormatter;

View File

@@ -0,0 +1,228 @@
/**
* 2007-2019 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
import LocalizationException from './exception/localization';
class NumberSymbol {
/**
* NumberSymbolList constructor.
*
* @param string decimal Decimal separator character
* @param string group Digits group separator character
* @param string list List elements separator character
* @param string percentSign Percent sign character
* @param string minusSign Minus sign character
* @param string plusSign Plus sign character
* @param string exponential Exponential character
* @param string superscriptingExponent Superscripting exponent character
* @param string perMille Permille sign character
* @param string infinity The infinity sign. Corresponds to the IEEE infinity bit pattern.
* @param string nan The NaN (Not A Number) sign. Corresponds to the IEEE NaN bit pattern.
*
* @throws LocalizationException
*/
constructor(
decimal,
group,
list,
percentSign,
minusSign,
plusSign,
exponential,
superscriptingExponent,
perMille,
infinity,
nan,
) {
this.decimal = decimal;
this.group = group;
this.list = list;
this.percentSign = percentSign;
this.minusSign = minusSign;
this.plusSign = plusSign;
this.exponential = exponential;
this.superscriptingExponent = superscriptingExponent;
this.perMille = perMille;
this.infinity = infinity;
this.nan = nan;
this.validateData();
}
/**
* Get the decimal separator.
*
* @return string
*/
getDecimal() {
return this.decimal;
}
/**
* Get the digit groups separator.
*
* @return string
*/
getGroup() {
return this.group;
}
/**
* Get the list elements separator.
*
* @return string
*/
getList() {
return this.list;
}
/**
* Get the percent sign.
*
* @return string
*/
getPercentSign() {
return this.percentSign;
}
/**
* Get the minus sign.
*
* @return string
*/
getMinusSign() {
return this.minusSign;
}
/**
* Get the plus sign.
*
* @return string
*/
getPlusSign() {
return this.plusSign;
}
/**
* Get the exponential character.
*
* @return string
*/
getExponential() {
return this.exponential;
}
/**
* Get the exponent character.
*
* @return string
*/
getSuperscriptingExponent() {
return this.superscriptingExponent;
}
/**
* Gert the per mille symbol (often "‰").
*
* @see https://en.wikipedia.org/wiki/Per_mille
*
* @return string
*/
getPerMille() {
return this.perMille;
}
/**
* Get the infinity symbol (often "∞").
*
* @see https://en.wikipedia.org/wiki/Infinity_symbol
*
* @return string
*/
getInfinity() {
return this.infinity;
}
/**
* Get the NaN (not a number) sign.
*
* @return string
*/
getNan() {
return this.nan;
}
/**
* Symbols list validation.
*
* @throws LocalizationException
*/
validateData() {
if (!this.decimal || typeof this.decimal !== 'string') {
throw new LocalizationException('Invalid decimal');
}
if (!this.group || typeof this.group !== 'string') {
throw new LocalizationException('Invalid group');
}
if (!this.list || typeof this.list !== 'string') {
throw new LocalizationException('Invalid symbol list');
}
if (!this.percentSign || typeof this.percentSign !== 'string') {
throw new LocalizationException('Invalid percentSign');
}
if (!this.minusSign || typeof this.minusSign !== 'string') {
throw new LocalizationException('Invalid minusSign');
}
if (!this.plusSign || typeof this.plusSign !== 'string') {
throw new LocalizationException('Invalid plusSign');
}
if (!this.exponential || typeof this.exponential !== 'string') {
throw new LocalizationException('Invalid exponential');
}
if (!this.superscriptingExponent || typeof this.superscriptingExponent !== 'string') {
throw new LocalizationException('Invalid superscriptingExponent');
}
if (!this.perMille || typeof this.perMille !== 'string') {
throw new LocalizationException('Invalid perMille');
}
if (!this.infinity || typeof this.infinity !== 'string') {
throw new LocalizationException('Invalid infinity');
}
if (!this.nan || typeof this.nan !== 'string') {
throw new LocalizationException('Invalid nan');
}
}
}
export default NumberSymbol;

View File

@@ -0,0 +1,176 @@
/**
* 2007-2019 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
import LocalizationException from '../exception/localization';
import NumberSymbol from '../number-symbol';
class NumberSpecification {
/**
* Number specification constructor.
*
* @param string positivePattern CLDR formatting pattern for positive amounts
* @param string negativePattern CLDR formatting pattern for negative amounts
* @param NumberSymbol symbol Number symbol
* @param int maxFractionDigits Maximum number of digits after decimal separator
* @param int minFractionDigits Minimum number of digits after decimal separator
* @param bool groupingUsed Is digits grouping used ?
* @param int primaryGroupSize Size of primary digits group in the number
* @param int secondaryGroupSize Size of secondary digits group in the number
*
* @throws LocalizationException
*/
constructor(
positivePattern,
negativePattern,
symbol,
maxFractionDigits,
minFractionDigits,
groupingUsed,
primaryGroupSize,
secondaryGroupSize,
) {
this.positivePattern = positivePattern;
this.negativePattern = negativePattern;
this.symbol = symbol;
this.maxFractionDigits = maxFractionDigits;
// eslint-disable-next-line
this.minFractionDigits = maxFractionDigits < minFractionDigits ? maxFractionDigits : minFractionDigits;
this.groupingUsed = groupingUsed;
this.primaryGroupSize = primaryGroupSize;
this.secondaryGroupSize = secondaryGroupSize;
if (!this.positivePattern || typeof this.positivePattern !== 'string') {
throw new LocalizationException('Invalid positivePattern');
}
if (!this.negativePattern || typeof this.negativePattern !== 'string') {
throw new LocalizationException('Invalid negativePattern');
}
if (!this.symbol || !(this.symbol instanceof NumberSymbol)) {
throw new LocalizationException('Invalid symbol');
}
if (typeof this.maxFractionDigits !== 'number') {
throw new LocalizationException('Invalid maxFractionDigits');
}
if (typeof this.minFractionDigits !== 'number') {
throw new LocalizationException('Invalid minFractionDigits');
}
if (typeof this.groupingUsed !== 'boolean') {
throw new LocalizationException('Invalid groupingUsed');
}
if (typeof this.primaryGroupSize !== 'number') {
throw new LocalizationException('Invalid primaryGroupSize');
}
if (typeof this.secondaryGroupSize !== 'number') {
throw new LocalizationException('Invalid secondaryGroupSize');
}
}
/**
* Get symbol.
*
* @return NumberSymbol
*/
getSymbol() {
return this.symbol;
}
/**
* Get the formatting rules for this number (when positive).
*
* This pattern uses the Unicode CLDR number pattern syntax
*
* @return string
*/
getPositivePattern() {
return this.positivePattern;
}
/**
* Get the formatting rules for this number (when negative).
*
* This pattern uses the Unicode CLDR number pattern syntax
*
* @return string
*/
getNegativePattern() {
return this.negativePattern;
}
/**
* Get the maximum number of digits after decimal separator (rounding if needed).
*
* @return int
*/
getMaxFractionDigits() {
return this.maxFractionDigits;
}
/**
* Get the minimum number of digits after decimal separator (fill with "0" if needed).
*
* @return int
*/
getMinFractionDigits() {
return this.minFractionDigits;
}
/**
* Get the "grouping" flag. This flag defines if digits
* grouping should be used when formatting this number.
*
* @return bool
*/
isGroupingUsed() {
return this.groupingUsed;
}
/**
* Get the size of primary digits group in the number.
*
* @return int
*/
getPrimaryGroupSize() {
return this.primaryGroupSize;
}
/**
* Get the size of secondary digits groups in the number.
*
* @return int
*/
getSecondaryGroupSize() {
return this.secondaryGroupSize;
}
}
export default NumberSpecification;

View File

@@ -0,0 +1,115 @@
/**
* 2007-2019 PrestaShop.
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-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/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
import LocalizationException from '../exception/localization';
import NumberSpecification from './number';
/**
* Currency display option: symbol notation.
*/
const CURRENCY_DISPLAY_SYMBOL = 'symbol';
class PriceSpecification extends NumberSpecification {
/**
* Price specification constructor.
*
* @param string positivePattern CLDR formatting pattern for positive amounts
* @param string negativePattern CLDR formatting pattern for negative amounts
* @param NumberSymbol symbol Number symbol
* @param int maxFractionDigits Maximum number of digits after decimal separator
* @param int minFractionDigits Minimum number of digits after decimal separator
* @param bool groupingUsed Is digits grouping used ?
* @param int primaryGroupSize Size of primary digits group in the number
* @param int secondaryGroupSize Size of secondary digits group in the number
* @param string currencySymbol Currency symbol of this price (eg. : €)
* @param currencyCode Currency code of this price (e.g.: EUR)
*
* @throws LocalizationException
*/
constructor(
positivePattern,
negativePattern,
symbol,
maxFractionDigits,
minFractionDigits,
groupingUsed,
primaryGroupSize,
secondaryGroupSize,
currencySymbol,
currencyCode,
) {
super(
positivePattern,
negativePattern,
symbol,
maxFractionDigits,
minFractionDigits,
groupingUsed,
primaryGroupSize,
secondaryGroupSize,
);
this.currencySymbol = currencySymbol;
this.currencyCode = currencyCode;
if (!this.currencySymbol || typeof this.currencySymbol !== 'string') {
throw new LocalizationException('Invalid currencySymbol');
}
if (!this.currencyCode || typeof this.currencyCode !== 'string') {
throw new LocalizationException('Invalid currencyCode');
}
}
/**
* Get type of display for currency symbol.
*
* @return string
*/
static getCurrencyDisplay() {
return CURRENCY_DISPLAY_SYMBOL;
}
/**
* Get the currency symbol
* e.g.: €.
*
* @return string
*/
getCurrencySymbol() {
return this.currencySymbol;
}
/**
* Get the currency ISO code
* e.g.: EUR.
*
* @return string
*/
getCurrencyCode() {
return this.currencyCode;
}
}
export default PriceSpecification;

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 TableSorting from '../../utils/table-sorting';
const $ = global.$;
$(() => {
new TableSorting($('table.table')).attach();
});

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 ModuleCard from '../../../components/module-card';
const $ = global.$;
$(() => {
new ModuleCard().init();
});

View File

@@ -0,0 +1,118 @@
<!--**
* 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
*-->
<template>
<div v-if="isReady" id="app" class="stock-app container-fluid">
<StockHeader />
<Search @search="onSearch" @applyFilter="applyFilter" />
<LowFilter v-if="isOverview" :filters="filters" @lowStockChecked="onLowStockChecked" />
<div class="card container-fluid pa-2 clearfix">
<router-view class="view" @resetFilters="resetFilters" @fetch="fetch"></router-view>
<PSPagination
:currentIndex="currentPagination"
:pagesCount="pagesCount"
@pageChanged="onPageChanged"
/>
</div>
</div>
</template>
<script>
import StockHeader from './header/stock-header';
import Search from './header/search';
import LowFilter from './header/filters/low-filter';
import PSPagination from 'app/widgets/ps-pagination';
export default {
name: 'app',
computed: {
isReady() {
return this.$store.state.isReady;
},
pagesCount() {
return this.$store.state.totalPages;
},
currentPagination() {
return this.$store.state.pageIndex;
},
isOverview() {
return this.$route.name === 'overview';
},
},
methods: {
onPageChanged(pageIndex) {
this.$store.dispatch('updatePageIndex', pageIndex);
this.fetch('asc');
},
fetch(sortDirection) {
const action = this.$route.name === 'overview' ? 'getStock' : 'getMovements';
const sorting = (sortDirection === 'desc') ? ' desc' : '';
this.$store.dispatch('isLoading');
this.filters = Object.assign({}, this.filters, {
order: `${this.$store.state.order}${sorting}`,
page_size: this.$store.state.productsPerPage,
page_index: this.$store.state.pageIndex,
keywords: this.$store.state.keywords,
});
this.$store.dispatch(action, this.filters);
},
onSearch(keywords) {
this.$store.dispatch('updateKeywords', keywords);
this.fetch();
},
applyFilter(filters) {
this.filters = filters;
this.fetch();
},
resetFilters() {
this.filters = {};
},
onLowStockChecked(isChecked) {
this.filters = Object.assign({}, this.filters, {
low_stock: isChecked,
});
this.fetch();
},
},
components: {
StockHeader,
Search,
PSPagination,
LowFilter,
},
data: () => ({
filters: {},
}),
};
</script>
<style lang="scss" type="text/scss">
// hide the layout header
#main-div > .header-toolbar {
height: 0;
display: none;
}
</style>

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
*-->
<template>
<nav aria-label="Breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a :href="catalogLink">{{trans('link_catalog')}}</a>
</li>
<li class="breadcrumb-item">
<a :href="stockLink">{{trans('link_stock')}}</a>
</li>
<li class="breadcrumb-item active">
<span v-if="isOverview">{{trans('link_overview')}}</span>
<span v-else>{{trans('link_movements')}}</span>
</li>
</ol>
</nav>
</template>
<script>
export default {
computed: {
isOverview() {
return this.$route.name === 'overview';
},
catalogLink() {
return window.data.catalogUrl;
},
stockLink() {
return window.data.stockUrl;
},
},
};
</script>

View File

@@ -0,0 +1,207 @@
<!--**
* 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
*-->
<template>
<div id="filters-container">
<button class="search-input collapse-button" type="button" data-toggle="collapse" data-target="#filters">
<i class="material-icons mr-1">filter_list</i>
<i class="material-icons float-right ">keyboard_arrow_down</i>
{{trans('button_advanced_filter')}}
</button>
<div id="filters" class="container-fluid collapse">
<div class="row">
<div class="col-lg-4">
<div v-if="isOverview" class="py-3">
<h2>{{trans('filter_suppliers')}}</h2>
<FilterComponent
:placeholder="trans('filter_search_suppliers')"
:list="this.$store.getters.suppliers"
class="filter-suppliers"
itemID="supplier_id"
label="name"
@active="onFilterActive"
/>
</div>
<div v-else class="py-3">
<h2>{{trans('filter_movements_type')}}</h2>
<PSSelect :items="movementsTypes" itemID="id_stock_mvt_reason" itemName="name" @change="onChange">
{{trans('none')}}
</PSSelect>
<h2 class="mt-4">{{trans('filter_movements_employee')}}</h2>
<PSSelect :items="employees" itemID="id_employee" itemName="name" @change="onChange">
{{trans('none')}}
</PSSelect>
<h2 class="mt-4">{{trans('filter_movements_period')}}</h2>
<form class="row">
<div class="col-md-6">
<label>{{trans('filter_datepicker_from')}}</label>
<PSDatePicker :locale="locale" @dpChange="onDpChange" @reset="onClear" type="sup"/>
</div>
<div class="col-md-6">
<label>{{trans('filter_datepicker_to')}}</label>
<PSDatePicker :locale="locale" @dpChange="onDpChange" @reset="onClear" type="inf" />
</div>
</form>
</div>
</div>
<div class="col-lg-4">
<div class="py-3">
<h2>{{trans('filter_categories')}}</h2>
<FilterComponent
:placeholder="trans('filter_search_category')"
:list="categoriesList"
class="filter-categories"
itemID="id_category"
label="name"
@active="onFilterActive"
/>
</div>
</div>
<div class="col-lg-4">
<div class="py-3">
<h2>{{trans('filter_status')}}</h2>
<PSRadio
id="enable"
:label="trans('filter_status_enable')"
:checked="false"
value="1"
@change="onRadioChange"
/>
<PSRadio
id="disable"
:label="trans('filter_status_disable')"
:checked="false"
value="0"
@change="onRadioChange"
/>
<PSRadio
id="all"
:label="trans('filter_status_all')"
:checked="true"
value="null"
@change="onRadioChange"
/>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import FilterComponent from './filters/filter-component';
import PSSelect from 'app/widgets/ps-select';
import PSButton from 'app/widgets/ps-button';
import PSDatePicker from 'app/widgets/ps-datepicker';
import PSRadio from 'app/widgets/ps-radio';
import _ from 'lodash';
export default {
computed: {
locale() {
return window.data.locale;
},
isOverview() {
return this.$route.name === 'overview';
},
employees() {
return this.$store.state.employees;
},
movementsTypes() {
return this.$store.state.movementsTypes;
},
categoriesList() {
return this.$store.getters.categories;
},
},
methods: {
onClear(event) {
delete this.date_add[event.dateType];
this.applyFilter();
},
onClick() {
this.applyFilter();
},
onFilterActive(list, type) {
if (type === 'supplier') {
this.suppliers = list;
} else {
this.categories = list;
}
this.disabled = !this.suppliers.length && !this.categories.length;
this.applyFilter();
},
applyFilter() {
this.$store.dispatch('isLoading');
this.$emit('applyFilter', {
suppliers: this.suppliers,
categories: this.categories,
id_stock_mvt_reason: this.id_stock_mvt_reason,
id_employee: this.id_employee,
date_add: this.date_add,
active: this.active,
});
},
onChange(item) {
if (item.itemID === 'id_stock_mvt_reason') {
this.id_stock_mvt_reason = item.value === 'default' ? [] : item.value;
} else {
this.id_employee = item.value === 'default' ? [] : item.value;
}
this.applyFilter();
},
onDpChange(event) {
this.date_add[event.dateType] = event.date.unix();
if (event.oldDate) {
this.applyFilter();
}
},
onRadioChange(value) {
this.active = value;
this.applyFilter();
},
},
components: {
FilterComponent,
PSSelect,
PSButton,
PSDatePicker,
PSRadio,
},
mounted() {
this.date_add = {};
this.$store.dispatch('getSuppliers');
this.$store.dispatch('getCategories');
},
data: () => ({
disabled: true,
suppliers: [],
categories: [],
id_stock_mvt_reason: [],
id_employee: [],
date_add: {},
active: null,
}),
};
</script>

View File

@@ -0,0 +1,188 @@
<!--**
* 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
*-->
<template>
<div class="filter-container">
<PSTags
v-if="!hasChildren"
ref="tags"
class="form-control search search-input mb-2"
:tags="tags"
:placeholder="hasPlaceholder?placeholder:''"
:hasIcon="true"
@tagChange="onTagChanged"
@typing="onTyping"
/>
<div v-if="hasChildren">
<PSTree
v-if="isOverview"
v-once
ref="tree"
:hasCheckbox="true"
:model="list"
@checked="onCheck"
:translations="PSTreeTranslations"
>
</PSTree>
<PSTree
v-else
ref="tree"
:hasCheckbox="true"
:model="list"
@checked="onCheck"
:translations="PSTreeTranslations"
>
</PSTree>
</div>
<ul
class="mt-1"
v-else
>
<li
v-for="(item, index) in items"
v-show="item.visible"
class="item"
>
<PSTreeItem
:label="item[label]"
:model="item"
@checked="onCheck"
:hasCheckbox="true"
/>
</li>
</ul>
</div>
</template>
<script>
import PSTags from 'app/widgets/ps-tags';
import PSTreeItem from 'app/widgets/ps-tree/ps-tree-item';
import PSTree from 'app/widgets/ps-tree/ps-tree';
import { EventBus } from 'app/utils/event-bus';
import _ from 'lodash';
export default {
props: ['placeholder', 'itemID', 'label', 'list'],
computed: {
isOverview() {
return this.$route.name === 'overview';
},
hasPlaceholder() {
return !this.tags.length;
},
items() {
const matchList = [];
this.list.filter((data) => {
const label = data[this.label].toLowerCase();
data.visible = false;
if (label.match(this.currentVal)) {
data.visible = true;
matchList.push(data);
}
if (data.children) {
this.hasChildren = true;
}
return data;
});
if (matchList.length === 1) {
this.match = matchList[0];
} else {
this.match = null;
}
return this.list;
},
PSTreeTranslations() {
return {
expand: this.trans('tree_expand'),
reduce: this.trans('tree_reduce'),
};
},
},
methods: {
onCheck(obj) {
const itemLabel = obj.item[this.label];
const filterType = this.hasChildren ? 'category' : 'supplier';
if (obj.checked) {
this.tags.push(itemLabel);
} else {
const index = this.tags.indexOf(itemLabel);
if (this.splice) {
this.tags.splice(index, 1);
}
this.splice = true;
}
if (this.tags.length) {
this.$emit('active', this.filterList(this.tags), filterType);
} else {
this.$emit('active', [], filterType);
}
},
onTyping(val) {
this.currentVal = val.toLowerCase();
},
onTagChanged(tag) {
let checkedTag = tag;
if (this.tags.indexOf(this.currentVal) !== -1) {
this.tags.pop();
}
this.splice = false;
if (this.match) {
checkedTag = this.match[this.label];
}
EventBus.$emit('toggleCheckbox', checkedTag);
this.currentVal = '';
},
filterList(tags) {
const idList = [];
const categoryList = this.$store.state.categoryList;
const list = this.hasChildren ? categoryList : this.list;
list.map((data) => {
const isInIdList = idList.indexOf(Number(data[this.itemID])) === -1;
if (tags.indexOf(data[this.label]) !== -1 && isInIdList) {
idList.push(Number(data[this.itemID]));
}
return idList;
});
return idList;
},
},
data() {
return {
currentVal: '',
match: null,
tags: [],
splice: true,
hasChildren: false,
};
},
components: {
PSTags,
PSTree,
PSTreeItem,
},
};
</script>

View File

@@ -0,0 +1,84 @@
<!--**
* 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
*-->
<template>
<div class="container-fluid">
<div class="row py-2">
<div class="col row ml-1">
<PSCheckbox ref="low-filter" id="low-filter" class="mt-1" @checked="onCheck">
<span slot="label" class="ml-2">{{trans('filter_low_stock')}}</span>
</PSCheckbox>
</div>
<div class="col mr-3 d-flex align-items-center justify-content-end">
<a :href="stockExporttUrl">
<span data-toggle="pstooltip" :title="stockExportTitle" data-html="true" data-placement="top">
<i class="material-icons">cloud_upload</i>
</span>
</a>
<a class="ml-2" :href="stockImportUrl" target="_blank">
<span data-toggle="pstooltip" :title="stockImportTitle" data-html="true" data-placement="top">
<i class="material-icons">cloud_download</i>
</span>
</a>
</div>
</div>
</div>
</template>
<script>
import PSCheckbox from 'app/widgets/ps-checkbox';
export default {
props: {
filters: {},
},
computed: {
stockImportTitle() {
return this.trans('title_import');
},
stockExportTitle() {
return this.trans('title_export');
},
stockImportUrl() {
return window.data.stockImportUrl;
},
stockExporttUrl() {
const params = $.param(this.filters);
return `${window.data.stockExportUrl}&${params}`;
},
},
methods: {
onCheck(checkbox) {
const isChecked = checkbox.checked ? 1 : 0;
this.$emit('lowStockChecked', isChecked);
},
},
mounted() {
$('[data-toggle="pstooltip"]').pstooltip();
},
components: {
PSCheckbox,
},
};
</script>

View File

@@ -0,0 +1,115 @@
<!--**
* 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
*-->
<template>
<div id="search" class="row mb-2">
<div class="col-md-8">
<div class="mb-2">
<form class="search-form" @submit.prevent>
<label>{{trans('product_search')}}</label>
<div class="input-group">
<PSTags ref="psTags" :tags="tags" @tagChange="onSearch" />
<div class="input-group-append">
<PSButton @click="onClick" class="search-button" :primary="true">
<i class="material-icons">search</i>
{{trans('button_search')}}
</PSButton>
</div>
</div>
</form>
</div>
<Filters @applyFilter="applyFilter"/>
</div>
<div class="col-md-4 alert-box">
<transition name="fade">
<PSAlert
v-if="showAlert"
:alertType="alertType"
:hasClose="true"
@closeAlert="onCloseAlert"
>
<span v-if="error">{{trans('alert_bulk_edit')}}</span>
<span v-else>{{trans('notification_stock_updated')}}</span>
</PSAlert>
</transition>
</div>
</div>
</template>
<script>
import Filters from './filters';
import PSTags from 'app/widgets/ps-tags';
import PSButton from 'app/widgets/ps-button';
import PSAlert from 'app/widgets/ps-alert';
import { EventBus } from 'app/utils/event-bus';
export default {
components: {
Filters,
PSTags,
PSButton,
PSAlert,
},
computed: {
error() {
return (this.alertType === 'ALERT_TYPE_DANGER');
},
},
methods: {
onClick() {
const tag = this.$refs.psTags.tag;
this.$refs.psTags.add(tag);
},
onSearch() {
this.$emit('search', this.tags);
},
applyFilter(filters) {
this.$emit('applyFilter', filters);
},
onCloseAlert() {
this.showAlert = false;
},
},
watch: {
$route() {
this.tags = [];
},
},
mounted() {
EventBus.$on('displayBulkAlert', (type) => {
this.alertType = type === 'success' ? 'ALERT_TYPE_SUCCESS' : 'ALERT_TYPE_DANGER';
this.showAlert = true;
setTimeout(_ => {
this.showAlert = false;
}, 5000);
});
},
data: () => ({
tags: [],
showAlert: false,
alertType: 'ALERT_TYPE_DANGER',
duration: false,
}),
};
</script>

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
*-->
<template>
<div class="header-toolbar">
<div class="container-fluid">
<Breadcrumb />
<div class="title-row">
<h1 class="title">{{trans('head_title')}}</h1>
</div>
</div>
<Tabs />
</div>
</template>
<script>
import Breadcrumb from './breadcrumb';
import Tabs from './tabs';
const $ = global.$;
function getOldHeaderToolbarButtons() {
return $('.header-toolbar')
.first()
.find('.toolbar-icons');
}
export default {
components: {
Breadcrumb,
Tabs,
},
mounted() {
// move the toolbar buttons to this header
const toolbarButtons = getOldHeaderToolbarButtons();
toolbarButtons.insertAfter($(this.$el).find('.title-row > .title'));
// signal header change (so size can be updated)
const event = $.Event('vueHeaderMounted', {
name: 'stock-header',
});
$(document).trigger(event);
},
};
</script>

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
*-->
<template>
<div class="page-head-tabs" id="head_tabs">
<ul class="nav nav-pills">
<li class="nav-item">
<router-link data-toggle="tab" class="nav-link" :class="{active : isOverview}" to="/" role="tab">{{trans('menu_stock')}}</router-link>
</li>
<li class="nav-item">
<router-link data-toggle="tab" class="nav-link" :class="{active : isMovements}" to="/movements" role="tab">{{trans('menu_movements')}}</router-link>
</li>
</ul>
</div>
</template>
<script>
export default {
computed: {
isOverview() {
return this.$route.name === 'overview';
},
isMovements() {
return this.$route.name === 'movements';
},
},
};
</script>

View File

@@ -0,0 +1,128 @@
<!--**
* 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
*-->
<template>
<section class="stock-movements">
<PSTable class="mt-1">
<thead>
<tr>
<th width="30%">
<PSSort order="product" @sort="sort" :current-sort="currentSort">
{{trans('title_product')}}
</PSSort>
</th>
<th>
<PSSort order="reference" @sort="sort" :current-sort="currentSort">
{{trans('title_reference')}}
</PSSort>
</th>
<th>
{{trans('title_movements_type')}}
</th>
<th class="text-center">
{{trans('title_quantity')}}
</th>
<th class="text-center">
<PSSort order="date_add" @sort="sort" :current-sort="currentSort">
{{trans('title_date')}}
</PSSort>
</th>
<th>
{{trans('title_employee')}}
</th>
</tr>
</thead>
<tbody>
<tr v-if="this.isLoading">
<td colspan="6">
<PSLoader v-for="(n, index) in 3" class="mt-1" :key="index">
<div class="background-masker header-top"></div>
<div class="background-masker header-left"></div>
<div class="background-masker header-bottom"></div>
<div class="background-masker subheader-left"></div>
<div class="background-masker subheader-bottom"></div>
</PSLoader>
</td>
</tr>
<tr v-else-if="emptyMovements">
<td colspan="6">
<PSAlert alertType="ALERT_TYPE_WARNING" :hasClose="false">
{{trans('no_product')}}
</PSAlert>
</td>
</tr>
<MovementLine v-else v-for="(product, index) in movements" key=${index} :product="product" />
</tbody>
</PSTable>
</section>
</template>
<script>
import PSTable from 'app/widgets/ps-table/ps-table';
import PSSort from 'app/widgets/ps-table/ps-sort';
import PSAlert from 'app/widgets/ps-alert';
import PSLoader from 'app/widgets/ps-loader';
import MovementLine from './movement-line';
const DEFAULT_SORT = 'desc';
export default {
computed: {
isLoading() {
return this.$store.state.isLoading;
},
movements() {
return this.$store.state.movements;
},
emptyMovements() {
return !this.$store.state.movements.length;
},
currentSort() {
return this.$store.state.order;
},
},
methods: {
sort(order, sortDirection) {
this.$store.dispatch('updateOrder', order);
this.$emit('fetch', sortDirection === 'desc' ? 'desc' : 'asc');
},
},
mounted() {
this.$store.dispatch('updatePageIndex', 1);
this.$store.dispatch('updateKeywords', []);
this.$store.dispatch('getEmployees');
this.$store.dispatch('getMovementsTypes');
this.$store.dispatch('updateOrder', 'date_add');
this.$emit('resetFilters');
this.$emit('fetch', DEFAULT_SORT);
},
components: {
PSTable,
PSSort,
PSAlert,
PSLoader,
MovementLine,
},
};
</script>

View File

@@ -0,0 +1,92 @@
<!--**
* 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
*-->
<template>
<tr>
<td>
<div class="d-flex align-items-center">
<PSMedia
class="d-flex align-items-center"
:thumbnail="thumbnail"
>
<p>
{{ product.product_name }}
<small v-if="hasCombination"><br />
{{ combinationName }}
</small>
</p>
</PSMedia>
</div>
</td>
<td>
{{ product.product_reference }}
</td>
<td>
<a v-if="orderLink" :href="orderLink" target="_blank">
{{ product.movement_reason }}
</a>
<span v-else>{{ product.movement_reason }}</span>
</td>
<td class="text-sm-center">
<span class="qty-number" :class="{'is-positive' : isPositive}">
<span v-if="isPositive">+</span>
<span v-else>-</span>
{{ qty }}
</span>
</td>
<td class="text-sm-center">
{{ product.date_add }}
</td>
<td>
{{ employeeName }}
</td>
</tr>
</template>
<script>
import PSMedia from 'app/widgets/ps-media';
import productDesc from 'app/pages/stock/mixins/product-desc';
export default {
props: ['product'],
mixins: [productDesc],
computed: {
qty() {
return this.product.physical_quantity;
},
employeeName() {
return `${this.product.employee_firstname} ${this.product.employee_lastname}`;
},
isPositive() {
return this.product.sign > 0;
},
orderLink() {
return this.product.order_link !== 'N/A' ? this.product.order_link : null;
},
},
components: {
PSMedia,
},
};
</script>

View File

@@ -0,0 +1,65 @@
<!--**
* 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
*-->
<template>
<section class="stock-overview">
<ProductsActions />
<ProductsTable
:isLoading="isLoading"
@sort="sort"
/>
</section>
</template>
<script>
import ProductsActions from './products-actions';
import ProductsTable from './products-table';
const DEFAULT_SORT = 'asc';
export default {
computed: {
isLoading() {
return this.$store.state.isLoading;
},
},
methods: {
sort(sortDirection) {
this.$emit('fetch', sortDirection);
},
},
mounted() {
this.$store.dispatch('updatePageIndex', 1);
this.$store.dispatch('updateKeywords', []);
this.$store.dispatch('updateOrder', 'product');
this.$store.dispatch('isLoading');
this.$emit('resetFilters');
this.$emit('fetch', DEFAULT_SORT);
},
components: {
ProductsActions,
ProductsTable,
},
};
</script>

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
*-->
<template>
<div class="col-md-4">
<div class="movements">
<PSButton
type="button"
class="update-qty float-sm-right"
:class="classObject"
:disabled="disabled"
:primary="true"
@click="sendQty"
>
<i class="material-icons">edit</i>
{{trans('button_movement_type')}}
</PSButton>
</div>
</div>
</template>
<script>
import PSButton from 'app/widgets/ps-button';
export default {
computed: {
disabled() {
return !this.$store.state.hasQty;
},
classObject() {
return {
'btn-primary': !this.disabled,
};
},
},
methods: {
sendQty() {
this.$store.dispatch('updateQtyByProductsId');
},
},
components: {
PSButton,
},
};
</script>
<style lang="scss" scoped>
@import "../../../../../../scss/config/_settings.scss";
.update-qty {
color: white;
transition: background-color 0.2s ease;
}
</style>

View File

@@ -0,0 +1,174 @@
<!--**
* 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
*-->
<template>
<tr :class="{'low-stock':lowStock}">
<td>
<div class="d-flex align-items-center">
<PSCheckbox
:id="id"
:ref="id"
:model="product"
@checked="productChecked"
/>
<PSMedia
class="d-flex align-items-center ml-2"
:thumbnail="thumbnail"
>
<p>
{{ product.product_name }}
<small v-if="hasCombination"><br />
{{ combinationName }}
</small>
</p>
</PSMedia>
</div>
</td>
<td>
{{ reference }}
</td>
<td>
{{ product.supplier_name }}
</td>
<td v-if="product.active" class="text-sm-center">
<i class="material-icons enable">check</i>
</td>
<td v-else class="text-sm-center">
<i class="material-icons disable">close</i>
</td>
<td class="text-sm-center" :class="{'stock-warning':lowStock}">
{{ physical }}
<span v-if="updatedQty" class="qty-update" :class="{'stock-warning':lowStock}">
<i class="material-icons">trending_flat</i>
{{physicalQtyUpdated}}
</span>
</td>
<td class="text-sm-center" :class="{'stock-warning':lowStock}">
{{ product.product_reserved_quantity }}
</td>
<td class="text-sm-center" :class="{'stock-warning':lowStock}">
{{ product.product_available_quantity }}
<span v-if="updatedQty" class="qty-update" :class="{'stock-warning':lowStock}">
<i class="material-icons">trending_flat</i>
{{availableQtyUpdated}}
</span>
<span v-if="lowStock" class="stock-warning ico ml-2" data-toggle="pstooltip" data-placement="top" data-html="true" :title="lowStockLevel">!</span>
</td>
<td class="qty-spinner text-right">
<Spinner :product="product" @updateProductQty="updateProductQty" />
</td>
</tr>
</template>
<script>
import Spinner from './spinner';
import PSCheckbox from 'app/widgets/ps-checkbox';
import PSMedia from 'app/widgets/ps-media';
import ProductDesc from 'app/pages/stock/mixins/product-desc';
import { EventBus } from 'app/utils/event-bus';
import _ from 'lodash';
export default {
props: ['product'],
mixins: [ProductDesc],
computed: {
reference() {
if (this.product.combination_reference !== 'N/A') {
return this.product.combination_reference;
}
return this.product.product_reference;
},
updatedQty() {
return !!this.product.qty;
},
physicalQtyUpdated() {
return Number(this.physical) + Number(this.product.qty);
},
availableQtyUpdated() {
return Number(this.product.product_available_quantity) + Number(this.product.qty);
},
physical() {
const productAvailableQty = Number(this.product.product_available_quantity);
const productReservedQty = Number(this.product.product_reserved_quantity);
return productAvailableQty + productReservedQty;
},
lowStock() {
return this.product.product_low_stock_alert;
},
lowStockLevel() {
return `<div class="text-sm-left">
<p>${this.trans('product_low_stock')}</p>
<p><strong>${this.trans('product_low_stock_level')} ${this.product.product_low_stock_threshold}</strong></p>
</div>`;
},
lowStockAlert() {
return `<div class="text-sm-left">
<p><strong>${this.trans('product_low_stock_alert')} ${this.product.product_low_stock_alert}</strong></p>
</div>`;
},
id() {
return `product-${this.product.product_id}${this.product.combination_id}`;
},
},
methods: {
productChecked(checkbox) {
if (checkbox.checked) {
this.$store.dispatch('addSelectedProduct', checkbox.item);
} else {
this.$store.dispatch('removeSelectedProduct', checkbox.item);
}
},
updateProductQty(productToUpdate) {
const updatedProduct = {
product_id: productToUpdate.product.product_id,
combination_id: productToUpdate.product.combination_id,
delta: productToUpdate.delta,
};
this.$store.dispatch('updateProductQty', updatedProduct);
if (productToUpdate.delta) {
this.$store.dispatch('addProductToUpdate', updatedProduct);
} else {
this.$store.dispatch('removeProductToUpdate', updatedProduct);
}
},
},
mounted() {
EventBus.$on('toggleProductsCheck', (checked) => {
const ref = this.id;
if (this.$refs[ref]) {
this.$refs[ref].checked = checked;
}
});
$('[data-toggle="pstooltip"]').pstooltip();
},
data: () => ({
bulkEdition: false,
}),
components: {
Spinner,
PSMedia,
PSCheckbox,
},
};
</script>

View File

@@ -0,0 +1,147 @@
<!--**
* 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
*-->
<template>
<div class="row product-actions">
<div
class="col-md-8 qty d-flex align-items-center"
:class="{'active' : isFocused}"
>
<PSCheckbox
id="bulk-action"
ref="bulk-action"
class="mt-3"
:isIndeterminate="isIndeterminate"
@checked="bulkChecked"
/>
<div class="ml-2">
<small>{{trans('title_bulk')}}</small>
<PSNumber
class="bulk-qty"
:danger="danger"
:value="bulkEditQty"
:buttons="this.isFocused"
@focus="focusIn"
@blur="focusOut($event)"
@change="onChange"
@keyup="onKeyUp"
/>
</div>
</div>
<div class="col-md-4">
<PSButton
type="button"
class="update-qty float-sm-right my-4 mr-2"
:class="{'btn-primary': disabled }"
:disabled="disabled"
:primary="true"
@click="sendQty"
>
<i class="material-icons">edit</i>
{{trans('button_movement_type')}}
</PSButton>
</div>
</div>
</template>
<script>
import PSNumber from 'app/widgets/ps-number';
import PSCheckbox from 'app/widgets/ps-checkbox';
import PSButton from 'app/widgets/ps-button';
import { EventBus } from 'app/utils/event-bus';
export default {
computed: {
disabled() {
return !this.$store.state.hasQty;
},
bulkEditQty() {
return this.$store.state.bulkEditQty;
},
isIndeterminate() {
const selectedProductsLng = this.selectedProductsLng;
const productsLng = this.$store.state.products.length;
const isIndeterminate = (selectedProductsLng > 0 && selectedProductsLng < productsLng);
if (isIndeterminate) {
this.$refs['bulk-action'].checked = true;
}
return isIndeterminate;
},
selectedProductsLng() {
return this.$store.getters.selectedProductsLng;
},
},
watch: {
selectedProductsLng(value) {
if (value === 0 && this.$refs['bulk-action']) {
this.$refs['bulk-action'].checked = false;
this.isFocused = false;
}
if (value === 1 && this.$refs['bulk-action']) {
this.isFocused = true;
}
},
},
methods: {
focusIn() {
this.danger = !this.selectedProductsLng;
this.isFocused = !this.danger;
if (this.danger) {
EventBus.$emit('displayBulkAlert', 'error');
}
},
focusOut(event) {
this.isFocused = $(event.target).hasClass('ps-number');
this.danger = false;
},
bulkChecked(checkbox) {
if (!checkbox.checked) {
this.$store.dispatch('updateBulkEditQty', null);
}
if (!this.isIndeterminate) {
EventBus.$emit('toggleProductsCheck', checkbox.checked);
}
},
sendQty() {
this.$store.dispatch('updateQtyByProductsId');
},
onChange(value) {
this.$store.dispatch('updateBulkEditQty', value);
},
onKeyUp(event) {
this.isFocused = true;
this.$store.dispatch('updateBulkEditQty', event.target.value);
},
},
data: () => ({
isFocused: false,
danger: false,
}),
components: {
PSNumber,
PSCheckbox,
PSButton,
},
};
</script>

View File

@@ -0,0 +1,129 @@
<!--**
* 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
*-->
<template>
<PSTable class="mt-1">
<thead>
<tr class="column-headers">
<th scope="col" width="27%" class="product-title">
<PSSort order="product" @sort="sort" :current-sort="currentSort">
{{trans('title_product')}}
</PSSort>
</th>
<th scope="col">
<PSSort order="reference" @sort="sort" :current-sort="currentSort">
{{trans('title_reference')}}
</PSSort>
</th>
<th>
<PSSort order="supplier" @sort="sort" :current-sort="currentSort">
{{trans('title_supplier')}}
</PSSort>
</th>
<th class="text-center">
{{trans('title_status')}}
</th>
<th class="text-center">
<PSSort order="physical_quantity" @sort="sort" :current-sort="currentSort">
{{trans('title_physical')}}
</PSSort>
</th>
<th class="text-center">
{{trans('title_reserved')}}
</th>
<th class="text-center">
<PSSort order="available_quantity" @sort="sort" :current-sort="currentSort">
{{trans('title_available')}}
</PSSort>
</th>
<th :title="trans('title_edit_quantity')">
<i class="material-icons">edit</i>
{{trans('title_edit_quantity')}}
</th>
</tr>
</thead>
<tbody>
<tr v-if="this.isLoading">
<td colspan="8">
<PSLoader v-for="(n, index) in 3" class="mt-1" :key="index">
<div class="background-masker header-top"></div>
<div class="background-masker header-left"></div>
<div class="background-masker header-bottom"></div>
<div class="background-masker subheader-left"></div>
<div class="background-masker subheader-bottom"></div>
</PSLoader>
</td>
</tr>
<tr v-else-if="emptyProducts">
<td colspan="8">
<PSAlert alertType="ALERT_TYPE_WARNING" :hasClose="false" >
{{trans('no_product')}}
</PSAlert>
</td>
</tr>
<ProductLine
v-else
v-for="(product, index) in products"
:key=index
:product="product"
/>
</tbody>
</PSTable>
</template>
<script>
import ProductLine from './product-line';
import PSAlert from 'app/widgets/ps-alert';
import PSTable from 'app/widgets/ps-table/ps-table';
import PSSort from 'app/widgets/ps-table/ps-sort';
import PSLoader from 'app/widgets/ps-loader';
export default {
props: ['isLoading'],
components: {
ProductLine,
PSSort,
PSAlert,
PSTable,
PSLoader,
},
methods: {
sort(order, sortDirection) {
this.$store.dispatch('updateOrder', order);
this.$emit('sort', sortDirection === 'desc' ? 'desc' : 'asc');
},
},
computed: {
products() {
return this.$store.state.products;
},
emptyProducts() {
return !this.$store.state.products.length;
},
currentSort() {
return this.$store.state.order;
},
},
};
</script>

View File

@@ -0,0 +1,151 @@
<!--**
* 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
*-->
<template>
<form
class="qty"
:class="classObject"
@mouseover="focusIn"
@mouseleave="focusOut($event)"
@submit.prevent="sendQty"
>
<PSNumber
name="qty"
class="edit-qty"
placeholder="0"
pattern="\d*"
step="1"
buttons="true"
hoverButtons="true"
:value="qty"
@change="onChange"
@keyup="onKeyup($event)"
@focus="focusIn"
@blur="focusOut($event)"
/>
<transition name="fade">
<button v-if="isActive" class="check-button"><i class="material-icons">check</i></button>
</transition>
</form>
</template>
<script>
import PSNumber from 'app/widgets/ps-number';
const $ = global.$;
export default {
props: ['product'],
computed: {
qty() {
if (!this.product.qty) {
this.isEnabled = false;
this.value = '';
}
return this.product.qty;
},
id() {
return `qty-${this.product.product_id}-${this.product.combination_id}`;
},
classObject() {
return {
active: this.isActive,
disabled: !this.isEnabled,
};
},
},
methods: {
onChange(val) {
this.value = val;
this.isEnabled = !!val;
},
deActivate() {
this.isActive = false;
this.isEnabled = false;
this.value = null;
this.product.qty = null;
},
onKeyup(event) {
const val = event.target.value;
if (val === 0) {
this.deActivate();
} else {
this.isActive = true;
this.isEnabled = true;
this.value = val;
}
},
focusIn() {
this.isActive = true;
},
focusOut(event) {
const value = parseInt(this.value, 10);
if (!$(event.target).hasClass('ps-number') && (isNaN(value) || value === 0)) {
this.isActive = false;
}
this.isEnabled = !!this.value;
},
sendQty() {
const postUrl = this.product.edit_url;
if (parseInt(this.product.qty, 10) !== 0 && !isNaN(parseInt(this.value, 10))) {
this.$store.dispatch('updateQtyByProductId', {
url: postUrl,
delta: this.value,
});
this.deActivate();
}
},
},
watch: {
value(val) {
this.$emit('updateProductQty', {
product: this.product,
delta: val,
});
},
},
components: {
PSNumber,
},
data: () => ({
value: null,
isActive: false,
isEnabled: false,
}),
};
</script>
<style lang="scss" type="text/scss" scoped>
@import "~jquery-ui-dist/jquery-ui.css";
*{
outline: none;
}
.fade-enter-active, .fade-leave-active {
transition: opacity 0.2s ease;
}
.fade-enter, .fade-leave-to {
opacity: 0
}
</style>

View File

@@ -0,0 +1,42 @@
/**
* 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 Vue from 'vue';
import app from './components/app';
import store from './store/';
import router from './router';
import Translation from './mixins/translate';
Vue.mixin(Translation);
new Vue({
router,
store,
el: '#stock-app',
template: '<app />',
components: { app },
beforeMount() {
this.$store.dispatch('getTranslations');
},
});

View File

@@ -0,0 +1,48 @@
/**
* 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 {
computed: {
thumbnail() {
if (this.product.combination_thumbnail !== 'N/A') {
return `${window.data.baseUrl}/${this.product.combination_thumbnail}`;
} else if (this.product.product_thumbnail !== 'N/A') {
return `${window.data.baseUrl}/${this.product.product_thumbnail}`;
}
return null;
},
combinationName() {
const arr = this.product.combination_name.split(',');
let attr = '';
arr.forEach((attribute) => {
const value = attribute.split('-');
attr += attr.length ? ` - ${value[1]}` : value[1];
});
return attr;
},
hasCombination() {
return !!this.product.combination_id;
},
},
};

View File

@@ -0,0 +1,31 @@
/**
* 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 {
methods: {
trans(key) {
return this.$store.state.translations[key];
},
},
};

View File

@@ -0,0 +1,50 @@
/**
* 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 Vue from 'vue';
import VueRouter from 'vue-router';
import Overview from 'app/pages/stock/components/overview/index';
import Movements from 'app/pages/stock/components/movements/index';
Vue.use(VueRouter);
export default new VueRouter({
mode: 'history',
base: (() => {
const hasIndex = /(index\.php)/.exec(window.location.href);
return `${window.data.baseUrl}${hasIndex ? '/index.php' : ''}/sell/stocks`;
})(),
routes: [
{
path: '/',
name: 'overview',
component: Overview,
},
{
path: '/movements',
name: 'movements',
component: Movements,
},
],
});

View File

@@ -0,0 +1,190 @@
/**
* 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 Vue from 'vue';
import VueResource from 'vue-resource';
import * as types from './mutation-types';
import { showGrowl } from 'app/utils/growl';
import { EventBus } from 'app/utils/event-bus';
import _ from 'lodash';
Vue.use(VueResource);
export const getStock = ({ commit }, payload) => {
const url = window.data.apiStockUrl;
Vue.http.get(url, {
params: {
order: payload.order,
page_size: payload.page_size,
page_index: payload.page_index,
keywords: payload.keywords ? payload.keywords : [],
supplier_id: payload.suppliers ? payload.suppliers : [],
category_id: payload.categories ? payload.categories : [],
active: payload.active !== 'null' ? payload.active : [],
low_stock: payload.low_stock,
},
}).then((response) => {
commit(types.LOADING_STATE, false);
commit(types.SET_TOTAL_PAGES, response.headers.get('Total-Pages'));
commit(types.ADD_PRODUCTS, response.body);
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const getSuppliers = ({ commit }) => {
const url = window.data.suppliersUrl;
Vue.http.get(url).then((response) => {
commit(types.SET_SUPPLIERS, response.body);
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const getCategories = ({ commit }) => {
const url = window.data.categoriesUrl;
Vue.http.get(url).then((response) => {
commit(types.SET_CATEGORIES, response.body);
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const getMovements = ({ commit }, payload) => {
const url = window.data.apiMovementsUrl;
Vue.http.get(url, {
params: {
order: payload.order,
page_size: payload.page_size,
page_index: payload.page_index,
keywords: payload.keywords ? payload.keywords : [],
supplier_id: payload.suppliers ? payload.suppliers : [],
category_id: payload.categories ? payload.categories : [],
id_stock_mvt_reason: payload.id_stock_mvt_reason ? payload.id_stock_mvt_reason : [],
id_employee: payload.id_employee ? payload.id_employee : [],
date_add: payload.date_add ? payload.date_add : [],
},
}).then((response) => {
commit(types.LOADING_STATE, false);
commit(types.SET_TOTAL_PAGES, response.headers.get('Total-Pages'));
commit(types.SET_MOVEMENTS, response.body);
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const getTranslations = ({ commit }) => {
const url = window.data.translationUrl;
Vue.http.get(url).then((response) => {
commit(types.SET_TRANSLATIONS, response.body);
commit(types.APP_IS_READY);
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const getEmployees = ({ commit }) => {
const url = window.data.employeesUrl;
Vue.http.get(url).then((response) => {
commit(types.SET_EMPLOYEES_LIST, response.body);
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const getMovementsTypes = ({ commit }) => {
const url = window.data.movementsTypesUrl;
Vue.http.get(url).then((response) => {
commit(types.SET_MOVEMENTS_TYPES, response.body);
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const updateOrder = ({ commit }, order) => {
commit(types.UPDATE_ORDER, order);
};
export const updatePageIndex = ({ commit }, pageIndex) => {
commit(types.SET_PAGE_INDEX, pageIndex);
};
export const updateKeywords = ({ commit }, keywords) => {
commit(types.UPDATE_KEYWORDS, keywords);
};
export const isLoading = ({ commit }) => {
commit(types.LOADING_STATE, true);
};
export const updateProductQty = ({ commit }, payload) => {
commit(types.UPDATE_PRODUCT_QTY, payload);
};
export const updateQtyByProductId = ({ commit, state }, payload) => {
const url = payload.url;
const delta = payload.delta;
Vue.http.post(url, {
delta,
}).then((res) => {
commit(types.UPDATE_PRODUCT, res.body);
EventBus.$emit('displayBulkAlert', 'success');
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const updateQtyByProductsId = ({ commit, state }) => {
const url = state.editBulkUrl;
const productsQty = state.productsToUpdate;
Vue.http.post(url, productsQty).then((res) => {
commit(types.UPDATE_PRODUCTS_QTY, res.body);
EventBus.$emit('displayBulkAlert', 'success');
}, (error) => {
showGrowl('error', error.statusText);
});
};
export const updateBulkEditQty = ({ commit }, value) => {
commit(types.UPDATE_BULK_EDIT_QTY, value);
};
export const addProductToUpdate = ({ commit }, product) => {
commit(types.ADD_PRODUCT_TO_UPDATE, product);
};
export const removeProductToUpdate = ({ commit }, product) => {
commit(types.REMOVE_PRODUCT_TO_UPDATE, product);
};
export const addSelectedProduct = ({ commit }, product) => {
commit(types.ADD_SELECTED_PRODUCT, product);
};
export const removeSelectedProduct = ({ commit }, product) => {
commit(types.REMOVE_SELECTED_PRODUCT, product);
};

View File

@@ -0,0 +1,95 @@
/**
* 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 Vue from 'vue';
import Vuex from 'vuex';
import * as actions from './actions';
import mutations from './mutations';
import _ from 'lodash';
Vue.use(Vuex);
// root state object.
const state = {
order: '',
pageIndex: 1,
totalPages: 0,
productsPerPage: 30,
products: [],
hasQty: false,
keywords: [],
suppliers: {
data: [],
},
categories: [],
categoryList: [],
movements: [],
employees: [],
movementsTypes: [],
translations: {},
isLoading: false,
isReady: false,
editBulkUrl: '',
bulkEditQty: null,
productsToUpdate: [],
selectedProducts: [],
};
// getters are functions
const getters = {
suppliers(rootState) {
function convert(suppliers) {
suppliers.forEach((supplier) => {
supplier.id = supplier.supplier_id;
});
return suppliers;
}
return convert(rootState.suppliers.data);
},
categories(rootState) {
function convert(categories) {
categories.forEach((category) => {
category.children = _.values(category.children);
rootState.categoryList.push(category);
category.id = `${category.id_parent}-${category.id_category}`;
convert(category.children);
});
return categories;
}
return convert(rootState.categories);
},
selectedProductsLng(rootState) {
return rootState.selectedProducts.length;
},
};
// A Vuex instance is created by combining the state, mutations, actions,
// and getters.
export default new Vuex.Store({
state,
getters,
actions,
mutations,
});

View File

@@ -0,0 +1,45 @@
/**
* 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 const ADD_PRODUCTS = 'ADD_PRODUCTS';
export const ADD_PRODUCT_TO_UPDATE = 'ADD_PRODUCT_TO_UPDATE';
export const ADD_SELECTED_PRODUCT = 'ADD_SELECTED_PRODUCT';
export const APP_IS_READY = 'APP_IS_READY';
export const LOADING_STATE = 'LOADING_STATE';
export const REMOVE_PRODUCT_TO_UPDATE = 'REMOVE_PRODUCT_TO_UPDATE';
export const REMOVE_SELECTED_PRODUCT = 'REMOVE_SELECTED_PRODUCT';
export const SET_CATEGORIES = 'SET_CATEGORIES';
export const SET_EMPLOYEES_LIST = 'SET_EMPLOYEES_LIST';
export const SET_MOVEMENTS = 'SET_MOVEMENTS';
export const SET_MOVEMENTS_TYPES = 'SET_MOVEMENTS_TYPES';
export const SET_PAGE_INDEX = 'SET_PAGE_INDEX';
export const SET_SUPPLIERS = 'SET_SUPPLIERS';
export const SET_TOTAL_PAGES = 'SET_TOTAL_PAGES';
export const SET_TRANSLATIONS = 'SET_TRANSLATIONS';
export const UPDATE_BULK_EDIT_QTY = 'UPDATE_BULK_EDIT_QTY';
export const UPDATE_KEYWORDS = 'UPDATE_KEYWORDS';
export const UPDATE_PRODUCT = 'UPDATE_PRODUCT';
export const UPDATE_PRODUCT_QTY = 'UPDATE_PRODUCT_QTY';
export const UPDATE_PRODUCTS_QTY = 'UPDATE_PRODUCTS_QTY';
export const UPDATE_ORDER = 'UPDATE_ORDER';

View File

@@ -0,0 +1,185 @@
/**
* 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 * as types from './mutation-types';
export default {
[types.UPDATE_ORDER](state, order) {
state.order = order;
},
[types.UPDATE_KEYWORDS](state, keywords) {
state.keywords = keywords;
},
[types.SET_TOTAL_PAGES](state, totalPages) {
state.totalPages = Number(totalPages);
},
[types.SET_PAGE_INDEX](state, pageIndex) {
state.pageIndex = pageIndex;
},
[types.SET_SUPPLIERS](state, suppliers) {
state.suppliers = suppliers;
},
[types.SET_CATEGORIES](state, categories) {
state.categories = categories.data.tree.children;
},
[types.SET_MOVEMENTS](state, movements) {
state.movements = movements.data;
},
[types.SET_TRANSLATIONS](state, translations) {
translations.data.forEach((t) => {
state.translations[t.translation_id] = t.name;
});
},
[types.LOADING_STATE](state, isLoading) {
state.isLoading = isLoading;
},
[types.APP_IS_READY](state) {
state.isReady = true;
},
[types.SET_EMPLOYEES_LIST](state, employees) {
state.employees = employees.data;
},
[types.SET_MOVEMENTS_TYPES](state, movementsTypes) {
state.movementsTypes = movementsTypes.data;
},
[types.ADD_PRODUCTS](state, products) {
state.productsToUpdate = [];
state.selectedProducts = [];
_.forEach(products.data.data, (product) => {
product.qty = 0;
});
state.editBulkUrl = products.data.info.edit_bulk_url;
state.products = products.data.data;
},
[types.UPDATE_PRODUCT](state, updatedProduct) {
const index = _.findIndex(state.products, {
product_id: updatedProduct.product_id,
combination_id: updatedProduct.combination_id,
});
const updatedIndex = _.findIndex(state.productsToUpdate, {
product_id: updatedProduct.product_id,
combination_id: updatedProduct.combination_id,
});
updatedProduct.qty = 0;
state.products.splice(index, 1, updatedProduct);
state.productsToUpdate.splice(updatedIndex, 1);
},
[types.UPDATE_PRODUCTS_QTY](state, updatedProducts) {
state.productsToUpdate = [];
state.selectedProducts = [];
_.forEach(updatedProducts, (product) => {
const index = _.findIndex(state.products, {
product_id: product.product_id,
combination_id: product.combination_id,
});
product.qty = 0;
state.products.splice(index, 1, product);
});
state.hasQty = false;
},
[types.UPDATE_PRODUCT_QTY](state, updatedProduct) {
let hasQty = false;
const productToUpdate = _.find(state.products, {
product_id: updatedProduct.product_id,
combination_id: updatedProduct.combination_id,
});
_.forEach(state.products, (product) => {
productToUpdate.qty = updatedProduct.delta;
if (product.qty) {
hasQty = true;
}
});
state.hasQty = hasQty;
},
[types.ADD_PRODUCT_TO_UPDATE](state, updatedProduct) {
const index = _.findIndex(state.productsToUpdate, {
product_id: updatedProduct.product_id,
combination_id: updatedProduct.combination_id,
});
if (index !== -1) {
state.productsToUpdate.splice(index, 1, updatedProduct);
} else {
state.productsToUpdate.push(updatedProduct);
}
},
[types.REMOVE_PRODUCT_TO_UPDATE](state, updatedProduct) {
const index = _.findIndex(state.productsToUpdate, {
product_id: updatedProduct.product_id,
combination_id: updatedProduct.combination_id,
});
state.productsToUpdate.splice(index, 1);
},
[types.UPDATE_BULK_EDIT_QTY](state, value) {
state.bulkEditQty = value;
if (value) {
_.forEach(state.selectedProducts, (product) => {
const index = _.findIndex(state.productsToUpdate, {
product_id: product.product_id,
combination_id: product.combination_id,
});
product.qty = value;
product.delta = state.bulkEditQty;
if (index !== -1) {
state.productsToUpdate.splice(index, 1, product);
} else {
state.productsToUpdate.push(product);
}
});
state.hasQty = true;
}
if (value === null) {
_.forEach(state.selectedProducts, (product) => {
product.qty = 0;
});
state.productsToUpdate = [];
state.selectedProducts = [];
state.hasQty = false;
}
},
[types.ADD_SELECTED_PRODUCT](state, product) {
const index = _.findIndex(state.selectedProducts, {
product_id: product.product_id,
combination_id: product.combination_id,
});
if (index !== -1) {
state.selectedProducts.splice(index, 1, product);
} else {
state.selectedProducts.push(product);
}
},
[types.REMOVE_SELECTED_PRODUCT](state, product) {
const index = _.findIndex(state.selectedProducts, {
product_id: product.product_id,
combination_id: product.combination_id,
});
if (index !== -1) {
state.selectedProducts[index].qty = 0;
}
state.selectedProducts.splice(index, 1);
},
};

View File

@@ -0,0 +1,157 @@
<!--**
* 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
*-->
<template>
<div v-if="isReady" id="app" class="translations-app">
<TranslationsHeader />
<div class="container-fluid">
<div class="row justify-content-between align-items-center">
<Search @search="onSearch" />
<div class="translations-summary">
<span>{{ totalTranslations }}</span>
<span v-show="totalMissingTranslations"> - <span class="missing">{{ totalMissingTranslationsString }}</span></span>
</div>
</div>
<div class="row">
<Sidebar :modal="this.$refs.transModal" :principal="this.$refs.principal"/>
<Principal :modal="this.$refs.transModal" ref="principal" />
</div>
</div>
<PSModal ref="transModal" :translations="translations"/>
</div>
</template>
<script>
import TranslationsHeader from './header/translations-header';
import Search from './header/search';
import Sidebar from './sidebar';
import Principal from './principal';
import PSModal from 'app/widgets/ps-modal';
import { EventBus } from 'app/utils/event-bus';
export default {
name: 'app',
computed: {
isReady() {
return this.$store.getters.isReady;
},
totalTranslations() {
return (this.$store.state.totalTranslations <= 1) ? this.trans('label_total_domain_singular').replace('%nb_translation%', this.$store.state.totalTranslations) : this.trans('label_total_domain').replace('%nb_translations%', this.$store.state.totalTranslations);
},
totalMissingTranslations() {
return this.$store.state.totalMissingTranslations;
},
totalMissingTranslationsString() {
return this.totalMissingTranslations === 1 ? this.trans('label_missing_singular') : this.trans('label_missing').replace('%d', this.totalMissingTranslations);
},
translations() {
return {
button_save: this.trans('button_save'),
button_leave: this.trans('button_leave'),
modal_content: this.trans('modal_content'),
modal_title: this.trans('modal_title'),
};
},
},
mounted() {
$('a').on('click', (e) => {
if ($(e.currentTarget).attr('href')) {
this.destHref = $(e.currentTarget).attr('href');
}
});
window.onbeforeunload = () => {
if (!this.destHref && this.isEdited() && !this.leave) {
return true;
}
if (!this.leave && this.isEdited()) {
setTimeout(() => {
window.stop();
}, 500);
this.$refs.transModal.showModal();
this.$refs.transModal.$once('save', () => {
this.$refs.principal.saveTranslations();
this.leavePage();
});
this.$refs.transModal.$once('leave', () => {
this.leavePage();
});
return null;
}
};
},
methods: {
onSearch(keywords) {
this.$store.dispatch('getDomainsTree', {
store: this.$store,
});
this.$store.currentDomain = '';
},
/**
* Set leave to true and redirect the user to the new location
*/
leavePage() {
this.leave = true;
window.location.href = this.destHref;
},
isEdited() {
return this.$refs.principal.edited();
},
},
data: () => ({
destHref: null,
leave: false,
}),
components: {
TranslationsHeader,
Search,
Sidebar,
Principal,
PSModal,
},
};
</script>
<style lang="scss" type="text/scss">
@import "../../../../../scss/config/_settings.scss";
// hide the layout header
#main-div > .header-toolbar {
height: 0;
display: none;
}
.flex {
display: flex;
align-items: center;
}
.missing {
color: $danger;
}
.translations-summary {
font-weight: $font-weight-semibold;
font-size: 1rem;
}
</style>

View File

@@ -0,0 +1,45 @@
<!--**
* 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
*-->
<template>
<div class="mb-1">
<small>
<a :href="internationalLink">{{trans('link_international')}}</a> /
<a :href="translationLink">{{trans('link_translations')}}</a>
</small>
</div>
</template>
<script>
export default {
computed: {
internationalLink() {
return window.data.internationalUrl;
},
translationLink() {
return window.data.translationsUrl;
},
},
};
</script>

View File

@@ -0,0 +1,72 @@
<!--**
* 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
*-->
<template>
<div id="search" class="col-md-8 mb-4">
<form class="search-form" @submit.prevent>
<label>{{trans('search_label')}}</label>
<div class="input-group">
<PSTags ref="psTags" :tags="tags" @tagChange="onSearch" :placeholder="trans('search_placeholder')" />
<div class="input-group-append">
<PSButton @click="onClick" class="search-button" :primary="true">
<i class="material-icons">search</i>
{{trans('button_search')}}
</PSButton>
</div>
</div>
</form>
</div>
</template>
<script>
import PSTags from 'app/widgets/ps-tags';
import PSButton from 'app/widgets/ps-button';
export default {
components: {
PSTags,
PSButton,
},
methods: {
onClick() {
const tag = this.$refs.psTags.tag;
this.$refs.psTags.add(tag);
},
onSearch() {
this.$store.dispatch('updateSearch', this.tags);
this.$emit('search', this.tags);
},
},
watch: {
$route() {
this.tags = [];
},
},
data() {
return {
tags: [],
};
},
};
</script>

View File

@@ -0,0 +1,63 @@
<!--**
* 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
*-->
<template>
<div class="header-toolbar">
<div class="container-fluid">
<Breadcrumb />
<div class="title-row">
<h1 class="title">{{trans('head_title')}}</h1>
</div>
</div>
</div>
</template>
<script>
import Breadcrumb from './breadcrumb';
const $ = global.$;
function getOldHeaderToolbarButtons() {
return $('.header-toolbar')
.first()
.find('.toolbar-icons');
}
export default {
components: {
Breadcrumb,
},
mounted() {
// move the toolbar buttons to this header
const toolbarButtons = getOldHeaderToolbarButtons();
toolbarButtons.insertAfter($(this.$el).find('.title-row > .title'));
// signal header change (so size can be updated)
const event = $.Event('vueHeaderMounted', {
name: 'stock-header',
});
$(document).trigger(event);
},
};
</script>

View File

@@ -0,0 +1,288 @@
<!--**
* 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
*-->
<template>
<transition name="fade">
<div class="col-sm-9 card" v-if="principalReady">
<div class="p-3 translations-wrapper">
<PSAlert v-if="noResult" alertType="ALERT_TYPE_WARNING" :hasClose="false">
{{noResultInfo}}
</PSAlert>
<div class="translations-catalog row p-0" v-else>
<PSAlert v-if="searchActive" class="col-sm-12" alertType="ALERT_TYPE_INFO" :hasClose="false">
{{searchInfo}}
</PSAlert>
<div class="col-sm-8 pt-3">
<h3 class="domain-info">
<span>{{ currentDomain }}</span>
<span>{{ currentDomainTotalTranslations }}</span>
<span v-show="currentDomainTotalMissingTranslations"> - <span class="missing">{{ currentDomainTotalMissingTranslationsString }}</span></span>
</h3>
</div>
<div class="col-sm-4">
<PSPagination
:currentIndex="currentPagination"
:pagesCount="pagesCount"
class="float-sm-right"
@pageChanged="onPageChanged"
/>
</div>
<form class="col-sm-12"
method="post"
:action="saveAction"
:isEdited="isEdited"
@submit.prevent="saveTranslations"
>
<div class="row">
<div class="col-sm-12 mb-2">
<PSButton :primary="true" type="submit" class="float-sm-right">
{{ trans('button_save') }}
</PSButton>
</div>
</div>
<TranslationInput
v-for="(translation, key) in translationsCatalog"
:key="key"
:id="key"
:translated="translation"
:label="translation.default"
:extraInfo="getDomain(translation.tree_domain)"
@editedAction="isEdited"
>
</TranslationInput>
<div class="row">
<div class="col-sm-12">
<PSButton :primary="true" type="submit" class="float-sm-right mt-3">
{{ trans('button_save') }}
</PSButton>
</div>
</div>
</form>
<div class="col-sm-12">
<PSPagination
:currentIndex="currentPagination"
:pagesCount="pagesCount"
@pageChanged="onPageChanged"
/>
</div>
</div>
</div>
</div>
</transition>
</template>
<script>
import TranslationInput from './translation-input';
import PSButton from 'app/widgets/ps-button';
import PSPagination from 'app/widgets/ps-pagination';
import PSAlert from 'app/widgets/ps-alert';
import { EventBus } from 'app/utils/event-bus';
export default {
props: [
'modal',
],
computed: {
principalReady() {
return !this.$store.state.principalLoading;
},
translationsCatalog() {
this.translations = this.$store.getters.catalog.data.data;
return this.translations;
},
saveAction() {
return this.$store.getters.catalog.data.info ? this.$store.getters.catalog.data.info.edit_url : '';
},
resetAction() {
return this.$store.getters.catalog.data.info ? this.$store.getters.catalog.data.info.reset_url : '';
},
pagesCount() {
return this.$store.getters.totalPages;
},
currentPagination() {
return this.$store.getters.pageIndex;
},
currentDomain() {
return this.$store.state.currentDomain;
},
currentDomainTotalTranslations() {
return (this.$store.state.currentDomainTotalTranslations <= 1)
? `- ${this.trans('label_total_domain_singular').replace('%nb_translation%', this.$store.state.currentDomainTotalTranslations)}`
: `- ${this.trans('label_total_domain').replace('%nb_translations%', this.$store.state.currentDomainTotalTranslations)}`;
},
currentDomainTotalMissingTranslations() {
return this.$store.state.currentDomainTotalMissingTranslations;
},
currentDomainTotalMissingTranslationsString() {
let totalMissingTranslationsString = '';
if (this.currentDomainTotalMissingTranslations) {
if (this.currentDomainTotalMissingTranslations === 1) {
totalMissingTranslationsString = this.trans('label_missing_singular');
} else {
totalMissingTranslationsString = this.trans('label_missing').replace('%d', this.currentDomainTotalMissingTranslations);
}
}
return totalMissingTranslationsString;
},
noResult() {
return (this.$store.getters.currentDomain === '' || typeof this.$store.getters.currentDomain === 'undefined');
},
noResultInfo() {
return this.trans('no_result').replace('%s', this.$store.getters.searchTags.join(' - '));
},
searchActive() {
return this.$store.getters.searchTags.length;
},
searchInfo() {
const transKey = (this.$store.state.totalTranslations <= 1) ? 'search_info_singular' : 'search_info';
return this.trans(transKey)
.replace('%s', this.$store.getters.searchTags.join(' - '))
.replace('%d', this.$store.state.totalTranslations);
},
},
methods: {
/**
* Dispatch the event to change the page index,
* get the translations and reset the modified translations into the state
* @param {Number} pageIndex
*/
changePage: function changePage(pageIndex) {
this.$store.dispatch('updatePageIndex', pageIndex);
this.fetch();
this.$store.state.modifiedTranslations = [];
},
isEdited(input) {
if (input.translation.edited) {
this.$store.state.modifiedTranslations[input.id] = input.translation;
} else {
this.$store.state.modifiedTranslations.splice(
this.$store.state.modifiedTranslations.indexOf(input.id),
1
);
}
},
onPageChanged(pageIndex) {
if (this.edited()) {
this.modal.showModal();
this.modal.$once('save', () => {
this.saveTranslations();
this.changePage(pageIndex);
});
this.modal.$once('leave', () => {
this.changePage(pageIndex);
});
} else {
this.changePage(pageIndex);
}
},
fetch() {
this.$store.dispatch('getCatalog', {
url: this.$store.getters.catalog.info.current_url_without_pagination,
page_size: this.$store.state.translationsPerPage,
page_index: this.$store.getters.pageIndex,
});
},
getDomain(domains) {
let domain = '';
domains.forEach((d) => {
domain += d + ' > ';
});
return domain.slice(0, -3);
},
saveTranslations() {
const modifiedTranslations = this.getModifiedTranslations();
if (modifiedTranslations.length) {
this.$store.dispatch('saveTranslations', {
url: this.saveAction,
translations: this.getModifiedTranslations(),
store: this.$store,
});
}
},
getModifiedTranslations() {
this.modifiedTranslations = [];
const targetTheme = (window.data.type === 'modules') ? '' : window.data.selected;
this.$store.state.modifiedTranslations.forEach((translation) => {
this.modifiedTranslations.push({
default: translation.default,
edited: translation.edited,
domain: translation.tree_domain.join(''),
locale: window.data.locale,
theme: targetTheme,
});
});
return this.modifiedTranslations;
},
edited() {
return this.$store.state.modifiedTranslations.length > 0;
},
},
data: () => ({
translations: [],
originalTranslations: [],
modifiedTranslations: [],
}),
mounted() {
EventBus.$on('resetTranslation', (el) => {
const translations = [];
translations.push({
default: el.default,
domain: el.tree_domain.join(''),
locale: window.data.locale,
theme: window.data.selected,
});
this.$store.dispatch('resetTranslation', {
url: this.resetAction,
translations,
});
});
},
components: {
TranslationInput,
PSButton,
PSPagination,
PSAlert,
},
};
</script>
<style lang="scss" scoped>
@import "../../../../../../scss/config/_settings.scss";
.fade-enter-active, .fade-leave-active {
transition: opacity .5s
}
.fade-enter, .fade-leave-to /* .fade-leave-active in <2.1.8 */ {
opacity: 0
}
</style>

View File

@@ -0,0 +1,99 @@
<!--**
* 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
*-->
<template>
<div class="form-group">
<label>{{label}}</label>
<textarea class="form-control" rows="2" v-model="getTranslated" :class="{ missing : isMissing }"></textarea>
<PSButton class="mt-3 float-sm-right" :primary="false" ghost @click="resetTranslation">
{{ trans('button_reset') }}
</PSButton>
<small class="mt-3">{{extraInfo}}</small>
</div>
</template>
<script>
import PSButton from 'app/widgets/ps-button';
import { EventBus } from 'app/utils/event-bus';
export default {
name: 'TranslationInput',
props: {
id: {
type: Number,
},
extraInfo: {
type: String,
required: false,
},
label: {
type: String,
required: true,
},
translated: {
required: true,
},
},
computed: {
getTranslated: {
get() {
return this.translated.database ? this.translated.database : this.translated.xliff;
},
set(modifiedValue) {
const modifiedTranslated = this.translated;
modifiedTranslated.database = modifiedValue;
modifiedTranslated.edited = modifiedValue;
this.$emit('input', modifiedTranslated);
this.$emit('editedAction', {
translation: modifiedTranslated,
id: this.id,
});
},
},
isMissing() {
return this.getTranslated === null;
},
},
methods: {
resetTranslation() {
this.getTranslated = '';
EventBus.$emit('resetTranslation', this.translated);
},
},
components: {
PSButton,
},
};
</script>
<style lang="scss" scoped>
@import "../../../../../../scss/config/_settings.scss";
.form-group {
overflow: hidden;
}
.missing {
border: 1px solid $danger;
}
</style>

View File

@@ -0,0 +1,222 @@
<!--**
* 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
*-->
<template>
<div class="col-sm-3">
<div class="card p-3">
<PSTree
ref="domainTree"
:model="domainsTree"
className="translationTree"
:translations="translations"
:currentItem="currentItem"
v-if="treeReady"
/>
<PSSpinner v-else />
</div>
</div>
</template>
<script>
import PSTree from 'app/widgets/ps-tree/ps-tree';
import PSSpinner from 'app/widgets/ps-spinner';
import { EventBus } from 'app/utils/event-bus';
export default {
props: [
'modal',
'principal',
],
computed: {
treeReady() {
return !this.$store.state.sidebarLoading;
},
currentItem() {
if (this.$store.getters.currentDomain === '' || typeof this.$store.getters.currentDomain === 'undefined') {
if (this.domainsTree.length) {
const domain = this.getFirstDomainToDisplay(this.domainsTree);
EventBus.$emit('reduce');
this.$store.dispatch('updateCurrentDomain', domain);
if (domain !== '') {
this.$store.dispatch('getCatalog', { url: domain.dataValue });
EventBus.$emit('setCurrentElement', domain.full_name);
return domain.full_name;
}
this.$store.dispatch('updatePrincipalLoading', false);
return '';
}
}
return this.$store.getters.currentDomain;
},
domainsTree() {
return this.$store.getters.domainsTree;
},
translations() {
return {
expand: this.trans('sidebar_expand'),
reduce: this.trans('sidebar_collapse'),
extra: this.trans('label_missing'),
extra_singular: this.trans('label_missing_singular'),
};
},
},
mounted() {
this.$store.dispatch('getDomainsTree', {
store: this.$store,
});
EventBus.$on('lastTreeItemClick', (el) => {
if (this.edited()) {
this.modal.showModal();
this.modal.$once('save', () => {
this.principal.saveTranslations();
this.itemClick(el);
});
this.modal.$once('leave', () => {
this.itemClick(el);
});
} else {
this.itemClick(el);
}
});
},
methods: {
/**
* Update the domain, retrieve the translations catalog, set the page to 1
* and reset the modified translations
* @param {object} el - Domain to set
*/
itemClick: function itemClick(el) {
this.$store.dispatch('updateCurrentDomain', el.item);
this.$store.dispatch('getCatalog', { url: el.item.dataValue });
this.$store.dispatch('updatePageIndex', 1);
this.$store.state.modifiedTranslations = [];
},
getFirstDomainToDisplay: function getFirstDomainToDisplay(tree) {
const keys = Object.keys(tree);
let toDisplay = '';
for (let i = 0; i < tree.length; i++) {
if (!tree[keys[i]].disable) {
if (tree[keys[i]].children && tree[keys[i]].children.length > 0) {
return getFirstDomainToDisplay(tree[keys[i]].children);
}
toDisplay = tree[keys[i]];
break;
}
}
return toDisplay;
},
/**
* Check if some translations have been edited
* @returns {boolean}
*/
edited: function edited() {
return this.$store.state.modifiedTranslations.length > 0;
},
},
components: {
PSTree,
PSSpinner,
},
};
</script>
<style lang="scss" type="text/scss">
@import "../../../../../../scss/config/_settings.scss";
.translationTree {
.tree-name {
margin-bottom: .9375rem;
&.active {
font-weight: bold;
}
&.extra {
color: $danger;
}
}
.tree-extra-label {
color: $danger;
text-transform: uppercase;
font-size: .65rem;
margin-left: auto;
}
.tree-extra-label-mini {
background-color: $danger;
color: #ffffff;
padding: 0 0.5rem;
border-radius: 0.75rem;
display: inline-block;
font-size: .75rem;
height: 1.5rem;
margin-left: auto;
}
.tree-label {
&:hover {
color: $primary;
}
}
}
.ps-loader {
$loader-white-height: 20px;
$loader-line-height: 16px;
.animated-background {
height: 144px!important;
animation-duration: 2s!important;
}
.background-masker {
&.header-left {
left: 0;
top: $loader-line-height;
height: 108px;
width: 20px;
}
&.content-top {
left: 0;
top: $loader-line-height;
height: $loader-white-height;
}
&.content-first-end {
left: 0;
top: $loader-line-height*2+$loader-white-height;
height: $loader-white-height;
}
&.content-second-end {
left: 0;
top: $loader-line-height*3+$loader-white-height*2;
height: $loader-white-height;
}
&.content-third-end {
left: 0;
top: $loader-line-height*4+$loader-white-height*3;
height: $loader-white-height;
}
}
}
</style>

View File

@@ -0,0 +1,42 @@
/**
* 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 Vue from 'vue';
import app from './components/app';
import store from './store/';
import router from './router';
import Translation from './mixins/translate';
Vue.mixin(Translation);
new Vue({
router,
store,
el: '#translations-app',
template: '<app />',
components: { app },
beforeMount() {
this.$store.dispatch('getTranslations');
},
});

View File

@@ -0,0 +1,31 @@
/**
* 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 {
methods: {
trans(key) {
return this.$store.getters.translations[key];
},
},
};

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 Vue from 'vue';
import VueRouter from 'vue-router';
import Overview from 'app/pages/translations/components/app';
Vue.use(VueRouter);
export default new VueRouter({
mode: 'history',
base: `${window.data.baseUrl}/translations`,
routes: [
{
path: '/',
name: 'overview',
component: Overview,
},
],
});

View File

@@ -0,0 +1,143 @@
/**
* 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 Vue from 'vue';
import VueResource from 'vue-resource';
import * as types from './mutation-types';
import { showGrowl } from 'app/utils/growl';
Vue.use(VueResource);
export const getTranslations = ({ commit }) => {
const url = window.data.translationUrl;
Vue.http.get(url).then((response) => {
commit(types.SET_TRANSLATIONS, response.body);
commit(types.APP_IS_READY);
}, (error) => {
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
});
};
export const getCatalog = ({ commit }, payload) => {
commit(types.PRINCIPAL_LOADING, true);
Vue.http.get(payload.url, {
params: {
page_size: payload.page_size,
page_index: payload.page_index,
},
}).then((response) => {
commit(types.SET_TOTAL_PAGES, response.headers.get('Total-Pages'));
commit(types.SET_CATALOG, response.body);
commit(types.PRINCIPAL_LOADING, false);
}, (error) => {
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
});
};
export const getDomainsTree = ({ commit }, payload) => {
const url = window.data.domainsTreeUrl;
const params = {};
commit(types.SIDEBAR_LOADING, true);
commit(types.PRINCIPAL_LOADING, true);
if (payload.store.getters.searchTags.length) {
params.search = payload.store.getters.searchTags;
}
Vue.http.get(url, {
params,
}).then((response) => {
commit(types.SET_DOMAINS_TREE, response.body);
commit(types.SIDEBAR_LOADING, false);
commit(types.RESET_CURRENT_DOMAIN);
}, (error) => {
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
});
};
export const refreshCounts = ({ commit }, payload) => {
const url = window.data.domainsTreeUrl;
const params = {};
if (payload.store.getters.searchTags.length) {
params.search = payload.store.getters.searchTags;
}
Vue.http.get(url, {
params,
}).then((response) => {
payload.store.state.currentDomainTotalMissingTranslations -= payload.successfullySaved;
commit(types.SET_DOMAINS_TREE, response.body);
}, (error) => {
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
});
};
export const saveTranslations = ({ commit }, payload) => {
const url = payload.url;
const translations = payload.translations;
Vue.http.post(url, {
translations,
}).then(() => {
payload.store.dispatch('refreshCounts', {
successfullySaved: translations.length,
store: payload.store,
});
payload.store.state.modifiedTranslations = [];
return showGrowl('notice', 'Translations successfully updated');
}, (error) => {
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
});
};
export const resetTranslation = ({ commit }, payload) => {
const url = payload.url;
const translations = payload.translations;
Vue.http.post(url, {
translations,
}).then(() => {
showGrowl('notice', 'Translations successfully reset');
}, (error) => {
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
});
};
export const updatePageIndex = ({ commit }, pageIndex) => {
commit(types.SET_PAGE_INDEX, pageIndex);
};
export const updateCurrentDomain = ({ commit }, currentDomain) => {
commit(types.SET_CURRENT_DOMAIN, currentDomain);
};
export const updatePrincipalLoading = ({ commit }, principalLoading) => {
commit(types.PRINCIPAL_LOADING, principalLoading);
};
export const updateSearch = ({ commit }, searchTags) => {
commit(types.SEARCH_TAGS, searchTags);
};

View File

@@ -0,0 +1,108 @@
/**
* 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 Vue from 'vue';
import Vuex from 'vuex';
import * as actions from './actions';
import mutations from './mutations';
import _ from 'lodash';
Vue.use(Vuex);
// root state object.
const state = {
pageIndex: 1,
totalPages: 0,
translationsPerPage: 20,
currentDomain: '',
translations: {
data: {},
info: {},
},
catalog: {
data: {},
info: {},
},
domainsTree: [],
totalMissingTranslations: 0,
totalTranslations: 0,
currentDomainTotalTranslations: 0,
currentDomainTotalMissingTranslations: 0,
isReady: false,
sidebarLoading: true,
principalLoading: true,
searchTags: [],
modifiedTranslations: [],
};
// getters are functions
const getters = {
totalPages(rootState) {
return rootState.totalPages;
},
pageIndex(rootState) {
return rootState.pageIndex;
},
currentDomain(rootState) {
return rootState.currentDomain;
},
translations(rootState) {
return rootState.translations;
},
catalog(rootState) {
return rootState.catalog;
},
domainsTree() {
function convert(domains) {
domains.forEach((domain) => {
domain.children = _.values(domain.children);
domain.extraLabel = domain.total_missing_translations;
domain.dataValue = domain.domain_catalog_link;
domain.warning = Boolean(domain.total_missing_translations);
domain.disable = !domain.total_translations;
domain.id = domain.full_name;
convert(domain.children);
});
return domains;
}
return convert(state.domainsTree);
},
isReady(rootState) {
return rootState.isReady;
},
searchTags(rootState) {
return rootState.searchTags;
},
};
// A Vuex instance is created by combining the state, mutations, actions,
// and getters.
export default new Vuex.Store({
state,
getters,
actions,
mutations,
});

View File

@@ -0,0 +1,35 @@
/**
* 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 const SET_TRANSLATIONS = 'SET_TRANSLATIONS';
export const SET_CATALOG = 'SET_CATALOG';
export const SET_DOMAINS_TREE = 'SET_DOMAINS_TREE';
export const APP_IS_READY = 'APP_IS_READY';
export const SET_TOTAL_PAGES = 'SET_TOTAL_PAGES';
export const SET_PAGE_INDEX = 'SET_PAGE_INDEX';
export const SET_CURRENT_DOMAIN = 'SET_CURRENT_DOMAIN';
export const RESET_CURRENT_DOMAIN = 'RESET_CURRENT_DOMAIN';
export const SIDEBAR_LOADING = 'SIDEBAR_LOADING';
export const PRINCIPAL_LOADING = 'PRINCIPAL_LOADING';
export const SEARCH_TAGS = 'SEARCH_TAGS';

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 * as types from './mutation-types';
export default {
[types.SET_TRANSLATIONS](state, translations) {
translations.data.forEach((t) => {
state.translations[t.translation_id] = t.name;
});
},
[types.SET_CATALOG](state, catalog) {
state.catalog = catalog;
},
[types.SET_DOMAINS_TREE](state, domainsTree) {
state.totalMissingTranslations = domainsTree.data.tree.total_missing_translations;
state.totalTranslations = domainsTree.data.tree.total_translations;
state.domainsTree = domainsTree.data.tree.children;
},
[types.APP_IS_READY](state) {
state.isReady = true;
},
[types.SET_TOTAL_PAGES](state, totalPages) {
state.totalPages = Number(totalPages);
},
[types.SET_PAGE_INDEX](state, pageIndex) {
state.pageIndex = pageIndex;
},
[types.SET_CURRENT_DOMAIN](state, currentDomain) {
state.currentDomain = currentDomain.full_name;
state.currentDomainTotalTranslations = currentDomain.total_translations;
state.currentDomainTotalMissingTranslations = currentDomain.total_missing_translations;
},
[types.RESET_CURRENT_DOMAIN](state) {
state.currentDomain = '';
state.currentDomainTotalTranslations = 0;
state.currentDomainTotalMissingTranslations = 0;
},
[types.SIDEBAR_LOADING](state, isLoading) {
state.sidebarLoading = isLoading;
},
[types.PRINCIPAL_LOADING](state, isLoading) {
state.principalLoading = isLoading;
},
[types.SEARCH_TAGS](state, searchTags) {
state.searchTags = searchTags;
},
};

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
*/
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
// root state object.
const state = {
};
// getters are functions
const getters = {
};
// A Vuex instance is created by combining the state, mutations, actions,
// and getters.
export default new Vuex.Store({
state,
getters,
modules: {
}
});

View File

@@ -0,0 +1,81 @@
/**
* 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 'url-polyfill';
const $ = global.$;
const replaceDatePicker = () => {
const datepickerWidget = $('body').find('.bootstrap-datetimepicker-widget:last');
if (datepickerWidget.length <= 0) {
return;
}
const position = datepickerWidget.offset();
const originalHeight = datepickerWidget.outerHeight();
const margin = (datepickerWidget.outerHeight(true) - originalHeight) / 2;
// Move datepicker to the exact same place it was but attached to body
datepickerWidget.appendTo('body');
// Height changed because the css from column-filters is not applied any more
let top = (position.top) + margin;
// Datepicker is settle to the top position
if (datepickerWidget.hasClass('top')) {
top += (originalHeight - datepickerWidget.outerHeight(true) - margin);
}
datepickerWidget.css({
position: 'absolute',
top,
bottom: 'auto',
left: position.left,
right: 'auto',
});
$(window).on('resize', replaceDatePicker);
};
/**
* Enable all datepickers.
*/
const init = function initDatePickers() {
$('.datepicker input[type="text"]').datetimepicker(
{
locale: global.full_language_code,
format: 'YYYY-MM-DD',
},
).on(
'dp.show',
replaceDatePicker,
).on(
'dp.hide',
() => {
$(window).off('resize', replaceDatePicker);
},
);
};
export default init;

View File

@@ -0,0 +1,26 @@
/**
* 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 Vue from 'vue';
export const EventBus = new Vue();

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
*/
const $ = global.$;
/**
* Enable all datepickers.
*/
const initInvalidFields = () => {
$('input,select,textarea').on('invalid', function scroll() {
this.scrollIntoView(false);
});
};
export default initInvalidFields;

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 function showGrowl(type, message) {
window.$.growl[type]({
title: '',
size: "large",
message: message,
duration: 1000
});
};

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
*/
/**
* Send a Post Request to reset search Action.
*/
const $ = global.$;
const init = function resetSearch(url, redirectUrl) {
$.post(url).then(() => window.location.assign(redirectUrl));
};
export default init;

View File

@@ -0,0 +1,162 @@
/**
* 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 Vue from 'vue';
import serp from './serp.vue';
const $ = window.$;
/**
* Vue component displaying a search page result, Google style.
* Requires a tag with the id "#serp-app" to be present in the DOM to run it.
* The component is automatically updated by watching several inputs.
* Set the proper class to link a input to a part of the panel.
*/
class SerpApp {
constructor(selectors, url) {
// If the selector cannot be found, we do not load the Vue app
if ($(selectors.container).length === 0) {
return;
}
this.originalUrl = url;
this.useMultiLang = selectors.multiLanguageInput !== undefined &&
selectors.multiLanguageItem !== undefined;
if (this.useMultiLang) {
this.multiLangInputSelector = selectors.multiLanguageInput;
this.attachMultiLangEvents(selectors.multiLanguageItem);
}
this.data = {
url,
title: '',
description: '',
};
this.vm = new Vue({
el: selectors.container,
template: '<serp ref="serp" :url="url" :title="title" :description="description" />',
components: { serp },
data: this.data,
});
this.initializeSelectors(selectors);
this.attachInputEvents();
}
attachMultiLangEvents(itemSelector) {
$('body').on(
'click',
itemSelector,
() => {
this.checkTitle();
this.checkDesc();
this.checkUrl();
},
);
}
initializeSelectors(selectors) {
this.defaultTitle = $(selectors.defaultTitle);
this.watchedTitle = $(selectors.watchedTitle);
this.defaultDescription = $(selectors.defaultDescription);
this.watchedDescription = $(selectors.watchedDescription);
this.watchedMetaUrl = $(selectors.watchedMetaUrl);
}
attachInputEvents() {
$(this.defaultTitle).on('keyup change', () => this.checkTitle());
$(this.watchedTitle).on('keyup change', () => this.checkTitle());
$(this.defaultDescription).on('keyup change', () => this.checkDesc());
$(this.watchedDescription).on('keyup change', () => this.checkDesc());
this.watchedMetaUrl.on('keyup change', () => this.checkUrl());
this.checkTitle();
this.checkDesc();
this.checkUrl();
}
setTitle(title) {
this.data.title = title;
}
setDescription(description) {
this.data.description = description;
}
setUrl(rewrite) {
this.data.url = this.originalUrl.replace(
'{friendy-url}',
rewrite,
);
}
checkTitle() {
let defaultTitle = this.defaultTitle;
let watchedTitle = this.watchedTitle;
if (this.useMultiLang) {
watchedTitle = watchedTitle.closest(this.multiLangInputSelector).find('input');
defaultTitle = defaultTitle.closest(this.multiLangInputSelector).find('input');
}
const title1 = watchedTitle.length ? watchedTitle.val() : '';
const title2 = defaultTitle.length ? defaultTitle.val() : '';
this.setTitle(title1 === '' ? title2 : title1);
// Always check for url if title change
this.checkUrl();
}
checkDesc() {
let watchedDescription = this.watchedDescription;
let defaultDescription = this.defaultDescription;
if (this.useMultiLang) {
watchedDescription = watchedDescription
.closest(this.multiLangInputSelector)
.find(this.watchedDescription.is('input') ? 'input' : 'textarea');
defaultDescription = defaultDescription
.closest(this.multiLangInputSelector)
.find(this.defaultDescription.is('input') ? 'input' : 'textarea');
}
const desc1 = watchedDescription.length ? watchedDescription.val().innerText || watchedDescription.val() : '';
const desc2 = defaultDescription.length ? $(defaultDescription.val()).text() || defaultDescription.val() : '';
this.setDescription(desc1 === '' ? desc2 : desc1);
}
checkUrl() {
let watchedMetaUrl = this.watchedMetaUrl;
if (this.useMultiLang) {
watchedMetaUrl = watchedMetaUrl.closest(this.multiLangInputSelector).find('input');
}
this.setUrl(watchedMetaUrl.val());
}
}
export default SerpApp;

View File

@@ -0,0 +1,146 @@
<!--**
* 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
*-->
<template>
<div id="serp">
<div class="serp-preview">
<div class="serp-title">{{ displayedTitle }}</div>
<div class="serp-url">{{ url }}<span class="serp-arrow"></span></div>
<div class="serp-description">{{ displayedDescription }}</div>
</div>
</div>
</template>
<script>
export default {
name: 'serp',
props: {
url: {
type: String,
default: 'https://www.example.com/',
},
description: {
type: String,
default: '',
},
title: {
type: String,
default: '',
},
},
computed: {
displayedTitle() {
if (this.title.length > 70) {
return `${this.title.substring(0, 70)}...`;
}
return this.title;
},
displayedDescription() {
if (this.description.length > 150) {
return `${this.description.substring(0, 150)}...`;
}
return this.description;
},
},
};
</script>
<style lang="scss" type="text/scss" scoped>
.serp-preview {
margin-top: 15px;
margin-bottom: 15px;
border-radius: 2px;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.12);
background-color: #ffffff;
border: solid 1px #e7e7e7;
padding: 30px;
max-width: 700px;
.serp-arrow {
border-bottom-color: rgb(0, 102, 33);
border-bottom-style: solid;
border-bottom-width: 0px;
border-left-color: rgba(0, 0, 0, 0);
border-left-style: solid;
border-left-width: 4px;
border-right-color: rgba(0, 0, 0, 0);
border-right-style: solid;
border-right-width: 4px;
border-top-color: rgb(0, 102, 33);
border-top-style: solid;
border-top-width: 5px;
color: rgb(128, 128, 128);
cursor: default;
font-family: arial, sans-serif;
font-size: 11px;
font-weight: bold;
height: 0px;
position: absolute;
line-height: 27px;
margin-left: 3px;
margin-top: 6px;
text-align: center;
user-select: none;
visibility: visible;
white-space: nowrap;
width: 0px;
}
.serp-title {
color: #1A0DAB;
cursor: pointer;
font-family: arial, regular;
font-size: 18px;
font-weight: normal;
text-align: left;
text-decoration: none;
visibility: visible;
white-space: nowrap;
}
.serp-url {
color: #006621;
font-family: arial, regular;
font-size: 14px;
font-style: normal;
font-weight: normal;
line-height: 24px;
text-align: left;
visibility: visible;
}
.serp-description {
color: #545454;
font-family: arial, regular;
font-size: 13px;
font-weight: normal;
text-align: left;
visibility: visible;
word-wrap: break-word;
}
}
</style>

View File

@@ -0,0 +1,79 @@
/**
* 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 $ = global.$;
/**
* Allow to display the last SQL query in a modal and redirect to SQL Manager.
*/
class SqlManager {
showLastSqlQuery() {
$('#catalog_sql_query_modal_content textarea[name="sql"]').val($('tbody.sql-manager').data('query'));
$('#catalog_sql_query_modal .btn-sql-submit').click(() => {
$('#catalog_sql_query_modal_content').submit();
});
$('#catalog_sql_query_modal').modal('show');
}
sendLastSqlQuery(name) {
$('#catalog_sql_query_modal_content textarea[name="sql"]').val($('tbody.sql-manager').data('query'));
$('#catalog_sql_query_modal_content input[name="name"]').val(name);
$('#catalog_sql_query_modal_content').submit();
}
createSqlQueryName() {
let container = false;
let current = false;
if ($('.breadcrumb')) {
container = $('.breadcrumb li').eq(0).text().replace(/\s+/g, ' ').trim();
current = $('.breadcrumb li').eq(-1).text().replace(/\s+/g, ' ').trim();
}
let title = false;
if ($('h2.title')) {
title = $('h2.title').first().text().replace(/\s+/g, ' ').trim();
}
let name = false;
if (container && current && container != current) {
name = container + ' > ' + current;
} else if (container) {
name = container;
} else if (current) {
name = current;
}
if (title && title != current && title != container) {
if (name) {
name = name + ' > ' + title;
} else {
name = title;
}
}
return name.trim();
}
}
export default SqlManager;

View File

@@ -0,0 +1,110 @@
/**
* 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 $ = global.$;
/**
* Makes a table sortable by columns.
* This forces a page reload with more query parameters.
*/
class TableSorting {
/**
* @param {jQuery} table
*/
constructor(table) {
this.selector = '.ps-sortable-column';
this.columns = $(table).find(this.selector);
}
/**
* Attaches the listeners
*/
attach() {
this.columns.on('click', (e) => {
const $column = $(e.delegateTarget);
this._sortByColumn($column, this._getToggledSortDirection($column));
});
}
/**
* Sort using a column name
* @param {string} columnName
* @param {string} direction "asc" or "desc"
*/
sortBy(columnName, direction) {
const $column = this.columns.is(`[data-sort-col-name="${columnName}"]`);
if (!$column) {
throw new Error(`Cannot sort by "${columnName}": invalid column`);
}
this._sortByColumn($column, direction);
}
/**
* Sort using a column element
* @param {jQuery} column
* @param {string} direction "asc" or "desc"
* @private
*/
_sortByColumn(column, direction) {
window.location = this._getUrl(column.data('sortColName'), (direction === 'desc') ? 'desc' : 'asc', column.data('sortPrefix'));
}
/**
* Returns the inverted direction to sort according to the column's current one
* @param {jQuery} column
* @return {string}
* @private
*/
_getToggledSortDirection(column) {
return column.data('sortDirection') === 'asc' ? 'desc' : 'asc';
}
/**
* Returns the url for the sorted table
* @param {string} colName
* @param {string} direction
* @param {string} prefix
* @return {string}
* @private
*/
_getUrl(colName, direction, prefix) {
const url = new URL(window.location.href);
const params = url.searchParams;
if (prefix) {
params.set(prefix+'[orderBy]', colName);
params.set(prefix+'[sortOrder]', direction);
} else {
params.set('orderBy', colName);
params.set('sortOrder', direction);
}
return url.toString();
}
}
export default TableSorting;

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
*-->
<template>
<div class="ps-alert alert" :class="classObject" role="alert">
<button
v-if="hasClose"
type="button"
class="close"
data-dismiss="alert"
aria-label="Close"
@click.stop="onClick"
>
<span class="material-icons">close</span>
</button>
<p class="alert-text">
<slot />
</p>
</div>
</template>
<script>
const ALERT_TYPE_INFO = 'ALERT_TYPE_INFO';
const ALERT_TYPE_WARNING = 'ALERT_TYPE_WARNING';
const ALERT_TYPE_DANGER = 'ALERT_TYPE_DANGER';
const ALERT_TYPE_SUCCESS = 'ALERT_TYPE_SUCCESS';
export default {
props: {
duration: false,
alertType: { type: String, required: true },
hasClose: { type: Boolean, required: true },
},
computed: {
classObject() {
return {
'alert-info': this.alertType === ALERT_TYPE_INFO,
'alert-warning': this.alertType === ALERT_TYPE_WARNING,
'alert-danger': this.alertType === ALERT_TYPE_DANGER,
'alert-success': this.alertType === ALERT_TYPE_SUCCESS,
};
},
isInfo() {
return this.alertType === ALERT_TYPE_INFO;
},
},
methods: {
onClick() {
this.$emit('closeAlert');
},
},
};
</script>

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
*-->
<template>
<button type="button" class="btn" :class="classObject" @click="onClick" >
<slot />
</button>
</template>
<script>
export default {
props: {
primary: { type: Boolean },
ghost: { type: Boolean },
},
computed: {
classObject() {
if (this.ghost) {
return {
'btn-outline-primary': this.primary,
'btn-outline-secondary': !this.primary,
};
}
return {
'btn-primary': this.primary,
'btn-secondary': !this.primary,
};
},
},
methods: {
onClick() {
this.$emit('click');
},
},
};
</script>

View File

@@ -0,0 +1,63 @@
<!--**
* 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
*-->
<template>
<div class="md-checkbox">
<label>
<input type="checkbox" :id="id" v-model="checked" :class="{'indeterminate' : isIndeterminate }">
<i class="md-checkbox-control"></i>
<slot name="label"></slot>
</label>
</div>
</template>
<script>
export default {
props: {
id: {
type: String,
},
model: {
type: Object,
required: false,
},
isIndeterminate: {
type: Boolean,
required: false,
default: false,
},
},
watch: {
checked(val) {
this.$emit('checked', {
checked: val,
item: this.model,
});
},
},
data: () => ({
checked: false,
}),
};
</script>

View File

@@ -0,0 +1,84 @@
<!--**
* 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
*-->
<template>
<div class="input-group date">
<input ref="datepicker" type="text" class="form-control" />
<div class="input-group-append">
<span class="input-group-text">
<i class="material-icons">event</i>
</span>
</div>
</div>
</template>
<script>
export default {
props: {
locale: {
type: String,
required: true,
default: 'en',
},
type: {
type: String,
required: true,
},
},
mounted() {
$(this.$refs.datepicker).datetimepicker({
format: 'YYYY-MM-DD',
showClear: true,
}).on('dp.change', (infos) => {
infos.dateType = this.type;
this.$emit(
infos.date ? 'dpChange' : 'reset',
infos,
);
});
},
};
</script>
<style lang="scss">
@import "../../../scss/config/_settings.scss";
.date {
a[data-action='clear']::before {
font-family: 'Material Icons';
content: "\E14C";
font-size: 20px;
position: absolute;
bottom: 15px;
left: 50%;
margin-left: -10px;
color: $gray-dark;
cursor:pointer;
}
.bootstrap-datetimepicker-widget tr td span:hover {
background-color: white;
}
}
</style>

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
*-->
<template>
<div class="ps-loader">
<div class="timeline-item">
<div class="animated-background">
<slot />
</div>
</div>
</div>
</template>
<script>
export default {
props: ['thumb'],
};
</script>
<style lang="scss" scoped>
@import "../../../scss/config/_settings.scss";
.ps-loader {
width: 100%;
.animated-background {
animation-duration: 1s;
animation-iteration-count: infinite;
animation-name: loading;
animation-timing-function: linear;
background: $gray-soft;
background: linear-gradient(to right, $gray-soft 8%, #ccc 18%, $gray-soft 33%);
background-size: 100%;
height: 40px;
position: relative;
}
.background-masker {
background: white;
position: absolute;
}
}
@keyframes loading{
0%{
background-position: -500px 0
}
100%{
background-position: 500px 0
}
}
</style>

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
*-->
<template>
<div class="media">
<img v-if="displayThumb" :src="thumbnail" class="thumbnail d-flex" />
<div v-else class="no-img"></div>
<div class="ml-2 desc media-body">
<slot />
</div>
</div>
</template>
<script>
export default {
props: ['thumbnail'],
computed: {
displayThumb() {
return !!this.thumbnail;
},
},
};
</script>
<style lang="scss" scoped>
@import "../../../scss/config/_settings.scss";
.product-title {
.has-combination & {
font-weight: 600;
}
}
.thumbnail, .no-img {
border: $gray-light 1px solid;
max-width: 47px;
}
.no-img {
background: white;
width: 47px;
height: 47px;
display: inline-block;
vertical-align: middle;
}
.desc {
white-space: normal;
}
small {
color: $gray-medium;
}
</style>

View File

@@ -0,0 +1,97 @@
<!--**
* 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
*-->
<template>
<div class="modal fade" id="ps-modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">
<i class="material-icons">close</i>
</button>
<h4 class="modal-title">{{translations.modal_title}}</h4>
</div>
<div class="modal-body">
{{translations.modal_content}}
</div>
<div class="modal-footer">
<PSButton @click="onSave" class="btn-lg" primary data-dismiss="modal">{{translations.button_save}}</PSButton>
<PSButton @click="onLeave" class="btn-lg" ghost data-dismiss="modal">{{translations.button_leave}}</PSButton>
</div>
</div>
</div>
</div>
</template>
<script>
import PSButton from 'app/widgets/ps-button';
import { EventBus } from 'app/utils/event-bus';
export default {
props: {
translations: {
type: Object,
required: false,
},
},
mounted() {
EventBus.$on('showModal', () => {
this.showModal();
});
EventBus.$on('hideModal', () => {
this.hideModal();
});
},
methods: {
showModal() {
$(this.$el).modal('show');
},
hideModal() {
$(this.$el).modal('hide');
},
onSave() {
this.$emit('save');
},
onLeave() {
this.$emit('leave');
},
},
components: {
PSButton,
},
};
</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>

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
*-->
<template>
<div class="ps-number" :class="{'hover-buttons': hoverButtons}">
<input
type="number"
class="form-control"
:class="{'danger': danger}"
:value="value"
placeholder="0"
@keyup="onKeyup($event)"
@focus="focusIn"
@blur.native="focusOut($event)"
/>
<div class="ps-number-spinner d-flex" v-if="buttons">
<span class="ps-number-up" @click="increment"></span>
<span class="ps-number-down" @click="decrement"></span>
</div>
</div>
</template>
<script>
export default {
props: {
value: '',
danger: false,
buttons: false,
hoverButtons: false,
},
methods: {
onKeyup($event) {
this.$emit('keyup', $event);
},
focusIn() {
this.$emit('focus');
},
focusOut($event) {
this.$emit('blur', $event);
},
increment() {
const value = parseInt(this.value === '' ? 0 : this.value, 10);
this.$emit('change', isNaN(value) ? 0 : value + 1);
},
decrement() {
const value = parseInt(this.value, 10);
this.$emit('change', isNaN(value) ? -1 : value - 1);
},
},
};
</script>

View File

@@ -0,0 +1,125 @@
<!--**
* 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
*-->
<template>
<nav class="mt-1 mx-auto" v-if="displayPagination">
<ul class="pagination" :class="{'multi':isMultiPagination}">
<li v-if="isMultiPagination" class="page-item previous">
<a v-show="activeLeftArrow" class="float-left page-link" @click="prev($event)" href="#">
<span class="sr-only">Previous</span>
</a>
</li>
<li class="page-item" :class="{'active' : checkCurrentIndex(index)}" v-for="index in pagesCount">
<a
v-if="showIndex(index)"
class="page-link"
:class="{
'pl-0' : showFirstDots(index),
'pr-0' : showLastDots(index)
}"
@click.prevent="changePage(index)"
href="#"
>
<span v-if="isMultiPagination" v-show="showFirstDots(index)">...</span>
{{ index }}
<span v-if="isMultiPagination" v-show="showLastDots(index)">...</span>
</a>
</li>
<li v-if="isMultiPagination" class="page-item next">
<a v-show="activeRightArrow" class="float-left page-link" @click="next($event)" href="#">
<span class="sr-only">Next</span>
</a>
</li>
</ul>
</nav>
</template>
<script>
export default {
props: ['pagesCount', 'currentIndex'],
computed: {
isMultiPagination() {
return this.pagesCount > this.multiPagesActivationLimit;
},
activeLeftArrow() {
return this.currentIndex !== 1;
},
activeRightArrow() {
return this.currentIndex !== this.pagesCount;
},
pagesToDisplay() {
return this.multiPagesToDisplay;
},
displayPagination() {
return this.pagesCount > 1;
},
},
methods: {
checkCurrentIndex(index) {
return this.currentIndex === index;
},
showIndex(index) {
const startPaginationIndex = index < this.currentIndex + this.multiPagesToDisplay;
const lastPaginationIndex = index > this.currentIndex - this.multiPagesToDisplay;
const indexToDisplay = startPaginationIndex && lastPaginationIndex;
const lastIndex = index === this.pagesCount;
const firstIndex = index === 1;
if (!this.isMultiPagination) {
return !this.isMultiPagination;
}
return indexToDisplay || firstIndex || lastIndex;
},
changePage(pageIndex) {
this.$emit('pageChanged', pageIndex);
},
showFirstDots(index) {
const pagesToDisplay = this.pagesCount - this.multiPagesToDisplay;
if (!this.isMultiPagination) {
return this.isMultiPagination;
}
return index === this.pagesCount && this.currentIndex <= pagesToDisplay;
},
showLastDots(index) {
if (!this.isMultiPagination) {
return this.isMultiPagination;
}
return index === 1 && this.currentIndex > this.multiPagesToDisplay;
},
prev() {
if (this.currentIndex > 1) {
this.changePage(this.currentIndex - 1);
}
},
next() {
if (this.currentIndex < this.pagesCount) {
this.changePage(this.currentIndex + 1);
}
},
},
data: () => ({
multiPagesToDisplay: 2,
multiPagesActivationLimit: 5,
}),
};
</script>

View File

@@ -0,0 +1,47 @@
<!--**
* 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
*-->
<template>
<div class="ps-radio">
<input type="radio" :id="id" name="radio-group" :checked="checked" @change="onChange">
<label :for="id">{{label}}</label>
</div>
</template>
<script>
export default{
props: {
id: { type: String, required: true },
label: { type: String, required: false },
checked: { type: Boolean, required: false },
value: { type: String, required: false },
},
methods: {
onChange() {
this.$emit('change', this.value);
},
},
};
</script>

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
*-->
<template>
<div class="ps-select">
<select class="form-control" v-model="selected" @change="onChange">
<option value="default" selected>
<slot />
</option>
<option
v-for="item in items"
:value="item[itemID]"
>
{{item[itemName]}}
</option>
</select>
</div>
</template>
<script>
export default {
props: ['items', 'itemID', 'itemName'],
methods: {
onChange() {
this.$emit('change', {
value: this.selected,
itemID: this.itemID,
});
},
},
data: () => ({ selected: 'default' }),
};
</script>
<style lang="scss" scoped>
@import "../../../scss/config/_settings.scss";
.ps-select {
position: relative;
select {
appearance: none;
border-radius: 0;
}
&::after {
content: "\E313";
font-family: 'Material Icons';
color: $gray-medium;
font-size: 20px;
position: absolute;
right: 5px;
top: 5px;
}
}
</style>

View File

@@ -0,0 +1,27 @@
<!--**
* 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
*-->
<template>
<div class="ps-spinner"></div>
</template>

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
*-->
<template>
<div class="ps-sortable-column" data-sort-col-name="id_product" :data-sort-is-current="isCurrent" :data-sort-direction="sortDirection" @click="sortToggle">
<span role="columnheader"><slot /></span>
<span role="button" class="ps-sort" aria-label="Tri"></span>
</div>
</template>
<script>
export default {
props: {
// column name
order: String,
// indicates the currently sorted column in the table
currentSort: String,
},
methods: {
sortToggle() {
// toggle direction
this.sortDirection = (this.sortDirection === 'asc') ? 'desc' : 'asc';
this.$emit('sort', this.order, this.sortDirection);
},
},
data: () => ({
sortDirection: 'asc',
}),
computed: {
isCurrent() {
return this.currentSort === this.order;
},
},
};
</script>

View File

@@ -0,0 +1,31 @@
<!--**
* 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
*-->
<template>
<div class="table-responsive">
<table class="table">
<slot />
</table>
</div>
</template>

View File

@@ -0,0 +1,86 @@
<!--**
* 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
*-->
<template>
<div class="tags-input search-input search d-flex flex-wrap" :class="{ 'search-with-icon': hasIcon }" @click="focus()">
<div class="tags-wrapper">
<span v-for="(tag, index) in tags" class="tag">{{ tag }}<i class="material-icons" @click="close(index)">close</i></span>
</div>
<input
ref = "tags"
:placeholder="placeholderToDisplay"
type="text"
v-model="tag"
class="form-control input"
@keyup="onKeyUp"
@keydown.enter="add(tag)"
@keydown.delete.stop="remove()"
:size="inputSize"
/>
</div>
</template>
<script>
export default {
props: ['tags', 'placeholder', 'hasIcon'],
computed: {
inputSize() {
return !this.tags.length && this.placeholder ? this.placeholder.length : 0;
},
placeholderToDisplay() {
return this.tags.length ? '' : this.placeholder;
},
},
methods: {
onKeyUp() {
this.$emit('typing', this.$refs.tags.value);
},
add(tag) {
if (tag) {
this.tags.push(tag.trim());
this.tag = '';
this.focus();
this.$emit('tagChange', this.tag);
}
},
close(index) {
const tagName = this.tags[index];
this.tags.splice(index, 1);
this.$emit('tagChange', tagName);
},
remove() {
if (this.tags.length && !this.tag.length) {
const tagName = this.tags[this.tags.length - 1];
this.tags.pop();
this.$emit('tagChange', tagName);
}
},
focus() {
this.$refs.tags.focus();
},
},
data: () => ({ tag: null }),
};
</script>

View File

@@ -0,0 +1,157 @@
<!--**
* 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
*-->
<template>
<div class="ps-tree-items" :class="{className}">
<div class="d-flex tree-name" :class="{active: active, disable: model.disable}" @click="clickElement">
<button class="btn btn-text" :class="[{hidden: isHidden}, chevronStatus]">
<span v-if="translations" class="sr-only">{{this.model.open ? translations.reduce : translations.expand}}</span>
</button>
<PSCheckbox :ref="model.name" :id="id" :model="model" @checked="onCheck" v-if="hasCheckbox"/>
<span class="tree-label" :class="{warning: isWarning}">{{model.name}}</span>
<span class="tree-extra-label d-sm-none d-xl-inline-block" v-if="displayExtraLabel">{{getExtraLabel}}</span>
<span class="tree-extra-label-mini d-xl-none" v-if="displayExtraLabel">{{this.model.extraLabel}}</span>
</div>
<ul v-show="open" v-if="isFolder" class="tree">
<li v-for="(element, index) in model.children" class="tree-item" :class="{disable: model.disable}">
<PSTreeItem
:ref="element.id"
:class="className"
:hasCheckbox="hasCheckbox"
:model="element"
:label="element.name"
:translations="translations"
:currentItem="currentItem"
@checked="onCheck"
@setCurrentElement ="setCurrentElement"
/>
</li>
</ul>
</div>
</template>
<script>
import PSCheckbox from 'app/widgets/ps-checkbox';
import { EventBus } from 'app/utils/event-bus';
export default {
name: 'PSTreeItem',
props: {
model: { type: Object, required: true },
className: { type: String, required: false },
hasCheckbox: { type: Boolean, required: false },
translations: { type: Object, required: false },
currentItem: { type: String, required: false },
},
computed: {
id() {
return this.model.id;
},
isFolder() {
return this.model.children && this.model.children.length;
},
displayExtraLabel() {
return this.isFolder && this.model.extraLabel;
},
getExtraLabel() {
let extraLabel = '';
if (this.model.extraLabel && this.model.extraLabel === 1) {
extraLabel = this.translations.extra_singular;
} else if (this.model.extraLabel) {
extraLabel = this.translations.extra.replace('%d', this.model.extraLabel);
}
return extraLabel;
},
isHidden() {
return !this.isFolder;
},
chevronStatus() {
return this.open? 'open' : 'closed';
},
isWarning() {
return !this.isFolder && this.model.warning;
},
active() {
return this.model.full_name === this.currentItem;
},
},
methods: {
setCurrentElement(el) {
if (this.$refs[el]) {
this.openTreeItemAction();
this.current = true;
this.parentElement(this.$parent);
} else {
this.current = false;
}
},
parentElement(parent) {
if (parent.clickElement) {
parent.clickElement();
this.parentElement(parent.$parent);
}
},
clickElement() {
return !this.model.disable ? this.openTreeItemAction() : false;
},
openTreeItemAction() {
this.setCurrentElement(this.model.full_name);
if (this.isFolder) {
this.open = !this.open;
} else {
EventBus.$emit('lastTreeItemClick', {
item: this.model,
});
}
},
onCheck(obj) {
this.$emit('checked', obj);
},
},
mounted() {
EventBus.$on('toggleCheckbox', (tag) => {
const checkbox = this.$refs[tag];
if (checkbox) {
checkbox.$data.checked = !checkbox.$data.checked;
}
}).$on('expand', () => {
this.open = true;
}).$on('reduce', () => {
this.open = false;
}).$on('setCurrentElement', (el) => {
this.setCurrentElement(el);
});
this.setCurrentElement(this.currentItem);
},
components: {
PSCheckbox,
},
data: () => ({
open: false,
current: false,
}),
};
</script>

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
*-->
<template>
<div class="ps-tree">
<div class="mb-3 tree-header">
<button class="btn btn-text text-uppercase pointer" @click="expand">
<i class="material-icons">keyboard_arrow_down</i>
<span v-if="translations">{{translations.expand}}</span>
</button>
<button class="btn btn-text float-right text-uppercase pointer" @click="reduce">
<i class="material-icons">keyboard_arrow_up</i>
<span v-if="translations">{{translations.reduce}}</span>
</button>
</div>
<ul class="tree" :class="className">
<li v-for="(element, index) in model">
<PSTreeItem
ref="item"
:hasCheckbox="hasCheckbox"
:model="element"
:label="element.name"
:translations="translations"
:currentItem="currentItem"
@checked="onCheck"
@setCurrentElement ="setCurrentElement"
/>
</li>
</ul>
</div>
</template>
<script>
import PSTreeItem from './ps-tree-item';
import { EventBus } from 'app/utils/event-bus';
export default {
name: 'PSTree',
props: {
model: Array,
className: String,
currentItem: String,
hasCheckbox: Boolean,
translations: {
type: Object,
required: false,
},
},
methods: {
onCheck(obj) {
this.$emit('checked', obj);
},
expand() {
EventBus.$emit('expand');
},
reduce() {
EventBus.$emit('reduce');
},
setCurrentElement(id) {
EventBus.$emit('setCurrentElement', id);
},
},
components: {
PSTreeItem,
},
};
</script>

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
*/
/**
* By default, bootstrap dropdowns close down when the user clicks anywhere.
* This plugin allows clicking inside the dropdown menu while keeping it open.
* In order to make a dropdown behave like this, simply add the class "dropdown-clickable" to its parent element.
*/
(($) => {
$.fn.clickableDropdown = function clickableDropdown() {
$(document).on('click', '.dropdown-clickable .dropdown-menu', (e) => {
e.stopPropagation();
});
return this;
};
// hook up the plugin
$(function initClickableDropdown() {
$(document).clickableDropdown();
});
})(window.$);

View File

@@ -0,0 +1,98 @@
/**
* 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 connecting to addons marketplace.
* Makes an addons connect request to the server, displays error messages if it fails.
*/
export default class AddonsConnector {
constructor(
addonsConnectFormSelector,
loadingSpinnerSelector
) {
this.addonsConnectFormSelector = addonsConnectFormSelector;
this.$loadingSpinner = $(loadingSpinnerSelector);
this._initEvents();
return {};
}
/**
* Initialize events related to connection to addons.
*
* @private
*/
_initEvents() {
$('body').on('submit', this.addonsConnectFormSelector, (event) => {
const $form = $(event.currentTarget);
event.preventDefault();
event.stopPropagation();
this._connect($form.attr('action'), $form.serialize());
});
}
/**
* Do a POST request to connect to addons.
*
* @param {String} addonsConnectUrl
* @param {Object} formData
*
* @private
*/
_connect(addonsConnectUrl, formData) {
$.ajax({
method: 'POST',
url: addonsConnectUrl,
dataType: 'json',
data: formData,
beforeSend: () => {
this.$loadingSpinner.show();
$('button.btn[type="submit"]', this.addonsConnectFormSelector).hide();
}
}).then((response) => {
if (response.success === 1) {
location.reload();
} else {
$.growl.error({
message: response.message
});
this.$loadingSpinner.hide();
$('button.btn[type="submit"]', this.addonsConnectFormSelector).fadeIn();
}
}, () => {
$.growl.error({
message: $(this.addonsConnectFormSelector).data('error-message'),
});
this.$loadingSpinner.hide();
$('button.btn[type="submit"]', this.addonsConnectFormSelector).show();
});
}
}

View File

@@ -0,0 +1,130 @@
/**
* 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.$;
/**
* Generates a password and informs about it's strength.
* You can pass a password input to watch the password strength and display feedback messages.
* You can also generate a random password into an input.
*/
export default class ChangePasswordHandler {
constructor(passwordStrengthFeedbackContainerSelector, options = {}) {
// Minimum length of the generated password.
this.minLength = options.minLength || 8;
// Feedback container holds messages representing password strength.
this.$feedbackContainer = $(passwordStrengthFeedbackContainerSelector);
return {
watchPasswordStrength: ($input) => this.watchPasswordStrength($input),
generatePassword: ($input) => this.generatePassword($input),
};
}
/**
* Watch password, which is entered in the input, strength and inform about it.
*
* @param {jQuery} $input the input to watch.
*/
watchPasswordStrength($input) {
$.passy.requirements.length.min = this.minLength;
$.passy.requirements.characters = 'DIGIT';
$input.each((index, element) => {
const $outputContainer = $('<span>');
$outputContainer.insertAfter($(element));
$(element).passy((strength, valid) => {
this._displayFeedback($outputContainer, strength, valid);
});
});
}
/**
* Generates a password and fills it to given input.
*
* @param {jQuery} $input the input to fill the password into.
*/
generatePassword($input) {
$input.passy('generate', this.minLength);
}
/**
* Display feedback about password's strength.
*
* @param {jQuery} $outputContainer a container to put feedback output into.
* @param {number} passwordStrength
* @param {boolean} isPasswordValid
*
* @private
*/
_displayFeedback($outputContainer, passwordStrength, isPasswordValid) {
const feedback = this._getPasswordStrengthFeedback(passwordStrength);
$outputContainer.text(feedback.message);
$outputContainer.removeClass('text-danger text-warning text-success');
$outputContainer.addClass(feedback.elementClass);
$outputContainer.toggleClass('d-none', !isPasswordValid);
}
/**
* Get feedback that describes given password strength.
* Response contains text message and element class.
*
* @param {number} strength
*
* @private
*/
_getPasswordStrengthFeedback(strength) {
switch (strength) {
case $.passy.strength.LOW:
return {
message: this.$feedbackContainer.find('.strength-low').text(),
elementClass: 'text-danger',
};
case $.passy.strength.MEDIUM:
return {
message: this.$feedbackContainer.find('.strength-medium').text(),
elementClass: 'text-warning',
};
case $.passy.strength.HIGH:
return {
message: this.$feedbackContainer.find('.strength-high').text(),
elementClass: 'text-success',
};
case $.passy.strength.EXTREME:
return {
message: this.$feedbackContainer.find('.strength-extreme').text(),
elementClass: 'text-success',
};
}
throw 'Invalid password strength indicator.';
}
}

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
*/
const $ = window.$;
/**
* ChoiceTable is responsible for managing common actions in choice table form type
*/
export default class ChoiceTable {
/**
* Init constructor
*/
constructor() {
$(document).on('change', '.js-choice-table-select-all', (e) => {
this.handleSelectAll(e);
});
}
/**
* Check/uncheck all boxes in table
*
* @param {Event} event
*/
handleSelectAll(event) {
const $selectAllCheckboxes = $(event.target);
const isSelectAllChecked = $selectAllCheckboxes.is(':checked');
$selectAllCheckboxes.closest('table').find('tbody input:checkbox').prop('checked', isSelectAllChecked);
}
}

View File

@@ -0,0 +1,72 @@
/**
* 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.$;
/**
* Toggle DNI input requirement on country selection
*
* Usage:
*
* <!-- Country select options must have need_dni attribute when needed -->
* <select name="id_country" id="id_country" states-url="path/to/states/api">
* ...
* <option value="6" need_dni="1">Spain</value>
* ...
* </select>
*
* In JS:
*
* new CountryDniRequiredToggler('#id_country', '#id_country_dni', 'label[for="id_country_dni"]');
*/
export default class CountryDniRequiredToggler {
constructor(countryInputSelector, countryDniInput, countryDniInputLabel) {
this.$countryDniInput = $(countryDniInput);
this.$countryDniInputLabel = $(countryDniInputLabel);
this.$countryInput = $(countryInputSelector);
this.countryInputSelectedSelector = `${countryInputSelector}>option:selected`;
this.countryDniInputLabelDangerSelector = `${countryDniInputLabel}>span.text-danger`;
this.$countryInput.on('change', () => this._toggle());
// toggle on page load
this._toggle();
}
/**
* Toggles DNI input required
*
* @private
*/
_toggle() {
const $countrySelectedOption = $(this.countryInputSelectedSelector);
$(this.countryDniInputLabelDangerSelector).remove();
this.$countryDniInput.attr('required', false);
if (1 === parseInt($countrySelectedOption.attr('need_dni'), 10)) {
this.$countryDniInput.attr('required', true);
this.$countryDniInputLabel.prepend($('<span class="text-danger">*</span>'));
}
}
}

View File

@@ -0,0 +1,98 @@
/**
* 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.$;
/**
* Displays, fills or hides State selection block depending on selected country.
*
* Usage:
*
* <!-- Country select must have unique identifier & url for states API -->
* <select name="id_country" id="id_country" states-url="path/to/states/api">
* ...
* </select>
*
* <!-- If selected country does not have states, then this block will be hidden -->
* <div class="js-state-selection-block">
* <select name="id_state">
* ...
* </select>
* </div>
*
* In JS:
*
* new CountryStateSelectionToggler('#id_country', '#id_state', '.js-state-selection-block');
*/
export default class CountryStateSelectionToggler {
constructor(countryInputSelector, countryStateSelector, stateSelectionBlockSelector) {
this.$stateSelectionBlock = $(stateSelectionBlockSelector);
this.$countryStateSelector = $(countryStateSelector);
this.$countryInput = $(countryInputSelector);
this.$countryInput.on('change', () => this._toggle());
// toggle on page load
this._toggle(true);
return {};
}
/**
* Toggles State selection
*
* @private
*/
_toggle(isFirstToggle = false) {
$.ajax({
url: this.$countryInput.data('states-url'),
method: 'GET',
dataType: 'json',
data: {
id_country: this.$countryInput.val(),
}
}).then((response) => {
if (response.states.length === 0) {
this.$stateSelectionBlock.fadeOut();
return;
}
this.$stateSelectionBlock.fadeIn();
if (isFirstToggle === false) {
this.$countryStateSelector.empty();
var _this = this;
$.each(response.states, function (index, value) {
_this.$countryStateSelector.append($('<option></option>').attr('value', value).text(index));
})
}
}).catch((response) => {
if (typeof response.responseJSON !== 'undefined') {
showErrorMessage(response.responseJSON.message);
}
});
}
}

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 EventEmitterClass from 'events';
/**
* We instanciate one EventEmitter (restricted via a const) so that every components
* register/dispatch on the same one and can communicate with each other.
*/
export const EventEmitter = new EventEmitterClass();

View File

@@ -0,0 +1,79 @@
/**
* 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.$;
/**
* Component which allows submitting very simple forms without having to use <form> element.
*
* Useful when performing actions on resource where URL contains all needed data.
* For example, to toggle category status via "POST /categories/2/toggle-status)"
* or delete cover image via "POST /categories/2/delete-cover-image".
*
* Usage example in template:
*
* <button class="js-form-submit-btn"
* data-form-submit-url="/my-custom-url" // (required) URL to which form will be submitted
* data-form-csrf-token="my-generated-csrf-token" // (optional) to increase security
* data-form-confirm-message="Are you sure?" // (optional) to confirm action before submit
* type="button" // make sure its simple button
* // so we can avoid submitting actual form
* // when our button is defined inside form
* >
* Click me to submit form
* </button>
*
* In page specific JS you have to enable this feature:
*
* new FormSubmitButton();
*/
export default class FormSubmitButton {
constructor() {
$(document).on('click', '.js-form-submit-btn', function (event) {
event.preventDefault();
const $btn = $(this);
if ($btn.data('form-confirm-message') && false === confirm($btn.data('form-confirm-message'))) {
return;
}
const $form = $('<form>', {
'action': $btn.data('form-submit-url'),
'method': 'POST',
});
if ($btn.data('form-csrf-token')) {
$form.append($('<input>', {
'type': '_hidden',
'name': '_csrf_token',
'value': $btn.data('form-csrf-token')
}));
}
$form.appendTo('body').submit();
});
}
}

View File

@@ -0,0 +1,248 @@
/**
* 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 ChangePasswordHandler from "../change-password-handler";
import PasswordValidator from "../password-validator";
const $ = window.$;
/**
* Class responsible for actions related to "change password" form type.
* Generates random passwords, validates new password and it's confirmation,
* displays error messages related to validation.
*/
export default class ChangePasswordControl {
constructor(
inputsBlockSelector,
showButtonSelector,
hideButtonSelector,
generatePasswordButtonSelector,
oldPasswordInputSelector,
newPasswordInputSelector,
confirmNewPasswordInputSelector,
generatedPasswordDisplaySelector,
passwordStrengthFeedbackContainerSelector
) {
// Block that contains password inputs
this.$inputsBlock = $(inputsBlockSelector);
// Button that shows the password inputs block
this.showButtonSelector = showButtonSelector;
// Button that hides the password inputs block
this.hideButtonSelector = hideButtonSelector;
// Button that generates a random password
this.generatePasswordButtonSelector = generatePasswordButtonSelector;
// Input to enter old password
this.oldPasswordInputSelector = oldPasswordInputSelector;
// Input to enter new password
this.newPasswordInputSelector = newPasswordInputSelector;
// Input to confirm the new password
this.confirmNewPasswordInputSelector = confirmNewPasswordInputSelector;
// Input that displays generated random password
this.generatedPasswordDisplaySelector = generatedPasswordDisplaySelector;
// Main input for password generation
this.$newPasswordInputs = this.$inputsBlock
.find(this.newPasswordInputSelector);
// Generated password will be copied to these inputs
this.$copyPasswordInputs = this.$inputsBlock
.find(this.confirmNewPasswordInputSelector)
.add(this.generatedPasswordDisplaySelector);
// All inputs in the change password block, that are submittable with the form.
this.$submittableInputs = this.$inputsBlock
.find(this.oldPasswordInputSelector)
.add(this.newPasswordInputSelector)
.add(this.confirmNewPasswordInputSelector);
this.passwordHandler = new ChangePasswordHandler(
passwordStrengthFeedbackContainerSelector
);
this.passwordValidator = new PasswordValidator(
this.newPasswordInputSelector,
this.confirmNewPasswordInputSelector
);
this._hideInputsBlock();
this._initEvents();
return {};
}
/**
* Initialize events.
*
* @private
*/
_initEvents() {
// Show the inputs block when show button is clicked
$(document).on('click', this.showButtonSelector, (e) => {
this._hide($(e.currentTarget));
this._showInputsBlock();
});
$(document).on('click', this.hideButtonSelector, () => {
this._hideInputsBlock();
this._show($(this.showButtonSelector));
});
// Watch and display feedback about password's strength
this.passwordHandler.watchPasswordStrength(this.$newPasswordInputs);
$(document).on('click', this.generatePasswordButtonSelector, () => {
// Generate the password into main input.
this.passwordHandler.generatePassword(this.$newPasswordInputs);
// Copy the generated password from main input to additional inputs
this.$copyPasswordInputs.val(this.$newPasswordInputs.val());
this._checkPasswordValidity();
});
// Validate new password and it's confirmation when any of the inputs is changed
$(document).on('keyup', `${this.newPasswordInputSelector},${this.confirmNewPasswordInputSelector}`, () => {
this._checkPasswordValidity();
});
// Prevent submitting the form if new password is not valid
$(document).on('submit', $(this.oldPasswordInputSelector).closest('form'), (event) => {
// If password input is disabled - we don't need to validate it.
if ($(this.oldPasswordInputSelector).is(':disabled')) {
return;
}
if (!this.passwordValidator.isPasswordValid()) {
event.preventDefault();
}
});
}
/**
* Check if password is valid, show error messages if it's not.
*
* @private
*/
_checkPasswordValidity() {
const $firstPasswordErrorContainer = $(this.newPasswordInputSelector).parent().find('.form-text');
const $secondPasswordErrorContainer = $(this.confirmNewPasswordInputSelector).parent().find('.form-text');
$firstPasswordErrorContainer
.text(this._getPasswordLengthValidationMessage())
.toggleClass('text-danger', !this.passwordValidator.isPasswordLengthValid())
;
$secondPasswordErrorContainer
.text(this._getPasswordConfirmationValidationMessage())
.toggleClass('text-danger', !this.passwordValidator.isPasswordMatchingConfirmation())
;
}
/**
* Get password confirmation validation message.
*
* @returns {String}
*
* @private
*/
_getPasswordConfirmationValidationMessage() {
if (!this.passwordValidator.isPasswordMatchingConfirmation()) {
return $(this.confirmNewPasswordInputSelector).data('invalid-password');
}
return '';
}
/**
* Get password length validation message.
*
* @returns {String}
*
* @private
*/
_getPasswordLengthValidationMessage() {
if (this.passwordValidator.isPasswordTooShort()) {
return $(this.newPasswordInputSelector).data('password-too-short')
}
if (this.passwordValidator.isPasswordTooLong()) {
return $(this.newPasswordInputSelector).data('password-too-long');
}
return '';
}
/**
* Show the password inputs block.
*
* @private
*/
_showInputsBlock() {
this._show(this.$inputsBlock);
this.$submittableInputs.removeAttr('disabled');
this.$submittableInputs.attr('required', 'required');
}
/**
* Hide the password inputs block.
*
* @private
*/
_hideInputsBlock() {
this._hide(this.$inputsBlock);
this.$submittableInputs.attr('disabled', 'disabled');
this.$submittableInputs.removeAttr('required');
this.$inputsBlock.find('input').val('');
this.$inputsBlock.find('.form-text').text('');
}
/**
* Hide an element.
*
* @param {jQuery} $el
*
* @private
*/
_hide($el) {
$el.addClass('d-none');
}
/**
* Show hidden element.
*
* @param {jQuery} $el
*
* @private
*/
_show($el) {
$el.removeClass('d-none');
}
}

View File

@@ -0,0 +1,158 @@
/**
* 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 UI interactions of choice tree
*/
export default class ChoiceTree {
/**
* @param {String} treeSelector
*/
constructor(treeSelector) {
this.$container = $(treeSelector);
this.$container.on('click', '.js-input-wrapper', (event) => {
const $inputWrapper = $(event.currentTarget);
this._toggleChildTree($inputWrapper);
});
this.$container.on('click', '.js-toggle-choice-tree-action', (event) => {
const $action = $(event.currentTarget);
this._toggleTree($action);
});
return {
enableAutoCheckChildren: () => this.enableAutoCheckChildren(),
enableAllInputs: () => this.enableAllInputs(),
disableAllInputs: () => this.disableAllInputs(),
};
}
/**
* Enable automatic check/uncheck of clicked item's children.
*/
enableAutoCheckChildren() {
this.$container.on('change', 'input[type="checkbox"]', (event) => {
const $clickedCheckbox = $(event.currentTarget);
const $itemWithChildren = $clickedCheckbox.closest('li');
$itemWithChildren
.find('ul input[type="checkbox"]')
.prop('checked', $clickedCheckbox.is(':checked'));
});
}
/**
* Enable all inputs in the choice tree.
*/
enableAllInputs() {
this.$container.find('input').removeAttr('disabled');
}
/**
* Disable all inputs in the choice tree.
*/
disableAllInputs() {
this.$container.find('input').attr('disabled', 'disabled');
}
/**
* Collapse or expand sub-tree for single parent
*
* @param {jQuery} $inputWrapper
*
* @private
*/
_toggleChildTree($inputWrapper) {
const $parentWrapper = $inputWrapper.closest('li');
if ($parentWrapper.hasClass('expanded')) {
$parentWrapper
.removeClass('expanded')
.addClass('collapsed');
return;
}
if ($parentWrapper.hasClass('collapsed')) {
$parentWrapper
.removeClass('collapsed')
.addClass('expanded');
}
}
/**
* Collapse or expand whole tree
*
* @param {jQuery} $action
*
* @private
*/
_toggleTree($action) {
const $parentContainer = $action.closest('.js-choice-tree-container');
const action = $action.data('action');
// toggle action configuration
const config = {
addClass: {
expand: 'expanded',
collapse: 'collapsed',
},
removeClass: {
expand: 'collapsed',
collapse: 'expanded',
},
nextAction: {
expand: 'collapse',
collapse: 'expand',
},
text: {
expand: 'collapsed-text',
collapse: 'expanded-text',
},
icon: {
expand: 'collapsed-icon',
collapse: 'expanded-icon',
}
};
$parentContainer.find('li').each((index, item) => {
const $item = $(item);
if ($item.hasClass(config.removeClass[action])) {
$item.removeClass(config.removeClass[action])
.addClass(config.addClass[action]);
}
});
$action.data('action', config.nextAction[action]);
$action.find('.material-icons').text($action.data(config.icon[action]));
$action.find('.js-toggle-text').text($action.data(config.text[action]));
}
}

View File

@@ -0,0 +1,89 @@
/**
* 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.$;
/**
* Component responsible for displaying form popover errors with modified width which is calculated based on the
* form group width.
*/
$(() => {
// loads form popover instance
$('[data-toggle="form-popover-error"]').popover({
html: true,
content: function () {
return getErrorContent(this);
},
});
/**
* Recalculates popover position so it is always aligned horizontally and width is identical
* to the child elements of the form.
* @param {Object} event
*/
const repositionPopover = (event) => {
const $element = $(event.currentTarget);
const $formGroup = $element.closest('.form-group');
const $invalidFeedbackContainer = $formGroup.find('.invalid-feedback-container');
const $errorPopover = $formGroup.find('.form-popover-error');
const localeVisibleElementWidth = $invalidFeedbackContainer.width();
$errorPopover.css('width', localeVisibleElementWidth);
const horizontalDifference = getHorizontalDifference($invalidFeedbackContainer, $errorPopover);
$errorPopover.css('left', `${horizontalDifference}px`);
};
/**
* gets horizontal difference which helps to align popover horizontally.
* @param {jQuery} $invalidFeedbackContainer
* @param {jQuery} $errorPopover
* @returns {number}
*/
const getHorizontalDifference = ($invalidFeedbackContainer, $errorPopover) => {
const inputHorizontalPosition = $invalidFeedbackContainer.offset().left;
const popoverHorizontalPosition = $errorPopover.offset().left;
return inputHorizontalPosition - popoverHorizontalPosition;
};
/**
* Gets popover error content pre-fetched in html. It used unique selector to identify which one content to render.
*
* @param popoverTriggerElement
* @returns {jQuery}
*/
const getErrorContent = (popoverTriggerElement) => {
const popoverTriggerId = $(popoverTriggerElement).data('id');
return $(`.js-popover-error-content[data-id="${popoverTriggerId}"]`).html();
};
// registers the event which displays the popover
$(document).on('shown.bs.popover', '[data-toggle="form-popover-error"]', (event) => repositionPopover(event));
});

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
*/
const $ = window.$;
/**
* Responsible for opening another page with specified url.
* For example used in 'Save and preview' cms page create/edit actions.
*
* Usage: In selector element attr 'data-preview-url' provide page url.
* The page will be opened once provided 'open_preview' parameter in query url
*/
export default class PreviewOpener {
constructor (previewUrlSelector) {
this.previewUrl = $(previewUrlSelector).data('preview-url');
this._open();
return {};
}
/**
* Opens new page of provided url
*
* @private
*/
_open() {
const urlParams = new URLSearchParams(location.search);
if (this.previewUrl && urlParams.has('open_preview')) {
window.open(this.previewUrl, '_blank');
}
}
}

View File

@@ -0,0 +1,59 @@
/**
* 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.$;
/**
* TextWithLengthCounter handles input with length counter UI.
*
* Usage:
*
* There must be an element that wraps both input & counter display with ".js-text-with-length-counter" class.
* Counter display must have ".js-countable-text-display" class and input must have ".js-countable-text-input" class.
* Text input must have "data-max-length" attribute.
*
* <div class="js-text-with-length-counter">
* <span class="js-countable-text"></span>
* <input class="js-countable-input" data-max-length="255">
* </div>
*
* In Javascript you must enable this component:
*
* new TextWithLengthCounter();
*/
export default class TextWithLengthCounter {
constructor() {
this.wrapperSelector = '.js-text-with-length-counter';
this.textSelector = '.js-countable-text';
this.inputSelector = '.js-countable-input';
$(document).on('input', `${this.wrapperSelector} ${this.inputSelector}`, (e) => {
const $input = $(e.currentTarget);
const remainingLength = $input.data('max-length') - $input.val().length;
$input.closest(this.wrapperSelector).find(this.textSelector).text(remainingLength);
});
}
}

View File

@@ -0,0 +1,59 @@
/**
* 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 component is implemented to work with TextWithRecommendedLengthType,
* but can be used as standalone component as well.
*
* Usage:
*
* Define your HTML with input and counter. Example:
*
* <input id="myInput"
* class="js-recommended-length-input"
* data-recommended-length-counter="#myInput_recommended_length_counter"
* >
*
* <div id"myInput_recommended_length_counter">
* <span class="js-current-length">0</span> of 70 characters used (recommended)
* </div>
*
* NOTE: You must use exactly the same Classes, but IDs can be different!
*
* Then enable component in JavaScript:
*
* new TextWithRecommendedLengthCounter();
*/
export default class TextWithRecommendedLengthCounter {
constructor() {
$(document).on('input', '.js-recommended-length-input', (event) => {
const $input = $(event.currentTarget);
$($input.data('recommended-length-counter')).find('.js-current-length').text($input.val().length);
});
}
}

View File

@@ -0,0 +1,97 @@
/**
* 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
*/
/**
* Generates random values for inputs.
*
* Usage:
*
* There should be a button in HTML with 2 required data-* properties:
* 1. data-target-input-id - input id for which value should be generated
* 2. data-generated-value-size -
*
* Example button: <button class="js-generator-btn"
* data-target-input-id="my-input-id"
* data-generated-value-length="16"
* >
* Generate!
* </button>
*
* In JavaScript you have to enable this functionality using GeneratableInput component like so:
*
* const generateableInput = new GeneratableInput();
* generateableInput.attachOn('.js-generator-btn'); // every time our button is clicked
* // it will generate random value of 16 characters
* // for input with id of "my-input-id"
*
* You can attach as many different buttons as you like using "attachOn()" function
* as long as 2 required data-* attributes are present at each button.
*/
export default class GeneratableInput {
constructor() {
return {
'attachOn': (btnSelector) => this._attachOn(btnSelector),
};
}
/**
* Attaches event listener on button than can generate value
*
* @param {String} generatorBtnSelector
*
* @private
*/
_attachOn(generatorBtnSelector) {
document.querySelector(generatorBtnSelector).addEventListener('click', (event) => {
const attributes = event.currentTarget.attributes;
const targetInputId = attributes.getNamedItem('data-target-input-id').value;
const generatedValueLength = parseInt(attributes.getNamedItem('data-generated-value-length').value);
const targetInput = document.querySelector('#' + targetInputId);
targetInput.value = this._generateValue(generatedValueLength)
});
}
/**
* Generates random value for input
*
* @param {Number} length
*
* @returns {string}
*
* @private
*/
_generateValue(length) {
const chars = '123456789ABCDEFGHIJKLMNPQRSTUVWXYZ';
let generatedValue = '';
for (let i = 1; i <= length; ++i) {
generatedValue += chars.charAt(Math.floor(Math.random() * chars.length));
}
return generatedValue;
}
}

View File

@@ -0,0 +1,77 @@
/**
* 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 DeleteCategoriesBulkActionExtension handles submitting of row action
*/
export default class DeleteCategoriesBulkActionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-delete-categories-bulk-action', (event) => {
event.preventDefault();
const submitUrl = $(event.currentTarget).data('categories-delete-url');
const $deleteCategoriesModal = $(`#${grid.getId()}_grid_delete_categories_modal`);
$deleteCategoriesModal.modal('show');
$deleteCategoriesModal.on('click', '.js-submit-delete-categories', () => {
const $checkboxes = grid.getContainer().find('.js-bulk-action-checkbox:checked');
const $categoriesToDeleteInputBlock = $('#delete_categories_categories_to_delete');
$checkboxes.each((i, element) => {
const $checkbox = $(element);
const categoryInput = $categoriesToDeleteInputBlock
.data('prototype')
.replace(/__name__/g, $checkbox.val());
const $input = $($.parseHTML(categoryInput)[0]);
$input.val($checkbox.val());
$categoriesToDeleteInputBlock.append($input);
});
const $form = $deleteCategoriesModal.find('form');
$form.attr('action', submitUrl);
$form.submit();
});
});
}
}

View File

@@ -0,0 +1,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.$;
/**
* Handles bulk delete for "Customers" grid.
*/
export default class DeleteCustomersBulkActionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-delete-customers-bulk-action', (event) => {
event.preventDefault();
const submitUrl = $(event.currentTarget).data('customers-delete-url');
const $modal = $(`#${grid.getId()}_grid_delete_customers_modal`);
$modal.modal('show');
$modal.on('click', '.js-submit-delete-customers', () => {
const $selectedCustomerCheckboxes = grid.getContainer().find('.js-bulk-action-checkbox:checked');
$selectedCustomerCheckboxes.each((i, checkbox) => {
const $input = $(checkbox);
this._addCustomerToDeleteCollectionInput($input.val());
});
const $form = $modal.find('form');
$form.attr('action', submitUrl);
$form.submit();
});
});
}
/**
* Create input with customer id and add it to delete collection input
*
* @private
*/
_addCustomerToDeleteCollectionInput(customerId) {
const $customersInput = $('#delete_customers_customers_to_delete');
const customerInput = $customersInput
.data('prototype')
.replace(/__name__/g, customerId)
;
const $item = $($.parseHTML(customerInput)[0]);
$item.val(customerId);
$customersInput.append($item);
}
}

View File

@@ -0,0 +1,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
*/
const $ = window.$;
/**
* Class CategoryDeleteRowActionExtension handles submitting of row action
*/
export default class DeleteCategoryRowActionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-delete-category-row-action', (event) => {
event.preventDefault();
const $deleteCategoriesModal = $('#' + grid.getId() + '_grid_delete_categories_modal');
$deleteCategoriesModal.modal('show');
$deleteCategoriesModal.on('click', '.js-submit-delete-categories', () => {
const $button = $(event.currentTarget);
const categoryId = $button.data('category-id');
const $categoriesToDeleteInputBlock = $('#delete_categories_categories_to_delete');
const categoryInput = $categoriesToDeleteInputBlock
.data('prototype')
.replace(/__name__/g, $categoriesToDeleteInputBlock.children().length);
const $item = $($.parseHTML(categoryInput)[0]);
$item.val(categoryId);
$categoriesToDeleteInputBlock.append($item);
const $form = $deleteCategoriesModal.find('form');
$form.attr('action', $button.data('category-delete-url'));
$form.submit();
});
});
}
}

View File

@@ -0,0 +1,84 @@
/**
* 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 DeleteCustomerRowActionExtension handles submitting of row action
*/
export default class DeleteCustomerRowActionExtension {
constructor() {
return {
extend: (grid) => this.extend(grid),
};
}
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-delete-customer-row-action', (event) => {
event.preventDefault();
const $deleteCustomersModal = $(`#${grid.getId()}_grid_delete_customers_modal`);
$deleteCustomersModal.modal('show');
$deleteCustomersModal.on('click', '.js-submit-delete-customers', () => {
const $button = $(event.currentTarget);
const customerId = $button.data('customer-id');
this._addCustomerInput(customerId);
const $form = $deleteCustomersModal.find('form');
$form.attr('action', $button.data('customer-delete-url'));
$form.submit();
});
});
}
/**
* Adds input for selected customer to delete form
*
* @param {integer} customerId
*
* @private
*/
_addCustomerInput(customerId) {
const $customersToDeleteInputBlock = $('#delete_customers_customers_to_delete');
const customerInput = $customersToDeleteInputBlock
.data('prototype')
.replace(/__name__/g, $customersToDeleteInputBlock.children().length);
const $item = $($.parseHTML(customerInput)[0]);
$item.val(customerId);
$customersToDeleteInputBlock.append($item);
}
}

View File

@@ -0,0 +1,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
*/
const $ = window.$;
/**
* Class SubmitRowActionExtension handles submitting of row action
*/
export default class SubmitRowActionExtension {
/**
* Extend grid
*
* @param {Grid} grid
*/
extend(grid) {
grid.getContainer().on('click', '.js-submit-row-action', (event) => {
event.preventDefault();
const $button = $(event.currentTarget);
const confirmMessage = $button.data('confirm-message');
if (confirmMessage.length && !confirm(confirmMessage)) {
return;
}
const method = $button.data('method');
const isGetOrPostMethod = ['GET', 'POST'].includes(method);
const $form = $('<form>', {
'action': $button.data('url'),
'method': isGetOrPostMethod ? method : 'POST',
}).appendTo('body');
if (!isGetOrPostMethod) {
$form.append($('<input>', {
'type': '_hidden',
'name': '_method',
'value': method
}));
}
$form.submit();
});
}
}

View File

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

Some files were not shown because too many files have changed in this diff Show More