1this.BX = this.BX || {}; 2(function (exports,main_core) { 3 'use strict'; 4 5 function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } 6 7 function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } } 8 9 var _currency = /*#__PURE__*/new WeakMap(); 10 11 var _format = /*#__PURE__*/new WeakMap(); 12 13 var CurrencyItem = /*#__PURE__*/function () { 14 function CurrencyItem(currency, format) { 15 babelHelpers.classCallCheck(this, CurrencyItem); 16 17 _classPrivateFieldInitSpec(this, _currency, { 18 writable: true, 19 value: '' 20 }); 21 22 _classPrivateFieldInitSpec(this, _format, { 23 writable: true, 24 value: {} 25 }); 26 27 babelHelpers.classPrivateFieldSet(this, _currency, currency); 28 babelHelpers.classPrivateFieldSet(this, _format, format); 29 } 30 31 babelHelpers.createClass(CurrencyItem, [{ 32 key: "getCurrency", 33 value: function getCurrency() { 34 return babelHelpers.classPrivateFieldGet(this, _currency); 35 } 36 }, { 37 key: "getFormat", 38 value: function getFormat() { 39 return babelHelpers.classPrivateFieldGet(this, _format); 40 } 41 }, { 42 key: "setFormat", 43 value: function setFormat(format) { 44 babelHelpers.classPrivateFieldSet(this, _format, format); 45 } 46 }]); 47 return CurrencyItem; 48 }(); 49 50 function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } 51 52 function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } 53 var CurrencyCore = /*#__PURE__*/function () { 54 function CurrencyCore() { 55 babelHelpers.classCallCheck(this, CurrencyCore); 56 } 57 58 babelHelpers.createClass(CurrencyCore, null, [{ 59 key: "getCurrencyList", 60 value: function getCurrencyList() { 61 return this.currencies; 62 } 63 }, { 64 key: "setCurrencyFormat", 65 value: function setCurrencyFormat(currency, format, replace) { 66 if (!main_core.Type.isStringFilled(currency) || !main_core.Type.isPlainObject(format)) { 67 return; 68 } 69 70 var index = this.getCurrencyIndex(currency); 71 72 if (index > -1 && !replace) { 73 return; 74 } 75 76 var innerFormat = _objectSpread(_objectSpread({}, this.defaultFormat), format); 77 78 if (index === -1) { 79 this.currencies.push(new CurrencyItem(currency, innerFormat)); 80 } else { 81 this.currencies[index].setFormat(innerFormat); 82 } 83 } 84 }, { 85 key: "setCurrencies", 86 value: function setCurrencies(currencies, replace) { 87 if (main_core.Type.isArray(currencies)) { 88 for (var i = 0; i < currencies.length; i++) { 89 if (!main_core.Type.isPlainObject(currencies[i]) || !main_core.Type.isStringFilled(currencies[i].CURRENCY) || !main_core.Type.isPlainObject(currencies[i].FORMAT)) { 90 continue; 91 } 92 93 this.setCurrencyFormat(currencies[i].CURRENCY, currencies[i].FORMAT, replace); 94 } 95 } 96 } 97 }, { 98 key: "getCurrencyFormat", 99 value: function getCurrencyFormat(currency) { 100 var index = this.getCurrencyIndex(currency); 101 return index > -1 ? this.getCurrencyList()[index].getFormat() : false; 102 } 103 }, { 104 key: "getCurrencyIndex", 105 value: function getCurrencyIndex(currency) { 106 var currencyList = this.getCurrencyList(); 107 108 for (var i = 0; i < currencyList.length; i++) { 109 if (currencyList[i].getCurrency() === currency) { 110 return i; 111 } 112 } 113 114 return -1; 115 } 116 }, { 117 key: "clearCurrency", 118 value: function clearCurrency(currency) { 119 var index = this.getCurrencyIndex(currency); 120 121 if (index > -1) { 122 this.currencies = BX.util.deleteFromArray(this.currencies, index); 123 } 124 } 125 }, { 126 key: "clean", 127 value: function clean() { 128 this.currencies = []; 129 } 130 }, { 131 key: "currencyFormat", 132 value: function currencyFormat(price, currency, useTemplate) { 133 var result = ''; 134 var format = this.getCurrencyFormat(currency); 135 136 if (main_core.Type.isObject(format)) { 137 format.CURRENT_DECIMALS = format.DECIMALS; 138 139 if (format.HIDE_ZERO === 'Y' && price == parseInt(price, 10)) { 140 format.CURRENT_DECIMALS = 0; 141 } 142 143 result = BX.util.number_format(price, format.CURRENT_DECIMALS, format.DEC_POINT, format.THOUSANDS_SEP); 144 145 if (useTemplate) { 146 result = format.FORMAT_STRING.replace(/(^|[^&])#/, '$1' + result); 147 } 148 } 149 150 return result; 151 } 152 }, { 153 key: "getPriceControl", 154 value: function getPriceControl(control, currency) { 155 var result = ''; 156 var format = this.getCurrencyFormat(currency); 157 158 if (main_core.Type.isObject(format)) { 159 result = format.FORMAT_STRING.replace(/(^|[^&])#/, '$1' + control.outerHTML); 160 } 161 162 return result; 163 } 164 }, { 165 key: "loadCurrencyFormat", 166 value: function loadCurrencyFormat(currency) { 167 var _this = this; 168 169 return new Promise(function (resolve, reject) { 170 var index = _this.getCurrencyIndex(currency); 171 172 if (index > -1) { 173 resolve(_this.getCurrencyList()[index].getFormat()); 174 } else { 175 BX.ajax.runAction("currency.format.get", { 176 data: { 177 currencyId: currency 178 } 179 }).then(function (response) { 180 var format = response.data; 181 182 _this.setCurrencyFormat(currency, format); 183 184 resolve(format); 185 })["catch"](function (response) { 186 reject(response.errors); 187 }); 188 } 189 }); 190 } 191 }]); 192 return CurrencyCore; 193 }(); 194 /** @deprecated use import { CurrencyCore } from 'currency.core' */ 195 196 babelHelpers.defineProperty(CurrencyCore, "currencies", []); 197 babelHelpers.defineProperty(CurrencyCore, "defaultFormat", { 198 'FORMAT_STRING': '#', 199 'DEC_POINT': '.', 200 'THOUSANDS_SEP': ' ', 201 'DECIMALS': 2, 202 'HIDE_ZERO': 'N' 203 }); 204 main_core.Reflection.namespace('BX.Currency').Core = CurrencyCore; 205 206 exports.CurrencyCore = CurrencyCore; 207 208}((this.BX.Currency = this.BX.Currency || {}),BX)); 209//# sourceMappingURL=currency-core.bundle.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.