-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfs-person-facts.html
139 lines (121 loc) · 3.67 KB
/
fs-person-facts.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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../paper-card/paper-card.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="../paper-styles/paper-styles.html">
<link rel="import" href="../fs-person-mixin/fs-person-mixin.html">
<link rel="import" href="../fs-fact/fs-fact.html">
<link rel="import" href="../fs-fact/fs-fact-types-menu.html">
<!--
List a FamilySearch person's facts.
Basic example:
<fs-person-facts person-id="PPP-PPPP"></fs-person-facts>
@group FamilySearch Elements
@customElement
@polymer
@demo demo/index.html
-->
<dom-module id="fs-person-facts">
<template>
<style>
:host {
display: block;
}
paper-card {
width: 100%;
}
.fact-container {
padding: 16px;
}
.fact-container:not(:first-child) {
border-top: 1px solid #e0e0e0;
}
[hidden] {
display: none !important;
}
</style>
<paper-card>
<template is="dom-repeat" items="{{facts}}">
<div class="fact-container">
<fs-fact editable fact="{{item}}" save-url="[[_saveUrl]]"></fs-fact>
</div>
</template>
<div class="fact-container">
<paper-button
hidden$="[[_selectingNewFactType]]"
on-tap="_addNewFact">Add Fact</paper-button>
<fs-fact-types-menu
hidden$="[[!_selectingNewFactType]]"
entity-type="person"
ignore-vitals="[[ignoreVitals]]"
value="{{_newFactType}}"></fs-fact-types-menu>
</div>
</paper-card>
</template>
<script>
class FSPersonFacts extends FSPersonMixin(Polymer.Element) {
static get is() { return 'fs-person-facts'; }
static get properties() {
return {
facts: {
type: Array,
value: function(){
return [];
}
},
/**
* Whether to ignore (hide) vital facts. This is useful when
* you are also using the fs-person-vitals component.
*/
ignoreVitals: {
type: Boolean,
value: false
},
/**
* Whether the user has indicated they want to add a new fact type
* and are still in the fact type selection process.
*/
_selectingNewFactType: {
type: Boolean,
value: false
},
/**
* Fact type the user has chosen for a new fact
*/
_newFactType: {
type: String,
observer: '_newFactTypeChosen'
},
/**
* URL that facts will be saved to
*/
_saveUrl: String
};
}
_personChanged() {
if(this.person && this.person.facts){
this._saveUrl = this.person.links.person.href;
this.facts = this.ignoreVitals ? this.person.facts.filter(f => !FsFactTypes.isVital(f.type)) : this.person.facts;
} else {
this.facts = [];
}
}
_addNewFact() {
this._selectingNewFactType = true;
}
_newFactTypeChosen(newFactType) {
if(newFactType) {
this._newFactType = '';
this._selectingNewFactType = false;
this.push('facts', {
type: newFactType
});
// Put the new fact into edit mode
setTimeout(() => {
Array.from(this.shadowRoot.querySelectorAll('fs-fact')).pop().edit = true;
});
}
}
}
customElements.define(FSPersonFacts.is, FSPersonFacts);
</script>
</dom-module>