embed some pref-feed helper functions into the tree

This commit is contained in:
Andrew Dolgov 2018-12-02 11:50:53 +03:00
parent 2e985d1733
commit 60cd467694
4 changed files with 215 additions and 224 deletions

View File

@ -1192,13 +1192,13 @@ class Pref_Feeds extends Handler_Protected {
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
print "<div onclick=\"CommonDialogs.quickAddFeed()\"
dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
print "<div onclick=\"editSelectedFeed()\"
print "<div onclick=\"dijit.byId('feedTree').editSelectedFeed()\"
dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
print "<div onclick=\"resetFeedOrder()\"
print "<div onclick=\"dijit.byId('feedTree').resetFeedOrder()\"
dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
print "<div onclick=\"batchSubscribe()\"
print "<div onclick=\"dijit.byId('feedTree').batchSubscribe()\"
dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
print "<div dojoType=\"dijit.MenuItem\" onclick=\"removeSelectedFeeds()\">"
print "<div dojoType=\"dijit.MenuItem\" onclick=\"dijit.byId('feedTree').removeSelectedFeeds()\">"
.__('Unsubscribe')."</div> ";
print "</div></div>";
@ -1206,11 +1206,11 @@ class Pref_Feeds extends Handler_Protected {
print "<div dojoType=\"dijit.form.DropDownButton\">".
"<span>" . __('Categories')."</span>";
print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
print "<div onclick=\"createCategory()\"
print "<div onclick=\"dijit.byId('feedTree').createCategory()\"
dojoType=\"dijit.MenuItem\">".__('Add category')."</div>";
print "<div onclick=\"resetCatOrder()\"
print "<div onclick=\"dijit.byId('feedTree').resetCatOrder()\"
dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
print "<div onclick=\"removeSelectedCategories()\"
print "<div onclick=\"dijit.byId('feedTree').removeSelectedCategories()\"
dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>";
print "</div></div>";

View File

@ -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();
}
});
});

View File

@ -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 = [];

View File

@ -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...");