diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-12 10:02:00 +0100 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-03-27 19:41:59 +0100 |
commit | f67a5cc9b3bea0a0308e0dec7f804ebb32485618 (patch) | |
tree | 09656a3ad6f39b71d387130066bacb9a463eb085 /src | |
parent | ae80cf1a5a8f3d72cba1a2d65a9c2468c94619b1 (diff) |
Add ABLABEL and ITEMX.property support
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/ContactDetails/ContactDetailsProperty.vue | 24 | ||||
-rw-r--r-- | src/models/contact.js | 40 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/components/ContactDetails/ContactDetailsProperty.vue b/src/components/ContactDetails/ContactDetailsProperty.vue index 048b3e20..568aa554 100644 --- a/src/components/ContactDetails/ContactDetailsProperty.vue +++ b/src/components/ContactDetails/ContactDetailsProperty.vue @@ -126,6 +126,11 @@ export default { * @returns {string} */ propName() { + // ! is this a ITEMXX.XXX property?? + if (this.propGroup[1]) { + return this.propGroup[1] + } + return this.property.name }, /** @@ -139,6 +144,7 @@ export default { if (this.propModel && this.propModel.force) { return this.propModel.force } + return this.property.getDefaultType() }, @@ -172,6 +178,16 @@ export default { }, /** + * Return the id and type of a property group + * e.g ITEMXX.tel => ['ITEMXX', 'tel'] + * + * @returns {Array} + */ + propGroup() { + return this.property.name.split('.') + }, + + /** * Returns the closest match to the selected type * or return the default selected as a new object if * none exists @@ -180,6 +196,14 @@ export default { */ selectType: { get() { + // ! if ABLABEL is present, this is a priority + const type = this.contact.vCard.getFirstPropertyValue(`${this.propGroup[0]}.x-ablabel`) + if (type) { + return { + id: type, + name: type + } + } if (this.propModel && this.propModel.options && this.type) { let selectedType = this.type diff --git a/src/models/contact.js b/src/models/contact.js index 2d383dd9..14ea06ff 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -35,6 +35,40 @@ const isEmpty = value => { return (Array.isArray(value) && value.join('') === '') || (!Array.isArray(value) && value === '') } +/** + * Parse a jCal and update the global designset + * if any grouped property is found + * + * @param {Array} jCal the contact ICAL.js jCal + * @returns {Boolean} + */ +const updateDesignSet = jCal => { + let result = false + jCal[1].forEach(prop => { + const propGroup = prop[0].split('.') + + // if this is a grouped property, update the designSet + if (propGroup.length === 2 && ( + ICAL.design.vcard.property[propGroup[1]] + || ICAL.design.vcard3.property[propGroup[1]] + )) { + // force update the main design sets + if (ICAL.design.vcard.property[propGroup[1]]) { + ICAL.design.vcard.property[prop[0]] + = ICAL.design.vcard.property[propGroup[1]] + result = true + } + if (ICAL.design.vcard3.property[propGroup[1]]) { + ICAL.design.vcard3.property[prop[0]] + = ICAL.design.vcard3.property[propGroup[1]] + + result = true + } + } + }) + return result +} + export default class Contact { /** @@ -54,6 +88,12 @@ export default class Contact { throw new Error('Only one contact is allowed in the vcard data') } + // add grouped properties to the design set + // if any found, refresh the contact jCal + if (updateDesignSet(jCal)) { + jCal = ICAL.parse(vcard) + } + this.jCal = jCal this.addressbook = addressbook this.vCard = new ICAL.Component(this.jCal) |