2018-12-02 15:38:27 +00:00
|
|
|
'use strict'
|
2020-06-04 20:27:22 +00:00
|
|
|
|
2020-06-05 04:44:57 +00:00
|
|
|
/* global __, App, Article, Lists, Effect */
|
|
|
|
/* global xhrPost, dojo, dijit, Notify, $$, Feeds */
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const Filters = {
|
|
|
|
filterDlgCheckAction: function(sender) {
|
|
|
|
const action = sender.value;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const action_param = $("filterDlg_paramBox");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (!action_param) {
|
|
|
|
console.log("filterDlgCheckAction: can't find action param box!");
|
|
|
|
return;
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
// 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});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
Element.hide(dijit.byId("filterDlg_actionParam").domNode);
|
|
|
|
Element.hide(dijit.byId("filterDlg_actionParamLabel").domNode);
|
|
|
|
Element.hide(dijit.byId("filterDlg_actionParamPlugin").domNode);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (action == 7) {
|
|
|
|
Element.show(dijit.byId("filterDlg_actionParamLabel").domNode);
|
|
|
|
} else if (action == 9) {
|
|
|
|
Element.show(dijit.byId("filterDlg_actionParamPlugin").domNode);
|
2018-12-02 14:00:58 +00:00
|
|
|
} else {
|
2020-06-04 16:50:13 +00:00
|
|
|
Element.show(dijit.byId("filterDlg_actionParam").domNode);
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
2020-06-04 16:50:13 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
Element.hide(action_param);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
createNewRuleElement: function(parentNode, replaceNode) {
|
|
|
|
const form = document.forms["filter_new_rule_form"];
|
|
|
|
const query = {op: "pref-filters", method: "printrulename", rule: dojo.formToJson(form)};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, (transport) => {
|
|
|
|
try {
|
|
|
|
const li = dojo.create("li");
|
|
|
|
|
|
|
|
const cb = dojo.create("input", {type: "checkbox"}, li);
|
|
|
|
|
|
|
|
new dijit.form.CheckBox({
|
|
|
|
onChange: function () {
|
|
|
|
Lists.onRowChecked(this);
|
|
|
|
},
|
|
|
|
}, cb);
|
|
|
|
|
|
|
|
dojo.create("input", {
|
|
|
|
type: "hidden",
|
|
|
|
name: "rule[]",
|
|
|
|
value: dojo.formToJson(form)
|
|
|
|
}, li);
|
|
|
|
|
|
|
|
dojo.create("span", {
|
|
|
|
onclick: function () {
|
|
|
|
dijit.byId('filterEditDlg').editRule(this);
|
|
|
|
},
|
|
|
|
innerHTML: transport.responseText
|
|
|
|
}, li);
|
|
|
|
|
|
|
|
if (replaceNode) {
|
|
|
|
parentNode.replaceChild(li, replaceNode);
|
|
|
|
} else {
|
|
|
|
parentNode.appendChild(li);
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
2020-06-04 16:50:13 +00:00
|
|
|
} catch (e) {
|
|
|
|
App.Error.report(e);
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
2020-06-04 16:50:13 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
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 query = {
|
|
|
|
op: "pref-filters", method: "printactionname",
|
|
|
|
action: dojo.formToJson(form)
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, (transport) => {
|
|
|
|
try {
|
|
|
|
const li = dojo.create("li");
|
|
|
|
|
|
|
|
const cb = dojo.create("input", {type: "checkbox"}, li);
|
|
|
|
|
|
|
|
new dijit.form.CheckBox({
|
|
|
|
onChange: function () {
|
|
|
|
Lists.onRowChecked(this);
|
|
|
|
},
|
|
|
|
}, cb);
|
|
|
|
|
|
|
|
dojo.create("input", {
|
|
|
|
type: "hidden",
|
|
|
|
name: "action[]",
|
|
|
|
value: dojo.formToJson(form)
|
|
|
|
}, li);
|
|
|
|
|
|
|
|
dojo.create("span", {
|
|
|
|
onclick: function () {
|
|
|
|
dijit.byId('filterEditDlg').editAction(this);
|
|
|
|
},
|
|
|
|
innerHTML: transport.responseText
|
|
|
|
}, li);
|
|
|
|
|
|
|
|
if (replaceNode) {
|
|
|
|
parentNode.replaceChild(li, replaceNode);
|
|
|
|
} else {
|
|
|
|
parentNode.appendChild(li);
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
2020-02-28 09:52:20 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
} catch (e) {
|
|
|
|
App.Error.report(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
addFilterRule: function(replaceNode, ruleStr) {
|
|
|
|
if (dijit.byId("filterNewRuleDlg"))
|
|
|
|
dijit.byId("filterNewRuleDlg").destroyRecursive();
|
|
|
|
|
|
|
|
const rule_dlg = new dijit.Dialog({
|
|
|
|
id: "filterNewRuleDlg",
|
|
|
|
title: ruleStr ? __("Edit rule") : __("Add rule"),
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
Filters.createNewRuleElement($("filterDlg_Matches"), replaceNode);
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
content: __('Loading, please wait...'),
|
|
|
|
});
|
2020-02-28 09:52:20 +00:00
|
|
|
|
2020-06-04 20:27:22 +00:00
|
|
|
const tmph = dojo.connect(rule_dlg, "onShow", null, function (/* e */) {
|
2020-06-04 16:50:13 +00:00
|
|
|
dojo.disconnect(tmph);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
xhrPost("backend.php", {op: 'pref-filters', method: 'newrule', rule: ruleStr}, (transport) => {
|
|
|
|
rule_dlg.attr('content', transport.responseText);
|
2018-12-02 14:00:58 +00:00
|
|
|
});
|
2020-06-04 16:50:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
rule_dlg.show();
|
|
|
|
},
|
|
|
|
addFilterAction: function(replaceNode, actionStr) {
|
|
|
|
if (dijit.byId("filterNewActionDlg"))
|
|
|
|
dijit.byId("filterNewActionDlg").destroyRecursive();
|
|
|
|
|
|
|
|
const query = "backend.php?op=pref-filters&method=newaction&action=" +
|
|
|
|
encodeURIComponent(actionStr);
|
|
|
|
|
|
|
|
const rule_dlg = new dijit.Dialog({
|
|
|
|
id: "filterNewActionDlg",
|
|
|
|
title: actionStr ? __("Edit action") : __("Add action"),
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
Filters.createNewActionElement($("filterDlg_Actions"), replaceNode);
|
|
|
|
this.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
href: query
|
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
rule_dlg.show();
|
|
|
|
},
|
|
|
|
editFilterTest: function(params) {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (dijit.byId("filterTestDlg"))
|
|
|
|
dijit.byId("filterTestDlg").destroyRecursive();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const test_dlg = new dijit.Dialog({
|
|
|
|
id: "filterTestDlg",
|
|
|
|
title: "Test Filter",
|
|
|
|
results: 0,
|
|
|
|
limit: 100,
|
|
|
|
max_offset: 10000,
|
|
|
|
getTestResults: function (params, offset) {
|
|
|
|
params.method = 'testFilterDo';
|
|
|
|
params.offset = offset;
|
|
|
|
params.limit = test_dlg.limit;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
console.log("getTestResults:" + offset);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
xhrPost("backend.php", params, (transport) => {
|
|
|
|
try {
|
|
|
|
const result = JSON.parse(transport.responseText);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) {
|
|
|
|
test_dlg.results += result.length;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
console.log("got results:" + result.length);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
$("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...")
|
|
|
|
.replace("%f", test_dlg.results)
|
|
|
|
.replace("%d", offset);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
console.log(offset + " " + test_dlg.max_offset);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
|
|
|
const tmp = dojo.create("table", { innerHTML: result[i]});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
$("prefFilterTestResultList").innerHTML += tmp.innerHTML;
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (test_dlg.results < 30 && offset < test_dlg.max_offset) {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
// get the next batch
|
|
|
|
window.setTimeout(function () {
|
|
|
|
test_dlg.getTestResults(params, offset + test_dlg.limit);
|
|
|
|
}, 0);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
} else {
|
|
|
|
// all done
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
Element.hide("prefFilterLoadingIndicator");
|
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (test_dlg.results == 0) {
|
|
|
|
$("prefFilterTestResultList").innerHTML = `<tr><td align='center'>
|
|
|
|
${__('No recent articles matching this filter have been found.')}</td></tr>`;
|
|
|
|
$("prefFilterProgressMsg").innerHTML = "Articles matching this filter:";
|
|
|
|
} else {
|
|
|
|
$("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:")
|
|
|
|
.replace("%d", test_dlg.results);
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
} else if (!result) {
|
|
|
|
console.log("getTestResults: can't parse results object");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
Element.hide("prefFilterLoadingIndicator");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
Notify.error("Error while trying to get filter test results.");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
} else {
|
|
|
|
console.log("getTestResults: dialog closed, bailing out.");
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
App.Error.report(e);
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
});
|
|
|
|
},
|
2021-02-12 07:35:13 +00:00
|
|
|
content: `
|
|
|
|
<div>
|
|
|
|
<img id='prefFilterLoadingIndicator' src='images/indicator_tiny.gif'>
|
|
|
|
<span id='prefFilterProgressMsg'>Looking for articles...</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<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>
|
|
|
|
`
|
2020-06-04 16:50:13 +00:00
|
|
|
});
|
|
|
|
|
2021-02-12 07:35:13 +00:00
|
|
|
dojo.connect(test_dlg, "onShow", null, function (/* e */) {
|
2020-06-04 16:50:13 +00:00
|
|
|
test_dlg.getTestResults(params, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test_dlg.show();
|
|
|
|
},
|
|
|
|
quickAddFilter: function() {
|
|
|
|
let query;
|
|
|
|
|
|
|
|
if (!App.isPrefs()) {
|
|
|
|
query = {
|
|
|
|
op: "pref-filters", method: "newfilter",
|
|
|
|
feed: Feeds.getActive(), is_cat: Feeds.activeIsCat()
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
query = {op: "pref-filters", method: "newfilter"};
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('quickAddFilter', query);
|
|
|
|
|
|
|
|
if (dijit.byId("feedEditDlg"))
|
|
|
|
dijit.byId("feedEditDlg").destroyRecursive();
|
|
|
|
|
|
|
|
if (dijit.byId("filterEditDlg"))
|
|
|
|
dijit.byId("filterEditDlg").destroyRecursive();
|
|
|
|
|
|
|
|
const dialog = new dijit.Dialog({
|
|
|
|
id: "filterEditDlg",
|
|
|
|
title: __("Create Filter"),
|
|
|
|
test: function () {
|
|
|
|
Filters.editFilterTest(dojo.formToObject("filter_new_form"));
|
|
|
|
},
|
|
|
|
selectRules: function (select) {
|
|
|
|
Lists.select("filterDlg_Matches", select);
|
|
|
|
},
|
|
|
|
selectActions: function (select) {
|
|
|
|
Lists.select("filterDlg_Actions", select);
|
|
|
|
},
|
|
|
|
editRule: function (e) {
|
|
|
|
const li = e.parentNode;
|
|
|
|
const rule = li.getElementsByTagName("INPUT")[1].value;
|
|
|
|
Filters.addFilterRule(li, rule);
|
|
|
|
},
|
|
|
|
editAction: function (e) {
|
|
|
|
const li = e.parentNode;
|
|
|
|
const action = li.getElementsByTagName("INPUT")[1].value;
|
|
|
|
Filters.addFilterAction(li, action);
|
|
|
|
},
|
|
|
|
addAction: function () {
|
|
|
|
Filters.addFilterAction();
|
|
|
|
},
|
|
|
|
addRule: function () {
|
|
|
|
Filters.addFilterRule();
|
|
|
|
},
|
|
|
|
deleteAction: function () {
|
|
|
|
$$("#filterDlg_Actions li[class*=Selected]").each(function (e) {
|
|
|
|
e.parentNode.removeChild(e)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
deleteRule: function () {
|
|
|
|
$$("#filterDlg_Matches li[class*=Selected]").each(function (e) {
|
|
|
|
e.parentNode.removeChild(e)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const query = dojo.formToQuery("filter_new_form");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
xhrPost("backend.php", query, () => {
|
|
|
|
if (App.isPrefs()) {
|
|
|
|
dijit.byId("filterTree").reload();
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
dialog.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
href: "backend.php?" + dojo.objectToQuery(query)
|
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (!App.isPrefs()) {
|
2020-06-05 04:44:57 +00:00
|
|
|
/* global getSelectionText */
|
2020-06-04 16:50:13 +00:00
|
|
|
const selectedText = getSelectionText();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const lh = dojo.connect(dialog, "onLoad", function () {
|
|
|
|
dojo.disconnect(lh);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (selectedText != "") {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
|
|
|
Feeds.getActive();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
Filters.addFilterRule(null, dojo.toJson(rule));
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
} else {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const query = {op: "rpc", method: "getlinktitlebyid", id: Article.getActive()};
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
xhrPost("backend.php", query, (transport) => {
|
|
|
|
const reply = JSON.parse(transport.responseText);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
let title = false;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (reply && reply.title) title = reply.title;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
if (title || Feeds.getActive() || Feeds.activeIsCat()) {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
console.log(title + " " + Feeds.getActive());
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
|
|
|
Feeds.getActive();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
|
2018-12-03 06:33:44 +00:00
|
|
|
|
2020-06-04 16:50:13 +00:00
|
|
|
Filters.addFilterRule(null, dojo.toJson(rule));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
dialog.show();
|
|
|
|
},
|
|
|
|
};
|