From 405424fc662474b38f237743c76c744ca259d38b Mon Sep 17 00:00:00 2001 From: Sevan Nerse Date: Thu, 31 Dec 2020 13:39:03 +0300 Subject: [PATCH 1/2] 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); + } + } + }, }, } From ad396db7b64933fa5b4d8ce8b418a15330f1a99a Mon Sep 17 00:00:00 2001 From: Sevan Nerse Date: Thu, 31 Dec 2020 13:55:47 +0300 Subject: [PATCH 2/2] dynamic options implemented to all partial form blades --- .../views/partials/form/multi_select_add_new_group.blade.php | 4 ++++ resources/views/partials/form/multi_select_group.blade.php | 4 ++++ .../partials/form/multi_select_remote_add_new_group.blade.php | 4 ++++ .../views/partials/form/multi_select_remote_group.blade.php | 4 ++++ resources/views/partials/form/select_add_new_group.blade.php | 4 ++++ resources/views/partials/form/select_group.blade.php | 4 ++++ .../views/partials/form/select_group_add_new_group.blade.php | 4 ++++ resources/views/partials/form/select_group_group.blade.php | 4 ++++ .../views/partials/form/select_remote_add_new_group.blade.php | 4 ++++ resources/views/partials/form/select_remote_group.blade.php | 4 ++++ 10 files changed, 40 insertions(+) diff --git a/resources/views/partials/form/multi_select_add_new_group.blade.php b/resources/views/partials/form/multi_select_add_new_group.blade.php index a19c1599f..efb9d5af2 100644 --- a/resources/views/partials/form/multi_select_add_new_group.blade.php +++ b/resources/views/partials/form/multi_select_add_new_group.blade.php @@ -19,6 +19,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) :value="{{ json_encode(old($name, $selected)) }}" @endif diff --git a/resources/views/partials/form/multi_select_group.blade.php b/resources/views/partials/form/multi_select_group.blade.php index bbc7c9e46..ce33f842e 100644 --- a/resources/views/partials/form/multi_select_group.blade.php +++ b/resources/views/partials/form/multi_select_group.blade.php @@ -19,6 +19,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) :value="{{ json_encode(old($name, $selected)) }}" @endif diff --git a/resources/views/partials/form/multi_select_remote_add_new_group.blade.php b/resources/views/partials/form/multi_select_remote_add_new_group.blade.php index 8f6e25580..9a7d06084 100644 --- a/resources/views/partials/form/multi_select_remote_add_new_group.blade.php +++ b/resources/views/partials/form/multi_select_remote_add_new_group.blade.php @@ -21,6 +21,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (!empty($selected) || old($name)) :value="{{ json_encode(old($name, $selected)) }}" @endif diff --git a/resources/views/partials/form/multi_select_remote_group.blade.php b/resources/views/partials/form/multi_select_remote_group.blade.php index a462a4132..c7a81485f 100644 --- a/resources/views/partials/form/multi_select_remote_group.blade.php +++ b/resources/views/partials/form/multi_select_remote_group.blade.php @@ -21,6 +21,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (!empty($selected) || old($name)) :value="{{ json_encode(old($name, $selected)) }}" @endif diff --git a/resources/views/partials/form/select_add_new_group.blade.php b/resources/views/partials/form/select_add_new_group.blade.php index 4c0540c40..0ea7ea92f 100644 --- a/resources/views/partials/form/select_add_new_group.blade.php +++ b/resources/views/partials/form/select_add_new_group.blade.php @@ -19,6 +19,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}" @endif diff --git a/resources/views/partials/form/select_group.blade.php b/resources/views/partials/form/select_group.blade.php index 3b96d963c..8b7f39340 100644 --- a/resources/views/partials/form/select_group.blade.php +++ b/resources/views/partials/form/select_group.blade.php @@ -19,6 +19,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}" @endif diff --git a/resources/views/partials/form/select_group_add_new_group.blade.php b/resources/views/partials/form/select_group_add_new_group.blade.php index c16bba08b..8ca502b84 100644 --- a/resources/views/partials/form/select_group_add_new_group.blade.php +++ b/resources/views/partials/form/select_group_add_new_group.blade.php @@ -19,6 +19,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}" @endif diff --git a/resources/views/partials/form/select_group_group.blade.php b/resources/views/partials/form/select_group_group.blade.php index b539e3c85..da7a7aca2 100644 --- a/resources/views/partials/form/select_group_group.blade.php +++ b/resources/views/partials/form/select_group_group.blade.php @@ -19,6 +19,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}" @endif diff --git a/resources/views/partials/form/select_remote_add_new_group.blade.php b/resources/views/partials/form/select_remote_add_new_group.blade.php index 004efbfbf..ef58df6f7 100644 --- a/resources/views/partials/form/select_remote_add_new_group.blade.php +++ b/resources/views/partials/form/select_remote_add_new_group.blade.php @@ -21,6 +21,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}" @endif diff --git a/resources/views/partials/form/select_remote_group.blade.php b/resources/views/partials/form/select_remote_group.blade.php index 358f28cac..8492f36b1 100644 --- a/resources/views/partials/form/select_remote_group.blade.php +++ b/resources/views/partials/form/select_remote_group.blade.php @@ -21,6 +21,10 @@ :disabled-options="{{ json_encode($attributes['disabledOptions']) }}" @endif + @if (isset($attributes['dynamicOptions'])) + :dynamic-options="{{ $attributes['dynamicOptions'] }}" + @endif + @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}" @endif