From 590b1fc39e104bd41a8ab213b98b38345dba4eac Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Feb 2021 18:21:36 +0300 Subject: [PATCH] a few more methods shuffled around --- classes/pref/filters.php | 6 +-- js/CommonFilters.js | 104 ++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/classes/pref/filters.php b/classes/pref/filters.php index cfff383d8..1aeaa8a3f 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -389,7 +389,7 @@ class Pref_Filters extends Handler_Protected { unset($line["match_on"]); print "
  • - ".$this->_get_rule_name($line)."". + ".$this->_get_rule_name($line)."". \Controls\hidden_tag("rule[]", (string)json_encode($line))."
  • "; } } @@ -429,7 +429,7 @@ class Pref_Filters extends Handler_Protected { unset($line["id"]); print "
  • - ".$this->_get_action_name($line)."". + ".$this->_get_action_name($line)."". \Controls\hidden_tag("action[]", (string)json_encode($line))."
  • "; } } @@ -861,7 +861,7 @@ class Pref_Filters extends Handler_Protected { print "
    "; print " - ${reply} + ${reply} ${App.FormFields.hidden_tag("rule[]", rule)}`; dojo.parser.parse(li); @@ -181,7 +152,7 @@ const Filters = { const li = document.createElement('li'); li.innerHTML = ` - ${reply} + ${reply} ${App.FormFields.hidden_tag("action[]", action)}`; dojo.parser.parse(li); @@ -197,8 +168,8 @@ const Filters = { } }); }, - addFilterRule: function(replaceNode, ruleStr) { - const add_dialog = new fox.SingleUseDialog({ + editRule: function(replaceNode, ruleStr) { + const edit_rule_dialog = new fox.SingleUseDialog({ id: "filterNewRuleDlg", title: ruleStr ? __("Edit rule") : __("Add rule"), execute: function () { @@ -210,19 +181,50 @@ const Filters = { content: __('Loading, please wait...'), }); - const tmph = dojo.connect(add_dialog, "onShow", null, function (/* e */) { + const tmph = dojo.connect(edit_rule_dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); xhr.post("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (reply) => { - add_dialog.attr('content', reply); + edit_rule_dialog.attr('content', reply); }); }); - add_dialog.show(); + edit_rule_dialog.show(); }, - addFilterAction: function(replaceNode, actionStr) { - const add_dialog = new fox.SingleUseDialog({ + editAction: function(replaceNode, actionStr) { + const edit_action_dialog = new fox.SingleUseDialog({ title: actionStr ? __("Edit action") : __("Add action"), + hideOrShowActionParam: function(sender) { + const action = sender.value; + + const action_param = App.byId("filterDlg_paramBox"); + + if (!action_param) { + console.log("hideOrShowActionParam: can't find action param box!"); + return; + } + + // if selected action supports parameters, enable params field + if (action == 4 || action == 6 || action == 7 || action == 9) { + Element.show(action_param); + + Element.hide(dijit.byId("filterDlg_actionParam").domNode); + Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode); + Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode); + + if (action == 7) { + Element.show(dijit.byId("filterDlg_actionParamLabel").domNode); + } else if (action == 9) { + Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode); + } else { + Element.show(dijit.byId("filterDlg_actionParam").domNode); + } + + } else { + Element.hide(action_param); + } + }, + execute: function () { if (this.validate()) { dialog.createNewActionElement(App.byId("filterDlg_Actions"), replaceNode); @@ -231,15 +233,15 @@ const Filters = { } }); - const tmph = dojo.connect(add_dialog, "onShow", null, function (/* e */) { + const tmph = dojo.connect(edit_action_dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); xhr.post("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (reply) => { - add_dialog.attr('content', reply); + edit_action_dialog.attr('content', reply); }); }); - add_dialog.show(); + edit_action_dialog.show(); }, selectRules: function (select) { Lists.select("filterDlg_Matches", select); @@ -247,17 +249,17 @@ const Filters = { selectActions: function (select) { Lists.select("filterDlg_Actions", select); }, - editRule: function (e) { + onRuleClicked: function (e) { const li = e.closest('li'); const rule = li.querySelector('input[name="rule[]"]').value - this.addFilterRule(li, rule); + this.editRule(li, rule); }, - editAction: function (e) { + onActionClicked: function (e) { const li = e.closest('li'); const action = li.querySelector('input[name="action[]"]').value - this.addFilterAction(li, action); + this.editAction(li, action); }, removeFilter: function () { const msg = __("Remove filter?"); @@ -277,10 +279,10 @@ const Filters = { } }, addAction: function () { - this.addFilterAction(); + this.editAction(); }, addRule: function () { - this.addFilterRule(); + this.editRule(); }, deleteAction: function () { App.findAll("#filterDlg_Actions li[class*=Selected]").forEach(function (e) { @@ -322,7 +324,7 @@ const Filters = { const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1}; - dialog.addFilterRule(null, dojo.toJson(rule)); + dialog.editRule(null, dojo.toJson(rule)); } else { @@ -342,7 +344,7 @@ const Filters = { const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1}; - dialog.addFilterRule(null, dojo.toJson(rule)); + dialog.editRule(null, dojo.toJson(rule)); } }); }