summaryrefslogtreecommitdiff
path: root/js/PrefFeedTree.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2018-12-02 11:50:53 +0300
committerAndrew Dolgov <[email protected]>2018-12-02 11:50:53 +0300
commit60cd4676943169a057518634e3060745e9112511 (patch)
treed07079f159e12174d5eb65b05d8b5eda62e16e19 /js/PrefFeedTree.js
parent2e985d173352487f96984577ac512a3639267edf (diff)
embed some pref-feed helper functions into the tree
Diffstat (limited to 'js/PrefFeedTree.js')
-rw-r--r--js/PrefFeedTree.js207
1 files changed, 207 insertions, 0 deletions
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();
+ }
});
});