Skip to content

Commit

Permalink
Add ABLABEL and ITEMX.property support
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Mar 27, 2019
1 parent ae80cf1 commit f67a5cc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/components/ContactDetails/ContactDetailsProperty.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
/**
Expand All @@ -139,6 +144,7 @@ export default {
if (this.propModel && this.propModel.force) {
return this.propModel.force
}

return this.property.getDefaultType()
},

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand All @@ -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)
Expand Down

0 comments on commit f67a5cc

Please sign in to comment.