-
Notifications
You must be signed in to change notification settings - Fork 13
/
px-datetime-presets.html
149 lines (133 loc) · 3.81 KB
/
px-datetime-presets.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
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../polymer/polymer.html"/>
<link rel="import" href="../px-moment-imports/px-moment-imports.html"/>
<link rel="import" href="../app-localize-behavior/app-localize-behavior.html"/>
<link rel="import" href="css/px-datetime-presets-styles.html"/>
<!--
The list of preset ranges in the rangepicker modal.
### Usage
<px-datetime-presets preset-ranges="{{...}}">
</px-datetime-presets>
@element px-datetime-presets
@homepage index.html
@demo index.html
-->
<dom-module id="px-datetime-presets">
<template>
<style include="px-datetime-presets-styles"></style>
<div class="presetTitle zeta">[[localize('Presets')]]</div>
<ul class="list-bare u-mt--">
<template is="dom-repeat" items="{{presetRanges}}" as="preset">
<li class="presetList">
<span class$="{{_getButtonClass(selectedItem, preset)}}" on-tap="_usePreset">{{preset.displayText}}</span>
</li>
</template>
</ul>
</template>
</dom-module>
<script>
Polymer({
is: 'px-datetime-presets',
behaviors: [
Polymer.AppLocalizeBehavior
],
properties: {
/**
* (optional)
*
* The preset date/time ranges to be displayed. If not set, will have no presets displayed.
*
*```
* [
* {
* "displayText": "Last 5 Minutes",
* "startDateTime": "2013-02-04T22:44:30.652Z",
* "endDateTime": "2013-02-04T22:49:30.652Z"
* },
* {
* "displayText": "Last 12 Hours",
* "startDateTime": function() {return moment().subtract(1, 'days').toISOString();},
* "endDateTime": function() {return moment().startOf('day').toISOString();}
* }
* ]
* ```
*
* startDateTime and endDateTime can also be functions, in which case
* they need to either return an ISO string as seen abode or a moment
* object
*
* @default no presets
*/
presetRanges: {
type: Object,
value: function(){
return [];
}
},
/**
*/
selectedItem: {
type: Object,
value: function(){
return {};
}
},
/**
* List of key/values to be included for translating this component
*/
resources: {
type: Object,
value: function() {
return {
'en': {
'Presets': 'Presets'
}
};
}
},
/**
* set a default for localizing
*/
language: {
type: String,
value: 'en'
},
/**
* Use the key for localization if value for language is missing. Should
* always be true for our components
*/
useKeyIfMissing: {
type: Boolean,
value: true
}
},
/**
*/
_usePreset: function(e) {
this.set('selectedItem', e.model.preset);
this.fire('px-preset-selected', e.model.preset);
},
/**
*/
_getButtonClass: function(selectedItem, presetObject){
var classlist = ['actionable'];
if(selectedItem === presetObject){
classlist.push('actionable--select');
}else {
classlist.push('actionable--action');
}
return classlist.join(' ');
}
});
</script>