From 049a37aa0e7d37cafd979e7d470c7649700b5010 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 17:05:28 +0300 Subject: WIP reshuffling of JS global context into separate logical objects --- js/prefs.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 50283efbf..bb547c113 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -6,7 +6,7 @@ function notify_callback2(transport, sticky) { notify_info(transport.responseText, sticky); } -function updateFeedList() { +function Feeds.reload() { const user_search = $("feed_search"); let search = ""; @@ -324,7 +324,7 @@ function removeSelectedFeeds() { ids: sel_rows.toString() }; xhrPost("backend.php", query, () => { - updateFeedList(); + Feeds.reload(); }); } @@ -524,7 +524,7 @@ function editSelectedFeeds() { xhrPost("backend.php", query, () => { dialog.hide(); - updateFeedList(); + Feeds.reload(); }); } }, @@ -618,7 +618,7 @@ function selectTab(id, noupdate) { switch (id) { case "feedConfig": - updateFeedList(); + Feeds.reload(); break; case "filterConfig": updateFilterList(); @@ -764,7 +764,7 @@ function pref_hotkey_handler(e) { quickAddFilter(); return false; case "help_dialog": - helpDialog("main"); + Utils.helpDialog("main"); return false; default: console.log("unhandled action: " + action_name + "; keycode: " + e.which); @@ -782,7 +782,7 @@ function removeCategory(id, item) { xhrPost("backend.php", query, () => { notify(''); - updateFeedList(); + Feeds.reload(); }); } } @@ -798,7 +798,7 @@ function removeSelectedCategories() { ids: sel_rows.toString() }; xhrPost("backend.php", query, () => { - updateFeedList(); + Feeds.reload(); }); } } else { @@ -816,7 +816,7 @@ function createCategory() { xhrPost("backend.php", { op: "pref-feeds", method: "addCat", cat: title }, () => { notify(''); - updateFeedList(); + Feeds.reload(); }); } } @@ -847,7 +847,7 @@ function showInactiveFeeds() { xhrPost("backend.php", query, () => { notify(''); dialog.hide(); - updateFeedList(); + Feeds.reload(); }); } @@ -1037,7 +1037,7 @@ function resetFeedOrder() { notify_progress("Loading, please wait..."); xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => { - updateFeedList(); + Feeds.reload(); }); } @@ -1045,7 +1045,7 @@ function resetCatOrder() { notify_progress("Loading, please wait..."); xhrPost("backend.php", { op: "pref-feeds", method: "catsortreset" }, () => { - updateFeedList(); + Feeds.reload(); }); } @@ -1057,7 +1057,7 @@ function editCat(id, item) { notify_progress("Loading, please wait..."); xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { - updateFeedList(); + Feeds.reload(); }); } } @@ -1176,7 +1176,7 @@ function batchSubscribe() { xhrPost("backend.php", this.attr('value'), () => { notify(""); - updateFeedList(); + Feeds.reload(); dialog.hide(); }); } -- cgit v1.2.3 From b9984c0ed6ed4086cec859a0366f3d71032fcd31 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 18:05:20 +0300 Subject: revert wrong changes in prefs.js --- js/prefs.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index bb547c113..59629955d 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -6,7 +6,7 @@ function notify_callback2(transport, sticky) { notify_info(transport.responseText, sticky); } -function Feeds.reload() { +function updateFeedList() { const user_search = $("feed_search"); let search = ""; @@ -324,7 +324,7 @@ function removeSelectedFeeds() { ids: sel_rows.toString() }; xhrPost("backend.php", query, () => { - Feeds.reload(); + updateFeedList(); }); } @@ -524,7 +524,7 @@ function editSelectedFeeds() { xhrPost("backend.php", query, () => { dialog.hide(); - Feeds.reload(); + updateFeedList(); }); } }, @@ -618,7 +618,7 @@ function selectTab(id, noupdate) { switch (id) { case "feedConfig": - Feeds.reload(); + updateFeedList(); break; case "filterConfig": updateFilterList(); @@ -782,7 +782,7 @@ function removeCategory(id, item) { xhrPost("backend.php", query, () => { notify(''); - Feeds.reload(); + updateFeedList(); }); } } @@ -798,7 +798,7 @@ function removeSelectedCategories() { ids: sel_rows.toString() }; xhrPost("backend.php", query, () => { - Feeds.reload(); + updateFeedList(); }); } } else { @@ -816,7 +816,7 @@ function createCategory() { xhrPost("backend.php", { op: "pref-feeds", method: "addCat", cat: title }, () => { notify(''); - Feeds.reload(); + updateFeedList(); }); } } @@ -847,7 +847,7 @@ function showInactiveFeeds() { xhrPost("backend.php", query, () => { notify(''); dialog.hide(); - Feeds.reload(); + updateFeedList(); }); } @@ -1037,7 +1037,7 @@ function resetFeedOrder() { notify_progress("Loading, please wait..."); xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => { - Feeds.reload(); + updateFeedList(); }); } @@ -1045,7 +1045,7 @@ function resetCatOrder() { notify_progress("Loading, please wait..."); xhrPost("backend.php", { op: "pref-feeds", method: "catsortreset" }, () => { - Feeds.reload(); + updateFeedList(); }); } @@ -1057,7 +1057,7 @@ function editCat(id, item) { notify_progress("Loading, please wait..."); xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { - Feeds.reload(); + updateFeedList(); }); } } @@ -1176,7 +1176,7 @@ function batchSubscribe() { xhrPost("backend.php", this.attr('value'), () => { notify(""); - Feeds.reload(); + updateFeedList(); dialog.hide(); }); } -- cgit v1.2.3 From ff708a9357ec16b4f6a49d242ce62063c9345136 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 18:08:09 +0300 Subject: prefs: initial objectification --- js/prefs.js | 178 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 89 insertions(+), 89 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 59629955d..032098f6f 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -1,6 +1,94 @@ /* global dijit, __ */ -let seq = ""; +const App = { + init: function() { + window.onerror = function (message, filename, lineno, colno, error) { + report_error(message, filename, lineno, colno, error); + }; + + 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/PrefFeedStore", + "fox/PrefFilterStore", + "fox/PrefFeedTree", + "fox/PrefFilterTree", + "fox/PrefLabelTree"], function (dojo, ready, parser) { + + ready(function () { + try { + parser.parse(); + + setLoadingProgress(50); + + const clientTzOffset = new Date().getTimezoneOffset() * 60; + const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset}; + + xhrPost("backend.php", params, (transport) => { + Utils.backendSanityCallback(transport); + }); + + } catch (e) { + exception_error(e); + } + }); + }); + }, + initSecondStage: function() { + document.onkeydown = pref_hotkey_handler; + setLoadingProgress(50); + notify(""); + + let tab = getURLParam('tab'); + + if (tab) { + tab = dijit.byId(tab + "Tab"); + if (tab) dijit.byId("pref-tabs").selectChild(tab); + } + + const method = getURLParam('method'); + + if (method == 'editFeed') { + const param = getURLParam('methodparam'); + + window.setTimeout(function () { + editFeed(param) + }, 100); + } + + setInterval(hotkeyPrefixTimeout, 5 * 1000); + } +} function notify_callback2(transport, sticky) { notify_info(transport.responseText, sticky); @@ -645,94 +733,6 @@ function selectTab(id, noupdate) { } } -function init_second_stage() { - document.onkeydown = pref_hotkey_handler; - setLoadingProgress(50); - notify(""); - - let tab = getURLParam('tab'); - - if (tab) { - tab = dijit.byId(tab + "Tab"); - if (tab) dijit.byId("pref-tabs").selectChild(tab); - } - - const method = getURLParam('method'); - - if (method == 'editFeed') { - const param = getURLParam('methodparam'); - - window.setTimeout(function() { editFeed(param) }, 100); - } - - setInterval(hotkeyPrefixTimeout, 5*1000); -} - -function init() { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; - - 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/PrefFeedStore", - "fox/PrefFilterStore", - "fox/PrefFeedTree", - "fox/PrefFilterTree", - "fox/PrefLabelTree"], function (dojo, ready, parser) { - - ready(function () { - try { - parser.parse(); - - setLoadingProgress(50); - - const clientTzOffset = new Date().getTimezoneOffset() * 60; - const params = { op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset }; - - xhrPost("backend.php", params, (transport) => { - backend_sanity_check_callback(transport); - }); - - } catch (e) { - exception_error(e); - } - }); - }); -} - - function validatePrefsReset() { if (confirm(__("Reset to defaults?"))) { -- cgit v1.2.3 From 44d3aedd382f6b9f38776fd2f2a8119f4160da55 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 18:10:30 +0300 Subject: prefs: hotkey handler to App --- js/prefs.js | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 032098f6f..15007d014 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -65,7 +65,7 @@ const App = { }); }, initSecondStage: function() { - document.onkeydown = pref_hotkey_handler; + document.onkeydown = this.hotkeyHandler; setLoadingProgress(50); notify(""); @@ -87,6 +87,30 @@ const App = { } setInterval(hotkeyPrefixTimeout, 5 * 1000); + }, + hotkeyHandler: function (event) { + if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; + + const action_name = keyeventToAction(event); + + if (action_name) { + switch (action_name) { + case "feed_subscribe": + quickAddFeed(); + return false; + case "create_label": + addLabel(); + return false; + case "create_filter": + quickAddFilter(); + return false; + case "help_dialog": + Utils.helpDialog("main"); + return false; + default: + console.log("unhandled action: " + action_name + "; keycode: " + event.which); + } + } } } @@ -747,31 +771,6 @@ function validatePrefsReset() { return false; } -function pref_hotkey_handler(e) { - if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return; - - const action_name = keyeventToAction(e); - - if (action_name) { - switch (action_name) { - case "feed_subscribe": - quickAddFeed(); - return false; - case "create_label": - addLabel(); - return false; - case "create_filter": - quickAddFilter(); - return false; - case "help_dialog": - Utils.helpDialog("main"); - return false; - default: - console.log("unhandled action: " + action_name + "; keycode: " + e.which); - } - } -} - function removeCategory(id, item) { if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) { -- cgit v1.2.3 From 4bed9be57d671324921bfd1d90d25b8cd0af3d4f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 18:25:32 +0300 Subject: js-ification: start on some common dialogs --- js/prefs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 15007d014..e83e69bd5 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -49,7 +49,7 @@ const App = { try { parser.parse(); - setLoadingProgress(50); + Utils.setLoadingProgress(50); const clientTzOffset = new Date().getTimezoneOffset() * 60; const params = {op: "rpc", method: "sanityCheck", clientTzOffset: clientTzOffset}; @@ -66,7 +66,7 @@ const App = { }, initSecondStage: function() { document.onkeydown = this.hotkeyHandler; - setLoadingProgress(50); + Utils.setLoadingProgress(50); notify(""); let tab = getURLParam('tab'); @@ -91,12 +91,12 @@ const App = { hotkeyHandler: function (event) { if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; - const action_name = keyeventToAction(event); + const action_name = Utils.keyeventToAction(event); if (action_name) { switch (action_name) { case "feed_subscribe": - quickAddFeed(); + CommonDialogs.quickAddFeed(); return false; case "create_label": addLabel(); -- cgit v1.2.3 From 642c37ea6117954fc19e2a800f2fce4c1304d89d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 21:01:53 +0300 Subject: further effocts to wrap JS stuff into objects --- js/prefs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index e83e69bd5..a9417cf3c 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -86,7 +86,7 @@ const App = { }, 100); } - setInterval(hotkeyPrefixTimeout, 5 * 1000); + setInterval(() => { hotkeyPrefixTimeout() }, 5 * 1000); }, hotkeyHandler: function (event) { if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; -- cgit v1.2.3 From cc26be0793c6c0e44a540c25f86627342a82714f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 21:51:00 +0300 Subject: migrate tt-rss.js contents to App --- js/prefs.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index a9417cf3c..8308a747f 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -65,7 +65,7 @@ const App = { }); }, initSecondStage: function() { - document.onkeydown = this.hotkeyHandler; + document.onkeydown = () => { App.hotkeyHandler(event) }; Utils.setLoadingProgress(50); notify(""); @@ -111,8 +111,11 @@ const App = { console.log("unhandled action: " + action_name + "; keycode: " + event.which); } } + }, + isPrefs: function() { + return true; } -} +}; function notify_callback2(transport, sticky) { notify_info(transport.responseText, sticky); @@ -909,10 +912,6 @@ function labelColorReset() { } } -function inPreferences() { - return true; -} - function editProfiles() { if (dijit.byId("profileEditDlg")) -- cgit v1.2.3 From de9509cd31d63b036f63fc56697e018263e52eda Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:07:00 +0300 Subject: hotkeys: simplify prefix timeout handling --- js/prefs.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 8308a747f..1541d49d0 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -85,8 +85,6 @@ const App = { editFeed(param) }, 100); } - - setInterval(() => { hotkeyPrefixTimeout() }, 5 * 1000); }, hotkeyHandler: function (event) { if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; -- cgit v1.2.3 From bc96eac2ac6579bfe7a4d99292c0ada3412dc54c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:19:20 +0300 Subject: addLabel -> CommonDialogs --- js/prefs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 1541d49d0..67be0b474 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -97,7 +97,7 @@ const App = { CommonDialogs.quickAddFeed(); return false; case "create_label": - addLabel(); + CommonDialogs.addLabel(); return false; case "create_filter": quickAddFilter(); -- cgit v1.2.3 From 1e2d4410d320fcee644add76293f229741a163cb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 1 Dec 2018 22:39:29 +0300 Subject: move some more shared stuff to CommonDialogs, Filters, and Utils --- js/prefs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 67be0b474..0d35355d2 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -82,7 +82,7 @@ const App = { const param = getURLParam('methodparam'); window.setTimeout(function () { - editFeed(param) + CommonDialogs.editFeed(param) }, 100); } }, @@ -100,7 +100,7 @@ const App = { CommonDialogs.addLabel(); return false; case "create_filter": - quickAddFilter(); + Filters.quickAddFilter(); return false; case "help_dialog": Utils.helpDialog("main"); @@ -575,7 +575,7 @@ function editSelectedFeed() { notify(""); - editFeed(rows[0], {}); + CommonDialogs.editFeed(rows[0], {}); } -- cgit v1.2.3 From da9f83c4aca502ad7fcd6439221d4deabdef0124 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 09:55:43 +0300 Subject: filter dialog fixes --- js/prefs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 0d35355d2..40068b95c 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -245,12 +245,12 @@ function editFilter(id) { editRule: function (e) { const li = e.parentNode; const rule = li.getElementsByTagName("INPUT")[1].value; - addFilterRule(li, rule); + Filters.addFilterRule(li, rule); }, editAction: function (e) { const li = e.parentNode; const action = li.getElementsByTagName("INPUT")[1].value; - addFilterAction(li, action); + Filters.addFilterAction(li, action); }, removeFilter: function () { const msg = __("Remove filter?"); @@ -268,10 +268,10 @@ function editFilter(id) { } }, addAction: function () { - addFilterAction(); + Filters.addFilterAction(); }, addRule: function () { - addFilterRule(); + Filters.addFilterRule(); }, deleteAction: function () { $$("#filterDlg_Actions li[class*=Selected]").each(function (e) { -- cgit v1.2.3 From 874560db547f718b82d77657dc019d840c30e0ed Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 10:33:58 +0300 Subject: remove obsolete row selection functions move getUrlParam() to Utils --- js/prefs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 40068b95c..f12c31441 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -69,17 +69,17 @@ const App = { Utils.setLoadingProgress(50); notify(""); - let tab = getURLParam('tab'); + let tab = Utils.urlParam('tab'); if (tab) { tab = dijit.byId(tab + "Tab"); if (tab) dijit.byId("pref-tabs").selectChild(tab); } - const method = getURLParam('method'); + const method = Utils.urlParam('method'); if (method == 'editFeed') { - const param = getURLParam('methodparam'); + const param = Utils.urlParam('methodparam'); window.setTimeout(function () { CommonDialogs.editFeed(param) -- cgit v1.2.3 From aa2f119eb656cc2064da691328239010f51afb98 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 10:46:09 +0300 Subject: remove getSelectedTableRowIds (Tables.getSelected) --- js/prefs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index f12c31441..3b9e090cc 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -314,7 +314,7 @@ function getSelectedLabels() { } function getSelectedUsers() { - return getSelectedTableRowIds("prefUserList"); + return Tables.getSelected("prefUserList"); } function getSelectedFeeds() { @@ -832,7 +832,7 @@ function showInactiveFeeds() { title: __("Feeds without recent updates"), style: "width: 600px", getSelectedFeeds: function () { - return getSelectedTableRowIds("prefInactiveFeedList"); + return Tables.getSelected("prefInactiveFeedList"); }, removeSelected: function () { const sel_rows = this.getSelectedFeeds(); @@ -922,7 +922,7 @@ function editProfiles() { title: __("Settings Profiles"), style: "width: 600px", getSelectedProfiles: function () { - return getSelectedTableRowIds("prefFeedProfileList"); + return Tables.getSelected("prefFeedProfileList"); }, removeSelected: function () { const sel_rows = this.getSelectedProfiles(); -- cgit v1.2.3 From e23b6e397dbbbba90f9a15a6fe2d45eb862efdc5 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 11:25:32 +0300 Subject: prefs: store active tab for reload, remove most old table row functions --- js/prefs.js | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 3b9e090cc..c2ff01d47 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -73,18 +73,34 @@ const App = { if (tab) { tab = dijit.byId(tab + "Tab"); - if (tab) dijit.byId("pref-tabs").selectChild(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"); - const method = Utils.urlParam('method'); + if (tab) { + tab = dijit.byId(tab); + if (tab) { + dijit.byId("pref-tabs").selectChild(tab); + } + } + } - if (method == 'editFeed') { - const param = Utils.urlParam('methodparam'); + dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) { + localStorage.setItem("ttrss:prefs-tab", elem.id); + }); - window.setTimeout(function () { - CommonDialogs.editFeed(param) - }, 100); - } }, hotkeyHandler: function (event) { if (event.target.nodeName == "INPUT" || event.target.nodeName == "TEXTAREA") return; @@ -725,8 +741,8 @@ function updateSystemList() { }); } -function selectTab(id, noupdate) { - if (!noupdate) { +function selectTab(id, selectOnly) { + if (!selectOnly) { notify_progress("Loading, please wait..."); switch (id) { @@ -754,7 +770,6 @@ function selectTab(id, noupdate) { const tab = dijit.byId(id + "Tab"); dijit.byId("pref-tabs").selectChild(tab); - } } -- cgit v1.2.3 From 2e985d173352487f96984577ac512a3639267edf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 11:34:57 +0300 Subject: move some label helper functions to prefLabelTree --- js/prefs.js | 54 ------------------------------------------------------ 1 file changed, 54 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index c2ff01d47..05023b053 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -316,19 +316,6 @@ function editFilter(id) { dialog.show(); } - -function getSelectedLabels() { - const tree = dijit.byId("labelTree"); - const items = tree.model.getCheckedItems(); - const rv = []; - - items.each(function(item) { - rv.push(tree.model.store.getValue(item, 'bare_id')); - }); - - return rv; -} - function getSelectedUsers() { return Tables.getSelected("prefUserList"); } @@ -372,28 +359,6 @@ function getSelectedFilters() { } -function removeSelectedLabels() { - - const sel_rows = getSelectedLabels(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected labels?"))) { - notify_progress("Removing selected labels..."); - - const query = { op: "pref-labels", method: "remove", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - updateLabelList(); - }); - } - } else { - alert(__("No labels are selected.")); - } - - return false; -} - function removeSelectedUsers() { const sel_rows = getSelectedUsers(); @@ -906,25 +871,6 @@ function opmlRegenKey() { return false; } -function labelColorReset() { - const labels = getSelectedLabels(); - - if (labels.length > 0) { - if (confirm(__("Reset selected labels to default colors?"))) { - - const query = { op: "pref-labels", method: "colorreset", - ids: labels.toString() }; - - xhrPost("backend.php", query, () => { - updateLabelList(); - }); - } - - } else { - alert(__("No labels are selected.")); - } -} - function editProfiles() { if (dijit.byId("profileEditDlg")) -- cgit v1.2.3 From 60cd4676943169a057518634e3060745e9112511 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 11:50:53 +0300 Subject: embed some pref-feed helper functions into the tree --- js/prefs.js | 216 ------------------------------------------------------------ 1 file changed, 216 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 05023b053..18facd9a9 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -320,32 +320,6 @@ function getSelectedUsers() { return Tables.getSelected("prefUserList"); } -function getSelectedFeeds() { - const tree = dijit.byId("feedTree"); - const items = tree.model.getCheckedItems(); - const rv = []; - - items.each(function(item) { - if (item.id[0].match("FEED:")) - rv.push(tree.model.store.getValue(item, 'bare_id')); - }); - - return rv; -} - -function getSelectedCategories() { - const tree = dijit.byId("feedTree"); - const items = tree.model.getCheckedItems(); - const rv = []; - - items.each(function(item) { - if (item.id[0].match("CAT:")) - rv.push(tree.model.store.getValue(item, 'bare_id')); - }); - - return rv; -} - function getSelectedFilters() { const tree = dijit.byId("filterTree"); const items = tree.model.getCheckedItems(); @@ -405,30 +379,6 @@ function removeSelectedFilters() { return false; } -function removeSelectedFeeds() { - - const sel_rows = getSelectedFeeds(); - - if (sel_rows.length > 0) { - if (confirm(__("Unsubscribe from selected feeds?"))) { - - notify_progress("Unsubscribing from selected feeds...", true); - - const query = { op: "pref-feeds", method: "remove", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - updateFeedList(); - }); - } - - } else { - alert(__("No feeds are selected.")); - } - - return false; -} - function editSelectedUser() { const rows = getSelectedUsers(); @@ -542,93 +492,6 @@ function joinSelectedFilters() { } } -function editSelectedFeed() { - const rows = getSelectedFeeds(); - - if (rows.length == 0) { - alert(__("No feeds are selected.")); - return; - } - - if (rows.length > 1) { - return editSelectedFeeds(); - } - - notify(""); - - CommonDialogs.editFeed(rows[0], {}); - -} - -function editSelectedFeeds() { - const rows = getSelectedFeeds(); - - if (rows.length == 0) { - alert(__("No feeds are selected.")); - return; - } - - notify_progress("Loading, please wait..."); - - if (dijit.byId("feedEditDlg")) - dijit.byId("feedEditDlg").destroyRecursive(); - - xhrPost("backend.php", { op: "pref-feeds", method: "editfeeds", ids: rows.toString() }, (transport) => { - notify(""); - - const dialog = new dijit.Dialog({ - id: "feedEditDlg", - title: __("Edit Multiple Feeds"), - style: "width: 600px", - getChildByName: function (name) { - let rv = null; - this.getChildren().each( - function (child) { - if (child.name == name) { - rv = child; - return; - } - }); - return rv; - }, - toggleField: function (checkbox, elem, label) { - this.getChildByName(elem).attr('disabled', !checkbox.checked); - - if ($(label)) - if (checkbox.checked) - $(label).removeClassName('insensitive'); - else - $(label).addClassName('insensitive'); - - }, - execute: function () { - if (this.validate() && confirm(__("Save changes to selected feeds?"))) { - const query = this.attr('value'); - - /* normalize unchecked checkboxes because [] is not serialized */ - - Object.keys(query).each((key) => { - let val = query[key]; - - if (typeof val == "object" && val.length == 0) - query[key] = ["off"]; - }); - - notify_progress("Saving data...", true); - - xhrPost("backend.php", query, () => { - dialog.hide(); - updateFeedList(); - }); - } - }, - content: transport.responseText - }); - - dialog.show(); - }); -} - function opmlImportComplete(iframe) { if (!iframe.contentDocument.body.innerHTML) return false; @@ -767,39 +630,6 @@ function removeCategory(id, item) { } } -function removeSelectedCategories() { - const sel_rows = getSelectedCategories(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected categories?"))) { - notify_progress("Removing selected categories..."); - - const query = { op: "pref-feeds", method: "removeCat", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - updateFeedList(); - }); - } - } else { - alert(__("No categories are selected.")); - } - - return false; -} - -function createCategory() { - const title = prompt(__("Category title:")); - - if (title) { - notify_progress("Creating category..."); - - xhrPost("backend.php", { op: "pref-feeds", method: "addCat", cat: title }, () => { - notify(''); - updateFeedList(); - }); - } -} function showInactiveFeeds() { const query = "backend.php?op=pref-feeds&method=inactiveFeeds"; @@ -989,23 +819,6 @@ function resetFilterOrder() { }); } - -function resetFeedOrder() { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: "pref-feeds", method: "feedsortreset" }, () => { - updateFeedList(); - }); -} - -function resetCatOrder() { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: "pref-feeds", method: "catsortreset" }, () => { - updateFeedList(); - }); -} - function editCat(id, item) { const new_name = prompt(__('Rename category to:'), item.name); @@ -1115,35 +928,6 @@ function gotoExportOpml(filename, settings) { document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp; } - -function batchSubscribe() { - const query = "backend.php?op=pref-feeds&method=batchSubscribe"; - - // overlapping widgets - if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); - if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "batchSubDlg", - title: __("Batch subscribe"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - notify_progress(__("Subscribing to feeds..."), true); - - xhrPost("backend.php", this.attr('value'), () => { - notify(""); - updateFeedList(); - dialog.hide(); - }); - } - }, - href: query - }); - - dialog.show(); -} - function clearPluginData(name) { if (confirm(__("Clear stored data for this plugin?"))) { notify_progress("Loading, please wait..."); -- cgit v1.2.3 From f26d404890a55a34ed5779b6f36e949d38705e8d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 12:03:28 +0300 Subject: prefs: move other tree-related functions to respective trees --- js/prefs.js | 280 ------------------------------------------------------------ 1 file changed, 280 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 18facd9a9..2bad86168 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -148,14 +148,6 @@ function updateFeedList() { }); } -function checkInactiveFeeds() { - xhrPost("backend.php", { op: "pref-feeds", method: "getinactivefeeds" }, (transport) => { - if (parseInt(transport.responseText) > 0) { - Element.show(dijit.byId("pref_feeds_inactive_btn").domNode); - } - }); -} - function updateUsersList(sort_key) { const user_search = $("user_search"); const search = user_search ? user_search.value : ""; @@ -218,120 +210,10 @@ function editUser(id) { dialog.show(); } -function editFilter(id) { - - const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); - - if (dijit.byId("feedEditDlg")) - dijit.byId("feedEditDlg").destroyRecursive(); - - if (dijit.byId("filterEditDlg")) - dijit.byId("filterEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "filterEditDlg", - title: __("Edit Filter"), - style: "width: 600px", - - test: function () { - const query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; - - editFilterTest(query); - }, - selectRules: function (select) { - $$("#filterDlg_Matches input[type=checkbox]").each(function (e) { - e.checked = select; - if (select) - e.parentNode.addClassName("Selected"); - else - e.parentNode.removeClassName("Selected"); - }); - }, - selectActions: function (select) { - $$("#filterDlg_Actions input[type=checkbox]").each(function (e) { - e.checked = select; - - if (select) - e.parentNode.addClassName("Selected"); - else - e.parentNode.removeClassName("Selected"); - - }); - }, - editRule: function (e) { - const li = e.parentNode; - const rule = li.getElementsByTagName("INPUT")[1].value; - Filters.addFilterRule(li, rule); - }, - editAction: function (e) { - const li = e.parentNode; - const action = li.getElementsByTagName("INPUT")[1].value; - Filters.addFilterAction(li, action); - }, - removeFilter: function () { - const msg = __("Remove filter?"); - - if (confirm(msg)) { - this.hide(); - - notify_progress("Removing filter..."); - - const query = { op: "pref-filters", method: "remove", ids: this.attr('value').id }; - - xhrPost("backend.php", query, () => { - updateFilterList(); - }); - } - }, - addAction: function () { - Filters.addFilterAction(); - }, - addRule: function () { - Filters.addFilterRule(); - }, - deleteAction: function () { - $$("#filterDlg_Actions li[class*=Selected]").each(function (e) { - e.parentNode.removeChild(e) - }); - }, - deleteRule: function () { - $$("#filterDlg_Matches li[class*=Selected]").each(function (e) { - e.parentNode.removeChild(e) - }); - }, - execute: function () { - if (this.validate()) { - - notify_progress("Saving data...", true); - - xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => { - dialog.hide(); - updateFilterList(); - }); - } - }, - href: query - }); - - dialog.show(); -} - function getSelectedUsers() { return Tables.getSelected("prefUserList"); } -function getSelectedFilters() { - const tree = dijit.byId("filterTree"); - const items = tree.model.getCheckedItems(); - const rv = []; - - items.each(function(item) { - rv.push(tree.model.store.getValue(item, 'bare_id')); - }); - - return rv; - -} function removeSelectedUsers() { @@ -357,28 +239,6 @@ function removeSelectedUsers() { return false; } -function removeSelectedFilters() { - - const sel_rows = getSelectedFilters(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected filters?"))) { - notify_progress("Removing selected filters..."); - - const query = { op: "pref-filters", method: "remove", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - updateFilterList(); - }); - } - } else { - alert(__("No filters are selected.")); - } - - return false; -} - function editSelectedUser() { const rows = getSelectedUsers(); @@ -455,43 +315,6 @@ function selectedUserDetails() { dialog.show(); } - -function editSelectedFilter() { - const rows = getSelectedFilters(); - - if (rows.length == 0) { - alert(__("No filters are selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select only one filter.")); - return; - } - - notify(""); - - editFilter(rows[0]); - -} - -function joinSelectedFilters() { - const rows = getSelectedFilters(); - - if (rows.length == 0) { - alert(__("No filters are selected.")); - return; - } - - if (confirm(__("Combine selected filters?"))) { - notify_progress("Joining filters..."); - - xhrPost("backend.php", { op: "pref-filters", method: "join", ids: rows.toString() }, () => { - updateFilterList(); - }); - } -} - function opmlImportComplete(iframe) { if (!iframe.contentDocument.body.innerHTML) return false; @@ -774,30 +597,6 @@ function editProfiles() { dialog.show(); } -/* -function activatePrefProfile() { - - const sel_rows = getSelectedFeedCats(); - - if (sel_rows.length == 1) { - - const ok = confirm(__("Activate selected profile?")); - - if (ok) { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() }, () => { - window.location.reload(); - }); - } - - } else { - alert(__("Please choose a profile to activate.")); - } - - return false; -} */ - function clearFeedAccessKeys() { if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { @@ -811,14 +610,6 @@ function clearFeedAccessKeys() { return false; } -function resetFilterOrder() { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: "pref-filters", method: "filtersortreset" }, () => { - updateFilterList(); - }); -} - function editCat(id, item) { const new_name = prompt(__('Rename category to:'), item.name); @@ -832,69 +623,6 @@ function editCat(id, item) { } } -function editLabel(id) { - const query = "backend.php?op=pref-labels&method=edit&id=" + - param_escape(id); - - if (dijit.byId("labelEditDlg")) - dijit.byId("labelEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "labelEditDlg", - title: __("Label Editor"), - style: "width: 600px", - setLabelColor: function (id, fg, bg) { - - let kind = ''; - let color = ''; - - if (fg && bg) { - kind = 'both'; - } else if (fg) { - kind = 'fg'; - color = fg; - } else if (bg) { - kind = 'bg'; - color = bg; - } - - const e = $("LICID-" + id); - - if (e) { - if (fg) e.style.color = fg; - if (bg) e.style.backgroundColor = bg; - } - - const query = { op: "pref-labels", method: "colorset", kind: kind, - ids: id, fg: fg, bg: bg, color: color }; - - xhrPost("backend.php", query, () => { - updateFilterList(); // maybe there's labels in there - }); - - }, - execute: function () { - if (this.validate()) { - const caption = this.attr('value').caption; - const fg_color = this.attr('value').fg_color; - const bg_color = this.attr('value').bg_color; - - dijit.byId('labelTree').setNameById(id, caption); - this.setLabelColor(id, fg_color, bg_color); - this.hide(); - - xhrPost("backend.php", this.attr('value'), () => { - updateFilterList(); // maybe there's labels in there - }); - } - }, - href: query - }); - - dialog.show(); -} - - function customizeCSS() { const query = "backend.php?op=pref-prefs&method=customizeCSS"; @@ -951,11 +679,3 @@ function clearSqlLog() { } } - -function updateSelectedPrompt() { - // no-op shim for toggleSelectedRow() -} - -function gotoMain() { - document.location.href = "index.php"; -} -- cgit v1.2.3 From 58e54282d36d54c2be0e50f78fbc500772a3b762 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 15:30:07 +0300 Subject: prefs: move more global functions into matching classes --- js/prefs.js | 387 +++++++++++++++++++++--------------------------------------- 1 file changed, 133 insertions(+), 254 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 2bad86168..fd9e3d380 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -131,6 +131,139 @@ const App = { } }; +const Prefs = { + clearEventLog: function() { + if (confirm(__("Clear event log?"))) { + + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { + updateSystemList(); + }); + } + }, + editProfiles: function() { + + if (dijit.byId("profileEditDlg")) + dijit.byId("profileEditDlg").destroyRecursive(); + + const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; + + const dialog = new dijit.Dialog({ + id: "profileEditDlg", + title: __("Settings Profiles"), + style: "width: 600px", + getSelectedProfiles: function () { + return Tables.getSelected("prefFeedProfileList"); + }, + removeSelected: function () { + const sel_rows = this.getSelectedProfiles(); + + if (sel_rows.length > 0) { + if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) { + notify_progress("Removing selected profiles...", true); + + const query = { + op: "rpc", method: "remprofiles", + ids: sel_rows.toString() + }; + + xhrPost("backend.php", query, () => { + notify(''); + Prefs.editProfiles(); + }); + } + + } else { + alert(__("No profiles are selected.")); + } + }, + activateProfile: function () { + const sel_rows = this.getSelectedProfiles(); + + if (sel_rows.length == 1) { + if (confirm(__("Activate selected profile?"))) { + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "rpc", method: "setprofile", id: sel_rows.toString()}, () => { + window.location.reload(); + }); + } + + } else { + alert(__("Please choose a profile to activate.")); + } + }, + addProfile: function () { + if (this.validate()) { + notify_progress("Creating profile...", true); + + const query = {op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile}; + + xhrPost("backend.php", query, () => { + notify(''); + Prefs.editProfiles(); + }); + + } + }, + execute: function () { + if (this.validate()) { + } + }, + href: query + }); + + dialog.show(); + }, + customizeCSS: function() { + const query = "backend.php?op=pref-prefs&method=customizeCSS"; + + if (dijit.byId("cssEditDlg")) + dijit.byId("cssEditDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "cssEditDlg", + title: __("Customize stylesheet"), + style: "width: 600px", + execute: function () { + notify_progress('Saving data...', true); + + xhrPost("backend.php", this.attr('value'), () => { + window.location.reload(); + }); + + }, + href: query + }); + + dialog.show(); + }, + confirmReset: function() { + if (confirm(__("Reset to defaults?"))) { + xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => { + Prefs.refresh(); + notify_info(transport.responseText); + }); + } + }, + clearPluginData: function(name) { + if (confirm(__("Clear stored data for this plugin?"))) { + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => { + Prefs.refresh(); + }); + } + }, + refresh: function() { + xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { + dijit.byId('genConfigTab').attr('content', transport.responseText); + notify(""); + }); + } +}; + function notify_callback2(transport, sticky) { notify_info(transport.responseText, sticky); } @@ -143,7 +276,6 @@ function updateFeedList() { xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => { dijit.byId('feedConfigTab').attr('content', transport.responseText); - selectTab("feedConfig", true); notify(""); }); } @@ -156,7 +288,6 @@ function updateUsersList(sort_key) { xhrPost("backend.php", query, (transport) => { dijit.byId('userConfigTab').attr('content', transport.responseText); - selectTab("userConfig", true) notify(""); }); } @@ -359,7 +490,6 @@ function opmlImport() { } } - function updateFilterList() { const user_search = $("filter_search"); let search = ""; @@ -378,13 +508,6 @@ function updateLabelList() { }); } -function updatePrefsList() { - xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { - dijit.byId('genConfigTab').attr('content', transport.responseText); - notify(""); - }); -} - function updateSystemList() { xhrPost("backend.php", { op: "pref-system" }, (transport) => { dijit.byId('systemConfigTab').attr('content', transport.responseText); @@ -392,112 +515,6 @@ function updateSystemList() { }); } -function selectTab(id, selectOnly) { - if (!selectOnly) { - notify_progress("Loading, please wait..."); - - switch (id) { - case "feedConfig": - updateFeedList(); - break; - case "filterConfig": - updateFilterList(); - break; - case "labelConfig": - updateLabelList(); - break; - case "genConfig": - updatePrefsList(); - break; - case "userConfig": - updateUsersList(); - break; - case "systemConfig": - updateSystemList(); - break; - default: - console.warn("unknown tab", id); - } - - const tab = dijit.byId(id + "Tab"); - dijit.byId("pref-tabs").selectChild(tab); - } -} - -function validatePrefsReset() { - if (confirm(__("Reset to defaults?"))) { - - const query = "?op=pref-prefs&method=resetconfig"; - - xhrPost("backend.php", { op: "pref-prefs", method: "resetconfig" }, (transport) => { - updatePrefsList(); - notify_info(transport.responseText); - }); - } - - return false; -} - -function removeCategory(id, item) { - - if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) { - notify_progress("Removing category..."); - - const query = { op: "pref-feeds", method: "removeCat", - ids: id }; - - xhrPost("backend.php", query, () => { - notify(''); - updateFeedList(); - }); - } -} - - -function showInactiveFeeds() { - const query = "backend.php?op=pref-feeds&method=inactiveFeeds"; - - if (dijit.byId("inactiveFeedsDlg")) - dijit.byId("inactiveFeedsDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "inactiveFeedsDlg", - title: __("Feeds without recent updates"), - style: "width: 600px", - getSelectedFeeds: function () { - return Tables.getSelected("prefInactiveFeedList"); - }, - removeSelected: function () { - const sel_rows = this.getSelectedFeeds(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected feeds?"))) { - notify_progress("Removing selected feeds...", true); - - const query = { op: "pref-feeds", method: "remove", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - notify(''); - dialog.hide(); - updateFeedList(); - }); - } - - } else { - alert(__("No feeds are selected.")); - } - }, - execute: function () { - if (this.validate()) { - } - }, - href: query - }); - - dialog.show(); -} - function opmlRegenKey() { if (confirm(__("Replace current OPML publishing address with a new one?"))) { notify_progress("Trying to change address...", true); @@ -524,79 +541,6 @@ function opmlRegenKey() { return false; } -function editProfiles() { - - if (dijit.byId("profileEditDlg")) - dijit.byId("profileEditDlg").destroyRecursive(); - - const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; - - const dialog = new dijit.Dialog({ - id: "profileEditDlg", - title: __("Settings Profiles"), - style: "width: 600px", - getSelectedProfiles: function () { - return Tables.getSelected("prefFeedProfileList"); - }, - removeSelected: function () { - const sel_rows = this.getSelectedProfiles(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) { - notify_progress("Removing selected profiles...", true); - - const query = { op: "rpc", method: "remprofiles", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - notify(''); - editProfiles(); - }); - } - - } else { - alert(__("No profiles are selected.")); - } - }, - activateProfile: function () { - const sel_rows = this.getSelectedProfiles(); - - if (sel_rows.length == 1) { - if (confirm(__("Activate selected profile?"))) { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: "rpc", method: "setprofile", id: sel_rows.toString() }, () => { - window.location.reload(); - }); - } - - } else { - alert(__("Please choose a profile to activate.")); - } - }, - addProfile: function () { - if (this.validate()) { - notify_progress("Creating profile...", true); - - const query = { op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile }; - - xhrPost("backend.php", query, () => { - notify(''); - editProfiles(); - }); - - } - }, - execute: function () { - if (this.validate()) { - } - }, - href: query - }); - - dialog.show(); -} - function clearFeedAccessKeys() { if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { @@ -610,72 +554,7 @@ function clearFeedAccessKeys() { return false; } -function editCat(id, item) { - const new_name = prompt(__('Rename category to:'), item.name); - - if (new_name && new_name != item.name) { - - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { - updateFeedList(); - }); - } -} - -function customizeCSS() { - const query = "backend.php?op=pref-prefs&method=customizeCSS"; - - if (dijit.byId("cssEditDlg")) - dijit.byId("cssEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "cssEditDlg", - title: __("Customize stylesheet"), - style: "width: 600px", - execute: function () { - notify_progress('Saving data...', true); - - xhrPost("backend.php", this.attr('value'), () => { - window.location.reload(); - }); - - }, - href: query - }); - - dialog.show(); -} - -function insertSSLserial(value) { - dijit.byId("SSL_CERT_SERIAL").attr('value', value); -} - function gotoExportOpml(filename, settings) { const tmp = settings ? 1 : 0; document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp; } - -function clearPluginData(name) { - if (confirm(__("Clear stored data for this plugin?"))) { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: "pref-prefs", method: "clearplugindata", name: name }, () => { - notify(''); - updatePrefsList(); - }); - } -} - -function clearSqlLog() { - - if (confirm(__("Clear all messages in the error log?"))) { - - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", { op: "pref-system", method: "clearLog" }, () => { - updateSystemList(); - }); - - } -} -- cgit v1.2.3 From b9869dbc01f505e87def7463e032914cab49f26c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:17:36 +0300 Subject: prefs: remove some more stuff from global context (user management, etc) --- js/prefs.js | 269 ++++++++++++++++++++++-------------------------------------- 1 file changed, 100 insertions(+), 169 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index fd9e3d380..2245f518f 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -132,6 +132,17 @@ const App = { }; const Prefs = { + clearFeedAccessKeys: function() { + if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { + notify_progress("Clearing URLs..."); + + xhrPost("backend.php", {op: "pref-feeds", method: "clearKeys"}, () => { + notify_info("Generated URLs cleared."); + }); + } + + return false; + }, clearEventLog: function() { if (confirm(__("Clear event log?"))) { @@ -264,187 +275,120 @@ const Prefs = { } }; -function notify_callback2(transport, sticky) { - notify_info(transport.responseText, sticky); -} +const Users = { + reload: function(sort) { + const user_search = $("user_search"); + const search = user_search ? user_search.value : ""; -function updateFeedList() { + xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => { + dijit.byId('userConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, + add: function() { + const login = prompt(__("Please enter username:"), ""); - const user_search = $("feed_search"); - let search = ""; - if (user_search) { search = user_search.value; } + if (login) { + notify_progress("Adding user..."); - xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => { - dijit.byId('feedConfigTab').attr('content', transport.responseText); - notify(""); - }); -} + xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => { + alert(transport.responseText); + Users.reload(); + }); -function updateUsersList(sort_key) { - const user_search = $("user_search"); - const search = user_search ? user_search.value : ""; + } + }, + edit: function(id) { + const query = "backend.php?op=pref-users&method=edit&id=" + + param_escape(id); - const query = { op: "pref-users", sort: sort_key, search: search }; + if (dijit.byId("userEditDlg")) + dijit.byId("userEditDlg").destroyRecursive(); - xhrPost("backend.php", query, (transport) => { - dijit.byId('userConfigTab').attr('content', transport.responseText); - notify(""); - }); -} + const dialog = new dijit.Dialog({ + id: "userEditDlg", + title: __("User Editor"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + notify_progress("Saving data...", true); -function addUser() { - const login = prompt(__("Please enter login:"), ""); + xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => { + dialog.hide(); + Users.reload(); + }); + } + }, + href: query + }); - if (login == null) { - return false; - } + dialog.show(); + }, + resetSelected: function() { + const rows = this.getSelection(); - if (login == "") { - alert(__("Can't create user: no login specified.")); - return false; - } + if (rows.length == 0) { + alert(__("No users are selected.")); + return; + } - notify_progress("Adding user..."); + if (rows.length > 1) { + alert(__("Please select one user.")); + return; + } - xhrPost("backend.php", { op: "pref-users", method: "add", login: login }, (transport) => { - notify_callback2(transport); - updateUsersList(); - }); + if (confirm(__("Reset password of selected user?"))) { + notify_progress("Resetting password for selected user..."); -} + const id = rows[0]; -function editUser(id) { + xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { + notify(''); + alert(transport.responseText); + }); - const query = "backend.php?op=pref-users&method=edit&id=" + - param_escape(id); + } + }, + removeSelected: function() { + const sel_rows = this.getSelection(); - if (dijit.byId("userEditDlg")) - dijit.byId("userEditDlg").destroyRecursive(); + if (sel_rows.length > 0) { + if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { + notify_progress("Removing selected users..."); - const dialog = new dijit.Dialog({ - id: "userEditDlg", - title: __("User Editor"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - notify_progress("Saving data...", true); + const query = { + op: "pref-users", method: "remove", + ids: sel_rows.toString() + }; - xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => { - dialog.hide(); - updateUsersList(); + xhrPost("backend.php", query, () => { + this.reload(); }); } - }, - href: query - }); - - dialog.show(); -} - -function getSelectedUsers() { - return Tables.getSelected("prefUserList"); -} - - -function removeSelectedUsers() { - - const sel_rows = getSelectedUsers(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { - notify_progress("Removing selected users..."); - - const query = { op: "pref-users", method: "remove", - ids: sel_rows.toString() }; - - xhrPost("backend.php", query, () => { - updateUsersList(); - }); + } else { + alert(__("No users are selected.")); } + }, + editSelected: function() { + const rows = this.getSelection(); - } else { - alert(__("No users are selected.")); - } - - return false; -} - -function editSelectedUser() { - const rows = getSelectedUsers(); - - if (rows.length == 0) { - alert(__("No users are selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select only one user.")); - return; - } - - notify(""); - - editUser(rows[0]); -} - -function resetSelectedUserPass() { - - const rows = getSelectedUsers(); - - if (rows.length == 0) { - alert(__("No users are selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select only one user.")); - return; - } - - if (confirm(__("Reset password of selected user?"))) { - notify_progress("Resetting password for selected user..."); - - const id = rows[0]; - - xhrPost("backend.php", { op: "pref-users", method: "resetPass", id: id }, (transport) => { - notify_info(transport.responseText, true); - }); - - } -} - -function selectedUserDetails() { - - const rows = getSelectedUsers(); + if (rows.length == 0) { + alert(__("No users are selected.")); + return; + } - if (rows.length == 0) { - alert(__("No users are selected.")); - return; - } + if (rows.length > 1) { + alert(__("Please select one user.")); + return; + } - if (rows.length > 1) { - alert(__("Please select only one user.")); - return; + this.edit(rows[0]); + }, + getSelection :function() { + return Tables.getSelected("prefUserList"); } - - const query = "backend.php?op=pref-users&method=userdetails&id=" + param_escape(rows[0]); - - if (dijit.byId("userDetailsDlg")) - dijit.byId("userDetailsDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "userDetailsDlg", - title: __("User details"), - style: "width: 600px", - execute: function () { - dialog.hide(); - }, - href: query - }); - - dialog.show(); -} +}; function opmlImportComplete(iframe) { if (!iframe.contentDocument.body.innerHTML) return false; @@ -541,19 +485,6 @@ function opmlRegenKey() { return false; } -function clearFeedAccessKeys() { - - if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { - notify_progress("Clearing URLs..."); - - xhrPost("backend.php", { op: "pref-feeds", method: "clearKeys" }, () => { - notify_info("Generated URLs cleared."); - }); - } - - return false; -} - function gotoExportOpml(filename, settings) { const tmp = settings ? 1 : 0; document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp; -- cgit v1.2.3 From 3a6dae92034791c199f9ddb4c60b8298b22c1d47 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:29:00 +0300 Subject: prefs: more of the same, really --- js/prefs.js | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 2245f518f..771120048 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -131,6 +131,7 @@ const App = { } }; +// noinspection JSUnusedGlobalSymbols const Prefs = { clearFeedAccessKeys: function() { if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { @@ -143,13 +144,19 @@ const Prefs = { return false; }, + updateEventLog: function() { + xhrPost("backend.php", { op: "pref-system" }, (transport) => { + dijit.byId('systemConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, clearEventLog: function() { if (confirm(__("Clear event log?"))) { notify_progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { - updateSystemList(); + this.updateEventLog(); }); } }, @@ -160,6 +167,7 @@ const Prefs = { const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; + // noinspection JSUnusedGlobalSymbols const dialog = new dijit.Dialog({ id: "profileEditDlg", title: __("Settings Profiles"), @@ -275,6 +283,7 @@ const Prefs = { } }; +// noinspection JSUnusedGlobalSymbols const Users = { reload: function(sort) { const user_search = $("user_search"); @@ -434,31 +443,6 @@ function opmlImport() { } } -function updateFilterList() { - const user_search = $("filter_search"); - let search = ""; - if (user_search) { search = user_search.value; } - - xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { - dijit.byId('filterConfigTab').attr('content', transport.responseText); - notify(""); - }); -} - -function updateLabelList() { - xhrPost("backend.php", { op: "pref-labels" }, (transport) => { - dijit.byId('labelConfigTab').attr('content', transport.responseText); - notify(""); - }); -} - -function updateSystemList() { - xhrPost("backend.php", { op: "pref-system" }, (transport) => { - dijit.byId('systemConfigTab').attr('content', transport.responseText); - notify(""); - }); -} - function opmlRegenKey() { if (confirm(__("Replace current OPML publishing address with a new one?"))) { notify_progress("Trying to change address...", true); -- cgit v1.2.3 From 35ded4bc844d74f120196012c194be9ab5517688 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:30:32 +0300 Subject: edit phrasing of some alert()s --- js/prefs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 771120048..3578a7007 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -194,7 +194,7 @@ const Prefs = { } } else { - alert(__("No profiles are selected.")); + alert(__("No profiles selected.")); } }, activateProfile: function () { @@ -337,7 +337,7 @@ const Users = { const rows = this.getSelection(); if (rows.length == 0) { - alert(__("No users are selected.")); + alert(__("No users selected.")); return; } @@ -376,14 +376,14 @@ const Users = { } } else { - alert(__("No users are selected.")); + alert(__("No users selected.")); } }, editSelected: function() { const rows = this.getSelection(); if (rows.length == 0) { - alert(__("No users are selected.")); + alert(__("No users selected.")); return; } -- cgit v1.2.3 From fda3ad39c8d89b07d4ead691bacdca6865e46517 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 17:00:58 +0300 Subject: split several utility objects into separate dojo modules --- js/prefs.js | 287 ++++-------------------------------------------------------- 1 file changed, 18 insertions(+), 269 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 3578a7007..8804bdba9 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -1,4 +1,10 @@ -/* global dijit, __ */ +/* global dijit, __,fox */ + +let Utils; +let CommonDialogs; +let Filters; +let Users; +let Prefs; const App = { init: function() { @@ -39,6 +45,11 @@ const App = { "dojo/data/ItemFileWriteStore", "lib/CheckBoxStoreModel", "lib/CheckBoxTree", + "fox/Utils", + "fox/CommonDialogs", + "fox/CommonFilters", + "fox/PrefUsers", + "fox/PrefHelpers", "fox/PrefFeedStore", "fox/PrefFilterStore", "fox/PrefFeedTree", @@ -47,6 +58,12 @@ const App = { ready(function () { try { + Utils = fox.Utils(); + CommonDialogs = fox.CommonDialogs(); + Filters = fox.CommonFilters(); + Users = fox.PrefUsers(); + Prefs = fox.PrefHelpers(); + parser.parse(); Utils.setLoadingProgress(50); @@ -131,274 +148,6 @@ const App = { } }; -// noinspection JSUnusedGlobalSymbols -const Prefs = { - clearFeedAccessKeys: function() { - if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { - notify_progress("Clearing URLs..."); - - xhrPost("backend.php", {op: "pref-feeds", method: "clearKeys"}, () => { - notify_info("Generated URLs cleared."); - }); - } - - return false; - }, - updateEventLog: function() { - xhrPost("backend.php", { op: "pref-system" }, (transport) => { - dijit.byId('systemConfigTab').attr('content', transport.responseText); - notify(""); - }); - }, - clearEventLog: function() { - if (confirm(__("Clear event log?"))) { - - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => { - this.updateEventLog(); - }); - } - }, - editProfiles: function() { - - if (dijit.byId("profileEditDlg")) - dijit.byId("profileEditDlg").destroyRecursive(); - - const query = "backend.php?op=pref-prefs&method=editPrefProfiles"; - - // noinspection JSUnusedGlobalSymbols - const dialog = new dijit.Dialog({ - id: "profileEditDlg", - title: __("Settings Profiles"), - style: "width: 600px", - getSelectedProfiles: function () { - return Tables.getSelected("prefFeedProfileList"); - }, - removeSelected: function () { - const sel_rows = this.getSelectedProfiles(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) { - notify_progress("Removing selected profiles...", true); - - const query = { - op: "rpc", method: "remprofiles", - ids: sel_rows.toString() - }; - - xhrPost("backend.php", query, () => { - notify(''); - Prefs.editProfiles(); - }); - } - - } else { - alert(__("No profiles selected.")); - } - }, - activateProfile: function () { - const sel_rows = this.getSelectedProfiles(); - - if (sel_rows.length == 1) { - if (confirm(__("Activate selected profile?"))) { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", {op: "rpc", method: "setprofile", id: sel_rows.toString()}, () => { - window.location.reload(); - }); - } - - } else { - alert(__("Please choose a profile to activate.")); - } - }, - addProfile: function () { - if (this.validate()) { - notify_progress("Creating profile...", true); - - const query = {op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile}; - - xhrPost("backend.php", query, () => { - notify(''); - Prefs.editProfiles(); - }); - - } - }, - execute: function () { - if (this.validate()) { - } - }, - href: query - }); - - dialog.show(); - }, - customizeCSS: function() { - const query = "backend.php?op=pref-prefs&method=customizeCSS"; - - if (dijit.byId("cssEditDlg")) - dijit.byId("cssEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "cssEditDlg", - title: __("Customize stylesheet"), - style: "width: 600px", - execute: function () { - notify_progress('Saving data...', true); - - xhrPost("backend.php", this.attr('value'), () => { - window.location.reload(); - }); - - }, - href: query - }); - - dialog.show(); - }, - confirmReset: function() { - if (confirm(__("Reset to defaults?"))) { - xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => { - Prefs.refresh(); - notify_info(transport.responseText); - }); - } - }, - clearPluginData: function(name) { - if (confirm(__("Clear stored data for this plugin?"))) { - notify_progress("Loading, please wait..."); - - xhrPost("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => { - Prefs.refresh(); - }); - } - }, - refresh: function() { - xhrPost("backend.php", { op: "pref-prefs" }, (transport) => { - dijit.byId('genConfigTab').attr('content', transport.responseText); - notify(""); - }); - } -}; - -// noinspection JSUnusedGlobalSymbols -const Users = { - reload: function(sort) { - const user_search = $("user_search"); - const search = user_search ? user_search.value : ""; - - xhrPost("backend.php", { op: "pref-users", sort: sort, search: search }, (transport) => { - dijit.byId('userConfigTab').attr('content', transport.responseText); - notify(""); - }); - }, - add: function() { - const login = prompt(__("Please enter username:"), ""); - - if (login) { - notify_progress("Adding user..."); - - xhrPost("backend.php", {op: "pref-users", method: "add", login: login}, (transport) => { - alert(transport.responseText); - Users.reload(); - }); - - } - }, - edit: function(id) { - const query = "backend.php?op=pref-users&method=edit&id=" + - param_escape(id); - - if (dijit.byId("userEditDlg")) - dijit.byId("userEditDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "userEditDlg", - title: __("User Editor"), - style: "width: 600px", - execute: function () { - if (this.validate()) { - notify_progress("Saving data...", true); - - xhrPost("backend.php", dojo.formToObject("user_edit_form"), (transport) => { - dialog.hide(); - Users.reload(); - }); - } - }, - href: query - }); - - dialog.show(); - }, - resetSelected: function() { - const rows = this.getSelection(); - - if (rows.length == 0) { - alert(__("No users selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select one user.")); - return; - } - - if (confirm(__("Reset password of selected user?"))) { - notify_progress("Resetting password for selected user..."); - - const id = rows[0]; - - xhrPost("backend.php", {op: "pref-users", method: "resetPass", id: id}, (transport) => { - notify(''); - alert(transport.responseText); - }); - - } - }, - removeSelected: function() { - const sel_rows = this.getSelection(); - - if (sel_rows.length > 0) { - if (confirm(__("Remove selected users? Neither default admin nor your account will be removed."))) { - notify_progress("Removing selected users..."); - - const query = { - op: "pref-users", method: "remove", - ids: sel_rows.toString() - }; - - xhrPost("backend.php", query, () => { - this.reload(); - }); - } - - } else { - alert(__("No users selected.")); - } - }, - editSelected: function() { - const rows = this.getSelection(); - - if (rows.length == 0) { - alert(__("No users selected.")); - return; - } - - if (rows.length > 1) { - alert(__("Please select one user.")); - return; - } - - this.edit(rows[0]); - }, - getSelection :function() { - return Tables.getSelected("prefUserList"); - } -}; - function opmlImportComplete(iframe) { if (!iframe.contentDocument.body.innerHTML) return false; -- cgit v1.2.3 From 807ff074540575e6ef8f99ad32b098a816091171 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 17:18:59 +0300 Subject: split main objects to dojo modules --- js/prefs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 8804bdba9..637bc7905 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -1,4 +1,4 @@ -/* global dijit, __,fox */ +/* global dijit, __ */ let Utils; let CommonDialogs; -- cgit v1.2.3 From f89924f7a19871e26d5805a6c1863903c6e474bf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 18:38:27 +0300 Subject: set use strict on JS modules; remove some mostly useless stuff like get_minified_js() --- js/prefs.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 637bc7905..7c4021201 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -1,3 +1,4 @@ +'use strict' /* global dijit, __ */ let Utils; -- cgit v1.2.3 From 526389b2d380177490605037fdc3a24ebc688fac Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 20:56:30 +0300 Subject: update notify_* calls to use Notify --- js/prefs.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 7c4021201..a1866f478 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -85,7 +85,7 @@ const App = { initSecondStage: function() { document.onkeydown = () => { App.hotkeyHandler(event) }; Utils.setLoadingProgress(50); - notify(""); + Notify.close(); let tab = Utils.urlParam('tab'); @@ -154,7 +154,7 @@ function opmlImportComplete(iframe) { Element.show(iframe); - notify(''); + Notify.close(); if (dijit.byId('opmlImportDlg')) dijit.byId('opmlImportDlg').destroyRecursive(); @@ -185,7 +185,7 @@ function opmlImport() { alert(__("Please choose an OPML file first.")); return false; } else { - notify_progress("Importing, please wait...", true); + Notify.progress("Importing, please wait...", true); Element.show("upload_iframe"); @@ -195,7 +195,7 @@ function opmlImport() { function opmlRegenKey() { if (confirm(__("Replace current OPML publishing address with a new one?"))) { - notify_progress("Trying to change address...", true); + Notify.progress("Trying to change address...", true); xhrJson("backend.php", { op: "pref-feeds", method: "regenOPMLKey" }, (reply) => { if (reply) { @@ -208,10 +208,10 @@ function opmlRegenKey() { new Effect.Highlight(e); - notify(''); + Notify.close(); } else { - notify_error("Could not change feed URL."); + Notify.error("Could not change feed URL."); } } }); -- cgit v1.2.3 From ac8361e6f6e81e25d3c17e14b973af53a9b93885 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 21:52:50 +0300 Subject: add AppBase as a shared ancestor for main and prefs app objects remove event.observe stuff from startup, unneeded --- js/prefs.js | 249 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 129 insertions(+), 120 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index a1866f478..75f285b38 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -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/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 { +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) { + + 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); + }; + 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(); - } 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"); + 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); + }); - if (tab) { - tab = dijit.byId(tab); - if (tab) { - dijit.byId("pref-tabs").selectChild(tab); + }, + 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; } - } - } + }); - dojo.connect(dijit.byId("pref-tabs"), "selectChild", function (elem) { - localStorage.setItem("ttrss:prefs-tab", elem.id); - }); + App = new _App(); - }, - 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); - } + } catch (e) { + exception_error(e); } - }, - isPrefs: function() { - return true; - } -}; + }); +}); function opmlImportComplete(iframe) { if (!iframe.contentDocument.body.innerHTML) return false; -- cgit v1.2.3 From 5ead558e435dd8d58f6666b445374b0005a60337 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 22:08:18 +0300 Subject: move Utils to AppBase where it belongs --- js/prefs.js | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 75f285b38..3600c5fb1 100755 --- a/js/prefs.js +++ b/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); -- cgit v1.2.3 From 84affc7b1d71769038dfd25d74e40d6bf744e5fb Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 09:33:44 +0300 Subject: rework dojo singleton modules to better work with phpstorm completion (ugh) - declare() is not needed there anyway remove event.observe from login form (not needed) load pluginhost via amd --- js/prefs.js | 5 ----- 1 file changed, 5 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 3600c5fb1..ea5d847a9 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -60,11 +60,6 @@ require(["dojo/_base/kernel", report_error(message, filename, lineno, colno, error); }; - CommonDialogs = fox.CommonDialogs(); - Filters = fox.CommonFilters(); - Users = fox.PrefUsers(); - Prefs = fox.PrefHelpers(); - parser.parse(); this.setLoadingProgress(50); -- cgit v1.2.3 From 78cc470193448048759b3f315ee630e50acb064b Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 10:51:14 +0300 Subject: remove some plugin JS code out of global context --- js/prefs.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index ea5d847a9..edb11bc7d 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -7,6 +7,8 @@ let Filters; let Users; let Prefs; +const Plugins = {}; + require(["dojo/_base/kernel", "dojo/_base/declare", "dojo/ready", -- cgit v1.2.3 From b3bc638a9fa87cdaf61bff446f8aa0534d2b49ee Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 12:26:49 +0300 Subject: refactor OPML export/import code to be less horrible --- js/prefs.js | 77 +------------------------------------------------------------ 1 file changed, 1 insertion(+), 76 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index edb11bc7d..4bdfb45ef 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -152,79 +152,4 @@ require(["dojo/_base/kernel", exception_error(e); } }); -}); - -function opmlImportComplete(iframe) { - if (!iframe.contentDocument.body.innerHTML) return false; - - Element.show(iframe); - - Notify.close(); - - if (dijit.byId('opmlImportDlg')) - dijit.byId('opmlImportDlg').destroyRecursive(); - - const content = iframe.contentDocument.body.innerHTML; - - const dialog = new dijit.Dialog({ - id: "opmlImportDlg", - title: __("OPML Import"), - style: "width: 600px", - onCancel: function () { - window.location.reload(); - }, - execute: function () { - window.location.reload(); - }, - content: content - }); - - dialog.show(); -} - -function opmlImport() { - - const opml_file = $("opml_file"); - - if (opml_file.value.length == 0) { - alert(__("Please choose an OPML file first.")); - return false; - } else { - Notify.progress("Importing, please wait...", true); - - Element.show("upload_iframe"); - - return true; - } -} - -function opmlRegenKey() { - if (confirm(__("Replace current OPML publishing address with a new one?"))) { - Notify.progress("Trying to change address...", true); - - xhrJson("backend.php", { op: "pref-feeds", method: "regenOPMLKey" }, (reply) => { - if (reply) { - const new_link = reply.link; - const e = $('pub_opml_url'); - - if (new_link) { - e.href = new_link; - e.innerHTML = new_link; - - new Effect.Highlight(e); - - Notify.close(); - - } else { - Notify.error("Could not change feed URL."); - } - } - }); - } - return false; -} - -function gotoExportOpml(filename, settings) { - const tmp = settings ? 1 : 0; - document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp; -} +}); \ No newline at end of file -- cgit v1.2.3 From 4d4034091af3d5f7308cc794cf38f654bbe3083f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 12:46:00 +0300 Subject: prefs: Prefs global -> Helpers --- js/prefs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index 4bdfb45ef..dafdbcdee 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -5,7 +5,7 @@ let App; let CommonDialogs; let Filters; let Users; -let Prefs; +let Helpers; const Plugins = {}; -- cgit v1.2.3 From 71fc6d45bd761a9d2715faa68f2b8c0271ee7169 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Dec 2018 13:38:13 +0300 Subject: refactor error reporting to AppBase; keep exception_error() for now as a shim --- js/prefs.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'js/prefs.js') diff --git a/js/prefs.js b/js/prefs.js index dafdbcdee..c89c0494f 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -58,10 +58,6 @@ require(["dojo/_base/kernel", try { const _App = declare("fox.App", AppBase, { constructor: function() { - window.onerror = function (message, filename, lineno, colno, error) { - report_error(message, filename, lineno, colno, error); - }; - parser.parse(); this.setLoadingProgress(50); @@ -73,7 +69,7 @@ require(["dojo/_base/kernel", try { this.backendSanityCallback(transport); } catch (e) { - exception_error(e); + this.Error.report(e); } }); }, @@ -149,7 +145,7 @@ require(["dojo/_base/kernel", App = new _App(); } catch (e) { - exception_error(e); + this.Error.report(e); } }); }); \ No newline at end of file -- cgit v1.2.3