diff --git a/bin/settings/AllowedCurrencies.js b/bin/settings/AllowedCurrencies.js index 5e21c6eb1dba62dc5b5dae2cb85ff62e19bf9a42..8d434cd11407cb8c73a7a6cb699f44af9f2c1298 100644 --- a/bin/settings/AllowedCurrencies.js +++ b/bin/settings/AllowedCurrencies.js @@ -60,11 +60,10 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [ * event : on import */ $onImport: function() { - let i, len; - this.$Input = this.getElm(); this.$Input.type = 'hidden'; + /* if (this.$Input.value !== '') { let values = {}; let value = this.$Input.value.split(','); @@ -75,6 +74,7 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [ this.setAttribute('values', values); } + */ this.$Elm = new Element('div', { 'class': 'quiqqer-currency-allowed', @@ -101,7 +101,7 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [ this.$Grid = new Grid(this.$Container, { pagination: true, multipleSelection: true, - height: 300, + height: 400, width: width, columnModel: [ { @@ -223,14 +223,33 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [ onRefresh: this.refresh }); - this.$Grid.refresh(); + this.$Grid.showLoader(); + + this.getAllowedCurrencies().then((result) => { + this.$Input.value = result.map((currency) => { + return currency.code; + }).join(','); + + let i, len; + let values = {}; + let value = this.$Input.value.split(','); + + for (i = 0, len = value.length; i < len; i++) { + values[value[i]] = 1; + } + + this.setAttribute('values', values); + this.$Grid.refresh(); + }); }, /** * refresh the currency list */ refresh: function() { - return this.getCurrencies().then(function(list) { + this.$Grid.showLoader(); + + return this.getCurrencies().then((list) => { let data = [], values = this.getAttribute('values'); @@ -286,7 +305,9 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [ Edit.disable(); Delete.disable(); - }.bind(this)); + this.$Grid.hideLoader(); + + }); }, /** @@ -324,6 +345,20 @@ define('package/quiqqer/currency/bin/settings/AllowedCurrencies', [ }); }, + /** + * Return all allowed (active) currencies + * + * @returns {Promise} + */ + getAllowedCurrencies: function() { + return new Promise((resolve, reject) => { + QUIAjax.get('package_quiqqer_currency_ajax_getAllowedCurrencies', resolve, { + 'package': 'quiqqer/currency', + onError: reject + }); + }); + }, + /** * Delete a currency *