From f26d404890a55a34ed5779b6f36e949d38705e8d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 12:03:28 +0300 Subject: prefs: move other tree-related functions to respective trees --- js/PrefFilterTree.js | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 173 insertions(+), 1 deletion(-) (limited to 'js/PrefFilterTree.js') 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; + }, + + + +}); }); -- cgit v1.2.3 From 3a6dae92034791c199f9ddb4c60b8298b22c1d47 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:29:00 +0300 Subject: prefs: more of the same, really --- js/PrefFilterTree.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'js/PrefFilterTree.js') diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 9940372dd..37a99be89 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -86,11 +86,21 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio return rv; }, + reload: function() { + const user_search = $("filter_search"); + let search = ""; + if (user_search) { search = user_search.value; } + + xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { + dijit.byId('filterConfigTab').attr('content', transport.responseText); + notify(""); + }); + }, resetFilterOrder: function() { notify_progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => { - updateFilterList(); + this.reload(); }); }, joinSelectedFilters: function() { @@ -105,7 +115,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio notify_progress("Joining filters..."); xhrPost("backend.php", {op: "pref-filters", method: "join", ids: rows.toString()}, () => { - updateFilterList(); + this.reload(); }); } }, @@ -187,7 +197,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id}; xhrPost("backend.php", query, () => { - updateFilterList(); + dijit.byId("filterTree").reload(); }); } }, @@ -214,7 +224,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => { dialog.hide(); - updateFilterList(); + dijit.byId("filterTree").reload(); }); } }, @@ -236,7 +246,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }; xhrPost("backend.php", query, () => { - updateFilterList(); + this.reload(); }); } } else { -- cgit v1.2.3 From 35ded4bc844d74f120196012c194be9ab5517688 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 16:30:32 +0300 Subject: edit phrasing of some alert()s --- js/PrefFilterTree.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'js/PrefFilterTree.js') diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 37a99be89..9a2dd6c1c 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -107,7 +107,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = getSelectedFilters(); if (rows.length == 0) { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); return; } @@ -123,7 +123,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio const rows = this.getSelectedFilters(); if (rows.length == 0) { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); return; } @@ -250,7 +250,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }); } } else { - alert(__("No filters are selected.")); + alert(__("No filters selected.")); } return false; -- cgit v1.2.3 From d9c5c93cef313127b9b5010fbe279fdbddedadec Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 20:07:57 +0300 Subject: move some more stuff out of common.js rework client-side cookie functions a bit limit dojo cachebust based on server scripts modification time remove param_escape() --- js/PrefFilterTree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/PrefFilterTree.js') diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 9a2dd6c1c..6823fa8ad 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -138,7 +138,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio }, editFilter: function(id) { - const query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); + const query = "backend.php?op=pref-filters&method=edit&id=" + encodeURIComponent(id); if (dijit.byId("feedEditDlg")) dijit.byId("feedEditDlg").destroyRecursive(); -- cgit v1.2.3 From 526389b2d380177490605037fdc3a24ebc688fac Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 2 Dec 2018 20:56:30 +0300 Subject: update notify_* calls to use Notify --- js/PrefFilterTree.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'js/PrefFilterTree.js') diff --git a/js/PrefFilterTree.js b/js/PrefFilterTree.js index 6823fa8ad..4f4e02d95 100644 --- a/js/PrefFilterTree.js +++ b/js/PrefFilterTree.js @@ -93,11 +93,11 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => { dijit.byId('filterConfigTab').attr('content', transport.responseText); - notify(""); + Notify.close(); }); }, resetFilterOrder: function() { - notify_progress("Loading, please wait..."); + Notify.progress("Loading, please wait..."); xhrPost("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => { this.reload(); @@ -112,7 +112,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio } if (confirm(__("Combine selected filters?"))) { - notify_progress("Joining filters..."); + Notify.progress("Joining filters..."); xhrPost("backend.php", {op: "pref-filters", method: "join", ids: rows.toString()}, () => { this.reload(); @@ -132,7 +132,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio return; } - notify(""); + Notify.close(); this.editFilter(rows[0]); }, @@ -192,7 +192,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio if (confirm(msg)) { this.hide(); - notify_progress("Removing filter..."); + Notify.progress("Removing filter..."); const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id}; @@ -220,7 +220,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio execute: function () { if (this.validate()) { - notify_progress("Saving data...", true); + Notify.progress("Saving data...", true); xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => { dialog.hide(); @@ -238,7 +238,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio if (sel_rows.length > 0) { if (confirm(__("Remove selected filters?"))) { - notify_progress("Removing selected filters..."); + Notify.progress("Removing selected filters..."); const query = { op: "pref-filters", method: "remove", -- cgit v1.2.3