-
Notifications
You must be signed in to change notification settings - Fork 5
/
cosmoz-omnitable-column-list-horizontal.html
165 lines (145 loc) · 3.98 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<link rel="import" href="../shadycss/apply-shim.html">
<link rel="import" href="../polymer/polymer-element.html"/>
<link rel="import" href="../polymer/lib/legacy/class.html"/>
<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-mixin.html">
<link rel="import" href="cosmoz-omnitable-column-list-mixin.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">
window.Cosmoz = window.Cosmoz || {};
/**
* @polymer
* @customElement
* @appliesMixin Cosmoz.OmnitableColumnMixin
* @appliesMixin Cosmoz.ListColumnMixin
*/
class OmnitableColumnListHorizontal extends Cosmoz.OmnitableColumnMixin(Cosmoz.ListColumnMixin(
Polymer.mixinBehaviors([Cosmoz.TranslatableBehavior], Polymer.Element)
)) {
static get is() {
return 'cosmoz-omnitable-column-list-horizontal';
}
static get properties() {
return {
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();
}
}
};
}
_computeAutocompleteItems(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(value) {
if (value == null) {
return null;
}
return value.toString();
}
_applySingleFilter(filterString, item) {
const value = this.get(this.valuePath, item);
if (value == null) {
return false;
}
return value.toString().toLowerCase() === filterString;
}
_applyMultiFilter(filter, item) {
const valueFilter = element => {
const value = this.valueProperty ? this.get(this.valueProperty, element) : element;
return value ? value.toString().toLowerCase() : null;
},
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);
}
_getDefaultFilter() {
return [];
}
getString() {
const value = super.getString.apply(this, arguments);
if (!Array.isArray(value) || value.length === 0) {
return '';
}
return value.join(', ');
}
}
customElements.define(
OmnitableColumnListHorizontal.is,
OmnitableColumnListHorizontal
);
Cosmoz.OmnitableColumnListHorizontal = OmnitableColumnListHorizontal;
</script>
</dom-module>