add AppBase as a shared ancestor for main and prefs app objects

remove event.observe stuff from startup, unneeded
This commit is contained in:
Andrew Dolgov 2018-12-02 21:52:50 +03:00
parent eeb49d375c
commit ac8361e6f6
10 changed files with 728 additions and 728 deletions

View File

@ -135,12 +135,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="referrer" content="no-referrer"/>
<script type="text/javascript">
Event.observe(window, 'load', function() {
App.init();
});
</script>
</head>
<body class="claro ttrss_main">

35
js/AppBase.js Normal file
View File

@ -0,0 +1,35 @@
'use strict'
/* global __, ngettext */
define(["dojo/_base/declare"], function (declare) {
return declare("fox.AppBase", null, {
_initParams: [],
getInitParam: function(k) {
return this._initParams[k];
},
setInitParam: function(k, v) {
this._initParams[k] = v;
},
constructor: function(args) {
//
},
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);
}
);
}
});
});

View File

@ -123,7 +123,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
postCreate: function() {
this.connect(this.model, "onChange", "updateCounter");
this.connect(this, "_expandNode", function() {
this.hideRead(getInitParam("hide_read_feeds"), getInitParam("hide_read_shows_special"));
this.hideRead(App.getInitParam("hide_read_feeds"), App.getInitParam("hide_read_shows_special"));
});
this.inherited(arguments);

View File

@ -83,7 +83,7 @@ define(["dojo/_base/declare"], function (declare) {
if (id > 0) {
if (has_img) {
this.setIcon(id, false,
getInitParam("icons_url") + "/" + id + ".ico?" + has_img);
App.getInitParam("icons_url") + "/" + id + ".ico?" + has_img);
} else {
this.setIcon(id, false, 'images/blank_icon.gif');
}
@ -91,7 +91,7 @@ define(["dojo/_base/declare"], function (declare) {
}
}
this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
this.hideOrShowFeeds(App.getInitParam("hide_read_feeds") == 1);
this._counters_prev = elems;
},
reloadCurrent: function(method) {
@ -132,7 +132,7 @@ define(["dojo/_base/declare"], function (declare) {
let query = {op: "rpc", method: "getAllCounters", seq: Utils.next_seq()};
if (!force)
query.last_article_id = getInitParam("last_article_id");
query.last_article_id = App.getInitParam("last_article_id");
xhrPost("backend.php", query, (transport) => {
Utils.handleRpcJson(transport);
@ -160,7 +160,7 @@ define(["dojo/_base/declare"], function (declare) {
const treeModel = new fox.FeedStoreModel({
store: store,
query: {
"type": getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
"type": App.getInitParam('enable_feed_cats') == 1 ? "category" : "feed"
},
rootId: "root",
rootLabel: "Feeds",
@ -221,9 +221,9 @@ define(["dojo/_base/declare"], function (declare) {
this.open({feed: this.getActive(), is_cat: this.activeIsCat()});
}
this.hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
this.hideOrShowFeeds(App.getInitParam("hide_read_feeds") == 1);
if (getInitParam("is_default_pw")) {
if (App.getInitParam("is_default_pw")) {
console.warn("user password is at default value");
const dialog = new dijit.Dialog({
@ -246,7 +246,7 @@ define(["dojo/_base/declare"], function (declare) {
}
// bw_limit disables timeout() so we request initial counters separately
if (getInitParam("bw_limit") == "1") {
if (App.getInitParam("bw_limit") == "1") {
this.requestCounters(true);
} else {
setTimeout(() => {
@ -281,18 +281,18 @@ define(["dojo/_base/declare"], function (declare) {
if (tree) return tree.selectFeed(feed, is_cat);
},
toggleUnread: function() {
const hide = !(getInitParam("hide_read_feeds") == "1");
const hide = !(App.getInitParam("hide_read_feeds") == "1");
xhrPost("backend.php", {op: "rpc", method: "setpref", key: "HIDE_READ_FEEDS", value: hide}, () => {
this.hideOrShowFeeds(hide);
setInitParam("hide_read_feeds", hide);
App.setInitParam("hide_read_feeds", hide);
});
},
hideOrShowFeeds: function(hide) {
const tree = dijit.byId("feedTree");
if (tree)
return tree.hideRead(hide, getInitParam("hide_read_shows_special"));
return tree.hideRead(hide, App.getInitParam("hide_read_shows_special"));
},
open: function(params) {
const feed = params.feed;
@ -366,7 +366,7 @@ define(["dojo/_base/declare"], function (declare) {
if (viewfeed_debug) {
window.open("backend.php?" +
dojo.objectToQuery(
Object.assign({debug: 1, csrf_token: getInitParam("csrf_token")}, query)
Object.assign({debug: 1, csrf_token: App.getInitParam("csrf_token")}, query)
));
}
@ -389,7 +389,7 @@ define(["dojo/_base/declare"], function (declare) {
catchupAll: function() {
const str = __("Mark all articles as read?");
if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
Notify.progress("Marking all feeds as read...");
@ -448,7 +448,7 @@ define(["dojo/_base/declare"], function (declare) {
str = str.replace("%s", fn)
.replace("%w", mark_what);
if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
return;
}
@ -463,7 +463,7 @@ define(["dojo/_base/declare"], function (declare) {
xhrPost("backend.php", catchup_query, (transport) => {
Utils.handleRpcJson(transport);
const show_next_feed = getInitParam("on_catchup_show_next_feed") == "1";
const show_next_feed = App.getInitParam("on_catchup_show_next_feed") == "1";
if (show_next_feed) {
const nuf = this.getNextUnread(feed, is_cat);
@ -486,7 +486,7 @@ define(["dojo/_base/declare"], function (declare) {
const str = __("Mark all articles in %s as read?").replace("%s", title);
if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
const rows = $$("#headlines-frame > div[id*=RROW][data-orig-feed-id='" + id + "']");

View File

@ -12,13 +12,13 @@ define(["dojo/_base/declare"], function (declare) {
if (App.isCombinedMode()) {
if (!in_body && (event.ctrlKey || id == Article.getActive() || getInitParam("cdm_expanded"))) {
if (!in_body && (event.ctrlKey || id == Article.getActive() || App.getInitParam("cdm_expanded"))) {
Article.openInNewWindow(id);
}
Article.setActive(id);
if (!getInitParam("cdm_expanded"))
if (!App.getInitParam("cdm_expanded"))
Article.cdmScrollToId(id);
return in_body;
@ -81,7 +81,7 @@ define(["dojo/_base/declare"], function (declare) {
// set topmost child in the buffer as active, but not if we're at the beginning (to prevent auto marking
// first article as read all the time)
if ($("headlines-frame").scrollTop != 0 &&
getInitParam("cdm_expanded") && getInitParam("cdm_auto_catchup") == 1) {
App.getInitParam("cdm_expanded") && App.getInitParam("cdm_auto_catchup") == 1) {
const rows = $$("#headlines-frame > div[id*=RROW]");
@ -113,7 +113,7 @@ define(["dojo/_base/declare"], function (declare) {
}
}
if (getInitParam("cdm_auto_catchup") == 1) {
if (App.getInitParam("cdm_auto_catchup") == 1) {
let rows = $$("#headlines-frame > div[id*=RROW][class*=Unread]");
@ -139,7 +139,7 @@ define(["dojo/_base/declare"], function (declare) {
console.log("we seem to be at an end");
if (getInitParam("on_catchup_show_next_feed") == "1") {
if (App.getInitParam("on_catchup_show_next_feed") == "1") {
Feeds.openNextUnread();
}
}
@ -150,7 +150,7 @@ define(["dojo/_base/declare"], function (declare) {
}
},
updateFloatingTitle: function(unread_only) {
if (!App.isCombinedMode()/* || !getInitParam("cdm_expanded")*/) return;
if (!App.isCombinedMode()/* || !App.getInitParam("cdm_expanded")*/) return;
const hf = $("headlines-frame");
const elems = $$("#headlines-frame > div[id*=RROW]");
@ -201,7 +201,7 @@ define(["dojo/_base/declare"], function (declare) {
}
},
unpackVisible: function() {
if (!App.isCombinedMode() || !getInitParam("cdm_expanded")) return;
if (!App.isCombinedMode() || !App.getInitParam("cdm_expanded")) return;
const rows = $$("#headlines-frame div[id*=RROW][data-content]");
const threshold = $("headlines-frame").scrollTop + $("headlines-frame").offsetHeight + 600;
@ -714,7 +714,7 @@ define(["dojo/_base/declare"], function (declare) {
str = str.replace("%d", rows.length);
str = str.replace("%s", fn);
if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
return;
}
@ -839,7 +839,7 @@ define(["dojo/_base/declare"], function (declare) {
str = str.replace("%d", rows.length);
str = str.replace("%s", fn);
if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
return;
}
@ -869,7 +869,7 @@ define(["dojo/_base/declare"], function (declare) {
str = str.replace("%d", rows.length);
str = str.replace("%s", fn);
if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
if (App.getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
return;
}
@ -952,7 +952,7 @@ define(["dojo/_base/declare"], function (declare) {
} else {
const msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length);
if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
if (App.getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
for (var i = 0; i < ids_to_mark.length; i++) {
var e = $("RROW-" + ids_to_mark[i]);
@ -1090,7 +1090,7 @@ define(["dojo/_base/declare"], function (declare) {
}));
const labels = getInitParam("labels");
const labels = App.getInitParam("labels");
if (labels && labels.length) {

View File

@ -28,7 +28,7 @@ define(["dojo/_base/declare"], function (declare) {
},
keyeventToAction: function(event) {
const hotkeys_map = getInitParam("hotkeys");
const hotkeys_map = App.getInitParam("hotkeys");
const keycode = event.which;
const keychar = String.fromCharCode(keycode).toLowerCase();
@ -191,7 +191,7 @@ define(["dojo/_base/declare"], function (declare) {
if (message == "UPDATE_COUNTERS") {
console.log("need to refresh counters...");
setInitParam("last_article_id", -1);
App.setInitParam("last_article_id", -1);
Feeds.requestCounters(true);
}
@ -228,9 +228,6 @@ define(["dojo/_base/declare"], function (declare) {
return false;
},
parseRuntimeInfo: function(data) {
//console.log("parsing runtime info...");
for (const k in data) {
if (data.hasOwnProperty(k)) {
const v = data[k];
@ -258,13 +255,13 @@ define(["dojo/_base/declare"], function (declare) {
}
if (k == "max_feed_id" || k == "num_feeds") {
if (init_params[k] != v) {
if (App.getInitParam(k) != v) {
console.log("feed count changed, need to reload feedlist.");
Feeds.reload();
}
}
init_params[k] = v;
App.setInitParam(k, v);
}
}
@ -315,13 +312,12 @@ define(["dojo/_base/declare"], function (declare) {
}
console.log("IP:", k, "=>", params[k]);
App.setInitParam(k, params[k]);
}
}
init_params = params;
// PluginHost might not be available on non-index pages
window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, init_params);
window.PluginHost && PluginHost.run(PluginHost.HOOK_PARAMS_LOADED, App._initParams);
}
App.initSecondStage();

View File

@ -1,28 +1,8 @@
'use strict'
/* global dijit, __ */
let init_params = {};
let _label_base_index = -1024;
let loading_progress = 0;
let notify_hide_timerid = false;
Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap(
function (callOriginal, options) {
if (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"] = getInitParam("csrf_token");
}
return callOriginal(options);
}
);
/* xhr shorthand helpers */
@ -239,15 +219,15 @@ const Notify = {
switch (kind) {
case this.KIND_INFO:
notify.addClassName("notify_info")
icon = getInitParam("icon_information");
icon = App.getInitParam("icon_information");
break;
case this.KIND_ERROR:
notify.addClassName("notify_error");
icon = getInitParam("icon_alert");
icon = App.getInitParam("icon_alert");
break;
case this.KIND_PROGRESS:
notify.addClassName("notify_progress");
icon = getInitParam("icon_indicator_white")
icon = App.getInitParam("icon_indicator_white")
break;
}
@ -255,7 +235,7 @@ const Notify = {
msgfmt += (" <span><img src=\"%s\" class='close' title=\"" +
__("Click to close") + "\" onclick=\"Notify.close()\"></span>")
.replace("%s", getInitParam("icon_cross"));
.replace("%s", App.getInitParam("icon_cross"));
notify.innerHTML = msgfmt;
notify.addClassName("visible");
@ -289,14 +269,6 @@ function displayIfChecked(checkbox, elemId) {
}
}
function getInitParam(key) {
return init_params[key];
}
function setInitParam(key, value) {
init_params[key] = value;
}
function fatalError(code, msg, ext_info) {
if (code == 6) {
window.location.href = "index.php";
@ -390,5 +362,5 @@ function popupOpenArticle(id) {
"height=900,width=900,resizable=yes,status=no,location=no,menubar=no,directories=no,scrollbars=yes,toolbar=no");
w.opener = null;
w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token");
w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + App.getInitParam("csrf_token");
}

View File

@ -1,64 +1,67 @@
'use strict'
/* global dijit, __ */
let App;
let Utils;
let CommonDialogs;
let Filters;
let Users;
let Prefs;
const App = {
init: function() {
window.onerror = function (message, filename, lineno, colno, error) {
report_error(message, filename, lineno, colno, error);
};
require(["dojo/_base/kernel",
"dojo/_base/declare",
"dojo/ready",
"dojo/parser",
"fox/AppBase",
"dojo/_base/loader",
"dojo/_base/html",
"dijit/ColorPalette",
"dijit/Dialog",
"dijit/form/Button",
"dijit/form/CheckBox",
"dijit/form/DropDownButton",
"dijit/form/FilteringSelect",
"dijit/form/MultiSelect",
"dijit/form/Form",
"dijit/form/RadioButton",
"dijit/form/ComboButton",
"dijit/form/Select",
"dijit/form/SimpleTextarea",
"dijit/form/TextBox",
"dijit/form/ValidationTextBox",
"dijit/InlineEditBox",
"dijit/layout/AccordionContainer",
"dijit/layout/AccordionPane",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/layout/TabContainer",
"dijit/Menu",
"dijit/ProgressBar",
"dijit/Toolbar",
"dijit/Tree",
"dijit/tree/dndSource",
"dojo/data/ItemFileWriteStore",
"lib/CheckBoxStoreModel",
"lib/CheckBoxTree",
"fox/Utils",
"fox/CommonDialogs",
"fox/CommonFilters",
"fox/PrefUsers",
"fox/PrefHelpers",
"fox/PrefFeedStore",
"fox/PrefFilterStore",
"fox/PrefFeedTree",
"fox/PrefFilterTree",
"fox/PrefLabelTree"], function (dojo, declare, ready, parser, AppBase) {
require(["dojo/_base/kernel",
"dojo/ready",
"dojo/parser",
"dojo/_base/loader",
"dojo/_base/html",
"dijit/ColorPalette",
"dijit/Dialog",
"dijit/form/Button",
"dijit/form/CheckBox",
"dijit/form/DropDownButton",
"dijit/form/FilteringSelect",
"dijit/form/MultiSelect",
"dijit/form/Form",
"dijit/form/RadioButton",
"dijit/form/ComboButton",
"dijit/form/Select",
"dijit/form/SimpleTextarea",
"dijit/form/TextBox",
"dijit/form/ValidationTextBox",
"dijit/InlineEditBox",
"dijit/layout/AccordionContainer",
"dijit/layout/AccordionPane",
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dijit/layout/TabContainer",
"dijit/Menu",
"dijit/ProgressBar",
"dijit/Toolbar",
"dijit/Tree",
"dijit/tree/dndSource",
"dojo/data/ItemFileWriteStore",
"lib/CheckBoxStoreModel",
"lib/CheckBoxTree",
"fox/Utils",
"fox/CommonDialogs",
"fox/CommonFilters",
"fox/PrefUsers",
"fox/PrefHelpers",
"fox/PrefFeedStore",
"fox/PrefFilterStore",
"fox/PrefFeedTree",
"fox/PrefFilterTree",
"fox/PrefLabelTree"], function (dojo, ready, parser) {
ready(function () {
try {
const _App = declare("fox.App", AppBase, {
constructor: function() {
window.onerror = function (message, filename, lineno, colno, error) {
report_error(message, filename, lineno, colno, error);
};
ready(function () {
try {
Utils = fox.Utils();
CommonDialogs = fox.CommonDialogs();
Filters = fox.CommonFilters();
@ -73,81 +76,87 @@ const App = {
const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset};
xhrPost("backend.php", params, (transport) => {
Utils.backendSanityCallback(transport);
try {
Utils.backendSanityCallback(transport);
} catch (e) {
exception_error(e);
}
});
},
initSecondStage: function() {
document.onkeydown = () => { App.hotkeyHandler(event) };
Utils.setLoadingProgress(50);
Notify.close();
let tab = Utils.urlParam('tab');
if (tab) {
tab = dijit.byId(tab + "Tab");
if (tab) {
dijit.byId("pref-tabs").selectChild(tab);
switch (Utils.urlParam('method')) {
case "editfeed":
window.setTimeout(function () {
CommonDialogs.editFeed(Utils.urlParam('methodparam'))
}, 100);
break;
default:
console.warn("initSecondStage, unknown method:", Utils.urlParam("method"));
}
}
} else {
let tab = localStorage.getItem("ttrss:prefs-tab");
if (tab) {
tab = dijit.byId(tab);
if (tab) {
dijit.byId("pref-tabs").selectChild(tab);
}
}
}
dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) {
localStorage.setItem("ttrss:prefs-tab", elem.id);
});
} catch (e) {
exception_error(e);
},
hotkeyHandler: function (event) {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return;
const action_name = Utils.keyeventToAction(event);
if (action_name) {
switch (action_name) {
case "feed_subscribe":
CommonDialogs.quickAddFeed();
return false;
case "create_label":
CommonDialogs.addLabel();
return false;
case "create_filter":
Filters.quickAddFilter();
return false;
case "help_dialog":
Utils.helpDialog("main");
return false;
default:
console.log("unhandled action: " + action_name + "; keycode: " + event.which);
}
}
},
isPrefs: function() {
return true;
}
});
});
},
initSecondStage: function() {
document.onkeydown = () => { App.hotkeyHandler(event) };
Utils.setLoadingProgress(50);
Notify.close();
let tab = Utils.urlParam('tab');
App = new _App();
if (tab) {
tab = dijit.byId(tab + "Tab");
if (tab) {
dijit.byId("pref-tabs").selectChild(tab);
switch (Utils.urlParam('method')) {
case "editfeed":
window.setTimeout(function () {
CommonDialogs.editFeed(Utils.urlParam('methodparam'))
}, 100);
break;
default:
console.warn("initSecondStage, unknown method:", Utils.urlParam("method"));
}
}
} else {
let tab = localStorage.getItem("ttrss:prefs-tab");
if (tab) {
tab = dijit.byId(tab);
if (tab) {
dijit.byId("pref-tabs").selectChild(tab);
}
}
} catch (e) {
exception_error(e);
}
dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) {
localStorage.setItem("ttrss:prefs-tab", elem.id);
});
},
hotkeyHandler: function (event) {
if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return;
const action_name = Utils.keyeventToAction(event);
if (action_name) {
switch (action_name) {
case "feed_subscribe":
CommonDialogs.quickAddFeed();
return false;
case "create_label":
CommonDialogs.addLabel();
return false;
case "create_filter":
Filters.quickAddFilter();
return false;
case "help_dialog":
Utils.helpDialog("main");
return false;
default:
console.log("unhandled action: " + action_name + "; keycode: " + event.which);
}
}
},
isPrefs: function() {
return true;
}
};
});
});
function opmlImportComplete(iframe) {
if (!iframe.contentDocument.body.innerHTML) return false;

File diff suppressed because it is too large Load Diff

View File

@ -100,13 +100,6 @@
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
Event.observe(window, 'load', function() {
App.init();
});
</script>
</head>
<body class="claro ttrss_main ttrss_prefs">