From 405424fc662474b38f237743c76c744ca259d38b Mon Sep 17 00:00:00 2001 From: Sevan Nerse Date: Thu, 31 Dec 2020 13:39:03 +0300 Subject: [PATCH] dynamic options feature is added to akaunting-select components --- .../assets/js/components/AkauntingSelect.vue | 51 +++++++++++++++++++ .../js/components/AkauntingSelectRemote.vue | 51 +++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/resources/assets/js/components/AkauntingSelect.vue b/resources/assets/js/components/AkauntingSelect.vue index 5a9fb0548..de12bbcc0 100644 --- a/resources/assets/js/components/AkauntingSelect.vue +++ b/resources/assets/js/components/AkauntingSelect.vue @@ -185,6 +185,8 @@ export default { options: null, + dynamicOptions: null, + disabledOptions: { type: Array, default: function () { @@ -686,6 +688,55 @@ export default { this.change(); }, + + dynamicOptions: function(options) { + if (this.group) { + // Option set sort_option data + if (!Array.isArray(options)) { + for (const [index, _options] of Object.entries(options)) { + let values = []; + + for (const [key, value] of Object.entries(_options)) { + values.push({ + key: key, + value: value + }); + } + + this.sort_options.push({ + key: index, + value: values + }); + } + } else { + options.forEach(function (option, index) { + this.sort_options.push({ + index: index, + key: option.id, + value: (option.title) ? option.title : (option.display_name) ? option.display_name : option.name + }); + }, this); + } + } else { + // Option set sort_option data + if (!Array.isArray(options)) { + for (const [key, value] of Object.entries(options)) { + this.sort_options.push({ + key: key, + value: value + }); + } + } else { + options.forEach(function (option, index) { + this.sort_options.push({ + index: index, + key: option.id, + value: (option.title) ? option.title : (option.display_name) ? option.display_name : option.name + }); + }, this); + } + } + }, }, } diff --git a/resources/assets/js/components/AkauntingSelectRemote.vue b/resources/assets/js/components/AkauntingSelectRemote.vue index ed67ff1a8..8e09698d2 100644 --- a/resources/assets/js/components/AkauntingSelectRemote.vue +++ b/resources/assets/js/components/AkauntingSelectRemote.vue @@ -286,6 +286,8 @@ export default { options: null, + dynamicOptions: null, + disabledOptions: { type: Array, default: function () { @@ -895,6 +897,55 @@ export default { this.change(); }, + + dynamicOptions: function(options) { + if (this.group) { + // Option set sort_option data + if (!Array.isArray(options)) { + for (const [index, _options] of Object.entries(options)) { + let values = []; + + for (const [key, value] of Object.entries(_options)) { + values.push({ + key: key, + value: value + }); + } + + this.sort_options.push({ + key: index, + value: values + }); + } + } else { + options.forEach(function (option, index) { + this.sort_options.push({ + index: index, + key: option.id, + value: (option.title) ? option.title : (option.display_name) ? option.display_name : option.name + }); + }, this); + } + } else { + // Option set sort_option data + if (!Array.isArray(options)) { + for (const [key, value] of Object.entries(options)) { + this.sort_options.push({ + key: key, + value: value + }); + } + } else { + options.forEach(function (option, index) { + this.sort_options.push({ + index: index, + key: option.id, + value: (option.title) ? option.title : (option.display_name) ? option.display_name : option.name + }); + }, this); + } + } + }, }, }