diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 4e52260c9..c00e52bde 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -328,7 +328,8 @@ class Pref_Filters extends Handler_Protected { "rules" => [], "actions" => [], "filter_types" => [], - "filter_actions" => [], + "action_types" => [], + "plugin_actions" => [], "labels" => Labels::get_all($_SESSION["uid"]) ]; @@ -343,7 +344,17 @@ class Pref_Filters extends Handler_Protected { ORDER BY name"); while ($line = $res->fetch()) { - $rv["filter_actions"][$line["id"]] = __($line["description"]); + $rv["action_types"][$line["id"]] = __($line["description"]); + } + + $filter_actions = PluginHost::getInstance()->get_filter_actions(); + + foreach ($filter_actions as $fclass => $factions) { + foreach ($factions as $faction) { + + $rv["plugin_actions"][$fclass . ":" . $faction["action"]] = + $fclass . ": " . $faction["description"]; + } } if ($filter_id) { @@ -393,167 +404,6 @@ class Pref_Filters extends Handler_Protected { } print json_encode($rv); } - - /*return; - - if (empty($filter_id) || $row = $sth->fetch()) { - - $enabled = $row["enabled"] ?? true; - $match_any_rule = $row["match_any_rule"] ?? false; - $inverse = $row["inverse"] ?? false; - $title = htmlspecialchars($row["title"] ?? ""); - - print "
"; - } */ } private function _get_rule_name($rule) { @@ -845,180 +695,8 @@ class Pref_Filters extends Handler_Protected { $feed_ids = explode(",", clean($_REQUEST["ids"])); print json_encode([ - "multiselect" => $this->feed_multi_select("feed_id", $feed_ids, 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"') + "multiselect" => $this->_feed_multi_select("feed_id", $feed_ids, 'style="width : 540px; height : 300px" dojoType="dijit.form.MultiSelect"') ]); - - /*return; - - $rule = json_decode(clean($_REQUEST["rule"]), true); - - if ($rule) { - $reg_exp = htmlspecialchars($rule["reg_exp"]); - $filter_type = $rule["filter_type"]; - $feed_id = $rule["feed_id"]; - $inverse_checked = !empty($rule["inverse"]); - } else { - $reg_exp = ""; - $filter_type = 1; - $feed_id = ["0"]; - $inverse_checked = false; - } - - print "";*/ - } - - function newaction() { - $action = json_decode(clean($_REQUEST["action"]), true); - - if ($action) { - $action_param = $action["action_param"]; - $action_id = (int)$action["action_id"]; - } else { - $action_param = ""; - $action_id = 0; - } - - print ""; } private function _get_name($id) { @@ -1152,7 +830,7 @@ class Pref_Filters extends Handler_Protected { $this->pdo->commit(); } - private function feed_multi_select($id, $default_ids = [], + private function _feed_multi_select($id, $default_ids = [], $attributes = "", $include_all_feeds = true, $root_id = null, $nest_level = 0) { @@ -1194,7 +872,7 @@ class Pref_Filters extends Handler_Protected { $line["id"], htmlspecialchars($line["title"])); if ($line["num_children"] > 0) - $rv .= $this->feed_multi_select($id, $default_ids, $attributes, + $rv .= $this->_feed_multi_select($id, $default_ids, $attributes, $include_all_feeds, $line["id"], $nest_level+1); $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 75e1fa8af..5874170b8 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -209,13 +209,13 @@ const Filters = { @@ -241,10 +241,14 @@ const Filters = { edit_rule_dialog.show(); }, - /*editAction: function(replaceNode, actionStr) { + editAction: function(replaceNode, actionStr) { const edit_action_dialog = new fox.SingleUseDialog({ title: actionStr ? __("Edit action") : __("Add action"), - hideOrShowActionParam: function(sender) { + select_labels: function(name, value, labels, attributes = {}, id = "") { + const values = Object.values(labels).map((label) => label.caption); + return App.FormFields.select_tag(name, value, values, attributes, id); + }, + toggleParam: function(sender) { const action = parseInt(sender.value); dijit.byId("filterDlg_actionParam").domNode.hide(); @@ -262,67 +266,72 @@ const Filters = { }, execute: function () { if (this.validate()) { - dialog.createNewActionElement(App.byId("filterDlg_Actions"), replaceNode); + dialog.insertAction(App.byId("filterDlg_Actions"), replaceNode); this.hide(); } - } - }); - - const tmph = dojo.connect(edit_action_dialog, "onShow", null, function () { - dojo.disconnect(tmph); - - 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); - }); - }); - - edit_action_dialog.show(); - }, */ - /*editAction: function(replaceNode, actionStr) { - const edit_action_dialog = new fox.SingleUseDialog({ - title: actionStr ? __("Edit action") : __("Add action"), - hideOrShowActionParam: function(sender) { - const action = parseInt(sender.value); - - 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 == 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); - this.hide(); - } - } + content: __("Loading, please wait...") }); const tmph = dojo.connect(edit_action_dialog, "onShow", null, function () { dojo.disconnect(tmph); - xhr.post("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (reply) => { + let action; + + if (actionStr) { + action = JSON.parse(actionStr); + } else { + action = { + action_id: 2, + action_param: "" + }; + } + + console.log(action); + + edit_action_dialog.attr('content', + ` + + `); + + dijit.byId("filterDlg_actionSelect").attr('value', action.action_id); + + /*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); - }); + });*/ }); edit_action_dialog.show(); - },*/ + }, selectRules: function (select) { Lists.select("filterDlg_Matches", select); }, @@ -395,18 +404,7 @@ const Filters = { const tmph = dojo.connect(dialog, 'onShow', function () { dojo.disconnect(tmph); - const query = {op: "pref-filters", method: "edit", id: filter_id}; - - /*if (!App.isPrefs()) { - query = { - op: "pref-filters", method: "edit", - feed: Feeds.getActive(), is_cat: Feeds.activeIsCat() - }; - } else { - query = {op: "pref-filters", method: "edit", id: id}; - }*/ - - xhr.json("backend.php", query, function (filter) { + xhr.json("backend.php", {op: "pref-filters", method: "edit", id: filter_id}, function (filter) { dialog.filter_info = filter; @@ -476,10 +474,10 @@ const Filters = { dojoType="dijit.MenuItem">${__("None")} -