move Utils to AppBase where it belongs

This commit is contained in:
Andrew Dolgov 2018-12-02 22:08:18 +03:00
parent ac8361e6f6
commit 5ead558e43
9 changed files with 370 additions and 381 deletions

View File

@ -51,7 +51,7 @@ class Feeds extends Handler_Protected {
$reply .= "<span class='r'> $reply .= "<span class='r'>
<a href=\"#\" <a href=\"#\"
title=\"".__("Show as feed")."\" title=\"".__("Show as feed")."\"
onclick=\"Utils.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\"> onclick=\"App.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">
<img class=\"noborder\" src=\"images/pub_set.png\"></a>"; <img class=\"noborder\" src=\"images/pub_set.png\"></a>";
@ -137,7 +137,7 @@ class Feeds extends Handler_Protected {
//$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>"; //$reply .= "<option value=\"catchupPage()\">".__('Mark as read')."</option>";
$reply .= "<option value=\"Utils.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">". $reply .= "<option value=\"App.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\">".
__('Show as feed')."</option>"; __('Show as feed')."</option>";
$reply .= "</select>"; $reply .= "</select>";

View File

@ -1306,7 +1306,7 @@ class Pref_Feeds extends Handler_Protected {
print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds."); print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.");
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Utils.displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">". print "<button dojoType=\"dijit.form.Button\" onclick=\"return App.displayDlg('".__("Public OPML URL")."','pubOPMLUrl')\">".
__('Display published OPML URL')."</button> "; __('Display published OPML URL')."</button> ";
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
@ -1323,7 +1323,7 @@ class Pref_Feeds extends Handler_Protected {
print "<p>"; print "<p>";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Utils.displayDlg('".__("Show as feed")."','generatedFeed', '$rss_url')\">". print "<button dojoType=\"dijit.form.Button\" onclick=\"return App.displayDlg('".__("Show as feed")."','generatedFeed', '$rss_url')\">".
__('Display URL')."</button> "; __('Display URL')."</button> ";
print "<button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"return Prefs.clearFeedAccessKeys()\">". print "<button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"return Prefs.clearFeedAccessKeys()\">".

View File

@ -3,6 +3,10 @@
define(["dojo/_base/declare"], function (declare) { define(["dojo/_base/declare"], function (declare) {
return declare("fox.AppBase", null, { return declare("fox.AppBase", null, {
_initParams: [], _initParams: [],
_rpc_seq: 0,
hotkey_prefix: 0,
hotkey_prefix_pressed: false,
hotkey_prefix_timeout: 0,
getInitParam: function(k) { getInitParam: function(k) {
return this._initParams[k]; return this._initParams[k];
}, },
@ -30,6 +34,325 @@ define(["dojo/_base/declare"], function (declare) {
return callOriginal(options); return callOriginal(options);
} }
); );
},
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});
if (loading_progress >= 90)
Element.hide("overlay");
},
keyeventToAction: function(event) {
const hotkeys_map = App.getInitParam("hotkeys");
const keycode = event.which;
const keychar = String.fromCharCode(keycode).toLowerCase();
if (keycode == 27) { // escape and drop prefix
this.hotkey_prefix = false;
}
if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl
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");
let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
// 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;
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) {
exception_error(e);
} }
}); });
return false;
},
handleRpcJson: function(transport) {
const netalert_dijit = dijit.byId("net-alert");
let netalert = false;
if (netalert_dijit) netalert = netalert_dijit.domNode;
try {
const reply = JSON.parse(transport.responseText);
if (reply) {
const error = reply['error'];
if (error) {
const code = error['code'];
const msg = error['msg'];
console.warn("[handleRpcJson] received fatal error " + code + "/" + msg);
if (code != 0) {
fatalError(code, msg);
return false;
}
}
const seq = reply['seq'];
if (seq && this.get_seq() != seq) {
console.log("[handleRpcJson] sequence mismatch: " + seq +
" (want: " + this.get_seq() + ")");
return true;
}
const message = reply['message'];
if (message == "UPDATE_COUNTERS") {
console.log("need to refresh counters...");
App.setInitParam("last_article_id", -1);
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 {
if (netalert)
netalert.show();
else
Notify.error("Communication problem with server.");
}
} catch (e) {
if (netalert)
netalert.show();
else
Notify.error("Communication problem with server.");
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;
}
if (k == "update_result") {
const updatesIcon = dijit.byId("updatesIcon").domNode;
if (v) {
Element.show(updatesIcon);
} else {
Element.hide(updatesIcon);
}
}
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);
if (!reply) {
fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
return;
}
const error_code = reply['error']['code'];
if (error_code && error_code != 0) {
return fatalError(error_code, reply['error']['message']);
}
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":
_label_base_index = parseInt(params[k]);
break;
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
window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, App._initParams);
}
this.initSecondStage();
},
explainError: function(code) {
return this.displayDlg(__("Error explained"), "explainError", code);
},
});
}); });

View File

@ -97,7 +97,7 @@ define(["dojo/_base/declare"], function (declare) {
Article.setActive(id); Article.setActive(id);
}, },
render: function (article) { render: function (article) {
Utils.cleanupMemory("content-insert"); App.cleanupMemory("content-insert");
dijit.byId("headlines-wrap-inner").addChild( dijit.byId("headlines-wrap-inner").addChild(
dijit.byId("content-insert")); dijit.byId("content-insert"));
@ -144,7 +144,7 @@ define(["dojo/_base/declare"], function (declare) {
xhrPost("backend.php", {op: "article", method: "view", id: id, cids: cids.toString()}, (transport) => { xhrPost("backend.php", {op: "article", method: "view", id: id, cids: cids.toString()}, (transport) => {
try { try {
const reply = Utils.handleRpcJson(transport); const reply = App.handleRpcJson(transport);
if (reply) { if (reply) {

View File

@ -129,13 +129,13 @@ define(["dojo/_base/declare"], function (declare) {
this.counters_last_request = timestamp; this.counters_last_request = timestamp;
let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()}; let query = {op: "rpc", method: "getAllCounters", seq: App.next_seq()};
if (!force) if (!force)
query.last_article_id = App.getInitParam("last_article_id"); query.last_article_id = App.getInitParam("last_article_id");
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
} else { } else {
@ -196,7 +196,7 @@ define(["dojo/_base/declare"], function (declare) {
try { try {
Feeds.init(); Feeds.init();
Utils.setLoadingProgress(25); App.setLoadingProgress(25);
} catch (e) { } catch (e) {
exception_error(e); exception_error(e);
} }
@ -210,7 +210,7 @@ define(["dojo/_base/declare"], function (declare) {
init: function() { init: function() {
console.log("in feedlist init"); console.log("in feedlist init");
Utils.setLoadingProgress(50); App.setLoadingProgress(50);
document.onkeydown = (event) => { App.hotkeyHandler(event) }; document.onkeydown = (event) => { App.hotkeyHandler(event) };
window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000); window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000);
@ -461,7 +461,7 @@ define(["dojo/_base/declare"], function (declare) {
Notify.progress("Loading, please wait...", true); Notify.progress("Loading, please wait...", true);
xhrPost("backend.php", catchup_query, (transport) => { xhrPost("backend.php", catchup_query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
const show_next_feed = App.getInitParam("on_catchup_show_next_feed") == "1"; const show_next_feed = App.getInitParam("on_catchup_show_next_feed") == "1";
@ -520,7 +520,7 @@ define(["dojo/_base/declare"], function (declare) {
Notify.progress("Loading, please wait...", true); Notify.progress("Loading, please wait...", true);
xhrPost("backend.php", {op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => { xhrPost("backend.php", {op: "rpc", method: "catchupFeed", feed_id: id, is_cat: false}, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
} }
}, },
@ -633,7 +633,7 @@ define(["dojo/_base/declare"], function (declare) {
console.log("in update_random_feed"); console.log("in update_random_feed");
xhrPost("backend.php", {op: "rpc", method: "updateRandom"}, (transport) => { xhrPost("backend.php", {op: "rpc", method: "updateRandom"}, (transport) => {
Utils.handleRpcJson(transport, true); App.handleRpcJson(transport, true);
}); });
}, },
}); });

View File

@ -222,7 +222,7 @@ define(["dojo/_base/declare"], function (declare) {
} }
}, },
onLoaded: function(transport, offset) { onLoaded: function(transport, offset) {
const reply = Utils.handleRpcJson(transport); const reply = App.handleRpcJson(transport);
console.log("Headlines.onLoaded: offset=", offset); console.log("Headlines.onLoaded: offset=", offset);
@ -438,7 +438,7 @@ define(["dojo/_base/declare"], function (declare) {
Notify.progress("Loading, please wait..."); Notify.progress("Loading, please wait...");
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
if (callback) callback(transport); if (callback) callback(transport);
}); });
}, },
@ -460,7 +460,7 @@ define(["dojo/_base/declare"], function (declare) {
}; };
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
}, },
selectionTogglePublished: function(ids) { selectionTogglePublished: function(ids) {
@ -482,7 +482,7 @@ define(["dojo/_base/declare"], function (declare) {
}; };
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
} }
}, },
@ -507,7 +507,7 @@ define(["dojo/_base/declare"], function (declare) {
if (!client_only) if (!client_only)
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
} }
}, },
@ -533,7 +533,7 @@ define(["dojo/_base/declare"], function (declare) {
if (!client_only) if (!client_only)
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
} }
@ -654,7 +654,7 @@ define(["dojo/_base/declare"], function (declare) {
if (row.className != origClassName) if (row.className != origClassName)
xhrPost("backend.php", xhrPost("backend.php",
{op: "rpc", method: "catchupSelected", cmode: cmode, ids: id}, (transport) => { {op: "rpc", method: "catchupSelected", cmode: cmode, ids: id}, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
} }
}, },
@ -672,7 +672,7 @@ define(["dojo/_base/declare"], function (declare) {
}; };
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
this.onLabelsUpdated(transport); this.onLabelsUpdated(transport);
}); });
}, },
@ -690,7 +690,7 @@ define(["dojo/_base/declare"], function (declare) {
}; };
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
this.onLabelsUpdated(transport); this.onLabelsUpdated(transport);
}); });
}, },
@ -721,7 +721,7 @@ define(["dojo/_base/declare"], function (declare) {
const query = {op: "rpc", method: "delete", ids: rows.toString()}; const query = {op: "rpc", method: "delete", ids: rows.toString()};
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
Feeds.reloadCurrent(); Feeds.reloadCurrent();
}); });
}, },
@ -850,7 +850,7 @@ define(["dojo/_base/declare"], function (declare) {
const query = {op: "rpc", method: op, ids: rows.toString()}; const query = {op: "rpc", method: op, ids: rows.toString()};
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
Feeds.reloadCurrent(); Feeds.reloadCurrent();
}); });
}, },
@ -888,7 +888,7 @@ define(["dojo/_base/declare"], function (declare) {
}; };
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
const reply = Utils.handleRpcJson(transport); const reply = App.handleRpcJson(transport);
if (reply) { if (reply) {
const batch = reply.ids; const batch = reply.ids;
@ -965,7 +965,7 @@ define(["dojo/_base/declare"], function (declare) {
}; };
xhrPost("backend.php", query, (transport) => { xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport); App.handleRpcJson(transport);
}); });
} }
} }

View File

@ -1,330 +0,0 @@
'use strict'
/* global __, ngettext */
define(["dojo/_base/declare"], function (declare) {
return declare("fox.Utils", null, {
_rpc_seq: 0,
hotkey_prefix: 0,
hotkey_prefix_pressed: false,
hotkey_prefix_timeout: 0,
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});
if (loading_progress >= 90)
Element.hide("overlay");
},
keyeventToAction: function(event) {
const hotkeys_map = App.getInitParam("hotkeys");
const keycode = event.which;
const keychar = String.fromCharCode(keycode).toLowerCase();
if (keycode == 27) { // escape and drop prefix
this.hotkey_prefix = false;
}
if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl
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");
let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")";
// 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;
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) {
exception_error(e);
}
});
return false;
},
handleRpcJson: function(transport) {
const netalert_dijit = dijit.byId("net-alert");
let netalert = false;
if (netalert_dijit) netalert = netalert_dijit.domNode;
try {
const reply = JSON.parse(transport.responseText);
if (reply) {
const error = reply['error'];
if (error) {
const code = error['code'];
const msg = error['msg'];
console.warn("[handleRpcJson] received fatal error " + code + "/" + msg);
if (code != 0) {
fatalError(code, msg);
return false;
}
}
const seq = reply['seq'];
if (seq && this.get_seq() != seq) {
console.log("[handleRpcJson] sequence mismatch: " + seq +
" (want: " + this.get_seq() + ")");
return true;
}
const message = reply['message'];
if (message == "UPDATE_COUNTERS") {
console.log("need to refresh counters...");
App.setInitParam("last_article_id", -1);
Feeds.requestCounters(true);
}
const counters = reply['counters'];
if (counters)
Feeds.parseCounters(counters);
const runtime_info = reply['runtime-info'];
if (runtime_info)
Utils.parseRuntimeInfo(runtime_info);
if (netalert) netalert.hide();
return reply;
} else {
if (netalert)
netalert.show();
else
Notify.error("Communication problem with server.");
}
} catch (e) {
if (netalert)
netalert.show();
else
Notify.error("Communication problem with server.");
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=\"Utils.explainError(1)\">Update daemon is not running.</span>", true);
return;
}
if (k == "update_result") {
const updatesIcon = dijit.byId("updatesIcon").domNode;
if (v) {
Element.show(updatesIcon);
} else {
Element.hide(updatesIcon);
}
}
if (k == "daemon_stamp_ok" && v != 1) {
Notify.error("<span onclick=\"Utils.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();
}
}
App.setInitParam(k, v);
}
}
PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
},
backendSanityCallback: function (transport) {
const reply = JSON.parse(transport.responseText);
if (!reply) {
fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
return;
}
const error_code = reply['error']['code'];
if (error_code && error_code != 0) {
return fatalError(error_code, reply['error']['message']);
}
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":
_label_base_index = parseInt(params[k]);
break;
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]);
App.setInitParam(k, params[k]);
}
}
// PluginHost might not be available on non-index pages
window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, App._initParams);
}
App.initSecondStage();
},
explainError: function(code) {
return this.displayDlg(__("Error explained"), "explainError", code);
},
});
});

View File

@ -2,7 +2,6 @@
/* global dijit, __ */ /* global dijit, __ */
let App; let App;
let Utils;
let CommonDialogs; let CommonDialogs;
let Filters; let Filters;
let Users; let Users;
@ -43,7 +42,6 @@ require(["dojo/_base/kernel",
"dojo/data/ItemFileWriteStore", "dojo/data/ItemFileWriteStore",
"lib/CheckBoxStoreModel", "lib/CheckBoxStoreModel",
"lib/CheckBoxTree", "lib/CheckBoxTree",
"fox/Utils",
"fox/CommonDialogs", "fox/CommonDialogs",
"fox/CommonFilters", "fox/CommonFilters",
"fox/PrefUsers", "fox/PrefUsers",
@ -62,7 +60,6 @@ require(["dojo/_base/kernel",
report_error(message, filename, lineno, colno, error); report_error(message, filename, lineno, colno, error);
}; };
Utils = fox.Utils();
CommonDialogs = fox.CommonDialogs(); CommonDialogs = fox.CommonDialogs();
Filters = fox.CommonFilters(); Filters = fox.CommonFilters();
Users = fox.PrefUsers(); Users = fox.PrefUsers();
@ -70,39 +67,41 @@ require(["dojo/_base/kernel",
parser.parse(); parser.parse();
Utils.setLoadingProgress(50); this.setLoadingProgress(50);
const clientTzOffset = new Date().getTimezoneOffset() * 60; const clientTzOffset = new Date().getTimezoneOffset() * 60;
const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset}; const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset};
xhrPost("backend.php", params, (transport) => { xhrPost("backend.php", params, (transport) => {
try { try {
Utils.backendSanityCallback(transport); this.backendSanityCallback(transport);
} catch (e) { } catch (e) {
exception_error(e); exception_error(e);
} }
}); });
}, },
initSecondStage: function() { initSecondStage: function() {
document.onkeydown = () => { App.hotkeyHandler(event) }; this.enableCsrfSupport();
Utils.setLoadingProgress(50);
document.onkeydown = (event) => { App.hotkeyHandler(event) };
App.setLoadingProgress(50);
Notify.close(); Notify.close();
let tab = Utils.urlParam('tab'); let tab = App.urlParam('tab');
if (tab) { if (tab) {
tab = dijit.byId(tab + "Tab"); tab = dijit.byId(tab + "Tab");
if (tab) { if (tab) {
dijit.byId("pref-tabs").selectChild(tab); dijit.byId("pref-tabs").selectChild(tab);
switch (Utils.urlParam('method')) { switch (App.urlParam('method')) {
case "editfeed": case "editfeed":
window.setTimeout(function () { window.setTimeout(function () {
CommonDialogs.editFeed(Utils.urlParam('methodparam')) CommonDialogs.editFeed(App.urlParam('methodparam'))
}, 100); }, 100);
break; break;
default: default:
console.warn("initSecondStage, unknown method:", Utils.urlParam("method")); console.warn("initSecondStage, unknown method:", App.urlParam("method"));
} }
} }
} else { } else {
@ -124,7 +123,7 @@ require(["dojo/_base/kernel",
hotkeyHandler: function (event) { hotkeyHandler: function (event) {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return;
const action_name = Utils.keyeventToAction(event); const action_name = App.keyeventToAction(event);
if (action_name) { if (action_name) {
switch (action_name) { switch (action_name) {
@ -138,7 +137,7 @@ require(["dojo/_base/kernel",
Filters.quickAddFilter(); Filters.quickAddFilter();
return false; return false;
case "help_dialog": case "help_dialog":
Utils.helpDialog("main"); App.helpDialog("main");
return false; return false;
default: default:
console.log("unhandled action: " + action_name + "; keycode: " + event.which); console.log("unhandled action: " + action_name + "; keycode: " + event.which);

View File

@ -2,7 +2,6 @@
/* global dijit,__ */ /* global dijit,__ */
let App; let App;
let Utils;
let CommonDialogs; let CommonDialogs;
let Filters; let Filters;
let Feeds; let Feeds;
@ -46,7 +45,6 @@ require(["dojo/_base/kernel",
"dijit/tree/dndSource", "dijit/tree/dndSource",
"dijit/tree/ForestStoreModel", "dijit/tree/ForestStoreModel",
"dojo/data/ItemFileWriteStore", "dojo/data/ItemFileWriteStore",
"fox/Utils",
"fox/CommonDialogs", "fox/CommonDialogs",
"fox/CommonFilters", "fox/CommonFilters",
"fox/Feeds", "fox/Feeds",
@ -67,7 +65,6 @@ require(["dojo/_base/kernel",
report_error(message, filename, lineno, colno, error); report_error(message, filename, lineno, colno, error);
}; };
Utils = fox.Utils();
CommonDialogs = fox.CommonDialogs(); CommonDialogs = fox.CommonDialogs();
Filters = fox.CommonFilters(); Filters = fox.CommonFilters();
Feeds = fox.Feeds(); Feeds = fox.Feeds();
@ -80,7 +77,7 @@ require(["dojo/_base/kernel",
if (!this.genericSanityCheck()) if (!this.genericSanityCheck())
return; return;
Utils.setLoadingProgress(30); this.setLoadingProgress(30);
this.initHotkeyActions(); this.initHotkeyActions();
const a = document.createElement('audio'); const a = document.createElement('audio');
@ -98,7 +95,7 @@ require(["dojo/_base/kernel",
xhrPost("backend.php", params, (transport) => { xhrPost("backend.php", params, (transport) => {
try { try {
Utils.backendSanityCallback(transport); App.backendSanityCallback(transport);
} catch (e) { } catch (e) {
exception_error(e); exception_error(e);
} }
@ -149,7 +146,7 @@ require(["dojo/_base/kernel",
Feeds.setActive(hash_feed_id, hash_feed_is_cat); Feeds.setActive(hash_feed_id, hash_feed_is_cat);
} }
Utils.setLoadingProgress(50); App.setLoadingProgress(50);
ArticleCache.clear(); ArticleCache.clear();
@ -193,7 +190,7 @@ require(["dojo/_base/kernel",
hotkeyHandler(event) { hotkeyHandler(event) {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return;
const action_name = Utils.keyeventToAction(event); const action_name = App.keyeventToAction(event);
if (action_name) { if (action_name) {
const action_func = this.hotkey_actions[action_name]; const action_func = this.hotkey_actions[action_name];
@ -414,7 +411,7 @@ require(["dojo/_base/kernel",
Feeds.open({feed: -2}); Feeds.open({feed: -2});
}; };
this.hotkey_actions["goto_tagcloud"] = function () { this.hotkey_actions["goto_tagcloud"] = function () {
Utils.displayDlg(__("Tag cloud"), "printTagCloud"); App.displayDlg(__("Tag cloud"), "printTagCloud");
}; };
this.hotkey_actions["goto_prefs"] = function () { this.hotkey_actions["goto_prefs"] = function () {
document.location.href = "prefs.php"; document.location.href = "prefs.php";
@ -469,7 +466,7 @@ require(["dojo/_base/kernel",
} }
}; };
this.hotkey_actions["help_dialog"] = function () { this.hotkey_actions["help_dialog"] = function () {
Utils.helpDialog("main"); App.helpDialog("main");
}; };
this.hotkey_actions["toggle_combined_mode"] = function () { this.hotkey_actions["toggle_combined_mode"] = function () {
Notify.progress("Loading, please wait..."); Notify.progress("Loading, please wait...");
@ -504,7 +501,7 @@ require(["dojo/_base/kernel",
document.location.href = "backend.php?op=logout"; document.location.href = "backend.php?op=logout";
break; break;
case "qmcTagCloud": case "qmcTagCloud":
Utils.displayDlg(__("Tag cloud"), "printTagCloud"); App.displayDlg(__("Tag cloud"), "printTagCloud");
break; break;
case "qmcSearch": case "qmcSearch":
Feeds.search(); Feeds.search();
@ -560,7 +557,7 @@ require(["dojo/_base/kernel",
} }
break; break;
case "qmcHKhelp": case "qmcHKhelp":
Utils.helpDialog("main"); App.helpDialog("main");
break; break;
default: default:
console.log("quickMenuGo: unknown action: " + opid); console.log("quickMenuGo: unknown action: " + opid);