2017-11-05 07:38:50 +08:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-30 12:30:35 +08:00
|
|
|
function reloadApp() {
|
|
|
|
window.location.reload(true);
|
|
|
|
}
|
|
|
|
|
2017-11-27 01:56:07 +08:00
|
|
|
function showMessage(message) {
|
2017-12-19 11:06:24 +08:00
|
|
|
console.log(now(), "message: ", message);
|
2017-11-27 01:56:07 +08:00
|
|
|
|
|
|
|
$.notify({
|
|
|
|
// options
|
|
|
|
message: message
|
|
|
|
},{
|
|
|
|
// settings
|
|
|
|
type: 'success',
|
2017-11-27 06:04:18 +08:00
|
|
|
delay: 3000
|
2017-11-27 01:56:07 +08:00
|
|
|
});
|
2017-08-14 09:42:10 +08:00
|
|
|
}
|
|
|
|
|
2017-12-13 12:47:17 +08:00
|
|
|
function showError(message, delay = 10000) {
|
2017-12-19 11:06:24 +08:00
|
|
|
console.log(now(), "error: ", message);
|
2017-11-27 01:56:07 +08:00
|
|
|
|
|
|
|
$.notify({
|
|
|
|
// options
|
|
|
|
message: message
|
|
|
|
},{
|
|
|
|
// settings
|
|
|
|
type: 'danger',
|
2017-12-13 12:47:17 +08:00
|
|
|
delay: delay
|
2017-11-27 01:56:07 +08:00
|
|
|
});
|
2017-09-07 10:06:43 +08:00
|
|
|
}
|
|
|
|
|
2017-12-07 08:53:23 +08:00
|
|
|
function throwError(message) {
|
2017-12-07 09:11:45 +08:00
|
|
|
messaging.logError(message);
|
|
|
|
|
|
|
|
throw new Error(message);
|
2017-12-07 08:53:23 +08:00
|
|
|
}
|
|
|
|
|
2017-12-11 04:31:43 +08:00
|
|
|
function parseDate(str) {
|
|
|
|
try {
|
|
|
|
return new Date(Date.parse(str));
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
throw new Error("Can't parse date from " + str + ": " + e.stack);
|
|
|
|
}
|
2017-10-01 10:36:14 +08:00
|
|
|
}
|
|
|
|
|
2017-12-15 11:38:38 +08:00
|
|
|
function padNum(num) {
|
|
|
|
return (num <= 9 ? "0" : "") + num;
|
|
|
|
}
|
|
|
|
|
2017-10-01 10:36:14 +08:00
|
|
|
function formatTime(date) {
|
2017-12-15 11:38:38 +08:00
|
|
|
return padNum(date.getHours()) + ":" + padNum(date.getMinutes());
|
2017-10-01 10:36:14 +08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:06:24 +08:00
|
|
|
function formatTimeWithSeconds(date) {
|
|
|
|
return padNum(date.getHours()) + ":" + padNum(date.getMinutes()) + ":" + padNum(date.getSeconds());
|
|
|
|
}
|
|
|
|
|
2017-10-01 10:36:14 +08:00
|
|
|
function formatDate(date) {
|
2017-12-15 11:38:38 +08:00
|
|
|
return padNum(date.getDate()) + ". " + padNum(date.getMonth() + 1) + ". " + date.getFullYear();
|
2017-10-01 10:36:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function formatDateTime(date) {
|
|
|
|
return formatDate(date) + " " + formatTime(date);
|
2017-12-01 08:58:00 +08:00
|
|
|
}
|
|
|
|
|
2017-12-19 11:06:24 +08:00
|
|
|
function now() {
|
|
|
|
return formatTimeWithSeconds(new Date());
|
|
|
|
}
|
|
|
|
|
2017-12-01 08:58:00 +08:00
|
|
|
function isElectron() {
|
|
|
|
return window && window.process && window.process.type;
|
2017-12-24 00:02:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function assertArguments() {
|
|
|
|
for (const i in arguments) {
|
2017-12-24 01:19:15 +08:00
|
|
|
if (!arguments[i]) {
|
|
|
|
throwError(`Argument idx#${i} should not be falsy: ${arguments[i]}`);
|
|
|
|
}
|
2017-12-24 00:02:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function assert(expr, message) {
|
|
|
|
if (!expr) {
|
|
|
|
throwError(message);
|
|
|
|
}
|
2017-12-24 01:19:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function isTopLevelNode(node) {
|
|
|
|
return isRootNode(node.getParent());
|
|
|
|
}
|
|
|
|
|
|
|
|
function isRootNode(node) {
|
|
|
|
return node.key === "root_1";
|
2017-12-29 08:00:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function escapeHtml(str) {
|
|
|
|
return $('<div/>').text(str).html();
|
2017-06-12 04:04:07 +08:00
|
|
|
}
|