-
Notifications
You must be signed in to change notification settings - Fork 0
/
strolch-wc-reports-behavior.html
191 lines (163 loc) · 6.68 KB
/
strolch-wc-reports-behavior.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<script>
StrolchReportsBehavior = {
properties: {
basePath: {
type: String,
value: './'
},
baseRestPath: {
type: String,
value: './'
},
localesPath: {
type: String,
value: './locales.json'
},
dlgTitle: {
type: String
},
dlgText: {
type: String
},
vaadinI18n: {
type: Object,
value: {
// An array with the full names of months starting with January.
monthNames: [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
],
// An array of weekday names starting with Sunday. Used in screen reader announcements.
weekdays: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
// An array of short weekday names starting with Sunday. Displayed in the calendar.
weekdaysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
// An integer indicating the first day of the week (0 = Sunday, 1 = Monday, etc.).
firstDayOfWeek: 0,
// Used in screen reader announcements along with week numbers, if they are displayed.
week: "Week",
// Translation of the Calendar icon button title.
calendar: "Calendar",
// Translation of the Clear icon button title.
clear: "Clear",
// Translation of the Today shortcut button text.
today: "Today",
// Translation of the Cancel button text.
cancel: "Cancel",
// A function to format given `Date` object as date string.
formatDate: function (datetime) {
if (typeof(datetime) == 'string') {
datetime = new Date(datetime);
}
var day = (datetime.getDate()).toString();
var month = (datetime.getMonth() + 1).toString();
var year = (datetime.getFullYear()).toString();
day = day.length < 2 ? "0" + day : day;
month = month.length < 2 ? "0" + month : month;
return day + "." + month + "." + year;
},
// A function to parse the given text to a `Date` object.
// Must properly parse (at least) text formatted by `formatDate`.
// Setting the property to null will disable keyboard input feature.
parseDate: function (datetimeString) {
var splitString = datetimeString.split(".");
if (splitString.length != 3) return null;
var year = Number(splitString[2]);
var month = Number(splitString[1]) - 1;
var day = Number(splitString[0]);
return new Date(year, month, day);
},
// A function to format given `monthName` and `fullYear` integer as calendar title string.
formatTitle: function (monthName, fullYear) {
return monthName + " " + fullYear;
}
}
}
},
toLocalDateTime: function (val) {
return Strolch.toLocalDateTime(val);
},
arrayToString: function (arr) {
var s = '';
for (var i = 0; i < arr.length; i++) {
s += arr[i];
if (i + 1 < arr.length)
s += ', ';
}
return s;
},
isEmptyArray: function (arr) {
return arr == null || arr.length == 0;
},
isNotEmptyArray: function (list) {
return !this.isEmptyArray(list);
},
isEmptyString: function (v) {
return v != null && v.length == 0
},
isNotEmptyString: function (v) {
return v != null && v.length > 0
},
lesserEqual: function (arg0, arg1) {
return arg0 <= arg1;
},
arrayFilled: function (array) {
return !!(array && array.length && array.length > 0);
},
toDateTime: function (val) {
function pad10(i) {
if (i < 10) return '0' + i;
return i;
}
function pad100(i) {
if (i < 10) return '00' + i;
if (i < 100) return '0' + i;
return i;
}
if (Strolch.isEmptyString(val) || val == '-') return '-';
var date = new Date(val);
var y = date.getFullYear();
var m = pad10(date.getMonth() + 1);
var d = pad10(date.getDate());
var h = pad10(date.getHours());
var mi = pad10(date.getMinutes());
var s = pad10(date.getSeconds());
var mil = pad100(date.getMilliseconds());
return y + m + d + h + mi + s;
},
_handleAjaxError: function (data) {
var dlgText;
if (data.detail.request.response) {
dlgText = data.detail.request.response.msg;
} else {
dlgText = data.detail.error;
}
this.fire('strolch-show-dialog', {
title: this.dlgTitle,
text: dlgText
});
},
onAjaxError: function (data) {
var dlgText;
if (data.detail.request.response) {
if (data.detail.request.response.msg) {
dlgText = data.detail.request.response.msg;
} else if (data.detail.request.response.charAt(0) == '{') {
var json = JSON.parse(data.detail.request.response);
if (json.msg) {
dlgText = json.msg;
} else {
dlgText = data.detail.request.response;
}
} else {
dlgText = data.detail.request.response;
}
} else {
dlgText = data.detail.error;
}
this.fire('strolch-show-dialog', {
title: this.dlgTitle,
text: dlgText
});
}
};
</script>