-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnylon-checked-group.html
77 lines (68 loc) · 1.73 KB
/
nylon-checked-group.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
<link rel="import" href="../polymer/polymer-element.html">
<dom-module id="nylon-checked-group">
<script>
/**
* `nylon-checked-group`
*
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class NylonCheckedGroup extends Polymer.Element {
static get is() {
return 'nylon-checked-group'
}
static get properties() {
return {
items: {
type: Array,
value: [],
observer: '_itemsOrValueChanged'
},
itemsBind: {
type: Array,
notify: true
},
value: {
type: Array,
value: [],
observer: '_itemsOrValueChanged',
notify: true
}
}
}
static get observers() {
return ['_itemsBindChanged(itemsBind.*)']
}
_itemsOrValueChanged() {
this.itemsBind = JSON.parse(JSON.stringify(this.items))
if(!this.value){
this.value = []
}
if(!this.items){
this.items = []
}
if ((this.value.length > 0) && (this.items.length > 0)) {
this._checkedItem()
}
}
_checkedItem() {
this.itemsBind = JSON.parse(JSON.stringify(this.itemsBind.map((row) => {
row.checked = this.value.indexOf(row.value) != -1
return row
})))
}
_itemsBindChanged(ob) {
if (ob.path != 'itemsBind') {
this.value = ob.base.filter((row) => {
return row.checked
}).map((row) => {
return row.value
})
}
}
}
window.customElements.define(NylonCheckedGroup.is, NylonCheckedGroup);
</script>
</dom-module>