2018-08-07 14:34:46 +00:00
|
|
|
<!--
|
|
|
|
- @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
-
|
|
|
|
- @author John Molakvoæ <skjnldsv@protonmail.com>
|
|
|
|
-
|
|
|
|
- @license GNU AGPL version 3 or any later version
|
|
|
|
-
|
|
|
|
- This program is free software: you can redistribute it and/or modify
|
|
|
|
- it under the terms of the GNU Affero General Public License as
|
|
|
|
- published by the Free Software Foundation, either version 3 of the
|
|
|
|
- License, or (at your option) any later version.
|
|
|
|
-
|
|
|
|
- This program is distributed in the hope that it will be useful,
|
|
|
|
- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
- GNU Affero General Public License for more details.
|
|
|
|
-
|
|
|
|
- You should have received a copy of the GNU Affero General Public License
|
|
|
|
- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
-
|
|
|
|
-->
|
|
|
|
|
|
|
|
<template>
|
2018-08-10 15:46:46 +00:00
|
|
|
<!-- If not in the rfcProps then we don't want to display it -->
|
|
|
|
<component v-if="propModel" :is="componentInstance" :select-type="selectType"
|
|
|
|
:prop-model="propModel" :value="value" />
|
2018-08-07 14:34:46 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import { Property } from 'ical.js'
|
2018-08-09 13:33:08 +00:00
|
|
|
import rfcProps from '../../models/rfcProps.js'
|
2018-08-10 15:46:46 +00:00
|
|
|
import PropertyText from '../properties/PropertyText'
|
|
|
|
import PropertyMultipleText from '../properties/PropertyMultipleText'
|
|
|
|
// import PropertySelect from '../properties/PropertyMultipleText'
|
2018-08-07 14:34:46 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Property',
|
2018-08-10 15:46:46 +00:00
|
|
|
|
2018-08-07 14:34:46 +00:00
|
|
|
props: {
|
|
|
|
property: {
|
|
|
|
type: Property,
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
},
|
2018-08-10 15:46:46 +00:00
|
|
|
|
2018-08-07 14:34:46 +00:00
|
|
|
computed: {
|
2018-08-10 15:46:46 +00:00
|
|
|
// dynamically load component based on property type
|
|
|
|
componentInstance() {
|
|
|
|
if (this.property.isMultiValue && this.propType === 'text') {
|
|
|
|
return PropertyMultipleText
|
|
|
|
} else if (this.propType && this.propType !== 'unknown') {
|
|
|
|
return PropertyText
|
|
|
|
}
|
|
|
|
return PropertyText
|
|
|
|
},
|
|
|
|
|
2018-08-09 13:33:08 +00:00
|
|
|
// rfc properties list
|
|
|
|
properties() {
|
|
|
|
return rfcProps.properties
|
|
|
|
},
|
|
|
|
fieldOrder() {
|
|
|
|
return rfcProps.fieldOrder
|
|
|
|
},
|
|
|
|
|
|
|
|
// the type of the prop e.g. FN
|
|
|
|
propName() {
|
|
|
|
return this.property.name
|
|
|
|
},
|
|
|
|
propType() {
|
|
|
|
return this.property.type
|
|
|
|
},
|
2018-08-10 15:46:46 +00:00
|
|
|
|
2018-08-09 13:33:08 +00:00
|
|
|
// template to use
|
|
|
|
propModel() {
|
2018-08-10 15:46:46 +00:00
|
|
|
return this.properties[this.propName]
|
|
|
|
},
|
|
|
|
|
|
|
|
// select type handler
|
|
|
|
selectType: {
|
|
|
|
get() {
|
|
|
|
if (this.propModel && this.propModel.options && this.type) {
|
|
|
|
|
|
|
|
let selectedType = this.type
|
|
|
|
// vcard 3.0 save pref alongside TYPE
|
|
|
|
.filter(type => type !== 'pref')
|
|
|
|
// we only use uppercase strings
|
|
|
|
.map(str => str.toUpperCase())
|
|
|
|
|
|
|
|
// Compare array and check if the number of exact matches
|
|
|
|
// equals the array length to find the exact property
|
|
|
|
return this.propModel.options.find(option => selectedType.length === option.id.split(',').reduce((matches, type) => {
|
|
|
|
matches += selectedType.indexOf(type) > -1 ? 1 : 0
|
|
|
|
return matches
|
|
|
|
}, 0))
|
|
|
|
} else if (this.type) {
|
|
|
|
return {
|
|
|
|
id: this.type.join(','),
|
|
|
|
name: this.type.join(',')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
set(data) {
|
|
|
|
// ical.js take types as arrays
|
|
|
|
this.type = data.id.split(',')
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:33:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// property value(s)
|
2018-08-10 15:46:46 +00:00
|
|
|
value: {
|
2018-08-07 14:34:46 +00:00
|
|
|
get() {
|
|
|
|
if (this.property.isMultiValue) {
|
|
|
|
return this.property.getValues()
|
|
|
|
}
|
|
|
|
return this.property.getFirstValue()
|
|
|
|
},
|
|
|
|
set(data) {
|
|
|
|
if (this.property.isMultiValue) {
|
|
|
|
return this.property.setValues(data)
|
|
|
|
}
|
|
|
|
return this.property.setValue(data)
|
|
|
|
}
|
2018-08-09 13:33:08 +00:00
|
|
|
},
|
2018-08-10 15:46:46 +00:00
|
|
|
|
2018-08-09 13:33:08 +00:00
|
|
|
// property meta type
|
|
|
|
type: {
|
|
|
|
get() {
|
2018-08-10 15:46:46 +00:00
|
|
|
let type = this.property.getParameter('type')
|
|
|
|
// ensure we have an array
|
|
|
|
if (type) {
|
|
|
|
return Array.isArray(type) ? type : [type]
|
|
|
|
}
|
2018-08-09 13:33:08 +00:00
|
|
|
},
|
|
|
|
set(data) {
|
|
|
|
this.property.setParameter('type', data)
|
|
|
|
}
|
|
|
|
},
|
2018-08-10 15:46:46 +00:00
|
|
|
|
2018-08-09 13:33:08 +00:00
|
|
|
// property meta pref
|
|
|
|
pref: {
|
|
|
|
get() {
|
|
|
|
return this.property.getParameter('pref')
|
|
|
|
},
|
|
|
|
set(data) {
|
|
|
|
this.property.setParameter('pref', data)
|
|
|
|
}
|
2018-08-07 14:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|