forked from Neovici/cosmoz-omnitable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcosmoz-omnitable-column-boolean.html
171 lines (139 loc) · 3.97 KB
/
cosmoz-omnitable-column-boolean.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
166
167
168
169
170
171
<link rel="import" href="cosmoz-omnitable-column-behavior.html">
<link rel="import" href="../paper-dropdown-menu/paper-dropdown-menu.html"/>
<link rel="import" href="../paper-listbox/paper-listbox.html"/>
<link rel="import" href="../paper-item/paper-item.html"/>
<dom-module id="cosmoz-omnitable-column-boolean">
<template>
<template class="cell">
[[ getString(item, valuePath) ]]
</template>
<template class="edit-cell">
<paper-dropdown-menu>
<paper-listbox class="dropdown-content" slot="dropdown-content"
attr-for-selected="value"
fallback-selection="[[ _computeSelected(item, valuePath) ]]"
on-selected-item-changed="_valueChanged">
<paper-item value="true">[[ trueLabel ]]</paper-item>
<paper-item value="false">[[ falseLabel ]]</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</template>
<template class="header">
<paper-dropdown-menu label="[[ title ]]"
horizontal-align="[[ preferredDropdownHorizontalAlign ]]" opened="{{ headerFocused }}">
<paper-listbox class="dropdown-content" slot="dropdown-content" attr-for-selected="value" selected="{{ _textFilter }}">
<paper-item value=""></paper-item>
<paper-item value="true">[[ trueLabel ]]</paper-item>
<paper-item value="false">[[ falseLabel ]]</paper-item>
</paper-listbox>
</paper-dropdown-menu>
</template>
</template>
<script>
Polymer({
is: 'cosmoz-omnitable-column-boolean',
properties: {
filter: {
type: Boolean,
notify: true,
value() {
return this._getDefaultFilter();
}
},
trueLabel: {
type: String,
value: 'True'
},
falseLabel: {
type: String,
value: 'False'
},
_textFilter: {
type: String,
observer: '_textFilterChanged'
},
_textValue: {
},
templatetemplateWidth: {
type: String,
value: '60px'
},
/**
* No need to grow, as the values in a boolean column should have known fixed width
* @returns {String} Default flex
*/
flex: {
type: String,
value: '0'
}
},
behaviors: [
Cosmoz.OmnitableColumnBehavior
],
observers: [
'_filterChanged(filter)'
],
// TODO(pasleq): same questions as for cosmoz-omnitable-column-date
_filterChangedFromInput: false,
_filterChangedFromAbove: false,
_textFilterChanged: function (textFilter) {
if (this._filterChangedFromAbove) {
this._filterChangedFromAbove = false;
return;
}
var b = null;
if (textFilter) {
b = textFilter === 'true';
}
this._filterChangedFromInput = true;
this.set('filter', b);
},
_filterChanged: function (filter) {
if (this._filterChangedFromInput) {
this._filterChangedFromInput = false;
return;
}
this._filterChangedFromAbove = true;
if (typeof filter === 'boolean') {
this._textFilter = filter.toString();
} else {
this._textFilter = null;
}
},
getString: function (item, valuePath) {
var value = this.get(valuePath || this.valuePath, item);
return value ? this.trueLabel : this.falseLabel;
},
getFilterFn: function () {
if (this.filter != null) {
return this._applySingleFilter.bind(this);
}
},
_applySingleFilter: function (item) {
var value = this.get(this.valuePath, item);
return value === this.filter;
},
_computeSelected: function (item, valuePath) {
var value = this.get(valuePath, item);
if (value != null) {
return value.toString();
}
},
/** OVERRIDES */
/** cosmoz-omnitable-column-behavior */
_valueChanged(e) {
var value = e.target.selected === 'true',
item = e.model.item,
oldValue = this.get(this.valuePath, item),
formatFn = value => {
return value ? this.trueLabel : this.falseLabel;
};
if (value === oldValue) {
return;
}
this.set(this.valuePath, value, item);
this._fireItemChangeEvent(item, this.valuePath, oldValue, formatFn.bind(this));
}
});
</script>
</dom-module>