Skip to content

Commit

Permalink
Add photo getters and setters, updateContact with photo. #603
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessica authored and Jessica committed Sep 19, 2018
1 parent be00470 commit 16ddf70
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/components/ContactDetails/ContactDetailsAvatar.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!--
import rfcProps from '../../models/rfcProps';
* @copyright Copyright (c) 2018 Team Popcorn <teampopcornberlin@gmail.com>
*
* @author Team Popcorn <teampopcornberlin@gmail.com>
Expand All @@ -23,14 +24,16 @@
<template>
<div id="contact-header-avatar">
<div class="contact-avatar-background" />
<img v-if="contact.avatar">
<img v-if="contact.photo" :src="contact.photo">
<input id="contact-avatar-upload" type="file" class="hidden"
accept="image/*" @change="processFile">
<label v-tooltip.auto="t('contacts', 'Upload a new picture')" for="contact-avatar-upload" class="icon-upload-white" />
</div>
</template>

<script>
import rfcProps from '../../models/rfcProps.js'

export default {
name: 'ContactAvatar',

Expand All @@ -43,27 +46,11 @@ export default {
methods: {
processFile(event) {
let file = event.target.files[0]
/* console.log(event.target.files)
alert(JSON.stringify(file, undefined, 2))
WIP */
let reader = new FileReader()
/* let selectedAddressbook = this.selectedAddressbook
this.$store.dispatch('changeStage', 'parsing')
this.$store.dispatch('setAddressbook', selectedAddressbook.displayName)
WIP */
let self = this
reader.onload = function(e) {
/* self.$store.dispatch('importContactsIntoAddressbook', { vcf: reader.result, addressbook: selectedAddressbook })
WIP */
console.log(reader.result) // eslint-disable-line
if (!self.contact.vCard.hasProperty('avatar')) {
let property = self.contact.vCard.addPropertyWithValue('avatar', reader.result)
// ^WIP: need to research how to set type as 'text' same as in following example:
// ["version", {…}, "text", "4.0", __ob__: Observer]
property.setParameter('type', 'text')
// ^WIP: need to research what above function is doing
console.log(self.contact.vCard) // eslint-disable-line
}
self.contact.vCard.addPropertyWithValue('photo', reader.result)
self.$store.dispatch('updateContact', self.contact)
}
reader.readAsDataURL(file)
}
Expand Down
20 changes: 20 additions & 0 deletions src/models/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ export default class Contact {
return this.uid + '@' + this.addressbook.id
}

/**
* Return the photo
*
* @readonly
* @memberof Contact
*/
get photo() {
return this.vCard.getFirstPropertyValue('photo')
}

/**
* Set the photo
*
* @memberof Contact
*/
set photo(photo) {
this.vCard.updatePropertyWithValue('photo', photo)
return true
}

/**
* Return the groups
*
Expand Down

0 comments on commit 16ddf70

Please sign in to comment.