-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathGrampsjsEvent.js
More file actions
218 lines (201 loc) · 5.64 KB
/
Copy pathGrampsjsEvent.js
File metadata and controls
218 lines (201 loc) · 5.64 KB
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
import {html, css} from 'lit'
import '@material/mwc-icon'
import {GrampsjsObject} from './GrampsjsObject.js'
import './GrampsjsFormEditEventDetails.js'
import './GrampsjsFormEditTitle.js'
import './GrampsjsTooltip.js'
import {fireEvent, emptyDate} from '../util.js'
const BASE_DIR = ''
export class GrampsjsEvent extends GrampsjsObject {
static get styles() {
return [
super.styles,
css`
:host {
}
`,
]
}
constructor() {
super()
this._objectsName = 'Events'
this._objectIcon = 'event'
this._objectEndpoint = 'events'
this._showReferences = false
}
renderProfile() {
return html`
<h2>
${this._renderTitle()}
${this.edit
? html`
<mwc-icon-button
id="btn-edit-type"
icon="edit"
class="edit"
@click="${this._handleEditType}"
></mwc-icon-button>
<grampsjs-tooltip for="btn-edit-type"
>${this._('Edit event type')}</grampsjs-tooltip
>
`
: ''}
</h2>
${this.data.description || this.edit
? html` <dl>
<div>
<dt>${this._('Description')}</dt>
<dd>${this.data.description}</dd>
</div>
</dl>`
: ''}
${this.edit
? html`
<mwc-icon-button
icon="edit"
class="edit"
@click="${this._handleEditDesc}"
></mwc-icon-button>
`
: ''}
<dl style="clear:left;">
${this.data?.profile?.date || this.edit
? html`
<div>
<dt>${this._('Date')}</dt>
<dd>${this.data.profile.date}</dd>
</div>
`
: ''}
${this.data?.profile?.place || this.edit
? html`
<div>
<dt>${this._('Place')}</dt>
<dd>
<a
href="${BASE_DIR}/place/${this.data.extended.place
.gramps_id}"
>${this.data.profile.place_name ||
this.data.profile.place}</a
>
</dd>
</div>
`
: ''}
</dl>
${this.edit
? html`
<mwc-icon-button
icon="edit"
class="edit"
@click="${this._handleEditDetails}"
></mwc-icon-button>
`
: ''}
`
}
// eslint-disable-next-line class-methods-use-this
_renderPerson(obj) {
if (obj === undefined) {
return ''
}
if (!obj?.name_display) {
return `${obj?.name_given || '…'} ${obj?.name_surname || '…'}`
}
return `${obj?.name_display}`
}
// eslint-disable-next-line class-methods-use-this
_renderFamily(obj) {
if (obj === undefined) {
return ''
}
return `${this._renderPerson(obj.family?.father)} & ${this._renderPerson(
obj.family?.mother
)}`
}
_renderPrimaryPeople() {
const primary = this._('Primary')
const family = this._('Family')
const people =
this.data?.profile?.participants?.people.filter(
obj => obj.role === primary || obj.role === 'Primary'
) || []
const families =
this.data?.profile?.participants?.families.filter(
obj => obj.role === family || obj.role === 'Family'
) || []
return `${people
.map(obj => this._renderPerson(obj.person), this)
.join(', ')}
${families.map(obj => this._renderFamily(obj), this).join(', ')}`
}
_renderTitle() {
if (
!this.data?.profile?.participants?.people?.length &&
!this.data?.profile?.participants?.families?.length
) {
// event without participants
return html`${this.data.profile.type}`
}
return html`${this.data.profile.type}: ${this._renderPrimaryPeople()}`
}
_handleEditDetails() {
const data = {date: this.data.date ?? emptyDate}
if (this.data.place) {
data.place = this.data.place
}
const place = this.data?.extended?.place
this.dialogContent = html`
<grampsjs-form-edit-event-details
@object:save="${this._handleSaveDetails}"
@object:cancel="${this._handleCancelDialog}"
.appState="${this.appState}"
.data=${data}
.place=${place}
>
</grampsjs-form-edit-event-details>
`
}
_handleSaveDetails(e) {
fireEvent(this, 'edit:action', {action: 'updateProp', data: e.detail.data})
e.preventDefault()
e.stopPropagation()
this.dialogContent = ''
}
_handleEditDesc() {
this.dialogContent = html`
<grampsjs-form-edit-title
@object:save="${this._handleSaveDesc}"
@object:cancel="${this._handleCancelDialog}"
.appState="${this.appState}"
.data=${{description: this.data?.description || ''}}
prop="description"
>
</grampsjs-form-edit-title>
`
}
_handleSaveDesc(e) {
fireEvent(this, 'edit:action', {action: 'updateProp', data: e.detail.data})
e.preventDefault()
e.stopPropagation()
this.dialogContent = ''
}
_handleEditType() {
this.dialogContent = html`
<grampsjs-form-edit-type
dialogTitle="${this._('Edit event type')}"
formId="event-type"
typeName="event_types"
@object:save="${this._handleSaveType}"
@object:cancel="${this._handleCancelDialog}"
.appState="${this.appState}"
.data=${{
type: this.data?.type?.string || this.data?.type || '',
}}
prop="value"
>
</grampsjs-form-edit-type>
`
}
}
window.customElements.define('grampsjs-event', GrampsjsEvent)