filter test dialog: pass contents via xhr POST

master
Andrew Dolgov 5 years ago
parent 0eb3f1c3dc
commit 8645f36c5b

@ -3,7 +3,7 @@ class Pref_Filters extends Handler_Protected {
function csrf_ignore($method) { function csrf_ignore($method) {
$csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule", $csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
"newaction", "savefilterorder"); "newaction", "savefilterorder", "testfilterdlg");
return array_search($method, $csrf_ignored) !== false; return array_search($method, $csrf_ignored) !== false;
} }
@ -159,22 +159,19 @@ class Pref_Filters extends Handler_Protected {
print json_encode($rv); print json_encode($rv);
} }
function testFilter() { function testFilterDlg() {
?>
<div>
<img id='prefFilterLoadingIndicator' src='images/indicator_tiny.gif'>&nbsp;
<span id='prefFilterProgressMsg'>Looking for articles...</span>
</div>
if (isset($_REQUEST["offset"])) return $this->testFilterDo(); <ul class='panel panel-scrollable list list-unstyled' id='prefFilterTestResultList'></ul>
//print __("Articles matching this filter:");
print "<div><img id='prefFilterLoadingIndicator' src='images/indicator_tiny.gif'>&nbsp;<span id='prefFilterProgressMsg'>Looking for articles...</span></div>";
print "<ul class='panel panel-scrollable list list-unstyled' id='prefFilterTestResultList'>";
print "</ul>";
print "<footer class='text-center'>";
print "<button dojoType='dijit.form.Button' onclick=\"dijit.byId('filterTestDlg').hide()\">".
__('Close this window')."</button>";
print "</footer>";
<footer class='text-center'>
<button dojoType='dijit.form.Button' onclick="dijit.byId('filterTestDlg').hide()"><?php echo __('Close this window') ?></button>
</footer>
<?php
} }
private function getfilterrules_list($filter_id) { private function getfilterrules_list($filter_id) {
@ -600,10 +597,6 @@ class Pref_Filters extends Handler_Protected {
} }
function editSave() { function editSave() {
if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") {
return $this->testFilter();
}
$filter_id = clean($_REQUEST["id"]); $filter_id = clean($_REQUEST["id"]);
$enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"])); $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"]));
$match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"]));
@ -714,10 +707,6 @@ class Pref_Filters extends Handler_Protected {
} }
function add() { function add() {
if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") {
return $this->testFilter();
}
$enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"])); $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"]));
$match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"])); $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"]));
$title = clean($_REQUEST["title"]); $title = clean($_REQUEST["title"]);

@ -409,7 +409,7 @@ define(["dojo/_base/declare"], function (declare) {
return false; return false;
}, },
editFeed: function (feed) { editFeeed: function (feed) {
if (feed <= 0) if (feed <= 0)
return alert(__("You can't edit this kind of feed.")); return alert(__("You can't edit this kind of feed."));

@ -183,7 +183,7 @@ define(["dojo/_base/declare"], function (declare) {
rule_dlg.show(); rule_dlg.show();
}, },
editFilterTest: function(query) { editFilterTest: function(params) {
if (dijit.byId("filterTestDlg")) if (dijit.byId("filterTestDlg"))
dijit.byId("filterTestDlg").destroyRecursive(); dijit.byId("filterTestDlg").destroyRecursive();
@ -195,12 +195,14 @@ define(["dojo/_base/declare"], function (declare) {
results: 0, results: 0,
limit: 100, limit: 100,
max_offset: 10000, max_offset: 10000,
getTestResults: function (query, offset) { getTestResults: function (params, offset) {
const updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; params.method = 'testFilterDo';
params.offset = offset;
params.limit = test_dlg.limit;
console.log("getTestResults:" + offset); console.log("getTestResults:" + offset);
xhrPost("backend.php", updquery, (transport) => { xhrPost("backend.php", params, (transport) => {
try { try {
const result = JSON.parse(transport.responseText); const result = JSON.parse(transport.responseText);
@ -216,9 +218,7 @@ define(["dojo/_base/declare"], function (declare) {
console.log(offset + " " + test_dlg.max_offset); console.log(offset + " " + test_dlg.max_offset);
for (let i = 0; i < result.length; i++) { for (let i = 0; i < result.length; i++) {
const tmp = new Element("table"); const tmp = dojo.create("table", { innerHTML: result[i]});
tmp.innerHTML = result[i];
dojo.parser.parse(tmp);
$("prefFilterTestResultList").innerHTML += tmp.innerHTML; $("prefFilterTestResultList").innerHTML += tmp.innerHTML;
} }
@ -262,11 +262,11 @@ define(["dojo/_base/declare"], function (declare) {
}); });
}, },
href: query href: "backend.php?op=pref-filters&method=testFilterDlg"
}); });
dojo.connect(test_dlg, "onLoad", null, function (e) { dojo.connect(test_dlg, "onLoad", null, function (e) {
test_dlg.getTestResults(query, 0); test_dlg.getTestResults(params, 0);
}); });
test_dlg.show(); test_dlg.show();
@ -296,9 +296,7 @@ define(["dojo/_base/declare"], function (declare) {
title: __("Create Filter"), title: __("Create Filter"),
style: "width: 600px", style: "width: 600px",
test: function () { test: function () {
const query = "backend.php?" + dojo.formToQuery("filter_new_form") + "&savemode=test"; Filters.editFilterTest(dojo.formToObject("filter_new_form"));
Filters.editFilterTest(query);
}, },
selectRules: function (select) { selectRules: function (select) {
Lists.select("filterDlg_Matches", select); Lists.select("filterDlg_Matches", select);

@ -149,9 +149,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
style: "width: 600px", style: "width: 600px",
test: function () { test: function () {
const query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; Filters.editFilterTest(dojo.formToObject("filter_edit_form"));
Filters.editFilterTest(query);
}, },
selectRules: function (select) { selectRules: function (select) {
Lists.select("filterDlg_Matches", select); Lists.select("filterDlg_Matches", select);

Loading…
Cancel
Save