summaryrefslogtreecommitdiff
path: root/js/CommonFilters.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-12 15:22:10 +0300
committerAndrew Dolgov <[email protected]>2021-02-12 15:22:10 +0300
commit3d11c61f326ef133427f6f37de4429e879c725f2 (patch)
tree472a31623e184383ae61d189662fb29a3808f454 /js/CommonFilters.js
parent219cc9a0ab0da20cb82df2647508e29f7f9d1515 (diff)
* OPML import: don't reload everything, just feed tree
* dialogs: use auto-destroying dialog for almost all dialogs instead of destroying them manually * some general dialog-related cleanup
Diffstat (limited to 'js/CommonFilters.js')
-rw-r--r--js/CommonFilters.js208
1 files changed, 102 insertions, 106 deletions
diff --git a/js/CommonFilters.js b/js/CommonFilters.js
index e0e8034ea..1d5b9236b 100644
--- a/js/CommonFilters.js
+++ b/js/CommonFilters.js
@@ -1,6 +1,6 @@
'use strict'
-/* global __, App, Article, Lists, Effect */
+/* global __, App, Article, Lists, Effect, fox */
/* global xhrPost, dojo, dijit, Notify, $$, Feeds */
const Filters = {
@@ -138,10 +138,7 @@ const Filters = {
},
test: function(params) {
- if (dijit.byId("filterTestDlg"))
- dijit.byId("filterTestDlg").destroyRecursive();
-
- const test_dlg = new dijit.Dialog({
+ const test_dlg = new fox.SingleUseDialog({
id: "filterTestDlg",
title: "Test Filter",
results: 0,
@@ -249,128 +246,127 @@ const Filters = {
console.log('Filters.edit', query);
xhrPost("backend.php", query, function (transport) {
- if (dijit.byId("feedEditDlg"))
- dijit.byId("feedEditDlg").destroyRecursive();
-
- if (dijit.byId("filterEditDlg"))
- dijit.byId("filterEditDlg").destroyRecursive();
-
- const dialog = new dijit.Dialog({
- id: "filterEditDlg",
- title: __("Create Filter"),
- test: function () {
- Filters.test(this.attr('value'));
- },
- selectRules: function (select) {
- Lists.select("filterDlg_Matches", select);
- },
- selectActions: function (select) {
- Lists.select("filterDlg_Actions", select);
- },
- editRule: function (e) {
- const li = e.closest('li');
- const rule = li.querySelector('input[name="rule[]"]').value
-
- Filters.addFilterRule(li, rule);
- },
- editAction: function (e) {
- const li = e.closest('li');
- const action = li.querySelector('input[name="action[]"]').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, () => {
- const tree = dijit.byId("filterTree");
-
- if (tree) tree.reload();
+ try {
+ const dialog = new fox.SingleUseDialog({
+ id: "filterEditDlg",
+ title: __("Create Filter"),
+ test: function () {
+ Filters.test(this.attr('value'));
+ },
+ selectRules: function (select) {
+ Lists.select("filterDlg_Matches", select);
+ },
+ selectActions: function (select) {
+ Lists.select("filterDlg_Actions", select);
+ },
+ editRule: function (e) {
+ const li = e.closest('li');
+ const rule = li.querySelector('input[name="rule[]"]').value
+
+ Filters.addFilterRule(li, rule);
+ },
+ editAction: function (e) {
+ const li = e.closest('li');
+ const action = li.querySelector('input[name="action[]"]').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, () => {
+ const tree = dijit.byId("filterTree");
+
+ if (tree) tree.reload();
+ });
+ }
+ },
+ addAction: function () {
+ Filters.addFilterAction();
+ },
+ addRule: function () {
+ Filters.addFilterRule();
+ },
+ deleteAction: function () {
+ $$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
+ e.parentNode.removeChild(e)
});
- }
- },
- 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()) {
+ },
+ deleteRule: function () {
+ $$("#filterDlg_Matches li[class*=Selected]").each(function (e) {
+ e.parentNode.removeChild(e)
+ });
+ },
+ execute: function () {
+ if (this.validate()) {
- Notify.progress("Saving data...", true);
+ Notify.progress("Saving data...", true);
- xhrPost("backend.php", this.attr('value'), () => {
- dialog.hide();
+ xhrPost("backend.php", this.attr('value'), () => {
+ dialog.hide();
- const tree = dijit.byId("filterTree");
- if (tree) tree.reload();
- });
- }
- },
- content: transport.responseText
- });
+ const tree = dijit.byId("filterTree");
+ if (tree) tree.reload();
+ });
+ }
+ },
+ content: transport.responseText
+ });
- if (!App.isPrefs()) {
- /* global getSelectionText */
- const selectedText = getSelectionText();
+ if (!App.isPrefs()) {
+ /* global getSelectionText */
+ const selectedText = getSelectionText();
- const lh = dojo.connect(dialog, "onShow", function () {
- dojo.disconnect(lh);
+ const lh = dojo.connect(dialog, "onShow", function () {
+ dojo.disconnect(lh);
- if (selectedText != "") {
+ if (selectedText != "") {
- const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
- Feeds.getActive();
+ const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
+ Feeds.getActive();
- const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
+ const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
- Filters.addFilterRule(null, dojo.toJson(rule));
+ Filters.addFilterRule(null, dojo.toJson(rule));
- } else {
+ } else {
- const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()};
+ const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()};
- xhrPost("backend.php", query, (transport) => {
- const reply = JSON.parse(transport.responseText);
+ xhrPost("backend.php", query, (transport) => {
+ const reply = JSON.parse(transport.responseText);
- let title = false;
+ let title = false;
- if (reply && reply.title) title = reply.title;
+ if (reply && reply.title) title = reply.title;
- if (title || Feeds.getActive() || Feeds.activeIsCat()) {
+ if (title || Feeds.getActive() || Feeds.activeIsCat()) {
- console.log(title + " " + Feeds.getActive());
+ console.log(title + " " + Feeds.getActive());
- const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
- Feeds.getActive();
+ const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
+ Feeds.getActive();
- const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
+ const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
- Filters.addFilterRule(null, dojo.toJson(rule));
- }
- });
- }
- });
+ Filters.addFilterRule(null, dojo.toJson(rule));
+ }
+ });
+ }
+ });
+ }
+ dialog.show();
+
+ } catch (e) {
+ App.Error.report(e);
}
- dialog.show();
});
},
};