191 lines
6.7 KiB
HTML
191 lines
6.7 KiB
HTML
|
<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>
|