summaryrefslogtreecommitdiff
path: root/js/App.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/App.js')
-rw-r--r--js/App.js36
1 files changed, 31 insertions, 5 deletions
diff --git a/js/App.js b/js/App.js
index db1e7459e..046365ff8 100644
--- a/js/App.js
+++ b/js/App.js
@@ -17,6 +17,15 @@ const App = {
hotkey_actions: {},
is_prefs: false,
LABEL_BASE_INDEX: -1024,
+ _translations: {},
+ l10n: {
+ ngettext: function(msg1, msg2, n) {
+ return self.__((parseInt(n) > 1) ? msg2 : msg1);
+ },
+ __: function(msg) {
+ return App._translations[msg] ? App._translations[msg] : msg;
+ }
+ },
FormFields: {
attributes_to_string: function(attributes) {
return Object.keys(attributes).map((k) =>
@@ -410,7 +419,7 @@ const App = {
if (error && error.code && error.code != App.Error.E_SUCCESS) {
console.warn("handleRpcJson: fatal error", error);
- this.Error.fatal(error.code);
+ this.Error.fatal(error.code, error.params);
return false;
}
@@ -526,12 +535,20 @@ const App = {
PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, this._initParams);
}
+ const translations = reply['translations'];
+
+ if (translations) {
+ console.log('reading translations...');
+ App._translations = translations;
+ }
+
this.initSecondStage();
},
Error: {
E_SUCCESS: "E_SUCCESS",
E_UNAUTHORIZED: "E_UNAUTHORIZED",
E_SCHEMA_MISMATCH: "E_SCHEMA_MISMATCH",
+ E_URL_SCHEME_MISMATCH: "E_URL_SCHEME_MISMATCH",
fatal: function (error, params = {}) {
if (error == App.Error.E_UNAUTHORIZED) {
window.location.href = "index.php";
@@ -539,9 +556,14 @@ const App = {
} else if (error == App.Error.E_SCHEMA_MISMATCH) {
window.location.href = "public.php?op=dbupdate";
return;
+ } else if (error == App.Error.E_URL_SCHEME_MISMATCH) {
+ params.description = __("URL scheme reported by your browser (%a) doesn't match server-configured SELF_URL_PATH (%b), check X-Forwarded-Proto.")
+ .replace("%a", params.client_scheme)
+ .replace("%b", params.server_scheme);
+ params.info = `SELF_URL_PATH: ${params.self_url_path}\nCLIENT_LOCATION: ${document.location.href}`
}
- return this.report(__("Fatal error: %s").replace("%s", error),
+ return this.report(error,
{...{title: __("Fatal error")}, ...params});
},
report: function(error, params = {}) {
@@ -572,10 +594,13 @@ const App = {
<div class='exception-contents'>
<h3>${message}</h3>
- <header>${__('Stack trace')}</header>
+ ${params.description ? `<p>${params.description}</p>` : ''}
+
+ ${error.stack ?
+ `<header>${__('Stack trace')}</header>
<section>
<textarea readonly='readonly'>${error.stack}</textarea>
- </section>
+ </section>` : ''}
${params && params.info ?
`
@@ -635,7 +660,8 @@ const App = {
op: "rpc",
method: "sanityCheck",
clientTzOffset: new Date().getTimezoneOffset() * 60,
- hasSandbox: "sandbox" in document.createElement("iframe")
+ hasSandbox: "sandbox" in document.createElement("iframe"),
+ clientLocation: window.location.href
};
xhr.json("backend.php", params, (reply) => {