From b4e96374bcc14b3be353f87a80f83b34615dec73 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 20 Feb 2021 21:48:05 +0300 Subject: [PATCH] more filter stuff --- classes/pref/filters.php | 20 ++++++++--------- js/CommonFilters.js | 47 +++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 1aeaa8a3f..9c250be19 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -860,7 +860,7 @@ class Pref_Filters extends Handler_Protected { print "
"; - print ""; - $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? - "" : "display : none"; + #$param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ? + # "" : "display : none"; - $param_hidden = ($action_id == 4 || $action_id == 6) ? - "" : "display : none"; + #$param_hidden = ($action_id == 4 || $action_id == 6) ? + # "" : "display : none"; - $label_param_hidden = ($action_id == 7) ? "" : "display : none"; - $plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; + #$label_param_hidden = ($action_id == 7) ? "" : "display : none"; + #$plugin_param_hidden = ($action_id == 9) ? "" : "display : none"; - print ""; - print " "; + #print ""; + #print " "; //print " " . __("with parameters:") . " "; print " $plugin_param_hidden], $filter_plugin_disabled), "filterDlg_actionParamPlugin"); - print ""; + #print ""; print " "; // tiny layout hack diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 88f9c83f5..bd6808f59 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -22,6 +22,11 @@ const Filters = { const dialog = new fox.SingleUseDialog({ id: "filterEditDlg", title: id ? __("Edit Filter") : __("Create Filter"), + ACTION_TAG: 4, + ACTION_SCORE: 6, + ACTION_LABEL: 7, + ACTION_PLUGIN: 9, + PARAM_ACTIONS: [4, 6, 7, 9], test: function() { const test_dialog = new fox.SingleUseDialog({ title: "Test Filter", @@ -193,36 +198,21 @@ const Filters = { const edit_action_dialog = new fox.SingleUseDialog({ title: actionStr ? __("Edit action") : __("Add action"), hideOrShowActionParam: function(sender) { - const action = sender.value; + const action = parseInt(sender.value); - const action_param = App.byId("filterDlg_paramBox"); - - if (!action_param) { - console.log("hideOrShowActionParam: can't find action param box!"); - return; - } + dijit.byId("filterDlg_actionParam").domNode.hide(); + dijit.byId("filterDlg_actionParamLabel").domNode.hide(); + dijit.byId("filterDlg_actionParamPlugin").domNode.hide(); // 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); + if (action == dialog.ACTION_LABEL) { + dijit.byId("filterDlg_actionParamLabel").domNode.show(); + } else if (action == dialog.ACTION_PLUGIN) { + dijit.byId("filterDlg_actionParamPlugin").domNode.show(); + } else if (dialog.PARAM_ACTIONS.indexOf(action) != -1) { + dijit.byId("filterDlg_actionParam").domNode.show(); } }, - execute: function () { if (this.validate()) { dialog.createNewActionElement(App.byId("filterDlg_Actions"), replaceNode); @@ -236,6 +226,10 @@ const Filters = { xhr.post("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (reply) => { edit_action_dialog.attr('content', reply); + + setTimeout(() => { + edit_action_dialog.hideOrShowActionParam(dijit.byId("filterDlg_actionSelect").attr('value')); + }, 250); }); }); @@ -308,6 +302,8 @@ const Filters = { content: __("Loading, please wait...") }); + + const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); @@ -345,6 +341,7 @@ const Filters = { } }); }); + dialog.show(); }, };