prefs: move other tree-related functions to respective trees

This commit is contained in:
Andrew Dolgov 2018-12-02 12:03:28 +03:00
parent 60cd467694
commit f26d404890
9 changed files with 252 additions and 290 deletions

View File

@ -1255,7 +1255,7 @@ class Pref_Feeds extends Handler_Protected {
<script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
Element.hide(\"feedlistLoading\");
checkInactiveFeeds();
dijit.byId('feedTree').checkInactiveFeeds();
</script>
</div>";

View File

@ -800,17 +800,17 @@ class Pref_Filters extends Handler_Protected {
print "<button dojoType=\"dijit.form.Button\" onclick=\"return Filters.quickAddFilter()\">".
__('Create filter')."</button> ";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return joinSelectedFilters()\">".
print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').joinSelectedFilters()\">".
__('Combine')."</button> ";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return editSelectedFilter()\">".
print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').editSelectedFilter()\">".
__('Edit')."</button> ";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return resetFilterOrder()\">".
print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').resetFilterOrder()\">".
__('Reset sort order')."</button> ";
print "<button dojoType=\"dijit.form.Button\" onclick=\"return removeSelectedFilters()\">".
print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').removeSelectedFilters()\">".
__('Remove')."</button> ";
print "</div>"; # toolbar
@ -840,7 +840,7 @@ class Pref_Filters extends Handler_Protected {
var bare_id = id.substr(id.indexOf(':')+1);
if (id.match('FILTER:')) {
editFilter(bare_id);
dijit.byId('filterTree').editFilter(bare_id);
}
</script>

View File

@ -310,7 +310,7 @@ class Pref_Labels extends Handler_Protected {
var bare_id = id.substr(id.indexOf(':')+1);
if (id.match('LABEL:')) {
editLabel(bare_id);
dijit.byId('labelTree').editLabel(bare_id);
}
</script>
</div>";

View File

@ -436,7 +436,7 @@ class Pref_Prefs extends Handler_Protected {
onComplete: function(transport) {
var msg = transport.responseText;
if (quit) {
gotoMain();
document.location.href = 'index.php';
} else {
if (msg == 'PREFS_NEED_RELOAD') {
window.location.reload();

View File

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

View File

@ -75,8 +75,180 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
this.inherited(arguments);
this.tree.model.store.save();
},
});
getSelectedFilters: function() {
const tree = this;
const items = tree.model.getCheckedItems();
const rv = [];
items.each(function (item) {
rv.push(tree.model.store.getValue(item, 'bare_id'));
});
return rv;
},
resetFilterOrder: function() {
notify_progress("Loading, please wait...");
xhrPost("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => {
updateFilterList();
});
},
joinSelectedFilters: function() {
const rows = getSelectedFilters();
if (rows.length == 0) {
alert(__("No filters are selected."));
return;
}
if (confirm(__("Combine selected filters?"))) {
notify_progress("Joining filters...");
xhrPost("backend.php", {op: "pref-filters", method: "join", ids: rows.toString()}, () => {
updateFilterList();
});
}
},
editSelectedFilter: function() {
const rows = this.getSelectedFilters();
if (rows.length == 0) {
alert(__("No filters are selected."));
return;
}
if (rows.length > 1) {
alert(__("Please select only one filter."));
return;
}
notify("");
this.editFilter(rows[0]);
},
editFilter: function(id) {
const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id);
if (dijit.byId("feedEditDlg"))
dijit.byId("feedEditDlg").destroyRecursive();
if (dijit.byId("filterEditDlg"))
dijit.byId("filterEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "filterEditDlg",
title: __("Edit Filter"),
style: "width: 600px",
test: function () {
const query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test";
Filters.editFilterTest(query);
},
selectRules: function (select) {
$$("#filterDlg_Matches input[type=checkbox]").each(function (e) {
e.checked = select;
if (select)
e.parentNode.addClassName("Selected");
else
e.parentNode.removeClassName("Selected");
});
},
selectActions: function (select) {
$$("#filterDlg_Actions input[type=checkbox]").each(function (e) {
e.checked = select;
if (select)
e.parentNode.addClassName("Selected");
else
e.parentNode.removeClassName("Selected");
});
},
editRule: function (e) {
const li = e.parentNode;
const rule = li.getElementsByTagName("INPUT")[1].value;
Filters.addFilterRule(li, rule);
},
editAction: function (e) {
const li = e.parentNode;
const action = li.getElementsByTagName("INPUT")[1].value;
Filters.addFilterAction(li, action);
},
removeFilter: function () {
const msg = __("Remove filter?");
if (confirm(msg)) {
this.hide();
notify_progress("Removing filter...");
const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id};
xhrPost("backend.php", query, () => {
updateFilterList();
});
}
},
addAction: function () {
Filters.addFilterAction();
},
addRule: function () {
Filters.addFilterRule();
},
deleteAction: function () {
$$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
e.parentNode.removeChild(e)
});
},
deleteRule: function () {
$$("#filterDlg_Matches li[class*=Selected]").each(function (e) {
e.parentNode.removeChild(e)
});
},
execute: function () {
if (this.validate()) {
notify_progress("Saving data...", true);
xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => {
dialog.hide();
updateFilterList();
});
}
},
href: query
});
dialog.show();
},
removeSelectedFilters: function() {
const sel_rows = this.getSelectedFilters();
if (sel_rows.length > 0) {
if (confirm(__("Remove selected filters?"))) {
notify_progress("Removing selected filters...");
const query = {
op: "pref-filters", method: "remove",
ids: sel_rows.toString()
};
xhrPost("backend.php", query, () => {
updateFilterList();
});
}
} else {
alert(__("No filters are selected."));
}
return false;
},
});
});

View File

@ -48,6 +48,69 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f
return rv;
},
editLabel: function(id) {
const query = "backend.php?op=pref-labels&method=edit&id=" +
param_escape(id);
if (dijit.byId("labelEditDlg"))
dijit.byId("labelEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "labelEditDlg",
title: __("Label Editor"),
style: "width: 600px",
setLabelColor: function (id, fg, bg) {
let kind = '';
let color = '';
if (fg && bg) {
kind = 'both';
} else if (fg) {
kind = 'fg';
color = fg;
} else if (bg) {
kind = 'bg';
color = bg;
}
const e = $("LICID-" + id);
if (e) {
if (fg) e.style.color = fg;
if (bg) e.style.backgroundColor = bg;
}
const query = {
op: "pref-labels", method: "colorset", kind: kind,
ids: id, fg: fg, bg: bg, color: color
};
xhrPost("backend.php", query, () => {
updateFilterList(); // maybe there's labels in there
});
},
execute: function () {
if (this.validate()) {
const caption = this.attr('value').caption;
const fg_color = this.attr('value').fg_color;
const bg_color = this.attr('value').bg_color;
dijit.byId('labelTree').setNameById(id, caption);
this.setLabelColor(id, fg_color, bg_color);
this.hide();
xhrPost("backend.php", this.attr('value'), () => {
updateFilterList(); // maybe there's labels in there
});
}
},
href: query
});
dialog.show();
},
resetColors: function() {
const labels = this.getSelectedLabels();

View File

@ -148,14 +148,6 @@ function updateFeedList() {
});
}
function checkInactiveFeeds() {
xhrPost("backend.php", { op: "pref-feeds", method: "getinactivefeeds" }, (transport) => {
if (parseInt(transport.responseText) > 0) {
Element.show(dijit.byId("pref_feeds_inactive_btn").domNode);
}
});
}
function updateUsersList(sort_key) {
const user_search = $("user_search");
const search = user_search ? user_search.value : "";
@ -218,120 +210,10 @@ function editUser(id) {
dialog.show();
}
function editFilter(id) {
const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id);
if (dijit.byId("feedEditDlg"))
dijit.byId("feedEditDlg").destroyRecursive();
if (dijit.byId("filterEditDlg"))
dijit.byId("filterEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "filterEditDlg",
title: __("Edit Filter"),
style: "width: 600px",
test: function () {
const query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test";
editFilterTest(query);
},
selectRules: function (select) {
$$("#filterDlg_Matches input[type=checkbox]").each(function (e) {
e.checked = select;
if (select)
e.parentNode.addClassName("Selected");
else
e.parentNode.removeClassName("Selected");
});
},
selectActions: function (select) {
$$("#filterDlg_Actions input[type=checkbox]").each(function (e) {
e.checked = select;
if (select)
e.parentNode.addClassName("Selected");
else
e.parentNode.removeClassName("Selected");
});
},
editRule: function (e) {
const li = e.parentNode;
const rule = li.getElementsByTagName("INPUT")[1].value;
Filters.addFilterRule(li, rule);
},
editAction: function (e) {
const li = e.parentNode;
const action = li.getElementsByTagName("INPUT")[1].value;
Filters.addFilterAction(li, action);
},
removeFilter: function () {
const msg = __("Remove filter?");
if (confirm(msg)) {
this.hide();
notify_progress("Removing filter...");
const query = { op: "pref-filters", method: "remove", ids: this.attr('value').id };
xhrPost("backend.php", query, () => {
updateFilterList();
});
}
},
addAction: function () {
Filters.addFilterAction();
},
addRule: function () {
Filters.addFilterRule();
},
deleteAction: function () {
$$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
e.parentNode.removeChild(e)
});
},
deleteRule: function () {
$$("#filterDlg_Matches li[class*=Selected]").each(function (e) {
e.parentNode.removeChild(e)
});
},
execute: function () {
if (this.validate()) {
notify_progress("Saving data...", true);
xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => {
dialog.hide();
updateFilterList();
});
}
},
href: query
});
dialog.show();
}
function getSelectedUsers() {
return Tables.getSelected("prefUserList");
}
function getSelectedFilters() {
const tree = dijit.byId("filterTree");
const items = tree.model.getCheckedItems();
const rv = [];
items.each(function(item) {
rv.push(tree.model.store.getValue(item, 'bare_id'));
});
return rv;
}
function removeSelectedUsers() {
@ -357,28 +239,6 @@ function removeSelectedUsers() {
return false;
}
function removeSelectedFilters() {
const sel_rows = getSelectedFilters();
if (sel_rows.length > 0) {
if (confirm(__("Remove selected filters?"))) {
notify_progress("Removing selected filters...");
const query = { op: "pref-filters", method: "remove",
ids: sel_rows.toString() };
xhrPost("backend.php", query, () => {
updateFilterList();
});
}
} else {
alert(__("No filters are selected."));
}
return false;
}
function editSelectedUser() {
const rows = getSelectedUsers();
@ -455,43 +315,6 @@ function selectedUserDetails() {
dialog.show();
}
function editSelectedFilter() {
const rows = getSelectedFilters();
if (rows.length == 0) {
alert(__("No filters are selected."));
return;
}
if (rows.length > 1) {
alert(__("Please select only one filter."));
return;
}
notify("");
editFilter(rows[0]);
}
function joinSelectedFilters() {
const rows = getSelectedFilters();
if (rows.length == 0) {
alert(__("No filters are selected."));
return;
}
if (confirm(__("Combine selected filters?"))) {
notify_progress("Joining filters...");
xhrPost("backend.php", { op: "pref-filters", method: "join", ids: rows.toString() }, () => {
updateFilterList();
});
}
}
function opmlImportComplete(iframe) {
if (!iframe.contentDocument.body.innerHTML) return false;
@ -774,30 +597,6 @@ function editProfiles() {
dialog.show();
}
/*
function activatePrefProfile() {
const sel_rows = getSelectedFeedCats();
if (sel_rows.length == 1) {
const ok = confirm(__("Activate selected profile?"));
if (ok) {
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."));
}
return false;
} */
function clearFeedAccessKeys() {
if (confirm(__("This will invalidate all previously generated feed URLs. Continue?"))) {
@ -811,14 +610,6 @@ function clearFeedAccessKeys() {
return false;
}
function resetFilterOrder() {
notify_progress("Loading, please wait...");
xhrPost("backend.php", { op: "pref-filters", method: "filtersortreset" }, () => {
updateFilterList();
});
}
function editCat(id, item) {
const new_name = prompt(__('Rename category to:'), item.name);
@ -832,69 +623,6 @@ function editCat(id, item) {
}
}
function editLabel(id) {
const query = "backend.php?op=pref-labels&method=edit&id=" +
param_escape(id);
if (dijit.byId("labelEditDlg"))
dijit.byId("labelEditDlg").destroyRecursive();
const dialog = new dijit.Dialog({
id: "labelEditDlg",
title: __("Label Editor"),
style: "width: 600px",
setLabelColor: function (id, fg, bg) {
let kind = '';
let color = '';
if (fg && bg) {
kind = 'both';
} else if (fg) {
kind = 'fg';
color = fg;
} else if (bg) {
kind = 'bg';
color = bg;
}
const e = $("LICID-" + id);
if (e) {
if (fg) e.style.color = fg;
if (bg) e.style.backgroundColor = bg;
}
const query = { op: "pref-labels", method: "colorset", kind: kind,
ids: id, fg: fg, bg: bg, color: color };
xhrPost("backend.php", query, () => {
updateFilterList(); // maybe there's labels in there
});
},
execute: function () {
if (this.validate()) {
const caption = this.attr('value').caption;
const fg_color = this.attr('value').fg_color;
const bg_color = this.attr('value').bg_color;
dijit.byId('labelTree').setNameById(id, caption);
this.setLabelColor(id, fg_color, bg_color);
this.hide();
xhrPost("backend.php", this.attr('value'), () => {
updateFilterList(); // maybe there's labels in there
});
}
},
href: query
});
dialog.show();
}
function customizeCSS() {
const query = "backend.php?op=pref-prefs&method=customizeCSS";
@ -951,11 +679,3 @@ function clearSqlLog() {
}
}
function updateSelectedPrompt() {
// no-op shim for toggleSelectedRow()
}
function gotoMain() {
document.location.href = "index.php";
}

View File

@ -127,7 +127,7 @@
<div id="header" dojoType="dijit.layout.ContentPane" region="top">
<!-- <a href='#' onclick="showHelp()"><?php echo __("Keyboard shortcuts") ?></a> | -->
<a href="#" onclick="gotoMain()"><?php echo __('Exit preferences') ?></a>
<a href="#" onclick="document.location.href = 'index.php'"><?php echo __('Exit preferences') ?></a>
</div>
<div id="main" dojoType="dijit.layout.BorderContainer">