move Utils to AppBase where it belongs
This commit is contained in:
parent
ac8361e6f6
commit
5ead558e43
|
@ -51,7 +51,7 @@ class Feeds extends Handler_Protected {
|
|||
$reply .= "<span class='r'>
|
||||
<a href=\"#\"
|
||||
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>";
|
||||
|
||||
|
||||
|
@ -137,7 +137,7 @@ class Feeds extends Handler_Protected {
|
|||
|
||||
//$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>";
|
||||
|
||||
$reply .= "</select>";
|
||||
|
|
|
@ -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 "<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> ";
|
||||
|
||||
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION,
|
||||
|
@ -1323,7 +1323,7 @@ class Pref_Feeds extends Handler_Protected {
|
|||
|
||||
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> ";
|
||||
|
||||
print "<button class=\"btn-danger\" dojoType=\"dijit.form.Button\" onclick=\"return Prefs.clearFeedAccessKeys()\">".
|
||||
|
|
323
js/AppBase.js
323
js/AppBase.js
|
@ -3,6 +3,10 @@
|
|||
define(["dojo/_base/declare"], function (declare) {
|
||||
return declare("fox.AppBase", null, {
|
||||
_initParams: [],
|
||||
_rpc_seq: 0,
|
||||
hotkey_prefix: 0,
|
||||
hotkey_prefix_pressed: false,
|
||||
hotkey_prefix_timeout: 0,
|
||||
getInitParam: function(k) {
|
||||
return this._initParams[k];
|
||||
},
|
||||
|
@ -30,6 +34,325 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
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);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
|
@ -97,7 +97,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
Article.setActive(id);
|
||||
},
|
||||
render: function (article) {
|
||||
Utils.cleanupMemory("content-insert");
|
||||
App.cleanupMemory("content-insert");
|
||||
|
||||
dijit.byId("headlines-wrap-inner").addChild(
|
||||
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) => {
|
||||
try {
|
||||
const reply = Utils.handleRpcJson(transport);
|
||||
const reply = App.handleRpcJson(transport);
|
||||
|
||||
if (reply) {
|
||||
|
||||
|
|
14
js/Feeds.js
14
js/Feeds.js
|
@ -129,13 +129,13 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
|
||||
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)
|
||||
query.last_article_id = App.getInitParam("last_article_id");
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
});
|
||||
|
||||
} else {
|
||||
|
@ -196,7 +196,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
|
||||
try {
|
||||
Feeds.init();
|
||||
Utils.setLoadingProgress(25);
|
||||
App.setLoadingProgress(25);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
|
@ -210,7 +210,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
init: function() {
|
||||
console.log("in feedlist init");
|
||||
|
||||
Utils.setLoadingProgress(50);
|
||||
App.setLoadingProgress(50);
|
||||
|
||||
document.onkeydown = (event) => { App.hotkeyHandler(event) };
|
||||
window.setInterval(() => { Headlines.catchupBatched() }, 10 * 1000);
|
||||
|
@ -461,7 +461,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
Notify.progress("Loading, please wait...", true);
|
||||
|
||||
xhrPost("backend.php", catchup_query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
|
||||
xhrPost("backend.php", {op: "rpc", method: "updateRandom"}, (transport) => {
|
||||
Utils.handleRpcJson(transport, true);
|
||||
App.handleRpcJson(transport, true);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -222,7 +222,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
}
|
||||
},
|
||||
onLoaded: function(transport, offset) {
|
||||
const reply = Utils.handleRpcJson(transport);
|
||||
const reply = App.handleRpcJson(transport);
|
||||
|
||||
console.log("Headlines.onLoaded: offset=", offset);
|
||||
|
||||
|
@ -438,7 +438,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
Notify.progress("Loading, please wait...");
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
if (callback) callback(transport);
|
||||
});
|
||||
},
|
||||
|
@ -460,7 +460,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
});
|
||||
},
|
||||
selectionTogglePublished: function(ids) {
|
||||
|
@ -482,7 +482,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -507,7 +507,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
|
||||
if (!client_only)
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
@ -533,7 +533,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
|
||||
if (!client_only)
|
||||
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)
|
||||
xhrPost("backend.php",
|
||||
{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) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
this.onLabelsUpdated(transport);
|
||||
});
|
||||
},
|
||||
|
@ -690,7 +690,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
this.onLabelsUpdated(transport);
|
||||
});
|
||||
},
|
||||
|
@ -721,7 +721,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
const query = {op: "rpc", method: "delete", ids: rows.toString()};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
Feeds.reloadCurrent();
|
||||
});
|
||||
},
|
||||
|
@ -850,7 +850,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
const query = {op: "rpc", method: op, ids: rows.toString()};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
Feeds.reloadCurrent();
|
||||
});
|
||||
},
|
||||
|
@ -888,7 +888,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
const reply = Utils.handleRpcJson(transport);
|
||||
const reply = App.handleRpcJson(transport);
|
||||
|
||||
if (reply) {
|
||||
const batch = reply.ids;
|
||||
|
@ -965,7 +965,7 @@ define(["dojo/_base/declare"], function (declare) {
|
|||
};
|
||||
|
||||
xhrPost("backend.php", query, (transport) => {
|
||||
Utils.handleRpcJson(transport);
|
||||
App.handleRpcJson(transport);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
330
js/Utils.js
330
js/Utils.js
|
@ -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);
|
||||
},
|
||||
|
||||
});
|
||||
});
|
25
js/prefs.js
25
js/prefs.js
|
@ -2,7 +2,6 @@
|
|||
/* global dijit, __ */
|
||||
|
||||
let App;
|
||||
let Utils;
|
||||
let CommonDialogs;
|
||||
let Filters;
|
||||
let Users;
|
||||
|
@ -43,7 +42,6 @@ require(["dojo/_base/kernel",
|
|||
"dojo/data/ItemFileWriteStore",
|
||||
"lib/CheckBoxStoreModel",
|
||||
"lib/CheckBoxTree",
|
||||
"fox/Utils",
|
||||
"fox/CommonDialogs",
|
||||
"fox/CommonFilters",
|
||||
"fox/PrefUsers",
|
||||
|
@ -62,7 +60,6 @@ require(["dojo/_base/kernel",
|
|||
report_error(message, filename, lineno, colno, error);
|
||||
};
|
||||
|
||||
Utils = fox.Utils();
|
||||
CommonDialogs = fox.CommonDialogs();
|
||||
Filters = fox.CommonFilters();
|
||||
Users = fox.PrefUsers();
|
||||
|
@ -70,39 +67,41 @@ require(["dojo/_base/kernel",
|
|||
|
||||
parser.parse();
|
||||
|
||||
Utils.setLoadingProgress(50);
|
||||
this.setLoadingProgress(50);
|
||||
|
||||
const clientTzOffset = new Date().getTimezoneOffset() * 60;
|
||||
const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset};
|
||||
|
||||
xhrPost("backend.php", params, (transport) => {
|
||||
try {
|
||||
Utils.backendSanityCallback(transport);
|
||||
this.backendSanityCallback(transport);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
initSecondStage: function() {
|
||||
document.onkeydown = () => { App.hotkeyHandler(event) };
|
||||
Utils.setLoadingProgress(50);
|
||||
this.enableCsrfSupport();
|
||||
|
||||
document.onkeydown = (event) => { App.hotkeyHandler(event) };
|
||||
App.setLoadingProgress(50);
|
||||
Notify.close();
|
||||
|
||||
let tab = Utils.urlParam('tab');
|
||||
let tab = App.urlParam('tab');
|
||||
|
||||
if (tab) {
|
||||
tab = dijit.byId(tab + "Tab");
|
||||
if (tab) {
|
||||
dijit.byId("pref-tabs").selectChild(tab);
|
||||
|
||||
switch (Utils.urlParam('method')) {
|
||||
switch (App.urlParam('method')) {
|
||||
case "editfeed":
|
||||
window.setTimeout(function () {
|
||||
CommonDialogs.editFeed(Utils.urlParam('methodparam'))
|
||||
CommonDialogs.editFeed(App.urlParam('methodparam'))
|
||||
}, 100);
|
||||
break;
|
||||
default:
|
||||
console.warn("initSecondStage, unknown method:", Utils.urlParam("method"));
|
||||
console.warn("initSecondStage, unknown method:", App.urlParam("method"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -124,7 +123,7 @@ require(["dojo/_base/kernel",
|
|||
hotkeyHandler: function (event) {
|
||||
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) {
|
||||
switch (action_name) {
|
||||
|
@ -138,7 +137,7 @@ require(["dojo/_base/kernel",
|
|||
Filters.quickAddFilter();
|
||||
return false;
|
||||
case "help_dialog":
|
||||
Utils.helpDialog("main");
|
||||
App.helpDialog("main");
|
||||
return false;
|
||||
default:
|
||||
console.log("unhandled action: " + action_name + "; keycode: " + event.which);
|
||||
|
|
19
js/tt-rss.js
19
js/tt-rss.js
|
@ -2,7 +2,6 @@
|
|||
/* global dijit,__ */
|
||||
|
||||
let App;
|
||||
let Utils;
|
||||
let CommonDialogs;
|
||||
let Filters;
|
||||
let Feeds;
|
||||
|
@ -46,7 +45,6 @@ require(["dojo/_base/kernel",
|
|||
"dijit/tree/dndSource",
|
||||
"dijit/tree/ForestStoreModel",
|
||||
"dojo/data/ItemFileWriteStore",
|
||||
"fox/Utils",
|
||||
"fox/CommonDialogs",
|
||||
"fox/CommonFilters",
|
||||
"fox/Feeds",
|
||||
|
@ -67,7 +65,6 @@ require(["dojo/_base/kernel",
|
|||
report_error(message, filename, lineno, colno, error);
|
||||
};
|
||||
|
||||
Utils = fox.Utils();
|
||||
CommonDialogs = fox.CommonDialogs();
|
||||
Filters = fox.CommonFilters();
|
||||
Feeds = fox.Feeds();
|
||||
|
@ -80,7 +77,7 @@ require(["dojo/_base/kernel",
|
|||
if (!this.genericSanityCheck())
|
||||
return;
|
||||
|
||||
Utils.setLoadingProgress(30);
|
||||
this.setLoadingProgress(30);
|
||||
this.initHotkeyActions();
|
||||
|
||||
const a = document.createElement('audio');
|
||||
|
@ -98,7 +95,7 @@ require(["dojo/_base/kernel",
|
|||
|
||||
xhrPost("backend.php", params, (transport) => {
|
||||
try {
|
||||
Utils.backendSanityCallback(transport);
|
||||
App.backendSanityCallback(transport);
|
||||
} catch (e) {
|
||||
exception_error(e);
|
||||
}
|
||||
|
@ -149,7 +146,7 @@ require(["dojo/_base/kernel",
|
|||
Feeds.setActive(hash_feed_id, hash_feed_is_cat);
|
||||
}
|
||||
|
||||
Utils.setLoadingProgress(50);
|
||||
App.setLoadingProgress(50);
|
||||
|
||||
ArticleCache.clear();
|
||||
|
||||
|
@ -193,7 +190,7 @@ require(["dojo/_base/kernel",
|
|||
hotkeyHandler(event) {
|
||||
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) {
|
||||
const action_func = this.hotkey_actions[action_name];
|
||||
|
@ -414,7 +411,7 @@ require(["dojo/_base/kernel",
|
|||
Feeds.open({feed: -2});
|
||||
};
|
||||
this.hotkey_actions["goto_tagcloud"] = function () {
|
||||
Utils.displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
App.displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
};
|
||||
this.hotkey_actions["goto_prefs"] = function () {
|
||||
document.location.href = "prefs.php";
|
||||
|
@ -469,7 +466,7 @@ require(["dojo/_base/kernel",
|
|||
}
|
||||
};
|
||||
this.hotkey_actions["help_dialog"] = function () {
|
||||
Utils.helpDialog("main");
|
||||
App.helpDialog("main");
|
||||
};
|
||||
this.hotkey_actions["toggle_combined_mode"] = function () {
|
||||
Notify.progress("Loading, please wait...");
|
||||
|
@ -504,7 +501,7 @@ require(["dojo/_base/kernel",
|
|||
document.location.href = "backend.php?op=logout";
|
||||
break;
|
||||
case "qmcTagCloud":
|
||||
Utils.displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
App.displayDlg(__("Tag cloud"), "printTagCloud");
|
||||
break;
|
||||
case "qmcSearch":
|
||||
Feeds.search();
|
||||
|
@ -560,7 +557,7 @@ require(["dojo/_base/kernel",
|
|||
}
|
||||
break;
|
||||
case "qmcHKhelp":
|
||||
Utils.helpDialog("main");
|
||||
App.helpDialog("main");
|
||||
break;
|
||||
default:
|
||||
console.log("quickMenuGo: unknown action: " + opid);
|
||||
|
|
Loading…
Reference in New Issue