'use strict' /* global __, App, Article, Lists, Effect, fox */ /* global xhrPost, dojo, dijit, Notify, $$, Feeds */ const Filters = { filterDlgCheckAction: function(sender) { const action = sender.value; const action_param = $("filterDlg_paramBox"); if (!action_param) { console.log("filterDlgCheckAction: can't find action param box!"); return; } // if selected action supports parameters, enable params field if (action == 4 || action == 6 || action == 7 || action == 9) { new Effect.Appear(action_param, {duration: 0.5}); 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); } }, createNewRuleElement: function(parentNode, replaceNode) { const rule = dojo.formToJson("filter_new_rule_form"); xhrPost("backend.php", {op: "pref-filters", method: "printrulename", rule: rule}, (transport) => { try { const li = document.createElement('li'); li.innerHTML = ` ${transport.responseText} ${App.FormFields.hidden("rule[]", rule)}`; dojo.parser.parse(li); if (replaceNode) { parentNode.replaceChild(li, replaceNode); } else { parentNode.appendChild(li); } } catch (e) { App.Error.report(e); } }); }, createNewActionElement: function(parentNode, replaceNode) { const form = document.forms["filter_new_action_form"]; if (form.action_id.value == 7) { form.action_param.value = form.action_param_label.value; } else if (form.action_id.value == 9) { form.action_param.value = form.action_param_plugin.value; } const action = dojo.formToJson(form); xhrPost("backend.php", { op: "pref-filters", method: "printactionname", action: action }, (transport) => { try { const li = document.createElement('li'); li.innerHTML = ` ${transport.responseText} ${App.FormFields.hidden("action[]", action)}`; dojo.parser.parse(li); if (replaceNode) { parentNode.replaceChild(li, replaceNode); } else { parentNode.appendChild(li); } } catch (e) { App.Error.report(e); } }); }, addFilterRule: function(replaceNode, ruleStr) { const dialog = new fox.SingleUseDialog({ id: "filterNewRuleDlg", title: ruleStr ? __("Edit rule") : __("Add rule"), execute: function () { if (this.validate()) { Filters.createNewRuleElement($("filterDlg_Matches"), replaceNode); this.hide(); } }, content: __('Loading, please wait...'), }); const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); xhrPost("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (transport) => { dialog.attr('content', transport.responseText); }); }); dialog.show(); }, addFilterAction: function(replaceNode, actionStr) { const dialog = new fox.SingleUseDialog({ title: actionStr ? __("Edit action") : __("Add action"), execute: function () { if (this.validate()) { Filters.createNewActionElement($("filterDlg_Actions"), replaceNode); this.hide(); } } }); const tmph = dojo.connect(dialog, "onShow", null, function (/* e */) { dojo.disconnect(tmph); xhrPost("backend.php", {op: 'pref-filters', method: 'newaction', action: actionStr}, (transport) => { dialog.attr('content', transport.responseText); }); }); dialog.show(); }, test: function(params) { const dialog = new fox.SingleUseDialog({ title: "Test Filter", results: 0, limit: 100, max_offset: 10000, getTestResults: function (params, offset) { params.method = 'testFilterDo'; params.offset = offset; params.limit = dialog.limit; console.log("getTestResults:" + offset); xhrPost("backend.php", params, (transport) => { try { const result = JSON.parse(transport.responseText); if (result && dialog && dialog.open) { dialog.results += result.length; console.log("got results:" + result.length); $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...") .replace("%f", dialog.results) .replace("%d", offset); console.log(offset + " " + dialog.max_offset); for (let i = 0; i < result.length; i++) { const tmp = dojo.create("table", { innerHTML: result[i]}); $("prefFilterTestResultList").innerHTML += tmp.innerHTML; } if (dialog.results < 30 && offset < dialog.max_offset) { // get the next batch window.setTimeout(function () { dialog.getTestResults(params, offset + dialog.limit); }, 0); } else { // all done Element.hide("prefFilterLoadingIndicator"); if (dialog.results == 0) { $("prefFilterTestResultList").innerHTML = `