-
Notifications
You must be signed in to change notification settings - Fork 0
/
ee-medication-list.html
118 lines (95 loc) · 3.05 KB
/
ee-medication-list.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
<link rel="import" href="../polymer/polymer.html">
<!-- Paper -->
<link rel="import" href="../paper-fab/paper-fab.html">
<!-- Iron -->
<link rel="import" href="../iron-resizable-behavior/iron-resizable-behavior.html">
<!-- Third -->
<link rel="import" href="../vaadin-combo-box/vaadin-combo-box.html">
<!-- Elfy -->
<link rel="import" href="../ee-shared-styles/shared-styles.html">
<link rel="import" href="../ee-helper-behavior/ee-helper-behavior.html">
<link rel="import" href="../js-data-behaviors/js-data-collection-behavior.html">
<link rel="import" href="../elfy-api/elfy-api.html">
<link rel="import" href="ee-medication.html">
<!--
`ee-medication-list`
medication add and display
@demo demo/index.html
-->
<dom-module id="ee-medication-list">
<template>
<style include="shared-styles">
:host {
display: block;
}
paper-fab {
margin: 12px auto;
}
.list-container {
background-color: #fff;
padding: 24px;
@apply(--ee-medication-list-container);
}
</style>
<div class="error">[[errorMessage]]</div>
<template is="dom-if" if="[[_lengthBigger(medications,0)]]" restamp="true">
<div class="h mb mt">
<span class="space">Name</span>
<span class="space">Dosage</span>
<span class="space"></span>
</div>
</template>
<div class="list-container" hidden="[[!careRecipient.id]]">
<template is="dom-repeat" items="{{medications}}" as="medication">
<ee-medication medication="{{medication}}" on-remove="_removeMedication"></ee-medication>
</template>
</div>
<paper-fab icon="add" on-tap="addMedication" hidden="[[!careRecipient.id]]"></paper-fab>
<div class="center" hidden="[[careRecipient.id]]">Please first select a care recipient.</div>
</template>
<script>
Polymer({
is: 'ee-medication-list',
behaviors: [
Elfy.EEHelperBehavior,
Elfy.JSDataCollectionBehavior,
Polymer.IronResizableBehavior,
],
properties: {
medications: {
type: Object,
value() { return [] }
},
careRecipient: {
type: Object,
value() { return {} },
notify: true
},
},
observers: [
'_careRecipientChanged(careRecipient, careRecipient.*)'
],
attached() {
this.fire('resize')
},
addMedication() {
if (!this.careRecipient || !this.careRecipient.id) return
var cr = App.Medication.createRecord()
cr.careRecipient = this.careRecipient
this.push('medications', cr)
},
_removeMedication(e) {
if (this.medications.indexOf(e.model.medication) > -1) {
this.splice('medications', this.medications.indexOf(e.model.medication), 1);
}
},
_careRecipientChanged(cr) {
this.set('medications', [])
if (cr && cr.id) {
this.JSData.collections = [{'name': 'medications', 'query': {'careRecipientId': cr.id}}]
this._loadData()
}
},
});
</script>
</dom-module>