prefs: move more global functions into matching classes

master
Andrew Dolgov 6 years ago
parent 50a4c2d723
commit 58e54282d3

@ -1156,7 +1156,7 @@ class Pref_Feeds extends Handler_Protected {
$inactive_button = "<button dojoType=\"dijit.form.Button\"
id=\"pref_feeds_inactive_btn\"
style=\"display : none\"
onclick=\"showInactiveFeeds()\">" .
onclick=\"dijit.byId('feedTree').showInactiveFeeds()\">" .
__("Inactive feeds") . "</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);
}
</script>
<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">

@ -542,7 +542,7 @@ class Pref_Prefs extends Handler_Protected {
} else if ($pref_name == "USER_STYLESHEET") {
print "<button dojoType=\"dijit.form.Button\"
onclick=\"customizeCSS()\">" . __('Customize') . "</button>";
onclick=\"Prefs.customizeCSS()\">" . __('Customize') . "</button>";
} else if ($pref_name == "USER_CSS_THEME") {
@ -608,11 +608,11 @@ class Pref_Prefs extends Handler_Protected {
print "<br/>";
print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\"
onclick=\"insertSSLserial('$cert_serial')\">" .
onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')\">" .
__('Register') . "</button>";
print " <button dojoType=\"dijit.form.Button\"
onclick=\"insertSSLserial('')\">" .
onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '')\">" .
__('Clear') . "</button>";
} else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
@ -659,10 +659,10 @@ class Pref_Prefs extends Handler_Protected {
</div>
</div>";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">".
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Prefs.editProfiles()\">".
__('Manage profiles')."</button> ";
print "<button dojoType=\"dijit.form.Button\" class=\"btn-danger\" onclick=\"return validatePrefsReset()\">".
print "<button dojoType=\"dijit.form.Button\" class=\"btn-danger\" onclick=\"return Prefs.confirmReset()\">".
__('Reset to defaults')."</button>";
print "&nbsp;";
@ -756,7 +756,7 @@ class Pref_Prefs extends Handler_Protected {
if (count($tmppluginhost->get_all($plugin)) > 0) {
if (in_array($name, $system_enabled)) {
print "<td><a href='#' onclick=\"clearPluginData('$name')\"
print "<td><a href='#' onclick=\"Prefs.clearPluginData('$name')\"
class='visibleLink'>".__("Clear data")."</a></td>";
}
}
@ -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 "<td><a href='#' onclick=\"clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
print "<td><a href='#' onclick=\"Prefs.clearPluginData('$name')\" class='visibleLink'>".__("Clear data")."</a></td>";
}
}

@ -26,7 +26,7 @@ class Pref_System extends Handler_Protected {
function index() {
print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">";
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Error Log')."\">";
print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Event Log')."\">";
if (LOG_DESTINATION == "sql") {
@ -40,7 +40,7 @@ class Pref_System extends Handler_Protected {
onclick=\"updateSystemList()\">".__('Refresh')."</button> ";
print "&nbsp;<button dojoType=\"dijit.form.Button\"
onclick=\"clearSqlLog()\">".__('Clear log')."</button> ";
class=\"btn-danger\" onclick=\"Prefs.clearEventLog()\">".__('Clear')."</button> ";
print "<p><table width=\"100%\" cellspacing=\"10\" class=\"prefErrorLog\">";

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

@ -131,6 +131,139 @@ const App = {
}
};
const Prefs = {
clearEventLog: function() {
if (confirm(__("Clear event log?"))) {
notify_progress("Loading, please wait...");
xhrPost("backend.php", {op: "pref-system", method: "clearLog"}, () => {
updateSystemList();
});
}
},
editProfiles: function() {
if (dijit.byId("profileEditDlg"))
dijit.byId("profileEditDlg").destroyRecursive();
const query = "backend.php?op=pref-prefs&method=editPrefProfiles";
const dialog = new dijit.Dialog({
id: "profileEditDlg",
title: __("Settings Profiles"),
style: "width: 600px",
getSelectedProfiles: function () {
return Tables.getSelected("prefFeedProfileList");
},
removeSelected: function () {
const sel_rows = this.getSelectedProfiles();
if (sel_rows.length > 0) {
if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) {
notify_progress("Removing selected profiles...", true);
const query = {
op: "rpc", method: "remprofiles",
ids: sel_rows.toString()
};
xhrPost("backend.php", query, () => {
notify('');
Prefs.editProfiles();
});
}
} else {
alert(__("No profiles are selected."));
}
},
activateProfile: function () {
const sel_rows = this.getSelectedProfiles();
if (sel_rows.length == 1) {
if (confirm(__("Activate selected profile?"))) {
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."));
}
},
addProfile: function () {
if (this.validate()) {
notify_progress("Creating profile...", true);
const query = {op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile};
xhrPost("backend.php", query, () => {
notify('');
Prefs.editProfiles();
});
}
},
execute: function () {
if (this.validate()) {
}
},
href: query
});
dialog.show();
},
customizeCSS: function() {
const query = "backend.php?op=pref-prefs&method=customizeCSS";
if (dijit.byId("cssEditDlg"))
dijit.byId("cssEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "cssEditDlg",
title: __("Customize stylesheet"),
style: "width: 600px",
execute: function () {
notify_progress('Saving data...', true);
xhrPost("backend.php", this.attr('value'), () => {
window.location.reload();
});
},
href: query
});
dialog.show();
},
confirmReset: function() {
if (confirm(__("Reset to defaults?"))) {
xhrPost("backend.php", {op: "pref-prefs", method: "resetconfig"}, (transport) => {
Prefs.refresh();
notify_info(transport.responseText);
});
}
},
clearPluginData: function(name) {
if (confirm(__("Clear stored data for this plugin?"))) {
notify_progress("Loading, please wait...");
xhrPost("backend.php", {op: "pref-prefs", method: "clearplugindata", name: name}, () => {
Prefs.refresh();
});
}
},
refresh: function() {
xhrPost("backend.php", { op: "pref-prefs" }, (transport) => {
dijit.byId('genConfigTab').attr('content', transport.responseText);
notify("");
});
}
};
function notify_callback2(transport, sticky) {
notify_info(transport.responseText, sticky);
}
@ -143,7 +276,6 @@ function updateFeedList() {
xhrPost("backend.php", { op: "pref-feeds", search: search }, (transport) => {
dijit.byId('feedConfigTab').attr('content', transport.responseText);
selectTab("feedConfig", true);
notify("");
});
}
@ -156,7 +288,6 @@ function updateUsersList(sort_key) {
xhrPost("backend.php", query, (transport) => {
dijit.byId('userConfigTab').attr('content', transport.responseText);
selectTab("userConfig", true)
notify("");
});
}
@ -359,7 +490,6 @@ function opmlImport() {
}
}
function updateFilterList() {
const user_search = $("filter_search");
let search = "";
@ -378,13 +508,6 @@ function updateLabelList() {
});
}
function updatePrefsList() {
xhrPost("backend.php", { op: "pref-prefs" }, (transport) => {
dijit.byId('genConfigTab').attr('content', transport.responseText);
notify("");
});
}
function updateSystemList() {
xhrPost("backend.php", { op: "pref-system" }, (transport) => {
dijit.byId('systemConfigTab').attr('content', transport.responseText);
@ -392,112 +515,6 @@ function updateSystemList() {
});
}
function selectTab(id, selectOnly) {
if (!selectOnly) {
notify_progress("Loading, please wait...");
switch (id) {
case "feedConfig":
updateFeedList();
break;
case "filterConfig":
updateFilterList();
break;
case "labelConfig":
updateLabelList();
break;
case "genConfig":
updatePrefsList();
break;
case "userConfig":
updateUsersList();
break;
case "systemConfig":
updateSystemList();
break;
default:
console.warn("unknown tab", id);
}
const tab = dijit.byId(id + "Tab");
dijit.byId("pref-tabs").selectChild(tab);
}
}
function validatePrefsReset() {
if (confirm(__("Reset to defaults?"))) {
const query = "?op=pref-prefs&method=resetconfig";
xhrPost("backend.php", { op: "pref-prefs", method: "resetconfig" }, (transport) => {
updatePrefsList();
notify_info(transport.responseText);
});
}
return false;
}
function removeCategory(id, item) {
if (confirm(__("Remove category %s? Any nested feeds would be placed into Uncategorized.").replace("%s", item.name))) {
notify_progress("Removing category...");
const query = { op: "pref-feeds", method: "removeCat",
ids: id };
xhrPost("backend.php", query, () => {
notify('');
updateFeedList();
});
}
}
function showInactiveFeeds() {
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();
}
function opmlRegenKey() {
if (confirm(__("Replace current OPML publishing address with a new one?"))) {
notify_progress("Trying to change address...", true);
@ -524,79 +541,6 @@ function opmlRegenKey() {
return false;
}
function editProfiles() {
if (dijit.byId("profileEditDlg"))
dijit.byId("profileEditDlg").destroyRecursive();
const query = "backend.php?op=pref-prefs&method=editPrefProfiles";
const dialog = new dijit.Dialog({
id: "profileEditDlg",
title: __("Settings Profiles"),
style: "width: 600px",
getSelectedProfiles: function () {
return Tables.getSelected("prefFeedProfileList");
},
removeSelected: function () {
const sel_rows = this.getSelectedProfiles();
if (sel_rows.length > 0) {
if (confirm(__("Remove selected profiles? Active and default profiles will not be removed."))) {
notify_progress("Removing selected profiles...", true);
const query = { op: "rpc", method: "remprofiles",
ids: sel_rows.toString() };
xhrPost("backend.php", query, () => {
notify('');
editProfiles();
});
}
} else {
alert(__("No profiles are selected."));
}
},
activateProfile: function () {
const sel_rows = this.getSelectedProfiles();
if (sel_rows.length == 1) {
if (confirm(__("Activate selected profile?"))) {
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."));
}
},
addProfile: function () {
if (this.validate()) {
notify_progress("Creating profile...", true);
const query = { op: "rpc", method: "addprofile", title: dialog.attr('value').newprofile };
xhrPost("backend.php", query, () => {
notify('');
editProfiles();
});
}
},
execute: function () {
if (this.validate()) {
}
},
href: query
});
dialog.show();
}
function clearFeedAccessKeys() {
if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) {
@ -610,72 +554,7 @@ function clearFeedAccessKeys() {
return false;
}
function editCat(id, item) {
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();
});
}
}
function customizeCSS() {
const query = "backend.php?op=pref-prefs&method=customizeCSS";
if (dijit.byId("cssEditDlg"))
dijit.byId("cssEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "cssEditDlg",
title: __("Customize stylesheet"),
style: "width: 600px",
execute: function () {
notify_progress('Saving data...', true);
xhrPost("backend.php", this.attr('value'), () => {
window.location.reload();
});
},
href: query
});
dialog.show();
}
function insertSSLserial(value) {
dijit.byId("SSL_CERT_SERIAL").attr('value', value);
}
function gotoExportOpml(filename, settings) {
const tmp = settings ? 1 : 0;
document.location.href = "backend.php?op=opml&method=export&filename=" + filename + "&settings=" + tmp;
}
function clearPluginData(name) {
if (confirm(__("Clear stored data for this plugin?"))) {
notify_progress("Loading, please wait...");
xhrPost("backend.php", { op: "pref-prefs", method: "clearplugindata", name: name }, () => {
notify('');
updatePrefsList();
});
}
}
function clearSqlLog() {
if (confirm(__("Clear all messages in the error log?"))) {
notify_progress("Loading, please wait...");
xhrPost("backend.php", { op: "pref-system", method: "clearLog" }, () => {
updateSystemList();
});
}
}

Loading…
Cancel
Save