diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-09-28 19:01:07 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-09-28 19:01:07 +0200 |
commit | f285b76b6c18e9f9642dde9ea1a8a25efb67ee4a (patch) | |
tree | ce2ca3cedbaa6c7eb3fba8987e0ec7c034e6fbe4 /src | |
parent | 4169161824c741093e85455c57314ee475088ffd (diff) |
Move addressbook
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/components/ContactDetails.vue | 20 | ||||
-rw-r--r-- | src/models/contact.js | 16 | ||||
-rw-r--r-- | src/store/addressbooks.js | 16 | ||||
-rw-r--r-- | src/store/contacts.js | 2 |
4 files changed, 38 insertions, 16 deletions
diff --git a/src/components/ContactDetails.vue b/src/components/ContactDetails.vue index 83fdc676..17c00b0a 100644 --- a/src/components/ContactDetails.vue +++ b/src/components/ContactDetails.vue @@ -406,18 +406,18 @@ export default { */ moveContactToAddressbook(addressbookId) { let addressbook = this.addressbooks.find(search => search.id === addressbookId) + this.loadingUpdate = true // TODO Make sure we do not overwrite contacts if (addressbook) { - this.$store - .dispatch('moveContactToAddressbook', { - // we need to use the store contact, not the local contact - // using this.contact and not this.localContact - contact: this.contact, - addressbook - }) - .then(() => { - this.updateContact() - }) + this.$store.dispatch('moveContactToAddressbook', { + // we need to use the store contact, not the local contact + // using this.contact and not this.localContact + contact: this.contact, + addressbook + }).then(() => { + this.updateContact() + this.loadingUpdate = false + }) } }, diff --git a/src/models/contact.js b/src/models/contact.js index b0eec0a5..f19ce260 100644 --- a/src/models/contact.js +++ b/src/models/contact.js @@ -30,11 +30,10 @@ export default class Contact { * * @param {string} vcard the vcard data as string with proper new lines * @param {object} addressbook the addressbook which the contat belongs to - * @param {string} [url=''] the url of the contact * @param {string} [etag=''] the current etag of the contact * @memberof Contact */ - constructor(vcard, addressbook, url = '', etag = '') { + constructor(vcard, addressbook, etag = '') { if (typeof vcard !== 'string' || vcard.length === 0) { throw new Error('Invalid vCard') } @@ -47,7 +46,6 @@ export default class Contact { this.jCal = jCal this.addressbook = addressbook this.vCard = new ICAL.Component(this.jCal) - this.url = url this.conflict = false // if no uid set, create one @@ -92,6 +90,18 @@ export default class Contact { } /** + * Return the url + * + * @readonly + * @memberof Contact + */ + get url() { + if (this.dav) { + return this.dav.url + } + } + + /** * Return the uid * * @readonly diff --git a/src/store/addressbooks.js b/src/store/addressbooks.js index b7828f4b..5906e909 100644 --- a/src/store/addressbooks.js +++ b/src/store/addressbooks.js @@ -305,7 +305,7 @@ const actions = { // We don't want to lose the url information // so we need to parse one by one const contacts = response.map(item => { - let contact = new Contact(item.data, addressbook, item.url, item.etag) + let contact = new Contact(item.data, addressbook, item.etag) Vue.set(contact, 'dav', item) return contact }) @@ -412,11 +412,23 @@ const actions = { async moveContactToAddressbook(context, { contact, addressbook }) { // only local move if the contact doesn't exists on the server if (contact.dav) { - await contact.dav.move(addressbook.dav) + // TODO: implement proper move + // await contact.dav.move(addressbook.dav) + // .catch((error) => { + // console.error(error) + // OC.Notification.showTemporary(t('contacts', 'An error occurred')) + // }) + let vData = ICAL.stringify(contact.vCard.jCal) + let newDav + await addressbook.dav.createVCard(vData) + .then((response) => { newDav = response }) + .catch((error) => { throw error }) + await contact.dav.delete() .catch((error) => { console.error(error) OC.Notification.showTemporary(t('contacts', 'An error occurred')) }) + await Vue.set(contact, 'dav', newDav) } await context.commit('deleteContactFromAddressbook', contact) await context.commit('updateContactAddressbook', { contact, addressbook }) diff --git a/src/store/contacts.js b/src/store/contacts.js index 60e2c6bf..a6511e5d 100644 --- a/src/store/contacts.js +++ b/src/store/contacts.js @@ -306,7 +306,7 @@ const actions = { } return contact.dav.fetchCompleteData() .then((response) => { - let newContact = new Contact(contact.dav.data, contact.addressbook, contact.dav.url, contact.dav.etag) + let newContact = new Contact(contact.dav.data, contact.addressbook, contact.dav.etag) context.commit('updateContact', newContact) }) .catch((error) => { throw error }) |