summaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorRichard Steinmetz <richard@steinmetz.cloud>2022-09-30 12:24:23 +0200
committerRichard Steinmetz <richard@steinmetz.cloud>2022-09-30 12:30:04 +0200
commit1bd8340fb3e6465719581a98c306c4c6c4c8f779 (patch)
tree96ccb1142bd40be898349e1d33d4401f5b61f9bc /src/components
parent58bd04f358af07fc01e94d8a819f393114e6151a (diff)
Refactor manger property select logic
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
Diffstat (limited to 'src/components')
-rw-r--r--src/components/ContactDetails.vue2
-rw-r--r--src/components/ContactDetails/ContactDetailsProperty.vue40
-rw-r--r--src/components/Properties/PropertySelect.vue2
3 files changed, 14 insertions, 30 deletions
diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue
index 089571fb..c1305141 100644
--- a/src/components/ContactDetails.vue
+++ b/src/components/ContactDetails.vue
@@ -218,6 +218,7 @@
duplication, we created a fake propModel and property with our own options here) -->
<PropertySelect v-masonry-tile
:prop-model="addressbookModel"
+ :options="addressbooksOptions"
:value.sync="addressbook"
:is-first-property="true"
:is-last-property="true"
@@ -481,7 +482,6 @@ export default {
* Store getters filtered and mapped to usable object
* This is the list of addressbooks that are available to write
*
- * @return {Array}
* @return {{id: string, name: string}[]}
*/
addressbooksOptions() {
diff --git a/src/components/ContactDetails/ContactDetailsProperty.vue b/src/components/ContactDetails/ContactDetailsProperty.vue
index feb8c06c..fe33352a 100644
--- a/src/components/ContactDetails/ContactDetailsProperty.vue
+++ b/src/components/ContactDetails/ContactDetailsProperty.vue
@@ -37,7 +37,7 @@
:local-contact="localContact"
:prop-name="propName"
:prop-type="propType"
- :options="propName === 'x-managersname' ? contactsOptions : sortedModelOptions"
+ :options="sortedModelOptions"
:is-read-only="isReadOnly"
@delete="onDelete"
@resize="onResize"
@@ -182,7 +182,17 @@ export default {
* @return {object[]}
*/
sortedModelOptions() {
- if (this.propModel.options) {
+ if (!this.propModel.options) {
+ return []
+ }
+
+ if (typeof this.propModel.options === 'function') {
+ return this.propModel.options({
+ contact: this.contact,
+ $store: this.$store,
+ selectType: this.selectType,
+ })
+ } else {
return this.propModel.options.reduce((list, option) => {
if (!list.find(search => search.name === option.name)) {
list.push(option)
@@ -190,7 +200,6 @@ export default {
return list
}, this.selectType ? [this.selectType] : [])
}
- return []
},
/**
@@ -213,31 +222,6 @@ export default {
},
/**
- * Return the options of contacts for x-managersname select
- *
- * @return {object[]}
- */
- contactsOptions() {
- if (this.propName !== 'x-managersname') {
- return []
- }
-
- // Only allow contacts of the same address book
- const otherContacts = this.otherContacts(this.contact)
- // Reduce to an object to eliminate duplicates
- return Object.values(otherContacts.reduce((prev, { key, value }) => {
- const contact = this.$store.getters.getContact(key)
- return {
- ...prev,
- [contact.uid]: {
- id: contact.key,
- name: contact.displayName,
- },
- }
- }, this.selectType ? { [this.selectType.value]: this.selectType } : {}))
- },
-
- /**
* Returns the closest match to the selected type
* or return the default selected as a new object if
* none exists
diff --git a/src/components/Properties/PropertySelect.vue b/src/components/Properties/PropertySelect.vue
index 8efe6c82..f357f3ba 100644
--- a/src/components/Properties/PropertySelect.vue
+++ b/src/components/Properties/PropertySelect.vue
@@ -39,7 +39,7 @@
</div>
<Multiselect v-model="matchedOptions"
- :options="propModel.options || options"
+ :options="options"
:placeholder="t('contacts', 'Select option')"
:disabled="isSingleOption || isReadOnly"
class="property__value"