From f26d404890a55a34ed5779b6f36e949d38705e8d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 12:03:28 +0300 Subject: [PATCH] prefs: move other tree-related functions to respective trees --- classes/pref/feeds.php | 2 +- classes/pref/filters.php | 10 +- classes/pref/labels.php | 2 +- classes/pref/prefs.php | 2 +- js/PrefFeedTree.js | 7 + js/PrefFilterTree.js | 174 +++++++++++++++++++++++- js/PrefLabelTree.js | 63 +++++++++ js/prefs.js | 280 --------------------------------------- prefs.php | 2 +- 9 files changed, 252 insertions(+), 290 deletions(-) diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 697daeab2..f34ed33eb 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -1255,7 +1255,7 @@ class Pref_Feeds extends Handler_Protected { "; diff --git a/classes/pref/filters.php b/classes/pref/filters.php index f9b4bfb2a..8fe3bbda6 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -800,17 +800,17 @@ class Pref_Filters extends Handler_Protected { print " "; - print " "; - print " "; - print " "; - print " "; print ""; # 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); } diff --git a/classes/pref/labels.php b/classes/pref/labels.php index ae68a6eb7..c52f8bd79 100644 --- a/classes/pref/labels.php +++ b/classes/pref/labels.php @@ -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); } "; diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index ccbc829a3..47062f739 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -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(); diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index 1f1c58f2f..a23624c08 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -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(); diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 1167365d6..9940372dd 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -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; + }, + + + +}); }); diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index e5eb595e5..ba052eb07 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -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(); diff --git a/js/prefs.js b/js/prefs.js index 18facd9a9..2bad86168 100755 --- a/js/prefs.js +++ b/js/prefs.js @@ -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"; -} diff --git a/prefs.php b/prefs.php index 6ff81af74..13001788b 100644 --- a/prefs.php +++ b/prefs.php @@ -127,7 +127,7 @@