2018-12-02 18:52:50 +00:00
|
|
|
'use strict'
|
|
|
|
/* global __, ngettext */
|
|
|
|
define(["dojo/_base/declare"], function (declare) {
|
|
|
|
return declare("fox.AppBase", null, {
|
|
|
|
_initParams: [],
|
2018-12-02 19:08:18 +00:00
|
|
|
_rpc_seq: 0,
|
|
|
|
hotkey_prefix: 0,
|
|
|
|
hotkey_prefix_pressed: false,
|
|
|
|
hotkey_prefix_timeout: 0,
|
2020-05-17 05:25:51 +00:00
|
|
|
Scrollable: {
|
|
|
|
scrollByPages: function (elem, page_offset, event) {
|
|
|
|
if (!elem) return;
|
|
|
|
|
|
|
|
/* keep a line or so from the previous page */
|
|
|
|
const offset = (elem.offsetHeight - (page_offset > 0 ? 50 : -50)) * page_offset;
|
|
|
|
|
|
|
|
this.scroll(elem, offset, event);
|
|
|
|
},
|
|
|
|
scroll: function(elem, offset, event) {
|
|
|
|
if (!elem) return;
|
|
|
|
|
|
|
|
if (event && event.repeat) {
|
|
|
|
elem.addClassName("forbid-smooth-scroll");
|
|
|
|
window.clearTimeout(this._scroll_reset_timeout);
|
|
|
|
|
|
|
|
this._scroll_reset_timeout = window.setTimeout(() => {
|
|
|
|
if (elem) elem.removeClassName("forbid-smooth-scroll");
|
|
|
|
}, 250)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
elem.removeClassName("forbid-smooth-scroll");
|
|
|
|
}
|
|
|
|
|
|
|
|
elem.scrollTop += offset;
|
|
|
|
},
|
2020-05-17 13:04:31 +00:00
|
|
|
isChildVisible: function(elem, ctr) {
|
|
|
|
if (!elem) return;
|
|
|
|
|
|
|
|
const ctop = ctr.scrollTop;
|
|
|
|
const cbottom = ctop + ctr.offsetHeight;
|
|
|
|
|
|
|
|
const etop = elem.offsetTop;
|
|
|
|
const ebottom = etop + elem.offsetHeight;
|
|
|
|
|
|
|
|
return etop >= ctop && ebottom <= cbottom ||
|
|
|
|
etop < ctop && ebottom > ctop || ebottom > cbottom && etop < cbottom;
|
|
|
|
},
|
2020-05-17 05:25:51 +00:00
|
|
|
},
|
2018-12-03 10:38:13 +00:00
|
|
|
constructor: function() {
|
|
|
|
window.onerror = this.Error.onWindowError;
|
|
|
|
},
|
2018-12-02 18:52:50 +00:00
|
|
|
getInitParam: function(k) {
|
|
|
|
return this._initParams[k];
|
|
|
|
},
|
|
|
|
setInitParam: function(k, v) {
|
|
|
|
this._initParams[k] = v;
|
|
|
|
},
|
2019-12-15 08:57:26 +00:00
|
|
|
nightModeChanged: function(is_night, link) {
|
2019-12-12 17:09:43 +00:00
|
|
|
console.log("night mode changed to", is_night);
|
|
|
|
|
|
|
|
if (link) {
|
2020-02-22 13:22:44 +00:00
|
|
|
const css_override = is_night ? "themes/night.css" : "themes/light.css";
|
2019-12-15 08:57:26 +00:00
|
|
|
link.setAttribute("href", css_override + "?" + Date.now());
|
2019-12-12 17:09:43 +00:00
|
|
|
}
|
|
|
|
},
|
2019-12-15 08:57:26 +00:00
|
|
|
setupNightModeDetection: function(callback) {
|
|
|
|
if (!$("theme_css")) {
|
2019-12-12 17:09:43 +00:00
|
|
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
|
2019-12-13 18:39:52 +00:00
|
|
|
try {
|
|
|
|
mql.addEventListener("change", () => {
|
2019-12-15 08:57:26 +00:00
|
|
|
this.nightModeChanged(mql.matches, $("theme_auto_css"));
|
2019-12-13 18:39:52 +00:00
|
|
|
});
|
2019-12-15 08:57:26 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.warn("exception while trying to set MQL event listener");
|
|
|
|
}
|
|
|
|
|
|
|
|
const link = new Element("link", {
|
|
|
|
rel: "stylesheet",
|
|
|
|
id: "theme_auto_css"
|
|
|
|
});
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
link.onload = function () {
|
|
|
|
document.querySelector("body").removeClassName("css_loading");
|
|
|
|
callback();
|
|
|
|
};
|
|
|
|
|
|
|
|
link.onerror = function(event) {
|
|
|
|
alert("Fatal error while loading application stylesheet: " + link.getAttribute("href"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.nightModeChanged(mql.matches, link);
|
2019-12-12 17:09:43 +00:00
|
|
|
|
2019-12-15 08:57:26 +00:00
|
|
|
document.querySelector("head").appendChild(link);
|
|
|
|
} else {
|
2019-12-15 10:35:09 +00:00
|
|
|
document.querySelector("body").removeClassName("css_loading");
|
|
|
|
|
2019-12-15 08:57:26 +00:00
|
|
|
if (callback) callback();
|
2019-12-12 17:09:43 +00:00
|
|
|
}
|
|
|
|
},
|
2018-12-02 18:52:50 +00:00
|
|
|
enableCsrfSupport: function() {
|
|
|
|
Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
|
|
|
|
function (callOriginal, options) {
|
|
|
|
|
|
|
|
if (App.getInitParam("csrf_token") != undefined) {
|
|
|
|
Object.extend(options, options || { });
|
|
|
|
|
|
|
|
if (Object.isString(options.parameters))
|
|
|
|
options.parameters = options.parameters.toQueryParams();
|
|
|
|
else if (Object.isHash(options.parameters))
|
|
|
|
options.parameters = options.parameters.toObject();
|
|
|
|
|
|
|
|
options.parameters["csrf_token"] = App.getInitParam("csrf_token");
|
|
|
|
}
|
|
|
|
|
|
|
|
return callOriginal(options);
|
|
|
|
}
|
|
|
|
);
|
2018-12-02 19:08:18 +00:00
|
|
|
},
|
|
|
|
urlParam: function(param) {
|
|
|
|
return String(window.location.href).parseQuery()[param];
|
|
|
|
},
|
|
|
|
next_seq: function() {
|
|
|
|
this._rpc_seq += 1;
|
|
|
|
return this._rpc_seq;
|
|
|
|
},
|
|
|
|
get_seq: function() {
|
|
|
|
return this._rpc_seq;
|
|
|
|
},
|
|
|
|
setLoadingProgress: function(p) {
|
|
|
|
loading_progress += p;
|
|
|
|
|
|
|
|
if (dijit.byId("loading_bar"))
|
|
|
|
dijit.byId("loading_bar").update({progress: loading_progress});
|
|
|
|
|
2018-12-09 18:17:50 +00:00
|
|
|
if (loading_progress >= 90) {
|
|
|
|
$("overlay").hide();
|
|
|
|
}
|
2018-12-02 19:08:18 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
keyeventToAction: function(event) {
|
|
|
|
|
|
|
|
const hotkeys_map = App.getInitParam("hotkeys");
|
|
|
|
const keycode = event.which;
|
Refactor hotkeys to use keypress instead of keydown
keydown returns the "raw" key in event.which. Depending on the keyboard
layout, this may not be what is wanted. For example, on a German
keyboard, Shift+7 has to be pressed to get a slash. However, event.which
will be 55, which corresponds to "7". In the keypress event, however,
event.which will be 47, which corresponds to "/".
Sadly, several important keys (such as escape and the arrow keys) do not
trigger a keypress event. Therefore, they have to be handled using a
keydown event.
This change refactors the hotkey support to make use of keypress events
whenever possible. This will make hotkeys work regardless of the user's
keyboard layout. Escape and arrow keys are still handled via keydown
events.
There should be only one change in behavior: I could not make Ctrl+/
work and therefore rebound the help dialog to "?".
2019-03-11 10:29:10 +00:00
|
|
|
const keychar = String.fromCharCode(keycode);
|
2018-12-02 19:08:18 +00:00
|
|
|
|
|
|
|
if (keycode == 27) { // escape and drop prefix
|
|
|
|
this.hotkey_prefix = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) {
|
|
|
|
|
|
|
|
this.hotkey_prefix = keychar;
|
|
|
|
$("cmdline").innerHTML = keychar;
|
|
|
|
Element.show("cmdline");
|
|
|
|
|
|
|
|
window.clearTimeout(this.hotkey_prefix_timeout);
|
|
|
|
this.hotkey_prefix_timeout = window.setTimeout(() => {
|
|
|
|
this.hotkey_prefix = false;
|
|
|
|
Element.hide("cmdline");
|
|
|
|
}, 3 * 1000);
|
|
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element.hide("cmdline");
|
|
|
|
|
Refactor hotkeys to use keypress instead of keydown
keydown returns the "raw" key in event.which. Depending on the keyboard
layout, this may not be what is wanted. For example, on a German
keyboard, Shift+7 has to be pressed to get a slash. However, event.which
will be 55, which corresponds to "7". In the keypress event, however,
event.which will be 47, which corresponds to "/".
Sadly, several important keys (such as escape and the arrow keys) do not
trigger a keypress event. Therefore, they have to be handled using a
keydown event.
This change refactors the hotkey support to make use of keypress events
whenever possible. This will make hotkeys work regardless of the user's
keyboard layout. Escape and arrow keys are still handled via keydown
events.
There should be only one change in behavior: I could not make Ctrl+/
work and therefore rebound the help dialog to "?".
2019-03-11 10:29:10 +00:00
|
|
|
let hotkey_name = "";
|
|
|
|
|
|
|
|
if (event.type == "keydown") {
|
|
|
|
hotkey_name = "(" + keycode + ")";
|
2018-12-02 19:08:18 +00:00
|
|
|
|
Refactor hotkeys to use keypress instead of keydown
keydown returns the "raw" key in event.which. Depending on the keyboard
layout, this may not be what is wanted. For example, on a German
keyboard, Shift+7 has to be pressed to get a slash. However, event.which
will be 55, which corresponds to "7". In the keypress event, however,
event.which will be 47, which corresponds to "/".
Sadly, several important keys (such as escape and the arrow keys) do not
trigger a keypress event. Therefore, they have to be handled using a
keydown event.
This change refactors the hotkey support to make use of keypress events
whenever possible. This will make hotkeys work regardless of the user's
keyboard layout. Escape and arrow keys are still handled via keydown
events.
There should be only one change in behavior: I could not make Ctrl+/
work and therefore rebound the help dialog to "?".
2019-03-11 10:29:10 +00:00
|
|
|
// ensure ^*char notation
|
|
|
|
if (event.shiftKey) hotkey_name = "*" + hotkey_name;
|
|
|
|
if (event.ctrlKey) hotkey_name = "^" + hotkey_name;
|
|
|
|
if (event.altKey) hotkey_name = "+" + hotkey_name;
|
|
|
|
if (event.metaKey) hotkey_name = "%" + hotkey_name;
|
|
|
|
} else {
|
|
|
|
hotkey_name = keychar ? keychar : "(" + keycode + ")";
|
|
|
|
}
|
2018-12-02 19:08:18 +00:00
|
|
|
|
|
|
|
const hotkey_full = this.hotkey_prefix ? this.hotkey_prefix + " " + hotkey_name : hotkey_name;
|
|
|
|
this.hotkey_prefix = false;
|
|
|
|
|
|
|
|
let action_name = false;
|
|
|
|
|
|
|
|
for (const sequence in hotkeys_map[1]) {
|
|
|
|
if (hotkeys_map[1].hasOwnProperty(sequence)) {
|
|
|
|
if (sequence == hotkey_full) {
|
|
|
|
action_name = hotkeys_map[1][sequence];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('keyeventToAction', hotkey_full, '=>', action_name);
|
|
|
|
|
|
|
|
return action_name;
|
|
|
|
},
|
|
|
|
cleanupMemory: function(root) {
|
|
|
|
const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode);
|
|
|
|
|
|
|
|
dijits.each(function (d) {
|
|
|
|
dojo.destroy(d.domNode);
|
|
|
|
});
|
|
|
|
|
|
|
|
$$("#" + root + " *").each(function (i) {
|
|
|
|
i.parentNode ? i.parentNode.removeChild(i) : true;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
helpDialog: function(topic) {
|
|
|
|
const query = "backend.php?op=backend&method=help&topic=" + encodeURIComponent(topic);
|
|
|
|
|
|
|
|
if (dijit.byId("helpDlg"))
|
|
|
|
dijit.byId("helpDlg").destroyRecursive();
|
|
|
|
|
|
|
|
const dialog = new dijit.Dialog({
|
|
|
|
id: "helpDlg",
|
|
|
|
title: __("Help"),
|
|
|
|
style: "width: 600px",
|
|
|
|
href: query,
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
},
|
|
|
|
displayDlg: function(title, id, param, callback) {
|
|
|
|
Notify.progress("Loading, please wait...", true);
|
|
|
|
|
|
|
|
const query = {op: "dlg", method: id, param: param};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, (transport) => {
|
|
|
|
try {
|
|
|
|
const content = transport.responseText;
|
|
|
|
|
|
|
|
let dialog = dijit.byId("infoBox");
|
|
|
|
|
|
|
|
if (!dialog) {
|
|
|
|
dialog = new dijit.Dialog({
|
|
|
|
title: title,
|
|
|
|
id: 'infoBox',
|
|
|
|
style: "width: 600px",
|
|
|
|
onCancel: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
onExecute: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
onClose: function () {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
content: content
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dialog.attr('title', title);
|
|
|
|
dialog.attr('content', content);
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
Notify.close();
|
|
|
|
|
|
|
|
if (callback) callback(transport);
|
|
|
|
} catch (e) {
|
2018-12-03 10:38:13 +00:00
|
|
|
this.Error.report(e);
|
2018-12-02 19:08:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
handleRpcJson: function(transport) {
|
|
|
|
|
2018-12-06 09:30:11 +00:00
|
|
|
const netalert = $$("#toolbar .net-alert")[0];
|
2018-12-02 19:08:18 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
const reply = JSON.parse(transport.responseText);
|
|
|
|
|
|
|
|
if (reply) {
|
|
|
|
const error = reply['error'];
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
const code = error['code'];
|
2018-12-11 10:18:38 +00:00
|
|
|
const msg = error['message'];
|
2018-12-02 19:08:18 +00:00
|
|
|
|
2018-12-11 10:18:38 +00:00
|
|
|
console.warn("[handleRpcJson] received fatal error ", code, msg);
|
2018-12-02 19:08:18 +00:00
|
|
|
|
|
|
|
if (code != 0) {
|
2018-12-11 10:18:38 +00:00
|
|
|
/* global ERRORS */
|
|
|
|
this.Error.fatal(ERRORS[code], {info: msg, code: code});
|
2018-12-02 19:08:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const seq = reply['seq'];
|
|
|
|
|
|
|
|
if (seq && this.get_seq() != seq) {
|
2018-12-16 09:41:27 +00:00
|
|
|
console.log("[handleRpcJson] sequence mismatch: ", seq, '!=', this.get_seq());
|
2018-12-02 19:08:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const message = reply['message'];
|
|
|
|
|
|
|
|
if (message == "UPDATE_COUNTERS") {
|
|
|
|
console.log("need to refresh counters...");
|
|
|
|
Feeds.requestCounters(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const counters = reply['counters'];
|
|
|
|
|
|
|
|
if (counters)
|
|
|
|
Feeds.parseCounters(counters);
|
|
|
|
|
|
|
|
const runtime_info = reply['runtime-info'];
|
|
|
|
|
|
|
|
if (runtime_info)
|
|
|
|
App.parseRuntimeInfo(runtime_info);
|
|
|
|
|
|
|
|
if (netalert) netalert.hide();
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
|
|
|
|
} else {
|
2018-12-06 09:30:11 +00:00
|
|
|
if (netalert) netalert.show();
|
|
|
|
|
|
|
|
Notify.error("Communication problem with server.");
|
2018-12-02 19:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} catch (e) {
|
2018-12-06 09:30:11 +00:00
|
|
|
if (netalert) netalert.show();
|
|
|
|
|
|
|
|
Notify.error("Communication problem with server.");
|
2018-12-02 19:08:18 +00:00
|
|
|
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
parseRuntimeInfo: function(data) {
|
|
|
|
for (const k in data) {
|
|
|
|
if (data.hasOwnProperty(k)) {
|
|
|
|
const v = data[k];
|
|
|
|
|
|
|
|
console.log("RI:", k, "=>", v);
|
|
|
|
|
|
|
|
if (k == "daemon_is_running" && v != 1) {
|
|
|
|
Notify.error("<span onclick=\"App.explainError(1)\">Update daemon is not running.</span>", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-10 07:53:11 +00:00
|
|
|
if (k == "recent_log_events") {
|
|
|
|
const alert = $$(".log-alert")[0];
|
|
|
|
|
|
|
|
if (alert) {
|
|
|
|
v > 0 ? alert.show() : alert.hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-02 19:08:18 +00:00
|
|
|
if (k == "daemon_stamp_ok" && v != 1) {
|
|
|
|
Notify.error("<span onclick=\"App.explainError(3)\">Update daemon is not updating feeds.</span>", true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k == "max_feed_id" || k == "num_feeds") {
|
|
|
|
if (App.getInitParam(k) != v) {
|
|
|
|
console.log("feed count changed, need to reload feedlist.");
|
|
|
|
Feeds.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setInitParam(k, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
|
|
|
|
},
|
|
|
|
backendSanityCallback: function (transport) {
|
|
|
|
const reply = JSON.parse(transport.responseText);
|
|
|
|
|
2018-12-11 10:18:38 +00:00
|
|
|
/* global ERRORS */
|
|
|
|
|
2018-12-02 19:08:18 +00:00
|
|
|
if (!reply) {
|
2018-12-11 10:18:38 +00:00
|
|
|
this.Error.fatal(ERRORS[3], {info: transport.responseText});
|
2018-12-02 19:08:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-11 10:18:38 +00:00
|
|
|
if (reply['error']) {
|
|
|
|
const code = reply['error']['code'];
|
2018-12-02 19:08:18 +00:00
|
|
|
|
2018-12-11 10:18:38 +00:00
|
|
|
if (code && code != 0) {
|
|
|
|
return this.Error.fatal(ERRORS[code],
|
|
|
|
{code: code, info: reply['error']['message']});
|
|
|
|
}
|
2018-12-02 19:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log("sanity check ok");
|
|
|
|
|
|
|
|
const params = reply['init-params'];
|
|
|
|
|
|
|
|
if (params) {
|
|
|
|
console.log('reading init-params...');
|
|
|
|
|
|
|
|
for (const k in params) {
|
|
|
|
if (params.hasOwnProperty(k)) {
|
|
|
|
switch (k) {
|
|
|
|
case "label_base_index":
|
2020-02-22 13:44:31 +00:00
|
|
|
LABEL_BASE_INDEX = parseInt(params[k]);
|
2018-12-02 19:08:18 +00:00
|
|
|
break;
|
2018-12-09 13:02:20 +00:00
|
|
|
case "cdm_auto_catchup":
|
2018-12-09 13:09:51 +00:00
|
|
|
if (params[k] == 1) {
|
|
|
|
const hl = $("headlines-frame");
|
|
|
|
if (hl) hl.addClassName("auto_catchup");
|
|
|
|
}
|
2018-12-09 13:02:20 +00:00
|
|
|
break;
|
2018-12-02 19:08:18 +00:00
|
|
|
case "hotkeys":
|
|
|
|
// filter mnemonic definitions (used for help panel) from hotkeys map
|
|
|
|
// i.e. *(191)|Ctrl-/ -> *(191)
|
|
|
|
|
|
|
|
const tmp = [];
|
|
|
|
for (const sequence in params[k][1]) {
|
|
|
|
if (params[k][1].hasOwnProperty(sequence)) {
|
|
|
|
const filtered = sequence.replace(/\|.*$/, "");
|
|
|
|
tmp[filtered] = params[k][1][sequence];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
params[k][1] = tmp;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("IP:", k, "=>", params[k]);
|
|
|
|
this.setInitParam(k, params[k]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginHost might not be available on non-index pages
|
2018-12-02 21:02:35 +00:00
|
|
|
if (typeof PluginHost !== 'undefined')
|
|
|
|
PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, App._initParams);
|
2018-12-02 19:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.initSecondStage();
|
|
|
|
},
|
|
|
|
explainError: function(code) {
|
|
|
|
return this.displayDlg(__("Error explained"), "explainError", code);
|
|
|
|
},
|
2018-12-03 10:38:13 +00:00
|
|
|
Error: {
|
2018-12-11 10:18:38 +00:00
|
|
|
fatal: function (error, params) {
|
|
|
|
params = params || {};
|
|
|
|
|
|
|
|
if (params.code) {
|
|
|
|
if (params.code == 6) {
|
|
|
|
window.location.href = "index.php";
|
|
|
|
return;
|
|
|
|
} else if (params.code == 5) {
|
|
|
|
window.location.href = "public.php?op=dbupdate";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.report(error,
|
|
|
|
Object.extend({title: __("Fatal error")}, params));
|
|
|
|
},
|
2018-12-03 10:38:13 +00:00
|
|
|
report: function(error, params) {
|
|
|
|
params = params || {};
|
|
|
|
|
|
|
|
if (!error) return;
|
|
|
|
|
|
|
|
console.error("[Error.report]", error, params);
|
|
|
|
|
|
|
|
const message = params.message ? params.message : error.toString();
|
|
|
|
|
|
|
|
try {
|
|
|
|
xhrPost("backend.php",
|
|
|
|
{op: "rpc", method: "log",
|
|
|
|
file: params.filename ? params.filename : error.fileName,
|
|
|
|
line: params.lineno ? params.lineno : error.lineNumber,
|
|
|
|
msg: message,
|
|
|
|
context: error.stack},
|
|
|
|
(transport) => {
|
|
|
|
console.warn("[Error.report] log response", transport.responseText);
|
|
|
|
});
|
|
|
|
} catch (re) {
|
|
|
|
console.error("[Error.report] exception while saving logging error on server", re);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (dijit.byId("exceptionDlg"))
|
|
|
|
dijit.byId("exceptionDlg").destroyRecursive();
|
|
|
|
|
2018-12-11 10:18:38 +00:00
|
|
|
let stack_msg = "";
|
|
|
|
|
|
|
|
if (error.stack)
|
|
|
|
stack_msg += `<div><b>Stack trace:</b></div>
|
|
|
|
<textarea name="stack" readonly="1">${error.stack}</textarea>`;
|
|
|
|
|
|
|
|
if (params.info)
|
|
|
|
stack_msg += `<div><b>Additional information:</b></div>
|
|
|
|
<textarea name="stack" readonly="1">${params.info}</textarea>`;
|
|
|
|
|
2018-12-11 09:45:05 +00:00
|
|
|
let content = `<div class="error-contents">
|
|
|
|
<p class="message">${message}</p>
|
2018-12-11 10:18:38 +00:00
|
|
|
${stack_msg}
|
2018-12-11 09:45:05 +00:00
|
|
|
<div class="dlgButtons">
|
|
|
|
<button dojoType="dijit.form.Button"
|
|
|
|
onclick=\"dijit.byId('exceptionDlg').hide()">${__('Close this window')}</button>
|
|
|
|
</div>
|
|
|
|
</div>`;
|
2018-12-03 10:38:13 +00:00
|
|
|
|
|
|
|
const dialog = new dijit.Dialog({
|
|
|
|
id: "exceptionDlg",
|
2018-12-11 10:18:38 +00:00
|
|
|
title: params.title || __("Unhandled exception"),
|
2018-12-03 10:38:13 +00:00
|
|
|
style: "width: 600px",
|
|
|
|
content: content
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
} catch (de) {
|
|
|
|
console.error("[Error.report] exception while showing error dialog", de);
|
|
|
|
|
|
|
|
alert(error.stack ? error.stack : message);
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
onWindowError: function (message, filename, lineno, colno, error) {
|
|
|
|
// called without context (this) from window.onerror
|
|
|
|
App.Error.report(error,
|
|
|
|
{message: message, filename: filename, lineno: lineno, colno: colno});
|
|
|
|
},
|
|
|
|
}
|
2018-12-02 18:52:50 +00:00
|
|
|
});
|
|
|
|
});
|