filter test dialog: pass contents via xhr POST

This commit is contained in:
Andrew Dolgov 2020-02-28 12:16:54 +03:00
parent 0eb3f1c3dc
commit 8645f36c5b
4 changed files with 24 additions and 39 deletions

View File

@ -3,7 +3,7 @@ class Pref_Filters extends Handler_Protected {
function csrf_ignore($method) {
$csrf_ignored = array("index", "getfiltertree", "edit", "newfilter", "newrule",
"newaction", "savefilterorder");
"newaction", "savefilterorder", "testfilterdlg");
return array_search($method, $csrf_ignored) !== false;
}
@ -159,22 +159,19 @@ class Pref_Filters extends Handler_Protected {
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();
//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>";
<ul class='panel panel-scrollable list list-unstyled' id='prefFilterTestResultList'></ul>
<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) {
@ -600,10 +597,6 @@ class Pref_Filters extends Handler_Protected {
}
function editSave() {
if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") {
return $this->testFilter();
}
$filter_id = clean($_REQUEST["id"]);
$enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"]));
$match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"]));
@ -714,10 +707,6 @@ class Pref_Filters extends Handler_Protected {
}
function add() {
if (clean($_REQUEST["savemode"] && $_REQUEST["savemode"]) == "test") {
return $this->testFilter();
}
$enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"]));
$match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"]));
$title = clean($_REQUEST["title"]);

View File

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

View File

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

View File

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