From f5aa1c9acd4ac3ef31ef40d9992a86977ee8a8e6 Mon Sep 17 00:00:00 2001 From: Sevan Nerse Date: Fri, 8 Jan 2021 15:52:22 +0300 Subject: [PATCH] option_sortable prop is activated --- .../assets/js/components/AkauntingSelect.vue | 65 ++++++------------- .../js/components/AkauntingSelectRemote.vue | 65 ++++++------------- 2 files changed, 40 insertions(+), 90 deletions(-) diff --git a/resources/assets/js/components/AkauntingSelect.vue b/resources/assets/js/components/AkauntingSelect.vue index 29c3058ce..1ba79e2cd 100644 --- a/resources/assets/js/components/AkauntingSelect.vue +++ b/resources/assets/js/components/AkauntingSelect.vue @@ -345,55 +345,13 @@ export default { computed: { sortOptions() { if (this.group) { - this.sort_options.sort(function (a, b) { - var nameA = a.key.toUpperCase(); // ignore upper and lowercase - var nameB = b.key.toUpperCase(); // ignore upper and lowercase - - if (nameA < nameB) { - return -1; - } - - if (nameA > nameB) { - return 1; - } - - // names must be equal - return 0; - }); + this.sort_options.sort(this.sortBy("key")); for (const [index, options] of Object.entries(this.sort_options)) { - options.value.sort(function (aa, bb) { - var nameAA = aa.value.toUpperCase(); // ignore upper and lowercase - var nameBB = bb.value.toUpperCase(); // ignore upper and lowercase - - if (nameAA < nameBB) { - return -1; - } - - if (nameAA > nameBB) { - return 1; - } - - // names must be equal - return 0; - }); + options.value.sort(this.sortBy(this.option_sortable)); } } else { - this.sort_options.sort(function (a, b) { - var nameA = a.value.toUpperCase(); // ignore upper and lowercase - var nameB = b.value.toUpperCase(); // ignore upper and lowercase - - if (nameA < nameB) { - return -1; - } - - if (nameA > nameB) { - return 1; - } - - // names must be equal - return 0; - }); + this.sort_options.sort(this.sortBy(this.option_sortable)); } return this.sort_options; @@ -424,6 +382,23 @@ export default { }, methods: { + sortBy(option) { + return (a, b) => { + var nameA = a.[option].toUpperCase(); // ignore upper and lowercase + var nameB = b.[option].toUpperCase(); // ignore upper and lowercase + + if (nameA < nameB) { + return -1; + } + + if (nameA > nameB) { + return 1; + } + + // names must be equal + return 0; + } + }, change() { // This controll added add new changed.. if (typeof(this.selected) === 'object' && typeof(this.selected.type) !== 'undefined') { diff --git a/resources/assets/js/components/AkauntingSelectRemote.vue b/resources/assets/js/components/AkauntingSelectRemote.vue index 95468bd4a..c2a812bb1 100644 --- a/resources/assets/js/components/AkauntingSelectRemote.vue +++ b/resources/assets/js/components/AkauntingSelectRemote.vue @@ -412,55 +412,13 @@ export default { computed: { sortOptions() { if (this.group) { - this.sort_options.sort(function (a, b) { - var nameA = a.key.toUpperCase(); // ignore upper and lowercase - var nameB = b.key.toUpperCase(); // ignore upper and lowercase - - if (nameA < nameB) { - return -1; - } - - if (nameA > nameB) { - return 1; - } - - // names must be equal - return 0; - }); + this.sort_options.sort(this.sortBy("key")); for (const [index, options] of Object.entries(this.sort_options)) { - options.value.sort(function (aa, bb) { - var nameAA = aa.value.toUpperCase(); // ignore upper and lowercase - var nameBB = bb.value.toUpperCase(); // ignore upper and lowercase - - if (nameAA < nameBB) { - return -1; - } - - if (nameAA > nameBB) { - return 1; - } - - // names must be equal - return 0; - }); + options.value.sort(this.sortBy(this.option_sortable)); } } else { - this.sort_options.sort(function (a, b) { - var nameA = a.value.toUpperCase(); // ignore upper and lowercase - var nameB = b.value.toUpperCase(); // ignore upper and lowercase - - if (nameA < nameB) { - return -1; - } - - if (nameA > nameB) { - return 1; - } - - // names must be equal - return 0; - }); + this.sort_options.sort(this.sortBy(this.option_sortable)); } return this.sort_options; @@ -491,6 +449,23 @@ export default { }, methods: { + sortBy(option) { + return (a, b) => { + var nameA = a.[option].toUpperCase(); // ignore upper and lowercase + var nameB = b.[option].toUpperCase(); // ignore upper and lowercase + + if (nameA < nameB) { + return -1; + } + + if (nameA > nameB) { + return 1; + } + + // names must be equal + return 0; + } + }, setSortOptions() { if (this.group) { // Option set sort_option data