-
Notifications
You must be signed in to change notification settings - Fork 1
/
fs-family.html
247 lines (207 loc) · 7.08 KB
/
fs-family.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../fs-api-aware/fs-api-aware.html">
<link rel="import" href="../fs-person-chip/fs-person-chip.html">
<link rel="import" href="../paper-card/paper-card.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../iron-collapse/iron-collapse.html">
<link rel="import" href="../polymer/lib/mixins/gesture-event-listeners.html">
<link rel="import" href="../polymer/lib/elements/dom-if.html">
<!--
Display a family.
Set the family:
<fs-family family="[[family]]"></fs-family>
You may have the children list collapsed by default:
<fs-family family="[[family]]" children-collapsed></fs-family>
A family object consists of a father, mother, and a list of children
{
father: {Object},
mother: {Object},
children: [ {Object} ]
}
@group FamilySearch Elements
@customElement
@polymer
@demo demo/index.html
-->
<dom-module id="fs-family">
<template>
<style>
:host {
display: block;
}
paper-card {
width: 100%;
}
.card-content fs-person-chip:last-of-type {
margin-top: 16px;
}
#children {
border-top: 1px solid #ddd;
}
#childrenList fs-person-chip {
margin: 8px 16px;
}
#childrenList fs-person-chip:first-child{
margin-top: 0px;
}
#noChildren {
color: --secondary-text-color;
}
</style>
<paper-card>
<div class="card-content">
<template is="dom-if" if="{{_hasFather(family)}}">
<fs-person-chip client-name="[[clientName]]" person="[[family.father]]" on-tap="_fatherTap"></fs-person-chip>
</template>
<template is="dom-if" if="{{!_hasFather(family)}}">
<fs-person-chip>
<paper-button on-tap="_addFather">+ Add Spouse</paper-button>
</fs-person-chip>
</template>
<template is="dom-if" if="{{_hasMother(family)}}">
<fs-person-chip client-name="[[clientName]]" person="[[family.mother]]" on-tap="_motherTap"></fs-person-chip>
</template>
<template is="dom-if" if="{{!_hasMother(family)}}">
<fs-person-chip>
<paper-button on-tap="_addMother">+ Add Spouse</paper-button>
</fs-person-chip>
</template>
</div>
<template is="dom-if" if="{{_displayChildren(family, addPersons)}}">
<div id="children">
<paper-button on-tap="_toggleChildren" noink>{{_buttonText(childrenCollapsed)}}</paper-button>
<iron-collapse opened="[[!childrenCollapsed]]">
<div id="childrenList">
<template is="dom-repeat" items="[[family.children]]">
<fs-person-chip client-name="[[clientName]]" person="[[item]]" on-tap="_childTap"></fs-person-chip>
</template>
<template is="dom-if" if="{{addPersons}}">
<paper-button on-tap="_addChild">+ Add Child</paper-button>
</template>
</div>
</iron-collapse>
</div>
</template>
</paper-card>
</template>
<script>
class FSFamily extends Polymer.GestureEventListeners(FSApiAwareMixin(Polymer.Element)) {
static get is() { return 'fs-family'; }
/**
* Fired when a person is clicked.
*
* @event person-click
* @param {{personId:string}} ID of the person that was clicked.
* @param {{sourceEvent:event}} Original click event.
*/
/**
* Fired when the "Add Child" button is clicked.
* This event does not bubble; it is designed to only be handled
* by the `fs-person-families` element.
*
* @event add-child
* @param {{fatherId:string}} ID of the father of the family
* @param {{motherId:string}} ID of the mother of the family
*/
/**
* Fired when the "Add Spouse" button is clicked for a husband.
* This event does not bubble; it is designed to only be handled
* by the `fs-person-families` element.
*
* @event add-father
* @param {{motherId:string}} ID of the mother of the family
* @param {{gender:string}} http://gedcomx.org/Male
*/
/**
* Fired when the "Add Spouse" button is clicked for a wife.
* This event does not bubble; it is designed to only be handled
* by the `fs-person-families` element.
*
* @event add-mother
* @param {{fatherId:string}} ID of the father of the family
* @param {{gender:string}} http://gedcomx.org/Female
*/
static get properties() {
return {
/**
* A family object has the form {father, mother, children[]}
*/
family: {
type: Object
},
/**
* When true the children list will be collapsed by default.
*/
childrenCollapsed: {
type: Boolean,
reflectToAttribute: true,
value: false
},
/**
* Whether the Add Spouse and Add Child buttons should be shown
*/
addPersons: {
type: Boolean,
value: false
}
};
}
_buttonText() {
return this.childrenCollapsed ? 'Show Children' : 'Hide Children';
}
_toggleChildren() {
this.childrenCollapsed = !this.childrenCollapsed;
}
_hasFather(family) {
return family.father;
}
_hasMother(family) {
return family.mother;
}
_fatherTap(e) {
if(this.family.father){
this._firePersonTap(e, this.family.father.id);
}
}
_motherTap(e) {
if(this.family.mother){
this._firePersonTap(e, this.family.mother.id);
}
}
_childTap(e) {
this._firePersonTap(e, e.model.item.id);
}
_firePersonTap(e, personId) {
e.detail.personId = personId;
this.dispatchEvent(new CustomEvent('person-click', {
detail: e.detail,
bubbles: true,
composed: true
}));
}
_displayChildren(family, addPersons) {
return addPersons || (family && Array.isArray(family.children) && family.children.length > 0);
}
_addChild() {
this._fireAddEvent('child');
}
_addFather() {
this._fireAddEvent('father', 'http://gedcomx.org/Male');
}
_addMother() {
this._fireAddEvent('mother', 'http://gedcomx.org/Female');
}
_fireAddEvent(person, gender) {
const detail = {gender};
if(this.family.father) {
detail.fatherId = this.family.father.id;
}
if(this.family.mother) {
detail.motherId = this.family.mother.id;
}
this.dispatchEvent(new CustomEvent(`add-${person}`, {detail}));
}
}
customElements.define(FSFamily.is, FSFamily);
</script>
</dom-module>