diff --git a/src/components/ContactDetails/ContactDetailsProperty.vue b/src/components/ContactDetails/ContactDetailsProperty.vue index 048b3e204..568aa5542 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() }, @@ -171,6 +177,16 @@ export default { return [] }, + /** + * 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 @@ -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 2d383dd96..14ea06ff9 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)