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/PrefFeedTree.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/PrefFeedTree.js') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index 9d6a9e86c..afa644251 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -55,13 +55,13 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio menu.addChild(new dijit.MenuItem({ label: __("Edit feed"), onClick: function() { - editFeed(this.getParent().row_id); + CommonDialogs.editFeed(this.getParent().row_id); }})); menu.addChild(new dijit.MenuItem({ label: __("Unsubscribe"), onClick: function() { - unsubscribeFeed(this.getParent().row_id, this.getParent().item.name); + CommonDialogs.unsubscribeFeed(this.getParent().row_id, this.getParent().item.name); }})); menu.bindDomNode(tnode.domNode); -- 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/PrefFeedTree.js | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) (limited to 'js/PrefFeedTree.js') 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(); + } }); }); -- 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/PrefFeedTree.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'js/PrefFeedTree.js') 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(); -- 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/PrefFeedTree.js | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'js/PrefFeedTree.js') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index a23624c08..afb56faa1 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -35,14 +35,14 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio menu.addChild(new dijit.MenuItem({ label: __("Edit category"), onClick: function() { - editCat(this.getParent().row_id, this.getParent().item, null); + dijit.byId("feedTree").editCategory(this.getParent().row_id, this.getParent().item, null); }})); menu.addChild(new dijit.MenuItem({ label: __("Remove category"), onClick: function() { - removeCategory(this.getParent().row_id, this.getParent().item); + dijit.byId("feedTree").removeCategory(this.getParent().row_id, this.getParent().item); }})); menu.bindDomNode(tnode.domNode); @@ -123,6 +123,16 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio updateFeedList(); }); }, + removeCategory: function(id, item) { + if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) { + notify_progress("Removing category..."); + + xhrPost("backend.php", {op: "pref-feeds", method: "removeCat", ids: id}, () => { + notify(''); + updateFeedList(); + }); + } + }, removeSelectedFeeds: function() { const sel_rows = this.getSelectedFeeds(); @@ -284,6 +294,22 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio dialog.show(); }); }, + editCategory: function(id, item) { + // uncategorized + if (String(item.id) == "CAT:0") + return; + + 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(); + }); + } + }, createCategory: function() { const title = prompt(__("Category title:")); @@ -321,6 +347,51 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio href: query }); + dialog.show(); + }, + showInactiveFeeds: function() { + 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(); } }); -- 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/PrefFeedTree.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'js/PrefFeedTree.js') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index afb56faa1..dbb188a34 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -82,6 +82,15 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio getIconClass: function (item, opened) { return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon"; }, + reload: function() { + const searchElem = $("feed_search"); + let search = (searchElem) ? searchElem.value : ""; + + xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => { + dijit.byId('feedConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, checkItemAcceptance: function(target, source, position) { const item = dijit.getEnclosingWidget(target).item; @@ -113,14 +122,14 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio notify_progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-feeds", method: "feedsortreset"}, () => { - updateFeedList(); + this.reload(); }); }, resetCatOrder: function() { notify_progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-feeds", method: "catsortreset"}, () => { - updateFeedList(); + this.reload(); }); }, removeCategory: function(id, item) { @@ -129,7 +138,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", {op: "pref-feeds", method: "removeCat", ids: id}, () => { notify(''); - updateFeedList(); + this.reload(); }); } }, @@ -147,7 +156,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }; xhrPost("backend.php", query, () => { - updateFeedList(); + this.reload(); }); } @@ -189,7 +198,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }; xhrPost("backend.php", query, () => { - updateFeedList(); + this.reload(); }); } } else { @@ -284,7 +293,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", query, () => { dialog.hide(); - updateFeedList(); + dijit.byId("feedTree").reload(); }); } }, @@ -306,7 +315,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio notify_progress("Loading, please wait..."); xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { - updateFeedList(); + this.reload(); }); } }, @@ -318,7 +327,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", {op: "pref-feeds", method: "addCat", cat: title}, () => { notify(''); - updateFeedList(); + this.reload(); }); } }, @@ -339,7 +348,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", this.attr('value'), () => { notify(""); - updateFeedList(); + dijit.byId("feedTree").reload(); dialog.hide(); }); } @@ -376,8 +385,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", query, () => { notify(''); + dijit.byId("feedTree").reload(); dialog.hide(); - updateFeedList(); }); } -- 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/PrefFeedTree.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/PrefFeedTree.js') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index dbb188a34..7beeadd38 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -161,7 +161,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } return false; @@ -202,7 +202,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }); } } else { - alert(__("No categories are selected.")); + alert(__("No categories selected.")); } return false; @@ -223,7 +223,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFeeds(); if (rows.length == 0) { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); return; } @@ -239,7 +239,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFeeds(); if (rows.length == 0) { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); return; } @@ -391,7 +391,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } } else { - alert(__("No feeds are selected.")); + alert(__("No feeds selected.")); } }, execute: function () { -- 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/PrefFeedTree.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'js/PrefFeedTree.js') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index 7beeadd38..accc4f0e5 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -88,7 +88,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => { dijit.byId('feedConfigTab').attr('content', transport.responseText); - notify(""); + Notify.close(); }); }, checkItemAcceptance: function(target, source, position) { @@ -119,14 +119,14 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } }, resetFeedOrder: function() { - notify_progress("Loading, please wait..."); + Notify.progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-feeds", method: "feedsortreset"}, () => { this.reload(); }); }, resetCatOrder: function() { - notify_progress("Loading, please wait..."); + Notify.progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-feeds", method: "catsortreset"}, () => { this.reload(); @@ -134,10 +134,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }, removeCategory: function(id, item) { if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) { - notify_progress("Removing category..."); + Notify.progress("Removing category..."); xhrPost("backend.php", {op: "pref-feeds", method: "removeCat", ids: id}, () => { - notify(''); + Notify.close(); this.reload(); }); } @@ -148,7 +148,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio if (sel_rows.length > 0) { if (confirm(__("Unsubscribe from selected feeds?"))) { - notify_progress("Unsubscribing from selected feeds...", true); + Notify.progress("Unsubscribing from selected feeds...", true); const query = { op: "pref-feeds", method: "remove", @@ -190,7 +190,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio if (sel_rows.length > 0) { if (confirm(__("Remove selected categories?"))) { - notify_progress("Removing selected categories..."); + Notify.progress("Removing selected categories..."); const query = { op: "pref-feeds", method: "removeCat", @@ -227,7 +227,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio return; } - notify(""); + Notify.close(); if (rows.length > 1) { return this.editMultiple(); @@ -243,13 +243,13 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio return; } - notify_progress("Loading, please wait..."); + 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(""); + Notify.close(); const dialog = new dijit.Dialog({ id: "feedEditDlg", @@ -289,7 +289,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio query[key] = ["off"]; }); - notify_progress("Saving data...", true); + Notify.progress("Saving data...", true); xhrPost("backend.php", query, () => { dialog.hide(); @@ -312,7 +312,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio if (new_name && new_name != item.name) { - notify_progress("Loading, please wait..."); + Notify.progress("Loading, please wait..."); xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => { this.reload(); @@ -323,10 +323,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const title = prompt(__("Category title:")); if (title) { - notify_progress("Creating category..."); + Notify.progress("Creating category..."); xhrPost("backend.php", {op: "pref-feeds", method: "addCat", cat: title}, () => { - notify(''); + Notify.close(); this.reload(); }); } @@ -344,10 +344,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio style: "width: 600px", execute: function () { if (this.validate()) { - notify_progress(__("Subscribing to feeds..."), true); + Notify.progress(__("Subscribing to feeds..."), true); xhrPost("backend.php", this.attr('value'), () => { - notify(""); + Notify.close(); dijit.byId("feedTree").reload(); dialog.hide(); }); @@ -376,7 +376,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio if (sel_rows.length > 0) { if (confirm(__("Remove selected feeds?"))) { - notify_progress("Removing selected feeds...", true); + Notify.progress("Removing selected feeds...", true); const query = { op: "pref-feeds", method: "remove", @@ -384,7 +384,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }; xhrPost("backend.php", query, () => { - notify(''); + Notify.close(); dijit.byId("feedTree").reload(); dialog.hide(); }); -- cgit v1.2.3