1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<template>
<div :class="{active: selectedContact === contact.key}" :id="id" tabindex="0"
class="app-content-list-item" @click.prevent.stop="selectContact" @keypress.enter.prevent.stop="selectContact">
<!-- keyboard accessibility will focus the input and not the label -->
<!--
<input ref="selected" :id="contact.key" type="checkbox"
class="app-content-list-item-checkbox checkbox" @keypress.enter.space.prevent.stop="toggleSelect">
<label :for="contact.key" @click.prevent.stop="toggleSelect" @keypress.enter.space.prevent.stop="toggleSelect" />
-->
<div :style="{ 'backgroundColor': colorAvatar }" class="app-content-list-item-icon">
{{ contact.displayName | firstLetter }}
<!-- try to fetch the avatar only if the contact exists on the server -->
<div v-if="contact.photo && contact.dav" :style="{ 'backgroundImage': avatarUrl }" class="app-content-list-item-icon__avatar" />
</div>
<div class="app-content-list-item-line-one">{{ contact.displayName }}</div>
<div v-if="contact.email" class="app-content-list-item-line-two">{{ contact.email }}</div>
<div v-if="contact.addressbook.readOnly" class="icon-delete" tabindex="0"
@click.prevent.stop="deleteContact" @keypress.enter.prevent.stop="deleteContact" />
</div>
</template>
<script>
export default {
name: 'ContentListItem',
filters: {
firstLetter(value) {
return value.charAt(0)
}
},
props: {
contact: {
type: Object,
required: true
}
},
computed: {
selectedGroup() {
return this.$route.params.selectedGroup
},
selectedContact() {
return this.$route.params.selectedContact
},
// usable and valid html id for scrollTo
id() {
return window.btoa(this.contact.key).slice(0, -2)
},
/**
* avatar color based on server toRgb method and the displayName
* @returns {String} the color in css format
*/
colorAvatar() {
try {
let color = this.contact.uid.toRgb()
return `rgb(${color.r}, ${color.g}, ${color.b})`
} catch (e) {
return 'grey'
}
},
avatarUrl() {
return `url(${this.contact.url}?photo)`
}
},
methods: {
/**
* Checkbox management method
*/
toggleSelect() {
// toggle checkbox here because we stop the propagation to not trigger selectContact
// therefore the selectContact prevent the checkbox label+input propagation
this.$refs.selected.checked = !this.$refs.selected.checked
},
/**
* Dispatch contact deletion request
*/
deleteContact() {
this.$store.dispatch('deleteContact', { contact: this.contact })
},
/**
* Select this contact within the list
*/
selectContact() {
// change url with router
this.$router.push({ name: 'contact', params: { selectedGroup: this.selectedGroup, selectedContact: this.contact.key } })
}
}
}
</script>
|