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 --- classes/pref/feeds.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 43570c740..23e9baee9 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1174,7 +1174,7 @@ class Pref_Feeds extends Handler_Protected { print "
-
"; @@ -1306,7 +1306,7 @@ class Pref_Feeds extends Handler_Protected { print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds."); - print " "; PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, @@ -1323,7 +1323,7 @@ class Pref_Feeds extends Handler_Protected { print "

"; - print " "; print ""; if (!(defined('_DISABLE_FEED_BROWSER') && _DISABLE_FEED_BROWSER)) { - print ""; + print ""; } print " diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 23e9baee9..c061243ee 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1149,7 +1149,7 @@ class Pref_Feeds extends Handler_Protected { if ($num_errors > 0) { $error_button = ""; } @@ -1190,7 +1190,7 @@ class Pref_Feeds extends Handler_Protected { print "

". "" . __('Feeds').""; print "
"; - print "
".__('Subscribe to feed')."
"; print "
".__('Edit selected feeds')."
"; diff --git a/js/feedlist.js b/js/feedlist.js index ddef1a586..f2f5e60ba 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -190,7 +190,7 @@ const Feeds = { try { Feeds.init(); - setLoadingProgress(25); + Utils.setLoadingProgress(25); } catch (e) { exception_error(e); } @@ -204,7 +204,7 @@ const Feeds = { init: function() { console.log("in feedlist init"); - setLoadingProgress(50); + Utils.setLoadingProgress(50); document.onkeydown = App.hotkeyHandler; setInterval(hotkeyPrefixTimeout, 3 * 1000); @@ -602,5 +602,35 @@ const Feeds = { if (nuf) return tree.model.store.getValue(nuf, 'bare_id'); - } + }, + search: function() { + const query = "backend.php?op=feeds&method=search¶m=" + + param_escape(Feeds.getActiveFeedId() + ":" + Feeds.activeFeedIsCat()); + + if (dijit.byId("searchDlg")) + dijit.byId("searchDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "searchDlg", + title: __("Search"), + style: "width: 600px", + execute: function () { + if (this.validate()) { + Feeds._search_query = this.attr('value'); + this.hide(); + Feeds.viewCurrentFeed(); + } + }, + href: query + }); + + dialog.show(); + }, + updateRandomFeed: function() { + console.log("in update_random_feed"); + + xhrPost("backend.php", {op: "rpc", method: "updateRandomFeed"}, (transport) => { + Utils.handleRpcJson(transport, true); + }); + }, }; diff --git a/js/functions.js b/js/functions.js index f2463dda3..0bddbbf0e 100755 --- a/js/functions.js +++ b/js/functions.js @@ -65,6 +65,70 @@ const Utils = { get_seq: function() { return this._rpc_seq; }, + setLoadingProgress: function(p) { + loading_progress += p; + + if (dijit.byId("loading_bar")) + dijit.byId("loading_bar").update({progress: loading_progress}); + + if (loading_progress >= 90) + Element.hide("overlay"); + + }, + keyeventToAction: function(e) { + + const hotkeys_map = getInitParam("hotkeys"); + const keycode = e.which; + const keychar = String.fromCharCode(keycode).toLowerCase(); + + if (keycode == 27) { // escape and drop prefix + hotkey_prefix = false; + } + + if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl + + if (!hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) { + + const date = new Date(); + const ts = Math.round(date.getTime() / 1000); + + hotkey_prefix = keychar; + hotkey_prefix_pressed = ts; + + $("cmdline").innerHTML = keychar; + Element.show("cmdline"); + + e.stopPropagation(); + + return false; + } + + Element.hide("cmdline"); + + let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; + + // ensure ^*char notation + if (e.shiftKey) hotkey_name = "*" + hotkey_name; + if (e.ctrlKey) hotkey_name = "^" + hotkey_name; + if (e.altKey) hotkey_name = "+" + hotkey_name; + if (e.metaKey) hotkey_name = "%" + hotkey_name; + + const hotkey_full = hotkey_prefix ? hotkey_prefix + " " + hotkey_name : hotkey_name; + hotkey_prefix = false; + + let action_name = false; + + for (const sequence in hotkeys_map[1]) { + if (sequence == hotkey_full) { + action_name = hotkeys_map[1][sequence]; + break; + } + } + + console.log('keyeventToAction', hotkey_full, '=>', action_name); + + return action_name; + }, cleanupMemory: function(root) { const dijits = dojo.query("[widgetid]", dijit.byId(root).domNode).map(dijit.byNode); @@ -311,6 +375,281 @@ const Utils = { } }; +const CommonDialogs = { + quickAddFeed: function() { + const query = "backend.php?op=feeds&method=quickAddFeed"; + + // overlapping widgets + if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); + if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "feedAddDlg", + title: __("Subscribe to Feed"), + style: "width: 600px", + show_error: function (msg) { + const elem = $("fadd_error_message"); + + elem.innerHTML = msg; + + if (!Element.visible(elem)) + new Effect.Appear(elem); + + }, + execute: function () { + if (this.validate()) { + console.log(dojo.objectToQuery(this.attr('value'))); + + const feed_url = this.attr('value').feed; + + Element.show("feed_add_spinner"); + Element.hide("fadd_error_message"); + + xhrPost("backend.php", this.attr('value'), (transport) => { + try { + + try { + var reply = JSON.parse(transport.responseText); + } catch (e) { + Element.hide("feed_add_spinner"); + alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console.")); + console.log('quickAddFeed, backend returned:' + transport.responseText); + return; + } + + const rc = reply['result']; + + notify(''); + Element.hide("feed_add_spinner"); + + console.log(rc); + + switch (parseInt(rc['code'])) { + case 1: + dialog.hide(); + notify_info(__("Subscribed to %s").replace("%s", feed_url)); + + Feeds.reload(); + break; + case 2: + dialog.show_error(__("Specified URL seems to be invalid.")); + break; + case 3: + dialog.show_error(__("Specified URL doesn't seem to contain any feeds.")); + break; + case 4: + const feeds = rc['feeds']; + + Element.show("fadd_multiple_notify"); + + const select = dijit.byId("feedDlg_feedContainerSelect"); + + while (select.getOptions().length > 0) + select.removeOption(0); + + select.addOption({value: '', label: __("Expand to select feed")}); + + let count = 0; + for (const feedUrl in feeds) { + select.addOption({value: feedUrl, label: feeds[feedUrl]}); + count++; + } + + Effect.Appear('feedDlg_feedsContainer', {duration: 0.5}); + + break; + case 5: + dialog.show_error(__("Couldn't download the specified URL: %s").replace("%s", rc['message'])); + break; + case 6: + dialog.show_error(__("XML validation failed: %s").replace("%s", rc['message'])); + break; + case 0: + dialog.show_error(__("You are already subscribed to this feed.")); + break; + } + + } catch (e) { + console.error(transport.responseText); + exception_error(e); + } + }); + } + }, + href: query + }); + + dialog.show(); + }, + showFeedsWithErrors: function() { + const query = {op: "pref-feeds", method: "feedsWithErrors"}; + + if (dijit.byId("errorFeedsDlg")) + dijit.byId("errorFeedsDlg").destroyRecursive(); + + const dialog = new dijit.Dialog({ + id: "errorFeedsDlg", + title: __("Feeds with update errors"), + style: "width: 600px", + getSelectedFeeds: function () { + return getSelectedTableRowIds("prefErrorFeedList"); + }, + 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(); + Feeds.reload(); + }); + } + + } else { + alert(__("No feeds are selected.")); + } + }, + execute: function () { + if (this.validate()) { + // + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); + + dialog.show(); + }, + feedBrowser: function() { + const query = {op: "feeds", method: "feedBrowser"}; + + if (dijit.byId("feedAddDlg")) + dijit.byId("feedAddDlg").hide(); + + if (dijit.byId("feedBrowserDlg")) + dijit.byId("feedBrowserDlg").destroyRecursive(); + + // noinspection JSUnusedGlobalSymbols + const dialog = new dijit.Dialog({ + id: "feedBrowserDlg", + title: __("More Feeds"), + style: "width: 600px", + getSelectedFeedIds: function () { + const list = $$("#browseFeedList li[id*=FBROW]"); + const selected = []; + + list.each(function (child) { + const id = child.id.replace("FBROW-", ""); + + if (child.hasClassName('Selected')) { + selected.push(id); + } + }); + + return selected; + }, + getSelectedFeeds: function () { + const list = $$("#browseFeedList li.Selected"); + const selected = []; + + list.each(function (child) { + const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; + const url = child.getElementsBySelector("a.fb_feedUrl")[0].href; + + selected.push([title, url]); + + }); + + return selected; + }, + + subscribe: function () { + const mode = this.attr('value').mode; + let selected = []; + + if (mode == "1") + selected = this.getSelectedFeeds(); + else + selected = this.getSelectedFeedIds(); + + if (selected.length > 0) { + dijit.byId("feedBrowserDlg").hide(); + + notify_progress("Loading, please wait...", true); + + const query = { + op: "rpc", method: "massSubscribe", + payload: JSON.stringify(selected), mode: mode + }; + + xhrPost("backend.php", query, () => { + notify(''); + Feeds.reload(); + }); + + } else { + alert(__("No feeds are selected.")); + } + + }, + update: function () { + Element.show('feed_browser_spinner'); + + xhrPost("backend.php", dialog.attr("value"), (transport) => { + notify(''); + + Element.hide('feed_browser_spinner'); + + const reply = JSON.parse(transport.responseText); + const mode = reply['mode']; + + if ($("browseFeedList") && reply['content']) { + $("browseFeedList").innerHTML = reply['content']; + } + + dojo.parser.parse("browseFeedList"); + + if (mode == 2) { + Element.show(dijit.byId('feed_archive_remove').domNode); + } else { + Element.hide(dijit.byId('feed_archive_remove').domNode); + } + }); + }, + removeFromArchive: function () { + const selected = this.getSelectedFeedIds(); + + if (selected.length > 0) { + if (confirm(__("Remove selected feeds from the archive? Feeds with stored articles will not be removed."))) { + Element.show('feed_browser_spinner'); + + const query = {op: "rpc", method: "remarchive", ids: selected.toString()}; + + xhrPost("backend.php", query, () => { + dialog.update(); + }); + } + } + }, + execute: function () { + if (this.validate()) { + this.subscribe(); + } + }, + href: "backend.php?" + dojo.objectToQuery(query) + }); + + dialog.show(); + } +}; + function report_error(message, filename, lineno, colno, error) { exception_error(error, null, filename, lineno); } @@ -665,17 +1004,6 @@ function explainError(code) { return Utils.displayDlg(__("Error explained"), "explainError", code); } -function setLoadingProgress(p) { - loading_progress += p; - - if (dijit.byId("loading_bar")) - dijit.byId("loading_bar").update({progress: loading_progress}); - - if (loading_progress >= 90) - Element.hide("overlay"); - -} - function strip_tags(s) { return s.replace(/<\/?[^>]+(>|$)/g, ""); } @@ -772,113 +1100,6 @@ function addLabel(select, callback) { } -function quickAddFeed() { - const query = "backend.php?op=feeds&method=quickAddFeed"; - - // overlapping widgets - if (dijit.byId("batchSubDlg")) dijit.byId("batchSubDlg").destroyRecursive(); - if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "feedAddDlg", - title: __("Subscribe to Feed"), - style: "width: 600px", - show_error: function(msg) { - const elem = $("fadd_error_message"); - - elem.innerHTML = msg; - - if (!Element.visible(elem)) - new Effect.Appear(elem); - - }, - execute: function() { - if (this.validate()) { - console.log(dojo.objectToQuery(this.attr('value'))); - - const feed_url = this.attr('value').feed; - - Element.show("feed_add_spinner"); - Element.hide("fadd_error_message"); - - xhrPost("backend.php", this.attr('value'), (transport) => { - try { - - try { - var reply = JSON.parse(transport.responseText); - } catch (e) { - Element.hide("feed_add_spinner"); - alert(__("Failed to parse output. This can indicate server timeout and/or network issues. Backend output was logged to browser console.")); - console.log('quickAddFeed, backend returned:' + transport.responseText); - return; - } - - const rc = reply['result']; - - notify(''); - Element.hide("feed_add_spinner"); - - console.log(rc); - - switch (parseInt(rc['code'])) { - case 1: - dialog.hide(); - notify_info(__("Subscribed to %s").replace("%s", feed_url)); - - Feeds.reload(); - break; - case 2: - dialog.show_error(__("Specified URL seems to be invalid.")); - break; - case 3: - dialog.show_error(__("Specified URL doesn't seem to contain any feeds.")); - break; - case 4: - const feeds = rc['feeds']; - - Element.show("fadd_multiple_notify"); - - const select = dijit.byId("feedDlg_feedContainerSelect"); - - while (select.getOptions().length > 0) - select.removeOption(0); - - select.addOption({value: '', label: __("Expand to select feed")}); - - let count = 0; - for (const feedUrl in feeds) { - select.addOption({value: feedUrl, label: feeds[feedUrl]}); - count++; - } - - Effect.Appear('feedDlg_feedsContainer', {duration : 0.5}); - - break; - case 5: - dialog.show_error(__("Couldn't download the specified URL: %s"). - replace("%s", rc['message'])); - break; - case 6: - dialog.show_error(__("XML validation failed: %s"). - replace("%s", rc['message'])); - break; - case 0: - dialog.show_error(__("You are already subscribed to this feed.")); - break; - } - - } catch (e) { - console.error(transport.responseText); - exception_error(e); - } - }); - } - }, - href: query}); - - dialog.show(); -} - function createNewRuleElement(parentNode, replaceNode) { const form = document.forms["filter_new_rule_form"]; const query = { op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form) }; @@ -1382,172 +1603,6 @@ function editFeed(feed) { dialog.show(); } -function feedBrowser() { - const query = { op: "feeds", method: "feedBrowser" }; - - if (dijit.byId("feedAddDlg")) - dijit.byId("feedAddDlg").hide(); - - if (dijit.byId("feedBrowserDlg")) - dijit.byId("feedBrowserDlg").destroyRecursive(); - - // noinspection JSUnusedGlobalSymbols - const dialog = new dijit.Dialog({ - id: "feedBrowserDlg", - title: __("More Feeds"), - style: "width: 600px", - getSelectedFeedIds: function () { - const list = $$("#browseFeedList li[id*=FBROW]"); - const selected = []; - - list.each(function (child) { - const id = child.id.replace("FBROW-", ""); - - if (child.hasClassName('Selected')) { - selected.push(id); - } - }); - - return selected; - }, - getSelectedFeeds: function () { - const list = $$("#browseFeedList li.Selected"); - const selected = []; - - list.each(function (child) { - const title = child.getElementsBySelector("span.fb_feedTitle")[0].innerHTML; - const url = child.getElementsBySelector("a.fb_feedUrl")[0].href; - - selected.push([title, url]); - - }); - - return selected; - }, - - subscribe: function () { - const mode = this.attr('value').mode; - let selected = []; - - if (mode == "1") - selected = this.getSelectedFeeds(); - else - selected = this.getSelectedFeedIds(); - - if (selected.length > 0) { - dijit.byId("feedBrowserDlg").hide(); - - notify_progress("Loading, please wait...", true); - - const query = { op: "rpc", method: "massSubscribe", - payload: JSON.stringify(selected), mode: mode }; - - xhrPost("backend.php", query, () => { - notify(''); - Feeds.reload(); - }); - - } else { - alert(__("No feeds are selected.")); - } - - }, - update: function () { - Element.show('feed_browser_spinner'); - - xhrPost("backend.php", dialog.attr("value"), (transport) => { - notify(''); - - Element.hide('feed_browser_spinner'); - - const reply = JSON.parse(transport.responseText); - const mode = reply['mode']; - - if ($("browseFeedList") && reply['content']) { - $("browseFeedList").innerHTML = reply['content']; - } - - dojo.parser.parse("browseFeedList"); - - if (mode == 2) { - Element.show(dijit.byId('feed_archive_remove').domNode); - } else { - Element.hide(dijit.byId('feed_archive_remove').domNode); - } - }); - }, - removeFromArchive: function () { - const selected = this.getSelectedFeedIds(); - - if (selected.length > 0) { - if (confirm(__("Remove selected feeds from the archive? Feeds with stored articles will not be removed."))) { - Element.show('feed_browser_spinner'); - - const query = { op: "rpc", method: "remarchive", ids: selected.toString() }; - - xhrPost("backend.php", query, () => { - dialog.update(); - }); - } - } - }, - execute: function () { - if (this.validate()) { - this.subscribe(); - } - }, - href: "backend.php?" + dojo.objectToQuery(query) - }); - - dialog.show(); -} - -// noinspection JSUnusedGlobalSymbols -function showFeedsWithErrors() { - const query = { op: "pref-feeds", method: "feedsWithErrors" }; - - if (dijit.byId("errorFeedsDlg")) - dijit.byId("errorFeedsDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "errorFeedsDlg", - title: __("Feeds with update errors"), - style: "width: 600px", - getSelectedFeeds: function() { - return getSelectedTableRowIds("prefErrorFeedList"); - }, - 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(); - Feeds.reload(); - }); - } - - } else { - alert(__("No feeds are selected.")); - } - }, - execute: function() { - if (this.validate()) { - // - } - }, - href: "backend.php?" + dojo.objectToQuery(query) - }); - - dialog.show(); -} - function get_timestamp() { const date = new Date(); return Math.round(date.getTime() / 1000); @@ -1602,58 +1657,3 @@ function popupOpenArticle(id) { w.opener = null; w.location = "backend.php?op=article&method=view&mode=raw&html=1&zoom=1&id=" + id + "&csrf_token=" + getInitParam("csrf_token"); } - -function keyeventToAction(e) { - - const hotkeys_map = getInitParam("hotkeys"); - const keycode = e.which; - const keychar = String.fromCharCode(keycode).toLowerCase(); - - if (keycode == 27) { // escape and drop prefix - hotkey_prefix = false; - } - - if (keycode == 16 || keycode == 17) return; // ignore lone shift / ctrl - - if (!hotkey_prefix && hotkeys_map[0].indexOf(keychar) != -1) { - - const date = new Date(); - const ts = Math.round(date.getTime() / 1000); - - hotkey_prefix = keychar; - hotkey_prefix_pressed = ts; - - $("cmdline").innerHTML = keychar; - Element.show("cmdline"); - - e.stopPropagation(); - - return false; - } - - Element.hide("cmdline"); - - let hotkey_name = keychar.search(/[a-zA-Z0-9]/) != -1 ? keychar : "(" + keycode + ")"; - - // ensure ^*char notation - if (e.shiftKey) hotkey_name = "*" + hotkey_name; - if (e.ctrlKey) hotkey_name = "^" + hotkey_name; - if (e.altKey) hotkey_name = "+" + hotkey_name; - if (e.metaKey) hotkey_name = "%" + hotkey_name; - - const hotkey_full = hotkey_prefix ? hotkey_prefix + " " + hotkey_name : hotkey_name; - hotkey_prefix = false; - - let action_name = false; - - for (const sequence in hotkeys_map[1]) { - if (sequence == hotkey_full) { - action_name = hotkeys_map[1][sequence]; - break; - } - } - - console.log('keyeventToAction', hotkey_full, '=>', action_name); - - return action_name; -} \ No newline at end of file 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(); diff --git a/js/tt-rss.js b/js/tt-rss.js index e48e4ece9..4c37102e6 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -1,10 +1,10 @@ /* global dijit, __ */ -let _widescreen_mode = false; let hotkey_actions = {}; const App = { global_unread: -1, + _widescreen_mode: false, init: function() { window.onerror = function (message, filename, lineno, colno, error) { @@ -56,7 +56,7 @@ const App = { if (!App.genericSanityCheck()) return false; - setLoadingProgress(30); + Utils.setLoadingProgress(30); init_hotkey_actions(); const a = document.createElement('audio'); @@ -132,21 +132,21 @@ const App = { Feeds.setActiveFeedId(hash_feed_id, hash_feed_is_cat); } - setLoadingProgress(50); + Utils.setLoadingProgress(50); ArticleCache.clear(); - _widescreen_mode = getInitParam("widescreen"); - this.switchPanelMode(_widescreen_mode); + this._widescreen_mode = getInitParam("widescreen"); + this.switchPanelMode(this._widescreen_mode); Headlines.initScrollHandler(); - console.log("second stage ok"); - if (getInitParam("simple_update")) { console.log("scheduling simple feed updater..."); - window.setTimeout(update_random_feed, 30 * 1000); + window.setInterval(Feeds.updateRandomFeed, 30 * 1000); } + + console.log("second stage ok"); }, genericSanityCheck: function() { setCookie("ttrss_test", "TEST"); @@ -176,7 +176,7 @@ const App = { hotkeyHandler(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) { const action_func = hotkey_actions[action_name]; @@ -235,29 +235,6 @@ const App = { }, }; -function search() { - const query = "backend.php?op=feeds&method=search¶m=" + - param_escape(Feeds.getActiveFeedId() + ":" + Feeds.activeFeedIsCat()); - - if (dijit.byId("searchDlg")) - dijit.byId("searchDlg").destroyRecursive(); - - const dialog = new dijit.Dialog({ - id: "searchDlg", - title: __("Search"), - style: "width: 600px", - execute: function() { - if (this.validate()) { - Feeds._search_query = this.attr('value'); - this.hide(); - Feeds.viewCurrentFeed(); - } - }, - href: query}); - - dialog.show(); -} - function init_hotkey_actions() { hotkey_actions["next_feed"] = function () { const rv = dijit.byId("feedTree").getNextFeed( @@ -290,7 +267,7 @@ function init_hotkey_actions() { moveToPost('prev', true, true); }; hotkey_actions["search_dialog"] = function () { - search(); + Feeds.search(); }; hotkey_actions["toggle_mark"] = function () { selectionToggleMarked(); @@ -361,14 +338,13 @@ function init_hotkey_actions() { hotkey_actions["feed_refresh"] = function () { if (Feeds.getActiveFeedId() != undefined) { Feeds.viewfeed({feed: Feeds.getActiveFeedId(), is_cat: Feeds.activeFeedIsCat()}); - return; } }; hotkey_actions["feed_unhide_read"] = function () { Feeds.toggleDispRead(); }; hotkey_actions["feed_subscribe"] = function () { - quickAddFeed(); + CommonDialogs.quickAddFeed(); }; hotkey_actions["feed_debug_update"] = function () { if (!Feeds.activeFeedIsCat() && parseInt(Feeds.getActiveFeedId()) > 0) { @@ -392,7 +368,6 @@ function init_hotkey_actions() { hotkey_actions["feed_catchup"] = function () { if (Feeds.getActiveFeedId() != undefined) { Feeds.catchupCurrentFeed(); - return; } }; hotkey_actions["feed_reverse"] = function () { @@ -467,13 +442,13 @@ function init_hotkey_actions() { }; hotkey_actions["toggle_widescreen"] = function () { if (!App.isCombinedMode()) { - _widescreen_mode = !_widescreen_mode; + App._widescreen_mode = !App._widescreen_mode; // reset stored sizes because geometry changed setCookie("ttrss_ci_width", 0); setCookie("ttrss_ci_height", 0); - App.switchPanelMode(_widescreen_mode); + App.switchPanelMode(App._widescreen_mode); } else { alert(__("Widescreen is not available in combined mode.")); } @@ -518,10 +493,10 @@ function quickMenuGo(opid) { Utils.displayDlg(__("Tag cloud"), "printTagCloud"); break; case "qmcSearch": - search(); + Feeds.search(); break; case "qmcAddFeed": - quickAddFeed(); + CommonDialogs.quickAddFeed(); break; case "qmcDigest": window.location.href = "backend.php?op=digest"; @@ -561,13 +536,13 @@ function quickMenuGo(opid) { break; case "qmcToggleWidescreen": if (!App.isCombinedMode()) { - _widescreen_mode = !_widescreen_mode; + App._widescreen_mode = !App._widescreen_mode; // reset stored sizes because geometry changed setCookie("ttrss_ci_width", 0); setCookie("ttrss_ci_height", 0); - App.switchPanelMode(_widescreen_mode); + App.switchPanelMode(App._widescreen_mode); } else { alert(__("Widescreen is not available in combined mode.")); } @@ -584,15 +559,6 @@ function inPreferences() { return false; } -function update_random_feed() { - console.log("in update_random_feed"); - - xhrPost("backend.php", { op: "rpc", method: "updateRandomFeed" }, (transport) => { - Utils.handleRpcJson(transport, true); - window.setTimeout(update_random_feed, 30*1000); - }); -} - function hash_get(key) { const kv = window.location.hash.substring(1).toQueryParams(); return kv[key]; diff --git a/tests/functional/BasicTest.php b/tests/functional/BasicTest.php index dc44a67e1..c5bc70b4e 100644 --- a/tests/functional/BasicTest.php +++ b/tests/functional/BasicTest.php @@ -30,7 +30,7 @@ class BasicTest extends PHPUnit_Extensions_Selenium2TestCase { $this->execute(["script" => "dijit.byId('filterEditDlg').hide();", "args" => []]); - $this->execute(["script" => "quickAddFeed()", "args" => []]); + $this->execute(["script" => "CommonDialog.quickAddFeed()", "args" => []]); $this->byCssSelector("#feedAddDlg")->displayed(); $this->execute(["script" => "dijit.byId('feedAddDlg').hide();", "args" => []]); -- cgit v1.2.3-54-g00ecf 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 --- classes/dlg.php | 2 +- classes/pref/feeds.php | 8 +- classes/pref/filters.php | 4 +- js/FeedTree.js | 2 +- js/PrefFeedTree.js | 4 +- js/functions.js | 877 ++++++++++++++++++++-------------------- js/prefs.js | 6 +- js/tt-rss.js | 8 +- js/viewfeed.js | 2 +- plugins/af_psql_trgm/init.php | 2 +- plugins/af_readability/init.php | 2 +- tests/functional/BasicTest.php | 2 +- 12 files changed, 463 insertions(+), 456 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/dlg.php b/classes/dlg.php index 50cbd12dd..02249ea96 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -174,7 +174,7 @@ class Dlg extends Handler_Protected { print "
"; - print " "; print ""; print "
"; @@ -1247,7 +1247,7 @@ class Pref_Feeds extends Handler_Protected { var bare_id = id.substr(id.indexOf(':')+1); if (id.match('FEED:')) { - editFeed(bare_id); + CommonDialogs.editFeed(bare_id); } else if (id.match('CAT:')) { editCat(bare_id, item); } @@ -1441,7 +1441,7 @@ class Pref_Feeds extends Handler_Protected { print "". + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". htmlspecialchars($line["title"]).""; print ""; @@ -1506,7 +1506,7 @@ class Pref_Feeds extends Handler_Protected { print "". + "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">". htmlspecialchars($line["title"]).": "; print ""; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index e3503d545..e60628f8f 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -797,7 +797,7 @@ class Pref_Filters extends Handler_Protected { dojoType=\"dijit.MenuItem\">".__('None')."
"; print "
"; - print " "; print " "; print " -- cgit v1.2.3-54-g00ecf 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 --- classes/feeds.php | 4 ++-- classes/pref/feeds.php | 4 ++-- classes/pref/filters.php | 4 ++-- classes/pref/prefs.php | 6 ++--- classes/pref/users.php | 2 +- include/feedbrowser.php | 4 ++-- include/functions.php | 2 +- js/functions.js | 61 +++++++++++++----------------------------------- js/prefs.js | 6 ++--- js/tt-rss.js | 2 +- js/viewfeed.js | 8 +++++++ 11 files changed, 41 insertions(+), 62 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/feeds.php b/classes/feeds.php index c9e5ca496..b32521130 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -406,7 +406,7 @@ class Feeds extends Handler_Protected { $reply['content'] .= "
"; $reply['content'] .= ""; $reply['content'] .= "$marked_pic"; @@ -505,7 +505,7 @@ class Feeds extends Handler_Protected { $tmp_content .= "
"; $tmp_content .= ""; $tmp_content .= "$marked_pic"; diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index f47d24501..efc76701e 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1435,7 +1435,7 @@ class Pref_Feeds extends Handler_Protected { # id needed for selectTableRows() print ""; print ""; @@ -1500,7 +1500,7 @@ class Pref_Feeds extends Handler_Protected { # id needed for selectTableRows() print ""; print ""; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index e48615395..f9b4bfb2a 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -429,7 +429,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars(json_encode($line)); - print "
  • ". + print "
  • ". "".$this->getRuleName($line)."". "
  • "; } @@ -473,7 +473,7 @@ class Pref_Filters extends Handler_Protected { $data = htmlspecialchars(json_encode($line)); - print "
  • ". + print "
  • ". "".$this->getActionName($line)."". "
  • "; } diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 82456f342..017f2e06c 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -799,7 +799,7 @@ class Pref_Prefs extends Handler_Protected { $plugin_icon = $checked ? "plugin.png" : "plugin_disabled.png"; - print ""; @@ -1023,7 +1023,7 @@ class Pref_Prefs extends Handler_Protected { print ""; @@ -1050,7 +1050,7 @@ class Pref_Prefs extends Handler_Protected { $edit_title = htmlspecialchars($line["title"]); print ""; diff --git a/classes/pref/users.php b/classes/pref/users.php index 1e6eae227..eda3e1a0e 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -419,7 +419,7 @@ class Pref_Users extends Handler_Protected { $line["created"] = make_local_datetime($line["created"], false); $line["last_login"] = make_local_datetime($line["last_login"], false); - print ""; diff --git a/include/feedbrowser.php b/include/feedbrowser.php index a0b1b6e8f..4f37241ea 100644 --- a/include/feedbrowser.php +++ b/include/feedbrowser.php @@ -53,7 +53,7 @@ $site_url = htmlspecialchars($line["site_url"]); $subscribers = $line["subscribers"]; - $check_box = ""; @@ -73,7 +73,7 @@ $feed_url = htmlspecialchars($line["feed_url"]); $site_url = htmlspecialchars($line["site_url"]); - $check_box = ""; if ($line['articles_archived'] > 0) { diff --git a/include/functions.php b/include/functions.php index f6d09fe67..2ec42c7ee 100755 --- a/include/functions.php +++ b/include/functions.php @@ -1244,7 +1244,7 @@ "g t" => "goto_tagcloud", "g *p" => "goto_prefs", // "other" => array( - "(9)|Tab" => "select_article_cursor", // tab + "r" => "select_article_cursor", "c l" => "create_label", "c f" => "create_filter", "c s" => "collapse_sidebar", diff --git a/js/functions.js b/js/functions.js index ce6d7aca9..033933794 100755 --- a/js/functions.js +++ b/js/functions.js @@ -53,8 +53,8 @@ Array.prototype.remove = function(s) { } }; -const ListUtils = { - onChecked: function(elem) { +const Lists = { + onRowChecked: function(elem) { // account for dojo checkboxes elem = elem.domNode || elem; @@ -62,11 +62,23 @@ const ListUtils = { } }; +const Tables = { + onRowChecked: function(elem) { + // account for dojo checkboxes + elem = elem.domNode || elem; + + elem.up("tr").toggleClassName("Selected"); + } +} + const Utils = { _rpc_seq: 0, hotkey_prefix: 0, hotkey_prefix_pressed: false, hotkey_prefix_timeout: 0, + urlParam: function(param) { + return String(window.location.href).parseQuery()[param]; + }, next_seq: function() { this._rpc_seq += 1; return this._rpc_seq; @@ -988,43 +1000,6 @@ function getCookie(name) { return unescape(dc.substring(begin + prefix.length, end)); } -function toggleSelectRowById(sender, id) { - const row = $(id); - return toggleSelectRow(sender, row); -} - -/* this is for dijit Checkbox */ -function toggleSelectRow2(sender, row, is_cdm) { - - if (!row) - if (!is_cdm) - row = sender.domNode.parentNode.parentNode; - else - row = sender.domNode.parentNode.parentNode.parentNode; // oh ffs - - if (sender.checked && !row.hasClassName('Selected')) - row.addClassName('Selected'); - else - row.removeClassName('Selected'); - - if (typeof Headlines != "undefined") - Headlines.updateSelectedPrompt(); -} - - -function toggleSelectRow(sender, row) { - - if (!row) row = sender.parentNode.parentNode; - - if (sender.checked && !row.hasClassName('Selected')) - row.addClassName('Selected'); - else - row.removeClassName('Selected'); - - if (typeof Headlines != "undefined") - Headlines.updateSelectedPrompt(); -} - // noinspection JSUnusedGlobalSymbols function displayIfChecked(checkbox, elemId) { if (checkbox.checked) { @@ -1034,10 +1009,6 @@ function displayIfChecked(checkbox, elemId) { } } -function getURLParam(param){ - return String(window.location.href).parseQuery()[param]; -} - // noinspection JSUnusedGlobalSymbols function closeInfoBox() { const dialog = dijit.byId("infoBox"); @@ -1140,7 +1111,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - ListUtils.onChecked(this); + Lists.onRowChecked(this); }, }, cb); @@ -1189,7 +1160,7 @@ const Filters = { new dijit.form.CheckBox({ onChange: function () { - ListUtils.onChecked(this); + Lists.onRowChecked(this); }, }, cb); 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) diff --git a/js/tt-rss.js b/js/tt-rss.js index b337e0ae5..71bb2337a 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -414,7 +414,7 @@ const App = { if (!row.hasClassName("active")) cb.attr("checked", !cb.attr("checked")); - toggleSelectRowById(cb, "RROW-" + id); + Headlines.onRowChecked(cb); return false; } } diff --git a/js/viewfeed.js b/js/viewfeed.js index 93bc56c9d..e7703ed55 100755 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1109,6 +1109,14 @@ const Headlines = { return rv; }, + onRowChecked: function(elem) { + // account for dojo checkboxes + elem = elem.domNode || elem; + + elem.up("div[id*=RROW]").toggleClassName("Selected"); + + this.updateSelectedPrompt(); + }, select: function(mode) { // mode = all,none,unread,invert,marked,published let query = "#headlines-frame > div[id*=RROW]"; -- cgit v1.2.3-54-g00ecf 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 --- classes/pref/feeds.php | 22 +++++-------- classes/pref/prefs.php | 11 +++---- classes/pref/users.php | 9 +++--- js/functions.js | 83 ++++++++++++++++---------------------------------- js/prefs.js | 39 ++++++++++++++++-------- 5 files changed, 70 insertions(+), 94 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index efc76701e..0a7fed7b2 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1412,9 +1412,9 @@ class Pref_Feeds extends Handler_Protected { print "
    ". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; print "
    "; #toolbar @@ -1428,15 +1428,12 @@ class Pref_Feeds extends Handler_Protected { while ($line = $sth->fetch()) { $feed_id = $line["id"]; - $this_row_id = "id=\"FUPDD-$feed_id\""; - # class needed for selectTableRows() - print ""; + print ""; - # id needed for selectTableRows() print ""; + type=\"checkbox\">"; print ""; print "". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; print ""; #toolbar @@ -1493,15 +1490,12 @@ class Pref_Feeds extends Handler_Protected { while ($line = $sth->fetch()) { $feed_id = $line["id"]; - $this_row_id = "id=\"FERDD-$feed_id\""; - # class needed for selectTableRows() - print ""; + print ""; - # id needed for selectTableRows() print ""; + type=\"checkbox\">"; print ""; print "". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; @@ -1019,10 +1019,9 @@ class Pref_Prefs extends Handler_Protected { print ""; - print ""; #odd + print ""; # data-row-id='0' <-- no point, shouldn't be removed print ""; @@ -1043,15 +1042,13 @@ class Pref_Prefs extends Handler_Protected { while ($line = $sth->fetch()) { $profile_id = $line["id"]; - $this_row_id = "id=\"FCATR-$profile_id\""; - print ""; + print ""; $edit_title = htmlspecialchars($line["title"]); print ""; diff --git a/classes/pref/users.php b/classes/pref/users.php index eda3e1a0e..fb7afcf04 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -354,9 +354,9 @@ class Pref_Users extends Handler_Protected { print "
    ". "" . __('Select').""; print "
    "; - print "
    ".__('All')."
    "; - print "
    ".__('None')."
    "; print "
    "; @@ -412,7 +412,7 @@ class Pref_Users extends Handler_Protected { $uid = $line["id"]; - print ""; + print ""; $line["login"] = htmlspecialchars($line["login"]); @@ -420,8 +420,7 @@ class Pref_Users extends Handler_Protected { $line["last_login"] = make_local_datetime($line["last_login"], false); print ""; + dojoType=\"dijit.form.CheckBox\" type=\"checkbox\">"; $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'"; diff --git a/js/functions.js b/js/functions.js index 6e61f4c9f..673e0e8f1 100755 --- a/js/functions.js +++ b/js/functions.js @@ -55,10 +55,14 @@ Array.prototype.remove = function(s) { const Lists = { onRowChecked: function(elem) { + const checked = elem.domNode ? elem.attr("checked") : elem.checked; // account for dojo checkboxes elem = elem.domNode || elem; - elem.up("li").toggleClassName("Selected"); + const row = elem.up("li"); + + if (row) + checked ? row.addClassName("Selected") : row.removeClassName("Selected"); } }; @@ -66,9 +70,30 @@ const Lists = { const Tables = { onRowChecked: function(elem) { // account for dojo checkboxes + const checked = elem.domNode ? elem.attr("checked") : elem.checked; elem = elem.domNode || elem; - elem.up("tr").toggleClassName("Selected"); + const row = elem.up("tr"); + + if (row) + checked ? row.addClassName("Selected") : row.removeClassName("Selected"); + + }, + select: function(elemId, selected) { + $(elemId).select("tr").each((row) => { + const checkNode = row.select(".dijitCheckBox,input[type=checkbox]")[0]; + if (checkNode) { + const widget = dijit.getEnclosingWidget(checkNode); + + if (widget) { + widget.attr("checked", selected); + } else { + checkNode.checked = selected; + } + + this.onRowChecked(widget); + } + }); }, getSelected: function(elemId) { const rv = []; @@ -1532,60 +1557,6 @@ function uploadFeedIcon() { return false; } -// mode = all, none, invert -function selectTableRows(id, mode) { - const rows = $(id).rows; - - for (let i = 0; i < rows.length; i++) { - const row = rows[i]; - let cb = false; - let dcb = false; - - if (row.id && row.className) { - const bare_id = row.id.replace(/^[A-Z]*?-/, ""); - const inputs = rows[i].getElementsByTagName("input"); - - for (let j = 0; j < inputs.length; j++) { - const input = inputs[j]; - - if (input.getAttribute("type") == "checkbox" && - input.id.match(bare_id)) { - - cb = input; - dcb = dijit.getEnclosingWidget(cb); - break; - } - } - - if (cb || dcb) { - const issel = row.hasClassName("Selected"); - - if (mode == "all" && !issel) { - row.addClassName("Selected"); - cb.checked = true; - if (dcb) dcb.set("checked", true); - } else if (mode == "none" && issel) { - row.removeClassName("Selected"); - cb.checked = false; - if (dcb) dcb.set("checked", false); - - } else if (mode == "invert") { - - if (issel) { - row.removeClassName("Selected"); - cb.checked = false; - if (dcb) dcb.set("checked", false); - } else { - row.addClassName("Selected"); - cb.checked = true; - if (dcb) dcb.set("checked", true); - } - } - } - } - } -} - // noinspection JSUnusedGlobalSymbols function label_to_feed_id(label) { return _label_base_index - 1 - Math.abs(label); 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-54-g00ecf 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 --- classes/pref/feeds.php | 14 ++-- js/PrefFeedTree.js | 207 +++++++++++++++++++++++++++++++++++++++++++++++ js/PrefLabelTree.js | 2 +- js/prefs.js | 216 ------------------------------------------------- 4 files changed, 215 insertions(+), 224 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 0a7fed7b2..697daeab2 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1192,13 +1192,13 @@ class Pref_Feeds extends Handler_Protected { print "
    "; print "
    ".__('Subscribe to feed')."
    "; - print "
    ".__('Edit selected feeds')."
    "; - print "
    ".__('Reset sort order')."
    "; - print "
    ".__('Batch subscribe')."
    "; - print "
    " + print "
    " .__('Unsubscribe')."
    "; print "
    "; @@ -1206,11 +1206,11 @@ class Pref_Feeds extends Handler_Protected { print "
    ". "" . __('Categories').""; print "
    "; - print "
    ".__('Add category')."
    "; - print "
    ".__('Reset sort order')."
    "; - print "
    ".__('Remove selected')."
    "; print "
    "; diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index afa644251..1f1c58f2f 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -109,6 +109,213 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio (id.match("root") && position == "over")); } }, + resetFeedOrder: function() { + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-feeds", method: "feedsortreset"}, () => { + updateFeedList(); + }); + }, + resetCatOrder: function() { + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-feeds", method: "catsortreset"}, () => { + updateFeedList(); + }); + }, + removeSelectedFeeds: function() { + const sel_rows = this.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; + }, + getSelectedCategories: function() { + const tree = this; + 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; + }, + removeSelectedCategories: function() { + const sel_rows = this.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; + }, + getSelectedFeeds: function() { + const tree = this; + 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; + }, + editSelectedFeed: function() { + const rows = this.getSelectedFeeds(); + + if (rows.length == 0) { + alert(__("No feeds are selected.")); + return; + } + + notify(""); + + if (rows.length > 1) { + return this.editMultiple(); + } else { + CommonDialogs.editFeed(rows[0], {}); + } + }, + editMultiple: function() { + const rows = this.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(); + }); + }, + createCategory: function() { + const title = prompt(__("Category title:")); + + if (title) { + notify_progress("Creating category..."); + + xhrPost("backend.php", {op: "pref-feeds", method: "addCat", cat: title}, () => { + notify(''); + updateFeedList(); + }); + } + }, + batchSubscribe: function() { + 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(); + } }); }); diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index c4c3ea103..e5eb595e5 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -38,7 +38,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible"; }, getSelectedLabels: function() { - const tree = dijit.byId("labelTree"); + const tree = this; const items = tree.model.getCheckedItems(); const rv = []; 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-54-g00ecf 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 --- classes/pref/feeds.php | 2 +- classes/pref/filters.php | 10 +- classes/pref/labels.php | 2 +- classes/pref/prefs.php | 2 +- js/PrefFeedTree.js | 7 ++ js/PrefFilterTree.js | 174 ++++++++++++++++++++++++++++- js/PrefLabelTree.js | 63 +++++++++++ js/prefs.js | 280 ----------------------------------------------- prefs.php | 2 +- 9 files changed, 252 insertions(+), 290 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 697daeab2..f34ed33eb 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1255,7 +1255,7 @@ class Pref_Feeds extends Handler_Protected { "; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index f9b4bfb2a..8fe3bbda6 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -800,17 +800,17 @@ class Pref_Filters extends Handler_Protected { print " "; - print " "; - print " "; - print " "; - print " "; print ""; # toolbar @@ -840,7 +840,7 @@ class Pref_Filters extends Handler_Protected { var bare_id = id.substr(id.indexOf(':')+1); if (id.match('FILTER:')) { - editFilter(bare_id); + dijit.byId('filterTree').editFilter(bare_id); } diff --git a/classes/pref/labels.php b/classes/pref/labels.php index ae68a6eb7..c52f8bd79 100644 --- a/classes/pref/labels.php +++ b/classes/pref/labels.php @@ -310,7 +310,7 @@ class Pref_Labels extends Handler_Protected { var bare_id = id.substr(id.indexOf(':')+1); if (id.match('LABEL:')) { - editLabel(bare_id); + dijit.byId('labelTree').editLabel(bare_id); } "; diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index ccbc829a3..47062f739 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -436,7 +436,7 @@ class Pref_Prefs extends Handler_Protected { onComplete: function(transport) { var msg = transport.responseText; if (quit) { - gotoMain(); + document.location.href = 'index.php'; } else { if (msg == 'PREFS_NEED_RELOAD') { window.location.reload(); diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index 1f1c58f2f..a23624c08 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -147,6 +147,13 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio return false; }, + checkInactiveFeeds: function() { + xhrPost("backend.php", {op: "pref-feeds", method: "getinactivefeeds"}, (transport) => { + if (parseInt(transport.responseText) > 0) { + Element.show(dijit.byId("pref_feeds_inactive_btn").domNode); + } + }); + }, getSelectedCategories: function() { const tree = this; const items = tree.model.getCheckedItems(); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 1167365d6..9940372dd 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -75,8 +75,180 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio this.inherited(arguments); this.tree.model.store.save(); }, - }); + getSelectedFilters: function() { + const tree = this; + const items = tree.model.getCheckedItems(); + const rv = []; + items.each(function (item) { + rv.push(tree.model.store.getValue(item, 'bare_id')); + }); + + return rv; + }, + resetFilterOrder: function() { + notify_progress("Loading, please wait..."); + + xhrPost("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => { + updateFilterList(); + }); + }, + joinSelectedFilters: function() { + 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(); + }); + } + }, + editSelectedFilter: function() { + const rows = this.getSelectedFilters(); + + if (rows.length == 0) { + alert(__("No filters are selected.")); + return; + } + + if (rows.length > 1) { + alert(__("Please select only one filter.")); + return; + } + + notify(""); + + this.editFilter(rows[0]); + }, + editFilter: function(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"; + + Filters.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(); + }, + removeSelectedFilters: function() { + const sel_rows = this.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; + }, + + + +}); }); diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index e5eb595e5..ba052eb07 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -48,6 +48,69 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f return rv; }, + editLabel: function(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(); + }, resetColors: function() { const labels = this.getSelectedLabels(); 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"; -} diff --git a/prefs.php b/prefs.php index 6ff81af74..13001788b 100644 --- a/prefs.php +++ b/prefs.php @@ -127,7 +127,7 @@
    -- cgit v1.2.3-54-g00ecf 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 --- classes/pref/feeds.php | 4 +- classes/pref/prefs.php | 14 +- classes/pref/system.php | 4 +- js/PrefFeedTree.js | 75 +++++++++- js/prefs.js | 387 +++++++++++++++++------------------------------- 5 files changed, 217 insertions(+), 267 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index f34ed33eb..a39090767 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1156,7 +1156,7 @@ class Pref_Feeds extends Handler_Protected { $inactive_button = ""; $feed_search = clean($_REQUEST["search"]); @@ -1249,7 +1249,7 @@ class Pref_Feeds extends Handler_Protected { if (id.match('FEED:')) { CommonDialogs.editFeed(bare_id); } else if (id.match('CAT:')) { - editCat(bare_id, item); + dijit.byId('feedTree').editCategory(bare_id, item); } "; return; } diff --git a/js/CommonDialogs.js b/js/CommonDialogs.js index cac4f9be1..cf21370d6 100644 --- a/js/CommonDialogs.js +++ b/js/CommonDialogs.js @@ -1,11 +1,30 @@ 'use strict' /* global __, ngettext */ define(["dojo/_base/declare"], function (declare) { + // noinspection JSUnusedGlobalSymbols return declare("fox.CommonDialogs", null, { closeInfoBox: function() { const dialog = dijit.byId("infoBox"); if (dialog) dialog.hide(); }, + uploadIconHandler: function(rc) { + switch (rc) { + case 0: + Notify.info("Upload complete."); + if (App.isPrefs()) { + Feeds.reload(); + } else { + setTimeout('Feeds.reload(false, false)', 50); + } + break; + case 1: + Notify.error("Upload failed: icon is too big."); + break; + case 2: + Notify.error("Upload failed."); + break; + } + }, removeFeedIcon: function(id) { if (confirm(__("Remove stored feed icon?"))) { Notify.progress("Removing feed icon...", true); diff --git a/js/common.js b/js/common.js index ec6381e31..1da3e6d1b 100755 --- a/js/common.js +++ b/js/common.js @@ -343,27 +343,6 @@ function fatalError(code, msg, ext_info) { return s.replace(/<\/?[^>]+(>|$)/g, ""); } */ -// noinspection JSUnusedGlobalSymbols -function uploadIconHandler(rc) { - switch (rc) { - case 0: - Notify.info("Upload complete."); - if (App.isPrefs()) { - Feeds.reload(); - } else { - setTimeout('Feeds.reload(false, false)', 50); - } - break; - case 1: - Notify.error("Upload failed: icon is too big."); - break; - case 2: - Notify.error("Upload failed."); - break; - } -} - - // noinspection JSUnusedGlobalSymbols function label_to_feed_id(label) { return _label_base_index - 1 - Math.abs(label); -- cgit v1.2.3-54-g00ecf 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 --- classes/feeds.php | 4 +- classes/pref/feeds.php | 4 +- js/AppBase.js | 325 +++++++++++++++++++++++++++++++++++++++++++++++- js/Article.js | 4 +- js/Feeds.js | 14 +-- js/Headlines.js | 26 ++-- js/Utils.js | 330 ------------------------------------------------- js/prefs.js | 25 ++-- js/tt-rss.js | 19 ++- 9 files changed, 370 insertions(+), 381 deletions(-) delete mode 100644 js/Utils.js (limited to 'classes/pref/feeds.php') diff --git a/classes/feeds.php b/classes/feeds.php index 1e62a9206..3c6c20f26 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -51,7 +51,7 @@ class Feeds extends Handler_Protected { $reply .= " + onclick=\"App.displayDlg('".__("Show as feed")."','generatedFeed', '$feed_id:$is_cat:$rss_link')\"> "; @@ -137,7 +137,7 @@ class Feeds extends Handler_Protected { //$reply .= ""; - $reply .= ""; $reply .= ""; diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 82cb84daf..961a09c28 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1306,7 +1306,7 @@ class Pref_Feeds extends Handler_Protected { print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds."); - print " "; PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, @@ -1323,7 +1323,7 @@ class Pref_Feeds extends Handler_Protected { print "

    "; - print " "; print " "; print ""; + "; - print "


    "; + print ""; + + print "

    "; - $opml_export_filename = "TinyTinyRSS_".date("Y-m-d").".opml"; + print "
    "; - print "

    " . __('Filename:') . - "  " . - __('Include settings') . ""; + print ""; - print "

    "; + print ""; + + print ""; print "
    "; - print "

    " . __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . "

    "; + print_notice(__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.')); print_warning("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds."); diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index 749e954cc..df42547b2 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -148,7 +148,85 @@ define(["dojo/_base/declare"], function (declare) { Notify.close(); }); } - } + }; + + Prefs.OPML = { + import: function() { + 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; + } + }, + onImportComplete: function(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 + }); + + dojo.connect(dialog, "onShow", function () { + Element.hide(iframe); + }); + + dialog.show(); + }, + export: function() { + console.log("export"); + window.open("backend.php?op=opml&method=export&" + dojo.formToQuery("opmlExportForm")); + }, + changeKey: function() { + 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; + }, + +}; return Prefs; }); 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-54-g00ecf 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 --- classes/dlg.php | 2 +- classes/pref/feeds.php | 8 ++++---- classes/pref/prefs.php | 10 +++++----- classes/pref/system.php | 4 ++-- js/PrefHelpers.js | 17 ++++++++--------- js/prefs.js | 2 +- 6 files changed, 21 insertions(+), 22 deletions(-) (limited to 'classes/pref/feeds.php') diff --git a/classes/dlg.php b/classes/dlg.php index 6617dfe07..7ac18bb90 100644 --- a/classes/dlg.php +++ b/classes/dlg.php @@ -49,7 +49,7 @@ class Dlg extends Handler_Protected { print "
    "; - print " "; print ""; print ""; @@ -1295,7 +1295,7 @@ class Pref_Feeds extends Handler_Protected { print "
    "; print ""; print "
    "; - print " "; - print ""; print " "; @@ -756,7 +756,7 @@ class Pref_Prefs extends Handler_Protected { if (count($tmppluginhost->get_all($plugin)) > 0) { if (in_array($name, $system_enabled)) { - print "
    "; } } @@ -816,7 +816,7 @@ class Pref_Prefs extends Handler_Protected { if (count($tmppluginhost->get_all($plugin)) > 0) { if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { - print ""; + print ""; } } diff --git a/classes/pref/system.php b/classes/pref/system.php index 17dfb10ca..d60b419cf 100644 --- a/classes/pref/system.php +++ b/classes/pref/system.php @@ -37,10 +37,10 @@ class Pref_System extends Handler_Protected { LIMIT 100"); print " "; + onclick=\"Helpers.updateEventLog()\">".__('Refresh')." "; print "  "; + class=\"btn-danger\" onclick=\"Helpers.clearEventLog()\">".__('Clear')." "; print "

    ".__("Clear data")."".__("Clear data")."".__("Clear data")."
    "; diff --git a/js/PrefHelpers.js b/js/PrefHelpers.js index df42547b2..e4ffb04ef 100644 --- a/js/PrefHelpers.js +++ b/js/PrefHelpers.js @@ -1,5 +1,5 @@ define(["dojo/_base/declare"], function (declare) { - Prefs = { + Helpers = { clearFeedAccessKeys: function() { if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) { Notify.progress("Clearing URLs..."); @@ -56,7 +56,7 @@ define(["dojo/_base/declare"], function (declare) { xhrPost("backend.php", query, () => { Notify.close(); - Prefs.editProfiles(); + Helpers.editProfiles(); }); } @@ -88,7 +88,7 @@ define(["dojo/_base/declare"], function (declare) { xhrPost("backend.php", query, () => { Notify.close(); - Prefs.editProfiles(); + Helpers.editProfiles(); }); } @@ -128,7 +128,7 @@ define(["dojo/_base/declare"], function (declare) { confirmReset: function() { if (confirm(__("Reset to defaults?"))) { xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => { - Prefs.refresh(); + Helpers.refresh(); Notify.info(transport.responseText); }); } @@ -138,7 +138,7 @@ define(["dojo/_base/declare"], function (declare) { Notify.progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => { - Prefs.refresh(); + Helpers.refresh(); }); } }, @@ -150,7 +150,7 @@ define(["dojo/_base/declare"], function (declare) { } }; - Prefs.OPML = { + Helpers.OPML = { import: function() { const opml_file = $("opml_file"); @@ -225,8 +225,7 @@ define(["dojo/_base/declare"], function (declare) { } return false; }, + }; -}; - - return Prefs; + return Helpers; }); 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-54-g00ecf