2020-06-04 20:27:22 +00:00
|
|
|
/* global __, lib, dijit, define, dojo, CommonDialogs, Notify, Tables, xhrPost */
|
|
|
|
|
2018-08-23 06:56:34 +00:00
|
|
|
define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
return declare("fox.PrefFeedTree", lib.CheckBoxTree, {
|
|
|
|
_createTreeNode: function(args) {
|
2018-11-29 18:21:06 +00:00
|
|
|
const tnode = this.inherited(arguments);
|
2016-08-10 10:40:24 +00:00
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
const icon = dojo.doc.createElement('img');
|
2017-05-27 17:25:59 +00:00
|
|
|
if (args.item.icon && args.item.icon[0]) {
|
2017-01-20 17:29:59 +00:00
|
|
|
icon.src = args.item.icon[0];
|
2017-05-27 17:25:59 +00:00
|
|
|
} else {
|
|
|
|
icon.src = 'images/blank_icon.gif';
|
2017-01-20 17:29:59 +00:00
|
|
|
}
|
2018-12-05 17:26:27 +00:00
|
|
|
icon.className = 'icon';
|
2017-05-27 17:25:59 +00:00
|
|
|
domConstruct.place(icon, tnode.iconNode, 'only');
|
2016-08-10 10:40:24 +00:00
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
let param = this.model.store.getValue(args.item, 'param');
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
if (param) {
|
|
|
|
param = dojo.doc.createElement('span');
|
|
|
|
param.className = 'feedParam';
|
|
|
|
param.innerHTML = args.item.param[0];
|
2017-01-21 17:54:36 +00:00
|
|
|
//domConstruct.place(param, tnode.labelNode, 'after');
|
|
|
|
domConstruct.place(param, tnode.rowNode, 'first');
|
2016-08-10 10:40:24 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
const id = args.item.id[0];
|
|
|
|
const bare_id = parseInt(id.substr(id.indexOf(':')+1));
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
if (id.match("CAT:") && bare_id > 0) {
|
|
|
|
var menu = new dijit.Menu();
|
|
|
|
menu.row_id = bare_id;
|
|
|
|
menu.item = args.item;
|
|
|
|
|
|
|
|
menu.addChild(new dijit.MenuItem({
|
|
|
|
label: __("Edit category"),
|
|
|
|
onClick: function() {
|
2018-12-02 12:30:07 +00:00
|
|
|
dijit.byId("feedTree").editCategory(this.getParent().row_id, this.getParent().item, null);
|
2016-08-10 10:40:24 +00:00
|
|
|
}}));
|
|
|
|
|
|
|
|
|
|
|
|
menu.addChild(new dijit.MenuItem({
|
|
|
|
label: __("Remove category"),
|
|
|
|
onClick: function() {
|
2018-12-02 12:30:07 +00:00
|
|
|
dijit.byId("feedTree").removeCategory(this.getParent().row_id, this.getParent().item);
|
2016-08-10 10:40:24 +00:00
|
|
|
}}));
|
|
|
|
|
|
|
|
menu.bindDomNode(tnode.domNode);
|
|
|
|
tnode._menu = menu;
|
|
|
|
} else if (id.match("FEED:")) {
|
|
|
|
var menu = new dijit.Menu();
|
|
|
|
menu.row_id = bare_id;
|
|
|
|
menu.item = args.item;
|
|
|
|
|
|
|
|
menu.addChild(new dijit.MenuItem({
|
|
|
|
label: __("Edit feed"),
|
|
|
|
onClick: function() {
|
2018-12-01 19:39:29 +00:00
|
|
|
CommonDialogs.editFeed(this.getParent().row_id);
|
2016-08-10 10:40:24 +00:00
|
|
|
}}));
|
|
|
|
|
|
|
|
menu.addChild(new dijit.MenuItem({
|
|
|
|
label: __("Unsubscribe"),
|
|
|
|
onClick: function() {
|
2018-12-01 19:39:29 +00:00
|
|
|
CommonDialogs.unsubscribeFeed(this.getParent().row_id, this.getParent().item.name);
|
2016-08-10 10:40:24 +00:00
|
|
|
}}));
|
|
|
|
|
|
|
|
menu.bindDomNode(tnode.domNode);
|
|
|
|
tnode._menu = menu;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return tnode;
|
|
|
|
},
|
|
|
|
onDndDrop: function() {
|
|
|
|
this.inherited(arguments);
|
|
|
|
this.tree.model.store.save();
|
|
|
|
},
|
|
|
|
getRowClass: function (item, opened) {
|
2018-12-08 13:10:37 +00:00
|
|
|
let rc = (!item.error || item.error == '') ? "dijitTreeRow" :
|
2016-08-10 10:40:24 +00:00
|
|
|
"dijitTreeRow Error";
|
2018-12-08 13:10:37 +00:00
|
|
|
|
|
|
|
if (item.updates_disabled > 0) rc += " UpdatesDisabled";
|
|
|
|
|
|
|
|
return rc;
|
2016-08-10 10:40:24 +00:00
|
|
|
},
|
|
|
|
getIconClass: function (item, opened) {
|
2018-12-05 17:26:27 +00:00
|
|
|
return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feed-icon";
|
2016-08-10 10:40:24 +00:00
|
|
|
},
|
2018-12-02 13:17:36 +00:00
|
|
|
reload: function() {
|
|
|
|
const searchElem = $("feed_search");
|
|
|
|
let search = (searchElem) ? searchElem.value : "";
|
|
|
|
|
|
|
|
xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => {
|
2021-02-11 12:49:32 +00:00
|
|
|
dijit.byId('feedsTab').attr('content', transport.responseText);
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 13:17:36 +00:00
|
|
|
});
|
|
|
|
},
|
2016-08-10 10:40:24 +00:00
|
|
|
checkItemAcceptance: function(target, source, position) {
|
2018-11-29 18:21:06 +00:00
|
|
|
const item = dijit.getEnclosingWidget(target).item;
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
// disable copying items
|
|
|
|
source.copyState = function() { return false; };
|
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
let source_item = false;
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
source.forInSelectedItems(function(node) {
|
|
|
|
source_item = node.data.item;
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!source_item || !item) return false;
|
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
const id = this.tree.model.store.getValue(item, 'id');
|
|
|
|
const source_id = source.tree.model.store.getValue(source_item, 'id');
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
//console.log(id + " " + position + " " + source_id);
|
|
|
|
|
|
|
|
if (source_id.match("FEED:")) {
|
|
|
|
return ((id.match("CAT:") && position == "over") ||
|
2010-11-18 07:15:14 +00:00
|
|
|
(id.match("FEED:") && position != "over"));
|
2016-08-10 10:40:24 +00:00
|
|
|
} else if (source_id.match("CAT:")) {
|
|
|
|
return ((id.match("CAT:") && !id.match("CAT:0")) ||
|
2010-11-18 07:15:14 +00:00
|
|
|
(id.match("root") && position == "over"));
|
2016-08-10 10:40:24 +00:00
|
|
|
}
|
|
|
|
},
|
2018-12-02 08:50:53 +00:00
|
|
|
resetFeedOrder: function() {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Loading, please wait...");
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-feeds", method: "feedsortreset"}, () => {
|
2018-12-02 13:17:36 +00:00
|
|
|
this.reload();
|
2018-12-02 08:50:53 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
resetCatOrder: function() {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Loading, please wait...");
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-feeds", method: "catsortreset"}, () => {
|
2018-12-02 13:17:36 +00:00
|
|
|
this.reload();
|
2018-12-02 08:50:53 +00:00
|
|
|
});
|
|
|
|
},
|
2018-12-02 12:30:07 +00:00
|
|
|
removeCategory: function(id, item) {
|
|
|
|
if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing category...");
|
2018-12-02 12:30:07 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-feeds", method: "removeCat", ids: id}, () => {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 13:17:36 +00:00
|
|
|
this.reload();
|
2018-12-02 12:30:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2018-12-02 08:50:53 +00:00
|
|
|
removeSelectedFeeds: function() {
|
|
|
|
const sel_rows = this.getSelectedFeeds();
|
|
|
|
|
|
|
|
if (sel_rows.length > 0) {
|
|
|
|
if (confirm(__("Unsubscribe from selected feeds?"))) {
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Unsubscribing from selected feeds...", true);
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
const query = {
|
|
|
|
op: "pref-feeds", method: "remove",
|
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 13:17:36 +00:00
|
|
|
this.reload();
|
2018-12-02 08:50:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No feeds selected."));
|
2018-12-02 08:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
2018-12-02 09:03:28 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2018-12-02 08:50:53 +00:00
|
|
|
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?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing selected categories...");
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
const query = {
|
|
|
|
op: "pref-feeds", method: "removeCat",
|
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 13:17:36 +00:00
|
|
|
this.reload();
|
2018-12-02 08:50:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No categories selected."));
|
2018-12-02 08:50:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No feeds selected."));
|
2018-12-02 08:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
if (rows.length > 1) {
|
|
|
|
return this.editMultiple();
|
|
|
|
} else {
|
|
|
|
CommonDialogs.editFeed(rows[0], {});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
editMultiple: function() {
|
|
|
|
const rows = this.getSelectedFeeds();
|
|
|
|
|
|
|
|
if (rows.length == 0) {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No feeds selected."));
|
2018-12-02 08:50:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Loading, please wait...");
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
if (dijit.byId("feedEditDlg"))
|
|
|
|
dijit.byId("feedEditDlg").destroyRecursive();
|
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-feeds", method: "editfeeds", ids: rows.toString()}, (transport) => {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
const dialog = new dijit.Dialog({
|
|
|
|
id: "feedEditDlg",
|
|
|
|
title: __("Edit Multiple Feeds"),
|
|
|
|
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)
|
2019-03-08 07:11:57 +00:00
|
|
|
$(label).removeClassName('text-muted');
|
2018-12-02 08:50:53 +00:00
|
|
|
else
|
2019-03-08 07:11:57 +00:00
|
|
|
$(label).addClassName('text-muted');
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
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"];
|
|
|
|
});
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Saving data...", true);
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
|
|
|
dialog.hide();
|
2018-12-02 13:17:36 +00:00
|
|
|
dijit.byId("feedTree").reload();
|
2018-12-02 08:50:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
content: transport.responseText
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
});
|
|
|
|
},
|
2018-12-02 12:30:07 +00:00
|
|
|
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) {
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Loading, please wait...");
|
2018-12-02 12:30:07 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", { op: 'pref-feeds', method: 'renamecat', id: id, title: new_name }, () => {
|
2018-12-02 13:17:36 +00:00
|
|
|
this.reload();
|
2018-12-02 12:30:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2018-12-02 08:50:53 +00:00
|
|
|
createCategory: function() {
|
|
|
|
const title = prompt(__("Category title:"));
|
|
|
|
|
|
|
|
if (title) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Creating category...");
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-feeds", method: "addCat", cat: title}, () => {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 13:17:36 +00:00
|
|
|
this.reload();
|
2018-12-02 08:50:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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"),
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress(__("Subscribing to feeds..."), true);
|
2018-12-02 08:50:53 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", this.attr('value'), () => {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 13:17:36 +00:00
|
|
|
dijit.byId("feedTree").reload();
|
2018-12-02 08:50:53 +00:00
|
|
|
dialog.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
href: query
|
|
|
|
});
|
|
|
|
|
2018-12-02 12:30:07 +00:00
|
|
|
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"),
|
|
|
|
getSelectedFeeds: function () {
|
2018-12-07 11:03:33 +00:00
|
|
|
return Tables.getSelected("inactive-feeds-list");
|
2018-12-02 12:30:07 +00:00
|
|
|
},
|
|
|
|
removeSelected: function () {
|
|
|
|
const sel_rows = this.getSelectedFeeds();
|
|
|
|
|
|
|
|
if (sel_rows.length > 0) {
|
|
|
|
if (confirm(__("Remove selected feeds?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing selected feeds...", true);
|
2018-12-02 12:30:07 +00:00
|
|
|
|
|
|
|
const query = {
|
|
|
|
op: "pref-feeds", method: "remove",
|
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 13:17:36 +00:00
|
|
|
dijit.byId("feedTree").reload();
|
2018-12-02 12:30:07 +00:00
|
|
|
dialog.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No feeds selected."));
|
2018-12-02 12:30:07 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
href: query
|
|
|
|
});
|
|
|
|
|
2018-12-02 08:50:53 +00:00
|
|
|
dialog.show();
|
|
|
|
}
|
2016-08-10 10:40:24 +00:00
|
|
|
});
|
2010-11-17 20:32:32 +00:00
|
|
|
});
|
|
|
|
|