2022-02-01 17:34:01 +01:00
|
|
|
<link rel="import" href="../polymer/polymer.html">
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
// custom behaviour accessing the configuration above
|
|
|
|
StrolchUtilBehaviorImpl = {
|
2022-02-10 20:30:20 +01:00
|
|
|
|
2022-02-01 17:34:01 +01:00
|
|
|
/*
|
|
|
|
* Strolch functions
|
|
|
|
*/
|
|
|
|
hasQueryPrivilege: function (privilegeValue) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return Strolch.hasRole("StrolchAdmin") || Strolch.hasQueryPrivilege(privilegeValue);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
hasSearchPrivilege: function (privilegeValue) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return Strolch.hasRole("StrolchAdmin") || Strolch.hasSearchPrivilege(privilegeValue);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
hasServicePrivilege: function (privilegeValue) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return Strolch.hasRole("StrolchAdmin") || Strolch.hasServicePrivilege(privilegeValue);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
hasPrivilege: function (privilege, value) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return Strolch.hasRole("StrolchAdmin") || Strolch.hasPrivilege(privilege, value);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
hasRole: function (name) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return Strolch.hasRole("StrolchAdmin") || Strolch.hasRole(name);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
hasFeatureRole: function (name) {
|
|
|
|
return Strolch.hasRole(name);
|
|
|
|
},
|
|
|
|
hasAnyFeatureRole: function () {
|
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
if (Strolch.hasRole(arguments[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2022-02-01 17:34:01 +01:00
|
|
|
hasComponent: function (name) {
|
|
|
|
return Strolch.hasComponent(name);
|
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2022-02-10 20:30:20 +01:00
|
|
|
* Boolean functions
|
2022-02-01 17:34:01 +01:00
|
|
|
*/
|
|
|
|
isDefined: function (arg0) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 != undefined;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isNull: function (arg0) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 == undefined || arg0 == null;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isNotNull: function (arg0) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 != undefined && arg0 != null;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isNaN: function (arg0) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return this.stringEmpty(arg0) || isNaN(arg0);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
equal: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 == arg1;
|
|
|
|
},
|
|
|
|
isEqual: function (arg0, arg1) {
|
|
|
|
return arg0 == arg1;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
notEqual: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 != arg1;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
defined: function (arg0) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return !!arg0;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
greater: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 > arg1;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
greaterEqual: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 >= arg1;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
lesser: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 < arg1;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
lesserEqual: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return arg0 <= arg1;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
and: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return !!(arg0 && arg1);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
or: function (arg0, arg1) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return !!(arg0 || arg1);
|
|
|
|
},
|
|
|
|
andMulti: function () {
|
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
if (!arguments[i])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
orMulti: function () {
|
|
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
|
|
if (arguments[i])
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Array functions
|
|
|
|
//
|
|
|
|
arrayToString: function (array) {
|
|
|
|
if (array == null || array.length === 0)
|
|
|
|
return "";
|
|
|
|
return array.join(", ");
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
arrayLength: function (array) {
|
|
|
|
return array != null ? array.length : 0;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
arrayFilled: function (array) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return array != null && array.length > 0;
|
|
|
|
},
|
|
|
|
arrayEmpty: function (array) {
|
|
|
|
return array == null || array.length === 0;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
arraySizeLessThan: function (array, size) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return array != null && array.length < size;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
arraySizeGreaterThanOrEq: function (array, size) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return array != null && array.length >= size;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
arrayEquals: function (array1, array2) {
|
2022-02-10 20:30:20 +01:00
|
|
|
if (array1 == null && array2 == null)
|
|
|
|
return true;
|
|
|
|
if (array1 == null && array2 != null)
|
|
|
|
return false;
|
|
|
|
if (array2 == null && array1 != null)
|
|
|
|
return false;
|
|
|
|
return (array1.length === array2.length) && array1.every(function (element, index) {
|
|
|
|
return element === array2[index];
|
|
|
|
});
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
stringToArray: function (string) {
|
|
|
|
if (string === null || string.length === 0)
|
|
|
|
return [];
|
|
|
|
var a = [];
|
2023-04-21 09:11:42 +02:00
|
|
|
var b = string.split(",");
|
2022-02-10 20:30:20 +01:00
|
|
|
for (var i = 0; i < b.length; i++) {
|
|
|
|
a.push(b[i].trim());
|
|
|
|
}
|
|
|
|
return a;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
stringArrayLength: function (string) {
|
|
|
|
if (string === null || string.length === 0)
|
|
|
|
return 0;
|
2023-04-21 09:11:42 +02:00
|
|
|
return string.split(",").length;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// String functions
|
|
|
|
//
|
|
|
|
stringOrEmpty: function (e) {
|
|
|
|
return e === null || e === undefined ? "" : e;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
stringEmpty: function () {
|
2022-02-10 20:30:20 +01:00
|
|
|
for (var i in arguments) {
|
|
|
|
var arg = arguments[i];
|
|
|
|
if (!arg || arg.length === 0) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isEmptyString: function (val) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return typeof val == "undefined" || val == null || val === "";
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isNotEmptyString: function (val) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return !this.isEmptyString(val);
|
|
|
|
},
|
|
|
|
formatVerbatimToHtml: function (s) {
|
|
|
|
if (s == null || s.length === 0)
|
|
|
|
return "";
|
2023-04-21 09:11:42 +02:00
|
|
|
return s.replace(/\n/g, "<br/>").replace(/ /g, " ");
|
2022-02-10 20:30:20 +01:00
|
|
|
},
|
|
|
|
pad10: function (i) {
|
2023-04-21 09:11:42 +02:00
|
|
|
if (i < 10) return "0" + i;
|
2022-02-10 20:30:20 +01:00
|
|
|
return i;
|
|
|
|
},
|
|
|
|
pad100: function (i) {
|
2023-04-21 09:11:42 +02:00
|
|
|
if (i < 10) return "00" + i;
|
|
|
|
if (i < 100) return "0" + i;
|
2022-02-10 20:30:20 +01:00
|
|
|
return i;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
//
|
|
|
|
// Math functions
|
|
|
|
//
|
|
|
|
add: function (arg0, arg1) {
|
|
|
|
return Number(arg0) + Number(arg1);
|
|
|
|
},
|
|
|
|
sub: function (arg0, arg1) {
|
|
|
|
return Number(arg0) - Number(arg1);
|
|
|
|
},
|
|
|
|
round: function (value) {
|
|
|
|
return Math.round(value * 1000) / 1000;
|
|
|
|
},
|
|
|
|
|
2022-06-13 16:21:34 +02:00
|
|
|
/**
|
|
|
|
* Decimal adjustment of a number.
|
|
|
|
*
|
|
|
|
* @param {String} type The type of adjustment.
|
|
|
|
* @param {Number} value The number.
|
|
|
|
* @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
|
|
|
|
* @returns {Number} The adjusted value.
|
|
|
|
*/
|
|
|
|
_decimalAdjust: function (type, value, exp) {
|
|
|
|
// If the exp is undefined or zero...
|
2023-04-21 09:11:42 +02:00
|
|
|
if (typeof exp === "undefined" || +exp === 0) {
|
2022-06-13 16:21:34 +02:00
|
|
|
return Math[type](value);
|
|
|
|
}
|
|
|
|
value = +value;
|
|
|
|
exp = +exp;
|
|
|
|
// If the value is not a number or the exp is not an integer...
|
2023-04-21 09:11:42 +02:00
|
|
|
if (isNaN(value) || !(typeof exp === "number" && exp % 1 === 0)) {
|
2022-06-13 16:21:34 +02:00
|
|
|
return NaN;
|
|
|
|
}
|
|
|
|
// Shift
|
2023-04-21 09:11:42 +02:00
|
|
|
value = value.toString().split("e");
|
|
|
|
value = Math[type](+(value[0] + "e" + (value[1] ? (+value[1] - exp) : -exp)));
|
2022-06-13 16:21:34 +02:00
|
|
|
// Shift back
|
2023-04-21 09:11:42 +02:00
|
|
|
value = value.toString().split("e");
|
|
|
|
return +(value[0] + "e" + (value[1] ? (+value[1] + exp) : exp));
|
2022-06-13 16:21:34 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// Decimal round
|
|
|
|
round10: function (value, exp) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return this._decimalAdjust("round", value, exp);
|
2022-06-13 16:21:34 +02:00
|
|
|
},
|
|
|
|
// Decimal floor
|
|
|
|
floor10: function (value, exp) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return this._decimalAdjust("floor", value, exp);
|
2022-06-13 16:21:34 +02:00
|
|
|
},
|
|
|
|
// Decimal ceil
|
|
|
|
ceil10: function (value, exp) {
|
2023-04-21 09:11:42 +02:00
|
|
|
return this._decimalAdjust("ceil", value, exp);
|
2022-06-13 16:21:34 +02:00
|
|
|
},
|
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
//
|
|
|
|
// i18n functions
|
|
|
|
//
|
|
|
|
hasMsg: function (value) {
|
|
|
|
return this.isNotEmptyString(value) && value !== "-";
|
|
|
|
},
|
|
|
|
localizeJsonMsg: function (jsonMsg) {
|
|
|
|
if (jsonMsg == null)
|
|
|
|
return jsonMsg;
|
2023-04-21 09:11:42 +02:00
|
|
|
if (this.localize == null)
|
|
|
|
return jsonMsg.message;
|
2022-02-10 20:30:20 +01:00
|
|
|
if (jsonMsg.values == null || jsonMsg.values.length === 0)
|
|
|
|
return this.localize(jsonMsg.key);
|
|
|
|
|
|
|
|
var values = [jsonMsg.key];
|
|
|
|
var keys = Object.keys(jsonMsg.values);
|
|
|
|
for (var i = 0; i < keys.length; i++) {
|
|
|
|
var key = keys[i];
|
|
|
|
values.push(key);
|
|
|
|
values.push(jsonMsg.values[key]);
|
|
|
|
}
|
|
|
|
return this.localize.apply(null, values);
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// Browser check functions
|
|
|
|
//
|
2022-02-01 17:34:01 +01:00
|
|
|
isChrome: function () {
|
2022-02-10 20:30:20 +01:00
|
|
|
var isChromium = window.chrome, //
|
|
|
|
winNav = window.navigator, //
|
|
|
|
vendorName = winNav.vendor, //
|
|
|
|
isOpera = winNav.userAgent.indexOf("OPR") > -1, //
|
|
|
|
isIEedge = winNav.userAgent.indexOf("Edge") > -1, //
|
|
|
|
isIOSChrome = winNav.userAgent.match("CriOS");
|
|
|
|
|
|
|
|
if (isIOSChrome) {
|
|
|
|
return true;
|
|
|
|
} else if (isChromium !== null && //
|
|
|
|
typeof isChromium !== "undefined" && //
|
|
|
|
vendorName === "Google Inc." && //
|
|
|
|
isOpera === false && //
|
|
|
|
isIEedge === false) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isFirefox: function () {
|
2023-04-21 09:11:42 +02:00
|
|
|
return navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isIE: function () {
|
2022-02-10 20:30:20 +01:00
|
|
|
var isIE = /*@cc_on!@*/false || !!document.documentMode;
|
|
|
|
return isIE;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
isEdge: function () {
|
2022-02-10 20:30:20 +01:00
|
|
|
return !this.isIE() && !!window.StyleMedia;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
//
|
|
|
|
// Date Time functions
|
|
|
|
//
|
2022-06-22 08:36:40 +02:00
|
|
|
formatDateTimeDashIfEmpty: function (string) {
|
|
|
|
if (string == null || string === "" || string === "-" || string === "1970-01-01T01:00:00+01:00")
|
|
|
|
return "-";
|
|
|
|
return Strolch.toLocalDateTime(string);
|
|
|
|
},
|
2022-02-01 17:34:01 +01:00
|
|
|
formatDateTime: function (string) {
|
|
|
|
return Strolch.toLocalDateTime(string);
|
|
|
|
},
|
2022-06-22 08:47:35 +02:00
|
|
|
formatDateDashIfEmpty: function (string) {
|
|
|
|
if (string == null || string === "" || string === "-" || string === "1970-01-01T01:00:00+01:00")
|
|
|
|
return "-";
|
|
|
|
return Strolch.toLocalDate(string);
|
|
|
|
},
|
|
|
|
formatDate: function (string) {
|
|
|
|
return Strolch.toLocalDate(string);
|
|
|
|
},
|
2022-07-11 10:24:38 +02:00
|
|
|
formatDateTimePaddedWithSeconds: function (value) {
|
|
|
|
return this.formatDateTime(value, true);
|
|
|
|
},
|
|
|
|
formatDateTimePadded: function (value, withSeconds) {
|
|
|
|
var dateTime;
|
|
|
|
if (value == null || value === "" || value === "-" || value === "1970-01-01T01:00:00+01:00")
|
|
|
|
return "-";
|
|
|
|
if (typeof (value) === "string") {
|
|
|
|
dateTime = new Date(value);
|
|
|
|
} else if (value instanceof Date) {
|
|
|
|
dateTime = value;
|
|
|
|
} else {
|
|
|
|
throw "Unhandled object type " + typeof (value) + ": " + value;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.getDateString(dateTime, true) + " " + this.getTimeString(dateTime, withSeconds);
|
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
parsePeriodUnit: function (p) {
|
2022-02-01 17:34:01 +01:00
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
// P3M -> months
|
|
|
|
// P3W -> weeks
|
|
|
|
// P3D -> days
|
|
|
|
// PT3H -> hours
|
|
|
|
// PT3M -> minutes
|
|
|
|
|
|
|
|
if (p == null || p.length < 3 || p === "PT0S" || p === "P0S")
|
|
|
|
return [0, "seconds"];
|
|
|
|
|
|
|
|
var value;
|
2023-04-21 09:11:42 +02:00
|
|
|
if (p.charAt(1) === "T") {
|
2022-02-10 20:30:20 +01:00
|
|
|
value = Number.parseInt(p.substring(2, p.length - 1));
|
|
|
|
switch (p.charAt(p.length - 1)) {
|
|
|
|
case "H":
|
|
|
|
return [value, "hours"];
|
|
|
|
case "M":
|
|
|
|
return [value, "minutes"];
|
|
|
|
case "S":
|
|
|
|
return [value, "seconds"];
|
|
|
|
default:
|
|
|
|
throw "Unhandled Period " + p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
value = Number.parseInt(p.substring(1, p.length - 1));
|
|
|
|
switch (p.charAt(p.length - 1)) {
|
|
|
|
case "M":
|
|
|
|
return [value, "months"];
|
|
|
|
case "W":
|
|
|
|
return [value, "weeks"];
|
|
|
|
case "D":
|
|
|
|
return [value, "days"];
|
|
|
|
default:
|
|
|
|
throw "Unhandled Period " + p;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
formatPeriod: function (p) {
|
|
|
|
if (p == null || p.length < 3)
|
|
|
|
return "-";
|
|
|
|
|
|
|
|
// P1D
|
|
|
|
// P1Y2M3DT4H5M6S
|
|
|
|
// PT1H1M
|
|
|
|
|
|
|
|
var i = 0;
|
2023-04-21 09:11:42 +02:00
|
|
|
if (p.charAt(i) !== "P")
|
2022-02-10 20:30:20 +01:00
|
|
|
throw "Illegal ISO8601 Period!";
|
|
|
|
i++;
|
|
|
|
|
2023-04-21 09:11:42 +02:00
|
|
|
var result = (this.localize == null ? "every" : this.localize("every")) + " ";
|
2022-02-10 20:30:20 +01:00
|
|
|
|
|
|
|
// period part
|
|
|
|
var pos;
|
|
|
|
var val;
|
2023-04-21 09:11:42 +02:00
|
|
|
if (p.charAt(i) !== "T") {
|
|
|
|
var timePartPos = p.indexOf("T");
|
2022-02-10 20:30:20 +01:00
|
|
|
if (timePartPos < 0)
|
|
|
|
timePartPos = p.length;
|
|
|
|
|
|
|
|
// year
|
2023-04-21 09:11:42 +02:00
|
|
|
pos = p.indexOf("Y", i);
|
2022-02-10 20:30:20 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
val = Number.parseFloat(p.substring(i, pos));
|
|
|
|
if (val > 0)
|
2023-04-21 09:11:42 +02:00
|
|
|
result += val + " " + (this.localize == null ? "years" : this.localize("years")) + " ";
|
2022-02-10 20:30:20 +01:00
|
|
|
i = pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// month
|
2023-04-21 09:11:42 +02:00
|
|
|
pos = p.indexOf("M", i);
|
2022-02-10 20:30:20 +01:00
|
|
|
if (pos > 0 && pos < timePartPos) {
|
|
|
|
val = Number.parseFloat(p.substring(i, pos));
|
|
|
|
if (val > 0)
|
2023-04-21 09:11:42 +02:00
|
|
|
result += val + " " + (this.localize == null ? "months" : this.localize("months")) + " ";
|
2022-02-10 20:30:20 +01:00
|
|
|
i = pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// day
|
2023-04-21 09:11:42 +02:00
|
|
|
pos = p.indexOf("D", i);
|
2022-02-10 20:30:20 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
val = Number.parseFloat(p.substring(i, pos));
|
|
|
|
if (val > 0)
|
2023-04-21 09:11:42 +02:00
|
|
|
result += val + " " + (this.localize == null ? "days" : this.localize("days")) + " ";
|
2022-02-10 20:30:20 +01:00
|
|
|
i = pos + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// time part
|
|
|
|
|
|
|
|
// hour
|
2023-04-21 09:11:42 +02:00
|
|
|
pos = p.indexOf("H", i);
|
2022-02-10 20:30:20 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
val = Number.parseFloat(p.substring(i, pos));
|
|
|
|
if (val > 0)
|
2023-04-21 09:11:42 +02:00
|
|
|
result += val + " " + (this.localize == null ? "hours" : this.localize("hours")) + " ";
|
2022-02-10 20:30:20 +01:00
|
|
|
i = pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// minute
|
2023-04-21 09:11:42 +02:00
|
|
|
pos = p.indexOf("M", i);
|
2022-02-10 20:30:20 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
val = Number.parseFloat(p.substring(i, pos));
|
|
|
|
if (val > 0)
|
2023-04-21 09:11:42 +02:00
|
|
|
result += val + " " + (this.localize == null ? "minutes" : this.localize("minutes")) + " ";
|
2022-02-10 20:30:20 +01:00
|
|
|
i = pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// seconds
|
2023-04-21 09:11:42 +02:00
|
|
|
pos = p.indexOf("S", i);
|
2022-02-10 20:30:20 +01:00
|
|
|
if (pos > 0) {
|
|
|
|
val = Number.parseFloat(p.substring(i, pos));
|
|
|
|
if (val > 0)
|
2023-04-21 09:11:42 +02:00
|
|
|
result += val + " " + (this.localize == null ? "seconds" : this.localize("seconds")) + " ";
|
2022-02-10 20:30:20 +01:00
|
|
|
i = pos + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
// gets the clock time as displayed in the UI
|
|
|
|
getTimeString: function (datetime, withSeconds) {
|
|
|
|
var hours = datetime.getHours().toString();
|
|
|
|
var minutes = datetime.getMinutes().toString();
|
|
|
|
|
|
|
|
hours = hours.length < 2 ? "0" + hours : hours;
|
|
|
|
minutes = minutes.length < 2 ? "0" + minutes : minutes;
|
|
|
|
|
|
|
|
if (!withSeconds)
|
|
|
|
return hours + ":" + minutes;
|
|
|
|
|
|
|
|
var seconds = datetime.getSeconds().toString();
|
|
|
|
seconds = seconds.length < 2 ? "0" + seconds : seconds;
|
|
|
|
return hours + ":" + minutes + "." + seconds;
|
|
|
|
},
|
|
|
|
getDateWithTimeString: function (date, timeString) {
|
|
|
|
var hourMin = timeString.split(":");
|
|
|
|
if (hourMin.length !== 2)
|
|
|
|
throw "TimeString " + timeString + " has invalid format!";
|
2022-02-01 17:34:01 +01:00
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
date.setHours(Number.parseInt(hourMin[0]));
|
|
|
|
date.setMinutes(Number.parseInt(hourMin[1]));
|
|
|
|
return date;
|
|
|
|
},
|
2022-02-01 17:34:01 +01:00
|
|
|
// gets the calendar date as displayed in the UI
|
|
|
|
getDateString: function (datetime, addCentury) {
|
2022-02-10 20:30:20 +01:00
|
|
|
if (datetime == null)
|
|
|
|
return "";
|
|
|
|
|
2023-04-21 09:11:42 +02:00
|
|
|
if (typeof (datetime) == "string") {
|
2022-02-10 20:30:20 +01:00
|
|
|
datetime = new Date(datetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
var day = (datetime.getDate()).toString();
|
|
|
|
var month = (datetime.getMonth() + 1).toString();
|
|
|
|
var year = (datetime.getFullYear()).toString();
|
2022-02-01 17:34:01 +01:00
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
day = day.length < 2 ? "0" + day : day;
|
|
|
|
month = month.length < 2 ? "0" + month : month;
|
|
|
|
year = addCentury ? year : year.slice(-2);
|
|
|
|
return day + "." + month + "." + year;
|
|
|
|
},
|
2022-02-01 17:34:01 +01:00
|
|
|
// gets the date of a date string from getDateString()
|
|
|
|
getDate: function (datetimeString) {
|
2022-02-10 20:30:20 +01:00
|
|
|
if (datetimeString == null || datetimeString.length === "")
|
|
|
|
return null;
|
|
|
|
|
|
|
|
if (datetimeString.indexOf("T") === 10) {
|
|
|
|
return new Date(datetimeString.substring(0, 10));
|
|
|
|
} else if (datetimeString.length === 10 && datetimeString.indexOf("-") === 4) {
|
|
|
|
return new Date(datetimeString);
|
|
|
|
}
|
2022-02-01 17:34:01 +01:00
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
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);
|
|
|
|
},
|
2022-02-01 17:34:01 +01:00
|
|
|
// gets the clock time of the current time
|
|
|
|
getCurrentTimeString: function () {
|
2022-02-10 20:30:20 +01:00
|
|
|
return this.getTimeString(new Date());
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
toDateTime: function (val) {
|
2023-04-21 09:11:42 +02:00
|
|
|
if (this.isEmptyString(val) || val === "-") return "-";
|
2022-02-10 20:30:20 +01:00
|
|
|
var date = new Date(val);
|
2022-02-01 17:34:01 +01:00
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
var y = date.getFullYear();
|
|
|
|
var m = this.pad10(date.getMonth() + 1);
|
|
|
|
var d = this.pad10(date.getDate());
|
|
|
|
var h = this.pad10(date.getHours());
|
|
|
|
var mi = this.pad10(date.getMinutes());
|
|
|
|
var s = this.pad10(date.getSeconds());
|
|
|
|
|
|
|
|
return y + m + d + h + mi + s;
|
|
|
|
},
|
2022-02-01 17:34:01 +01:00
|
|
|
toDateTimeNoDelim: function (val) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return this.toDateTime(val);
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
// gets the calendar date of the current time
|
|
|
|
getCurrentDateString: function () {
|
2022-02-10 20:30:20 +01:00
|
|
|
return this.getDateString(new Date());
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
clearTime: function (date) {
|
2022-02-10 20:30:20 +01:00
|
|
|
date.setHours(0);
|
|
|
|
date.setMinutes(0);
|
|
|
|
date.setSeconds(0);
|
|
|
|
date.setMilliseconds(0);
|
|
|
|
|
|
|
|
return date;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
dateToJson: function (date) {
|
2022-02-10 20:30:20 +01:00
|
|
|
date.setTime(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
|
|
|
|
return date.toJSON();
|
|
|
|
},
|
|
|
|
dateToIso: function (date) {
|
|
|
|
if (date == null || date === "") {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var tzo = -date.getTimezoneOffset(),
|
2023-04-21 09:11:42 +02:00
|
|
|
dif = tzo >= 0 ? "+" : "-",
|
2022-02-10 20:30:20 +01:00
|
|
|
pad = function (num) {
|
|
|
|
var norm = Math.floor(Math.abs(num));
|
2023-04-21 09:11:42 +02:00
|
|
|
return (norm < 10 ? "0" : "") + norm;
|
2022-02-10 20:30:20 +01:00
|
|
|
};
|
|
|
|
return date.getFullYear() +
|
2023-04-21 09:11:42 +02:00
|
|
|
"-" + pad(date.getMonth() + 1) +
|
|
|
|
"-" + pad(date.getDate()) +
|
|
|
|
"T" + pad(date.getHours()) +
|
|
|
|
":" + pad(date.getMinutes()) +
|
|
|
|
":" + pad(date.getSeconds()) +
|
2022-02-10 20:30:20 +01:00
|
|
|
dif + pad(tzo / 60) +
|
2023-04-21 09:11:42 +02:00
|
|
|
":" + pad(tzo % 60);
|
2022-02-10 20:30:20 +01:00
|
|
|
},
|
|
|
|
truncateTime: function (date) {
|
|
|
|
date.setTime(date.getTime() - (-date.getTimezoneOffset() * 60 * 1000));
|
|
|
|
date.setHours(0, 0, 0, 0);
|
|
|
|
return date;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
// returns true if a datetime has past
|
|
|
|
isPast: function (datetime) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return Date.now() > datetime.getTime();
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
// returns true if a datetime is future
|
|
|
|
isFuture: function (datetime) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return Date.now() < datetime.getTime();
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
// turns hours into milliseconds
|
|
|
|
hToMs: function (hour) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return hour * 3600000;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
// turns milliseconds into hours
|
|
|
|
msToH: function (milliseconds) {
|
2022-02-10 20:30:20 +01:00
|
|
|
return milliseconds / 3600000;
|
2022-02-01 17:34:01 +01:00
|
|
|
},
|
|
|
|
|
2022-02-10 20:30:20 +01:00
|
|
|
//
|
|
|
|
// Cookie functions
|
|
|
|
//
|
2022-02-01 17:34:01 +01:00
|
|
|
getCookie: function (cname) {
|
|
|
|
return Strolch.getCookie(cname);
|
|
|
|
},
|
|
|
|
setCookie: function (cname, cvalue, expiration) {
|
|
|
|
Strolch.setCookie(cname, cvalue, expiration);
|
|
|
|
},
|
|
|
|
deleteCookie: function (cname) {
|
|
|
|
Strolch.deleteCookie(cname);
|
2022-02-10 20:30:20 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// URL query functions
|
|
|
|
//
|
|
|
|
parseQueryParams: function (queryParamsS) {
|
|
|
|
var params = {};
|
|
|
|
if (queryParamsS.length === 0)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
var queryParams = queryParamsS.split("&");
|
|
|
|
for (var i = 0; i < queryParams.length; i++) {
|
|
|
|
var queryParam = queryParams[i];
|
|
|
|
var parts = queryParam.split("=");
|
|
|
|
if (parts.length !== 2) {
|
|
|
|
console.log("Ignoring bad query param " + queryParam);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
var key = parts[0];
|
|
|
|
params[key] = parts[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return params;
|
|
|
|
},
|
|
|
|
removeQueryParamsFromPath: function (path) {
|
|
|
|
var queryParamsIndex = path.indexOf("?");
|
|
|
|
if (queryParamsIndex < 0) {
|
|
|
|
return {
|
|
|
|
path: path,
|
|
|
|
params: null
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var returnPath = path.substring(0, queryParamsIndex);
|
|
|
|
var queryParams = this.parseQueryParams(path.substring(queryParamsIndex + 1));
|
|
|
|
|
|
|
|
return {
|
|
|
|
path: returnPath,
|
|
|
|
params: queryParams
|
|
|
|
};
|
|
|
|
},
|
|
|
|
// finds a path param of the form '/pathParam/{pathParamValue}/' and returns its value
|
|
|
|
findUrlPathParam: function (urlPath, pathParam) {
|
|
|
|
var regex = new RegExp("\/" + pathParam + "\/([^\/]+)", "i");
|
|
|
|
var matches = regex.exec(urlPath);
|
|
|
|
return matches && matches[1] ? matches[1] : null;
|
|
|
|
},
|
|
|
|
// add a sub route to the current path
|
|
|
|
pushSubRoutePath: function (route, routePath) {
|
|
|
|
var baseUrl = document.URL.substring(0, document.URL.indexOf("#") + 1);
|
|
|
|
var pushUrl = baseUrl + route.prefix + routePath;
|
|
|
|
history.pushState(null, null, pushUrl);
|
|
|
|
},
|
|
|
|
getPageId: function () {
|
|
|
|
var parts = document.location.hash.split("/");
|
|
|
|
if (parts[0] !== "#" || parts.length < 2)
|
|
|
|
return "";
|
|
|
|
return parts[1];
|
|
|
|
},
|
2022-05-26 09:09:49 +02:00
|
|
|
clearQueryParams: function () {
|
|
|
|
Strolch.clearQueryParams();
|
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
getQueryParamsAsString: function () {
|
|
|
|
return Strolch.getQueryParamsAsString();
|
|
|
|
},
|
2022-05-26 09:09:49 +02:00
|
|
|
getQueryParamsAsObject: function () {
|
|
|
|
return Strolch.getQueryParamsAsObject();
|
|
|
|
},
|
2022-02-10 20:30:20 +01:00
|
|
|
getQueryParamValue: function (paramName) {
|
|
|
|
return Strolch.getQueryParamValue(paramName);
|
|
|
|
},
|
|
|
|
setQueryParamValue: function (paramName, paramValue) {
|
|
|
|
Strolch.setQueryParamValue(paramName, paramValue);
|
|
|
|
},
|
|
|
|
setQueryParamsFromObject: function (object) {
|
|
|
|
Object.keys(object).forEach(function (key) {
|
|
|
|
this.setQueryParamValue(key, object[key]);
|
|
|
|
}.bind(this));
|
2022-04-21 11:14:53 +02:00
|
|
|
}
|
2022-02-01 17:34:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
StrolchUtilBehavior = [StrolchUtilBehaviorImpl];
|
|
|
|
</script>
|