forked from Neovici/cosmoz-omnitable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmoz-omnitable-column-list-horizontal.html
149 lines (129 loc) · 3.43 KB
/
cosmoz-omnitable-column-list-horizontal.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
140
141
142
143
144
145
146
147
148
149
<link rel="import" href="../paper-autocomplete-chips/paper-autocomplete-chips.html">
<link rel="import" href="../cosmoz-i18next/cosmoz-i18next.html">
<link rel="import" href="cosmoz-omnitable-column-behavior.html">
<dom-module id="cosmoz-omnitable-column-list-horizontal">
<template>
<template class="cell">
<style>
ul {
display: inline;
list-style: none;
}
ul li {
display: inline;
}
ul li:after {
content: ", ";
}
ul li:last-child:after {
content: "";
}
</style>
<ul>
<template is="dom-repeat" items="[[ get(valuePath, item) ]]" as="listitem">
<li>[[ listitem ]]</li>
</template>
</ul>
</template>
<template class="edit-cell">
<paper-input no-label-float type="text" on-change="_valueChanged" value="[[ getString(item, valuePath) ]]"></paper-input>
</template>
<template class="header">
<paper-autocomplete-chips
source="[[ _computeAutocompleteItems(values) ]]"
label="[[ title ]]"
selected-items="{{ filter }}"
text-property="[[ textProperty ]]"
value-property="[[ valueProperty ]]"
show-results-on-focus>
</paper-autocomplete-chips>
</template>
</template>
<script type="text/javascript">
Polymer({
is: 'cosmoz-omnitable-column-list-horizontal',
behaviors: [
Cosmoz.OmnitableColumnBehavior,
Cosmoz.TranslatableBehavior
],
properties: {
autocompleteSelectedItems: {
type: Array
},
/**
* Ask for a list of values
*/
bindValues: {
type: Boolean,
readOnly: true,
value: true
},
filter: {
type: Array,
notify: true,
value() {
return this._getDefaultFilter();
}
},
textProperty: {
type: String,
value: 'label'
},
valueProperty: {
type: String,
value: 'value'
}
},
_computeAutocompleteItems: function (values = this.values) {
const unique = [];
return values
.reduce((acc, val) => acc.concat(val), [])
// Make the item list unique
.filter((value, index, array) => {
if (array.indexOf(value) !== index) {
return false;
}
const val = this.valueProperty ? this.get(this.valueProperty, value) : value,
hasVal = unique.indexOf(val) !== -1;
if (hasVal) {
return false;
}
unique.push(val);
return true;
})
.sort();
},
_getLabelForValue: function (value) {
return value.toString();
},
getString(item, valuePath = this.valuePath) {
const values = this.get(valuePath, item);
if (values == null) {
return '';
}
return values
.map(value => this.textProperty ? this.get(this.textProperty, value) : value)
.filter((value, index, array) => array.indexOf(value) === index)
.join(', ');
},
_applySingleFilter: function (filterString, item) {
const value = this.get(this.valuePath, item).toString().toLowerCase();
return value === filterString;
},
_applyMultiFilter: function (filter, item) {
const valueFilter = element => {
const value = this.valueProperty ? this.get(this.valueProperty, element) : element;
return value.toString().toLowerCase();
},
filterArray = filter.map(valueFilter),
listValue = this.get(this.valuePath, item);
if (listValue == null) {
return filter.length === 0;
}
return listValue
.map(valueFilter)
.some(val => filterArray.indexOf(val) >= 0);
}
});
</script>
</dom-module>