-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfs-person-sources.html
99 lines (85 loc) · 2.54 KB
/
fs-person-sources.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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../fs-request/fs-request.html">
<link rel="import" href="../fs-api-aware/fs-api-aware.html">
<link rel="import" href="../paper-card/paper-card.html">
<link rel="import" href="../paper-item/paper-item.html">
<!--
List sources attached to a person in the Family Tree
Example:
<fs-person-sources person-id="PPP-PPPP"></fs-person-sources>
@group FamilySearch Elements
@customElement
@polymer
@demo demo/index.html
-->
<dom-module id="fs-person-sources">
<template>
<style>
:host, paper-card {
display: block;
}
</style>
<fs-request
auto
url="{{_computeUrl(personId)}}"
client-name="[[clientName]]"
on-response="_handleResponse"
on-loading-changed="_updateLoading"
require-authentication></fs-request>
<paper-card>
<template is="dom-repeat" items="{{sources}}">
<paper-item><a href="{{item.about}}" target="_blank">{{_sourceTitle(item)}}</a></paper-item>
</template>
<paper-item hidden$="{{!_isEmpty(sources)}}">No sources</paper-item>
</paper-card>
</template>
<script>
class FSPersonSources extends FSApiAwareMixin(Polymer.Element) {
static get is() { return 'fs-person-sources'; }
static get properties() {
return {
personId: {
type: String,
observer: '_personIdChanged',
reflectToAttribute: true
},
loading: {
type: Boolean,
readOnly: true,
value: false,
notify: true
},
sources: {
type: Array,
value: function(){
return [];
}
}
};
}
_personIdChanged() {
this.sources = [];
}
_updateLoading(e) {
this._setLoading(e.detail.value);
}
_computeUrl() {
if(this.personId){
return `/platform/tree/persons/${this.personId}/sources`;
}
}
_handleResponse(e) {
if(e && e.detail && e.detail.response && e.detail.response.data && e.detail.response.data.sourceDescriptions) {
this.sources = e.detail.response.data.sourceDescriptions;
}
}
_sourceTitle(source) {
return source.titles[0].value;
}
_isEmpty() {
return this.sources && this.sources.length === 0;
}
}
customElements.define(FSPersonSources.is, FSPersonSources);
</script>
</dom-module>