2018-12-02 15:38:27 +00:00
|
|
|
'use strict'
|
2020-06-04 20:27:22 +00:00
|
|
|
|
2021-02-12 16:55:05 +00:00
|
|
|
/* eslint-disable no-new */
|
|
|
|
|
2021-02-19 04:29:21 +00:00
|
|
|
/* global __, App, Article, Lists, fox */
|
2021-02-19 08:28:14 +00:00
|
|
|
/* global xhr, dojo, dijit, Notify, Feeds */
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 15:21:36 +00:00
|
|
|
/* exported Filters */
|
|
|
|
const Filters = {
|
2021-02-21 06:35:07 +00:00
|
|
|
edit: function(filter_id = null) { // if no id, new filter dialog
|
2020-06-04 16:50:13 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
const dialog = new fox.SingleUseDialog({
|
|
|
|
id: "filterEditDlg",
|
2021-03-03 11:10:18 +00:00
|
|
|
title: filter_id ? __("Edit filter") : __("Create new filter"),
|
2021-02-20 18:48:05 +00:00
|
|
|
ACTION_TAG: 4,
|
|
|
|
ACTION_SCORE: 6,
|
|
|
|
ACTION_LABEL: 7,
|
|
|
|
ACTION_PLUGIN: 9,
|
2021-12-20 04:56:16 +00:00
|
|
|
ACTION_REMOVE_TAG: 10,
|
|
|
|
PARAM_ACTIONS: [4, 6, 7, 9, 10],
|
2021-02-21 06:35:07 +00:00
|
|
|
filter_info: {},
|
2021-02-20 18:07:28 +00:00
|
|
|
test: function() {
|
|
|
|
const test_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 = test_dialog.limit;
|
|
|
|
|
|
|
|
console.log("getTestResults:" + offset);
|
|
|
|
|
|
|
|
xhr.json("backend.php", params, (result) => {
|
|
|
|
try {
|
|
|
|
if (result && test_dialog && test_dialog.open) {
|
|
|
|
test_dialog.results += result.length;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
console.log("got results:" + result.length);
|
2020-06-04 16:50:13 +00:00
|
|
|
|
2021-03-17 05:45:04 +00:00
|
|
|
const loading_message = test_dialog.domNode.querySelector(".loading-message");
|
|
|
|
const results_list = test_dialog.domNode.querySelector(".filter-results-list");
|
|
|
|
|
|
|
|
loading_message.innerHTML = __("Looking for articles (%d processed, %f found)...")
|
|
|
|
.replace("%f", test_dialog.results)
|
|
|
|
.replace("%d", offset);
|
2021-02-12 12:50:06 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
console.log(offset + " " + test_dialog.max_offset);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
for (let i = 0; i < result.length; i++) {
|
2021-03-17 05:45:04 +00:00
|
|
|
const tmp = dojo.create("div", { innerHTML: result[i]});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-03-17 05:45:04 +00:00
|
|
|
results_list.innerHTML += tmp.innerHTML;
|
2021-02-20 18:07:28 +00:00
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (test_dialog.results < 30 && offset < test_dialog.max_offset) {
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
// get the next batch
|
|
|
|
window.setTimeout(function () {
|
|
|
|
test_dialog.getTestResults(params, offset + test_dialog.limit);
|
|
|
|
}, 0);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
} else {
|
|
|
|
// all done
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-03-17 05:45:04 +00:00
|
|
|
test_dialog.domNode.querySelector(".loading-indicator").hide();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (test_dialog.results == 0) {
|
2021-03-17 05:45:04 +00:00
|
|
|
results_list.innerHTML = `<li class="text-center text-muted">
|
|
|
|
${__('No recent articles matching this filter have been found.')}</li>`;
|
|
|
|
|
|
|
|
loading_message.innerHTML = __("Articles matching this filter:");
|
2021-02-20 18:07:28 +00:00
|
|
|
} else {
|
2021-03-17 05:45:04 +00:00
|
|
|
loading_message.innerHTML = __("Found %d articles matching this filter:")
|
2021-02-20 18:07:28 +00:00
|
|
|
.replace("%d", test_dialog.results);
|
|
|
|
}
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
}
|
2021-02-20 15:15:08 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
} else if (!result) {
|
|
|
|
console.log("getTestResults: can't parse results object");
|
2021-03-17 05:45:04 +00:00
|
|
|
test_dialog.domNode.querySelector(".loading-indicator").hide();
|
2021-02-20 18:07:28 +00:00
|
|
|
Notify.error("Error while trying to get filter test results.");
|
2020-06-04 16:50:13 +00:00
|
|
|
} else {
|
2021-02-20 18:07:28 +00:00
|
|
|
console.log("getTestResults: dialog closed, bailing out.");
|
2020-06-04 16:50:13 +00:00
|
|
|
}
|
2021-02-20 15:15:08 +00:00
|
|
|
} catch (e) {
|
|
|
|
App.Error.report(e);
|
2018-12-02 14:00:58 +00:00
|
|
|
}
|
2021-02-20 15:15:08 +00:00
|
|
|
});
|
|
|
|
},
|
2021-02-20 18:07:28 +00:00
|
|
|
content: `
|
2021-03-17 05:45:04 +00:00
|
|
|
<div class="text-muted">
|
|
|
|
<img class="loading-indicator icon-three-dots" src="${App.getInitParam("icon_three_dots")}">
|
|
|
|
<span class="loading-message">${__("Looking for articles...")}</span>
|
2021-02-20 18:07:28 +00:00
|
|
|
</div>
|
|
|
|
|
2021-03-17 05:45:04 +00:00
|
|
|
<ul class='panel panel-scrollable list list-unstyled filter-results-list'></ul>
|
2021-02-20 18:07:28 +00:00
|
|
|
|
|
|
|
<footer class='text-center'>
|
|
|
|
<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>${__('Close this window')}</button>
|
|
|
|
</footer>
|
|
|
|
`
|
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
const tmph = dojo.connect(test_dialog, "onShow", null, function (/* e */) {
|
|
|
|
dojo.disconnect(tmph);
|
2020-06-04 16:50:13 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
test_dialog.getTestResults(dialog.attr('value'), 0);
|
|
|
|
});
|
2020-06-04 16:50:13 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
test_dialog.show();
|
|
|
|
},
|
2021-02-21 06:35:07 +00:00
|
|
|
insertRule: function(parentNode, replaceNode) {
|
2021-02-20 18:07:28 +00:00
|
|
|
const rule = dojo.formToJson("filter_new_rule_form");
|
2021-02-20 15:21:36 +00:00
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("backend.php", {op: "Pref_Filters", method: "printrulename", rule: rule}, (reply) => {
|
2021-02-20 18:07:28 +00:00
|
|
|
try {
|
|
|
|
const li = document.createElement('li');
|
2021-02-21 06:35:07 +00:00
|
|
|
li.addClassName("rule");
|
2021-02-20 15:21:36 +00:00
|
|
|
|
2021-03-03 16:07:39 +00:00
|
|
|
li.innerHTML = `${App.FormFields.checkbox_tag("", false, "", {onclick: 'Lists.onRowChecked(this)'})}
|
2021-02-21 06:35:07 +00:00
|
|
|
<span class="name" onclick='App.dialogOf(this).onRuleClicked(this)'>${reply}</span>
|
|
|
|
<span class="payload" >${App.FormFields.hidden_tag("rule[]", rule)}</span>`;
|
2021-02-20 15:21:36 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
dojo.parser.parse(li);
|
2021-02-20 15:21:36 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (replaceNode) {
|
|
|
|
parentNode.replaceChild(li, replaceNode);
|
|
|
|
} else {
|
|
|
|
parentNode.appendChild(li);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
App.Error.report(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2021-02-21 06:35:07 +00:00
|
|
|
insertAction: function(parentNode, replaceNode) {
|
2021-02-20 18:07:28 +00:00
|
|
|
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;
|
|
|
|
}
|
2021-02-20 15:21:36 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
const action = dojo.formToJson(form);
|
2021-02-20 15:21:36 +00:00
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("backend.php", { op: "Pref_Filters", method: "printactionname", action: action }, (reply) => {
|
2021-02-20 18:07:28 +00:00
|
|
|
try {
|
|
|
|
const li = document.createElement('li');
|
2021-02-21 06:35:07 +00:00
|
|
|
li.addClassName("action");
|
2021-02-20 15:21:36 +00:00
|
|
|
|
2021-03-03 16:07:39 +00:00
|
|
|
li.innerHTML = `${App.FormFields.checkbox_tag("", false, "", {onclick: 'Lists.onRowChecked(this)'})}
|
2021-02-21 06:35:07 +00:00
|
|
|
<span class="name" onclick='App.dialogOf(this).onActionClicked(this)'>${reply}</span>
|
|
|
|
<span class="payload">${App.FormFields.hidden_tag("action[]", action)}</span>`;
|
2020-06-04 16:50:13 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
dojo.parser.parse(li);
|
2020-06-04 16:50:13 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (replaceNode) {
|
|
|
|
parentNode.replaceChild(li, replaceNode);
|
|
|
|
} else {
|
|
|
|
parentNode.appendChild(li);
|
|
|
|
}
|
2021-02-12 11:31:36 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
} catch (e) {
|
|
|
|
App.Error.report(e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2021-02-21 06:35:07 +00:00
|
|
|
editRule: function(replaceNode, ruleStr = null) {
|
2021-02-20 18:07:28 +00:00
|
|
|
const edit_rule_dialog = new fox.SingleUseDialog({
|
|
|
|
id: "filterNewRuleDlg",
|
|
|
|
title: ruleStr ? __("Edit rule") : __("Add rule"),
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
2021-02-21 06:35:07 +00:00
|
|
|
dialog.insertRule(App.byId("filterDlg_Matches"), replaceNode);
|
2021-02-20 18:07:28 +00:00
|
|
|
this.hide();
|
|
|
|
}
|
2021-02-12 12:22:10 +00:00
|
|
|
},
|
2021-02-20 18:07:28 +00:00
|
|
|
content: __('Loading, please wait...'),
|
|
|
|
});
|
2021-02-12 12:22:10 +00:00
|
|
|
|
2021-02-21 06:35:07 +00:00
|
|
|
const tmph = dojo.connect(edit_rule_dialog, "onShow", null, function () {
|
2021-02-20 18:07:28 +00:00
|
|
|
dojo.disconnect(tmph);
|
2021-02-12 12:22:10 +00:00
|
|
|
|
2021-02-21 06:35:07 +00:00
|
|
|
let rule;
|
|
|
|
|
|
|
|
if (ruleStr) {
|
|
|
|
rule = JSON.parse(ruleStr);
|
|
|
|
} else {
|
|
|
|
rule = {
|
|
|
|
reg_exp: "",
|
|
|
|
filter_type: 1,
|
|
|
|
feed_id: ["0"],
|
|
|
|
inverse: false,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(rule, dialog.filter_info);
|
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.json("backend.php", {op: "Pref_Filters", method: "editrule", ids: rule.feed_id.join(",")}, function (editrule) {
|
2021-02-21 06:35:07 +00:00
|
|
|
edit_rule_dialog.attr('content',
|
|
|
|
`
|
|
|
|
<form name="filter_new_rule_form" id="filter_new_rule_form" onsubmit="return false">
|
|
|
|
|
|
|
|
<section>
|
|
|
|
<textarea dojoType="fox.form.ValidationTextArea"
|
|
|
|
required="true" id="filterDlg_regExp" ValidRegExp="true"
|
|
|
|
rows="4" style="font-size : 14px; width : 530px; word-break: break-all"
|
|
|
|
name="reg_exp">${rule.reg_exp}</textarea>
|
|
|
|
|
|
|
|
<div dojoType="dijit.Tooltip" id="filterDlg_regExp_tip" connectId="filterDlg_regExp" position="below"></div>
|
|
|
|
|
|
|
|
<fieldset>
|
2021-02-21 07:28:59 +00:00
|
|
|
<label class="checkbox">
|
2021-02-21 06:35:07 +00:00
|
|
|
${App.FormFields.checkbox_tag("inverse", rule.inverse)}
|
|
|
|
${__("Inverse regular expression matching")}
|
|
|
|
</label>
|
|
|
|
</fieldset>
|
|
|
|
<fieldset>
|
2021-02-21 07:28:59 +00:00
|
|
|
<label style="display : inline">${__("on")}</label>
|
2021-02-21 06:35:07 +00:00
|
|
|
${App.FormFields.select_hash("filter_type", rule.filter_type, dialog.filter_info.filter_types)}
|
|
|
|
<label style="padding-left : 10px; display : inline">${__("in")}</label>
|
|
|
|
</fieldset>
|
|
|
|
<fieldset>
|
|
|
|
<span id="filterDlg_feeds">
|
|
|
|
${editrule.multiselect}
|
|
|
|
</span>
|
|
|
|
</fieldset>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<footer>
|
|
|
|
${App.FormFields.button_tag(App.FormFields.icon("help") + " " + __("More info"), "", {class: 'pull-left alt-info',
|
|
|
|
onclick: "window.open('https://tt-rss.org/wiki/ContentFilters')"})}
|
2021-03-05 12:16:41 +00:00
|
|
|
${App.FormFields.submit_tag(App.FormFields.icon("save") + " " + __("Save"), {onclick: "App.dialogOf(this).execute()"})}
|
2021-02-21 06:35:07 +00:00
|
|
|
${App.FormFields.cancel_dialog_tag(__("Cancel"))}
|
|
|
|
</footer>
|
|
|
|
|
|
|
|
</form>
|
|
|
|
`);
|
2021-02-20 18:07:28 +00:00
|
|
|
});
|
2021-02-21 06:35:07 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
});
|
2021-02-12 12:22:10 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
edit_rule_dialog.show();
|
|
|
|
},
|
2021-02-21 07:28:59 +00:00
|
|
|
editAction: function(replaceNode, actionStr) {
|
2021-02-20 18:07:28 +00:00
|
|
|
const edit_action_dialog = new fox.SingleUseDialog({
|
|
|
|
title: actionStr ? __("Edit action") : __("Add action"),
|
2021-02-21 07:28:59 +00:00
|
|
|
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) {
|
2021-02-20 18:48:05 +00:00
|
|
|
const action = parseInt(sender.value);
|
2021-02-20 18:07:28 +00:00
|
|
|
|
2021-02-20 18:48:05 +00:00
|
|
|
dijit.byId("filterDlg_actionParam").domNode.hide();
|
|
|
|
dijit.byId("filterDlg_actionParamLabel").domNode.hide();
|
|
|
|
dijit.byId("filterDlg_actionParamPlugin").domNode.hide();
|
2021-02-12 12:22:10 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
// if selected action supports parameters, enable params field
|
2021-02-20 18:48:05 +00:00
|
|
|
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();
|
2021-02-12 12:22:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
2021-02-21 07:28:59 +00:00
|
|
|
dialog.insertAction(App.byId("filterDlg_Actions"), replaceNode);
|
2021-02-20 18:07:28 +00:00
|
|
|
this.hide();
|
|
|
|
}
|
2021-02-21 07:28:59 +00:00
|
|
|
},
|
|
|
|
content: __("Loading, please wait...")
|
2021-02-20 18:07:28 +00:00
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-21 06:35:07 +00:00
|
|
|
const tmph = dojo.connect(edit_action_dialog, "onShow", null, function () {
|
2021-02-20 18:07:28 +00:00
|
|
|
dojo.disconnect(tmph);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-21 07:28:59 +00:00
|
|
|
let action;
|
2021-02-21 06:35:07 +00:00
|
|
|
|
2021-02-21 07:28:59 +00:00
|
|
|
if (actionStr) {
|
|
|
|
action = JSON.parse(actionStr);
|
|
|
|
} else {
|
|
|
|
action = {
|
|
|
|
action_id: 2,
|
|
|
|
action_param: ""
|
|
|
|
};
|
2021-02-21 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2021-02-21 07:28:59 +00:00
|
|
|
console.log(action);
|
2021-02-21 06:35:07 +00:00
|
|
|
|
2021-02-21 07:28:59 +00:00
|
|
|
edit_action_dialog.attr('content',
|
|
|
|
`
|
|
|
|
<form name="filter_new_action_form" id="filter_new_action_form" onsubmit="return false;">
|
|
|
|
<section>
|
|
|
|
${App.FormFields.select_hash("action_id", -1,
|
|
|
|
dialog.filter_info.action_types,
|
|
|
|
{onchange: "App.dialogOf(this).toggleParam(this)"},
|
|
|
|
"filterDlg_actionSelect")}
|
|
|
|
|
|
|
|
<input dojoType="dijit.form.TextBox"
|
|
|
|
id="filterDlg_actionParam" style="$param_hidden"
|
|
|
|
name="action_param" value="${App.escapeHtml(action.action_param)}">
|
|
|
|
|
|
|
|
${edit_action_dialog.select_labels("action_param_label", action.action_param,
|
|
|
|
dialog.filter_info.labels,
|
|
|
|
{},
|
|
|
|
"filterDlg_actionParamLabel")}
|
|
|
|
|
|
|
|
${App.FormFields.select_hash("action_param_plugin", action.action_param,
|
|
|
|
dialog.filter_info.plugin_actions,
|
|
|
|
{},
|
|
|
|
"filterDlg_actionParamPlugin")}
|
|
|
|
</section>
|
|
|
|
<footer>
|
2021-03-05 12:16:41 +00:00
|
|
|
${App.FormFields.submit_tag(App.FormFields.icon("save") + " " + __("Save"), {onclick: "App.dialogOf(this).execute()"})}
|
2021-02-21 07:28:59 +00:00
|
|
|
${App.FormFields.cancel_dialog_tag(__("Cancel"))}
|
|
|
|
</footer>
|
|
|
|
</form>
|
|
|
|
`);
|
|
|
|
|
|
|
|
dijit.byId("filterDlg_actionSelect").attr('value', action.action_id);
|
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
/*xhr.post("backend.php", {op: 'Pref_Filters', method: 'newaction', action: actionStr}, (reply) => {
|
2021-02-21 06:35:07 +00:00
|
|
|
edit_action_dialog.attr('content', reply);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
edit_action_dialog.hideOrShowActionParam(dijit.byId("filterDlg_actionSelect").attr('value'));
|
|
|
|
}, 250);
|
2021-02-21 07:28:59 +00:00
|
|
|
});*/
|
2021-02-21 06:35:07 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
edit_action_dialog.show();
|
2021-02-21 07:28:59 +00:00
|
|
|
},
|
2021-02-20 18:07:28 +00:00
|
|
|
selectRules: function (select) {
|
|
|
|
Lists.select("filterDlg_Matches", select);
|
|
|
|
},
|
|
|
|
selectActions: function (select) {
|
|
|
|
Lists.select("filterDlg_Actions", select);
|
|
|
|
},
|
2021-02-21 06:35:07 +00:00
|
|
|
onRuleClicked: function (elem) {
|
|
|
|
|
|
|
|
const li = elem.closest('li');
|
|
|
|
const rule = li.querySelector('input[name="rule[]"]').value;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
this.editRule(li, rule);
|
|
|
|
},
|
2021-02-21 06:35:07 +00:00
|
|
|
onActionClicked: function (elem) {
|
|
|
|
|
|
|
|
const li = elem.closest('li');
|
|
|
|
const action = li.querySelector('input[name="action[]"]').value;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
this.editAction(li, action);
|
|
|
|
},
|
|
|
|
removeFilter: function () {
|
|
|
|
const msg = __("Remove filter?");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (confirm(msg)) {
|
|
|
|
this.hide();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
Notify.progress("Removing filter...");
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
const query = {op: "Pref_Filters", method: "remove", ids: this.attr('value').id};
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
xhr.post("backend.php", query, () => {
|
|
|
|
const tree = dijit.byId("filterTree");
|
|
|
|
|
|
|
|
if (tree) tree.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addAction: function () {
|
|
|
|
this.editAction();
|
|
|
|
},
|
|
|
|
addRule: function () {
|
|
|
|
this.editRule();
|
|
|
|
},
|
|
|
|
deleteAction: function () {
|
|
|
|
App.findAll("#filterDlg_Actions li[class*=Selected]").forEach(function (e) {
|
|
|
|
e.parentNode.removeChild(e)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
deleteRule: function () {
|
|
|
|
App.findAll("#filterDlg_Matches li[class*=Selected]").forEach(function (e) {
|
|
|
|
e.parentNode.removeChild(e)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
|
|
|
|
Notify.progress("Saving data...", true);
|
|
|
|
|
|
|
|
xhr.post("backend.php", this.attr('value'), () => {
|
|
|
|
dialog.hide();
|
|
|
|
|
2022-01-25 19:39:18 +00:00
|
|
|
Notify.close();
|
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
const tree = dijit.byId("filterTree");
|
|
|
|
if (tree) tree.reload();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
content: __("Loading, please wait...")
|
|
|
|
});
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
const tmph = dojo.connect(dialog, 'onShow', function () {
|
|
|
|
dojo.disconnect(tmph);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.json("backend.php", {op: "Pref_Filters", method: "edit", id: filter_id}, function (filter) {
|
2021-02-21 06:35:07 +00:00
|
|
|
|
|
|
|
dialog.filter_info = filter;
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
enabled: [ filter.enabled, __('Enabled') ],
|
|
|
|
match_any_rule: [ filter.match_any_rule, __('Match any rule') ],
|
|
|
|
inverse: [ filter.inverse, __('Inverse matching') ],
|
|
|
|
};
|
|
|
|
|
|
|
|
dialog.attr('content',
|
|
|
|
`
|
|
|
|
<form onsubmit='return false'>
|
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
${App.FormFields.hidden_tag("op", "Pref_Filters")}
|
2021-02-21 06:35:07 +00:00
|
|
|
${App.FormFields.hidden_tag("id", filter_id)}
|
|
|
|
${App.FormFields.hidden_tag("method", filter_id ? "editSave" : "add")}
|
|
|
|
${App.FormFields.hidden_tag("csrf_token", App.getInitParam('csrf_token'))}
|
|
|
|
|
2021-02-21 10:08:34 +00:00
|
|
|
<section class="horizontal">
|
|
|
|
<input required="true" dojoType="dijit.form.ValidationTextBox" style="width : 100%"
|
2021-02-21 06:35:07 +00:00
|
|
|
placeholder="${__("Title")}" name="title" value="${App.escapeHtml(filter.title)}">
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<div dojoType="dijit.layout.TabContainer" style="height : 300px">
|
|
|
|
<div dojoType="dijit.layout.ContentPane" title="${__('Match')}">
|
|
|
|
<div style="padding : 0" dojoType="dijit.layout.BorderContainer" gutters="false">
|
|
|
|
<div dojoType="fox.Toolbar" region="top">
|
|
|
|
<div dojoType="fox.form.DropDownButton">
|
|
|
|
<span>${__("Select")}</span>
|
|
|
|
<div dojoType="dijit.Menu" style="display: none;">
|
|
|
|
<!-- can"t use App.dialogOf() here because DropDownButton is not a child of the Dialog -->
|
|
|
|
<div onclick="dijit.byId('filterEditDlg').selectRules(true)"
|
|
|
|
dojoType="dijit.MenuItem">${__("All")}</div>
|
|
|
|
<div onclick="dijit.byId('filterEditDlg').selectRules(false)"
|
|
|
|
dojoType="dijit.MenuItem">${__("None")}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<button dojoType="dijit.form.Button" onclick="App.dialogOf(this).addRule()">
|
|
|
|
${__("Add")}
|
|
|
|
</button>
|
|
|
|
<button dojoType="dijit.form.Button" onclick="App.dialogOf(this).deleteRule()">
|
|
|
|
${__("Delete")}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div dojoType="dijit.layout.ContentPane" region="center">
|
|
|
|
<ul id="filterDlg_Matches">
|
|
|
|
${filter.rules.map((rule) => `
|
|
|
|
<li class='rule'>
|
|
|
|
${App.FormFields.checkbox_tag("", false, "", {onclick: 'Lists.onRowChecked(this)'})}
|
|
|
|
<span class='name' onclick='App.dialogOf(this).onRuleClicked(this)'>${rule.name}</span>
|
|
|
|
<span class='payload'>${App.FormFields.hidden_tag("rule[]", JSON.stringify(rule))}</span>
|
|
|
|
</li>
|
|
|
|
`).join("")}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div dojoType="dijit.layout.ContentPane" title="${__('Apply actions')}">
|
|
|
|
<div style="padding : 0" dojoType="dijit.layout.BorderContainer" gutters="false">
|
|
|
|
<div dojoType="fox.Toolbar" region="top">
|
|
|
|
<div dojoType="fox.form.DropDownButton">
|
|
|
|
<span>${__("Select")}</span>
|
|
|
|
<div dojoType="dijit.Menu" style="display: none">
|
|
|
|
<div onclick="dijit.byId('filterEditDlg').selectActions(true)"
|
|
|
|
dojoType="dijit.MenuItem">${__("All")}</div>
|
|
|
|
<div onclick="dijit.byId('filterEditDlg').selectActions(false)"
|
|
|
|
dojoType="dijit.MenuItem">${__("None")}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-21 07:28:59 +00:00
|
|
|
<button dojoType="dijit.form.Button" onclick="App.dialogOf(this).addAction()">
|
2021-02-21 06:35:07 +00:00
|
|
|
${__("Add")}
|
|
|
|
</button>
|
2021-02-21 07:28:59 +00:00
|
|
|
<button dojoType="dijit.form.Button" onclick="App.dialogOf(this).deleteAction()">
|
2021-02-21 06:35:07 +00:00
|
|
|
${__("Delete")}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div dojoType="dijit.layout.ContentPane" region="center">
|
|
|
|
<ul id="filterDlg_Actions">
|
|
|
|
${filter.actions.map((action) => `
|
|
|
|
<li class='rule'>
|
|
|
|
${App.FormFields.checkbox_tag("", false, "", {onclick: 'Lists.onRowChecked(this)'})}
|
2021-02-21 07:28:59 +00:00
|
|
|
<span class='name' onclick='App.dialogOf(this).onActionClicked(this)'>${App.escapeHtml(action.name)}</span>
|
2021-02-21 06:35:07 +00:00
|
|
|
<span class='payload'>${App.FormFields.hidden_tag("action[]", JSON.stringify(action))}</span>
|
|
|
|
</li>
|
|
|
|
`).join("")}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-02-21 10:08:34 +00:00
|
|
|
<section class="horizontal">
|
2021-02-21 06:35:07 +00:00
|
|
|
${Object.keys(options).map((name) =>
|
|
|
|
`
|
|
|
|
<fieldset class='narrow'>
|
|
|
|
<label class="checkbox">
|
|
|
|
${App.FormFields.checkbox_tag(name, options[name][0])}
|
|
|
|
${options[name][1]}
|
|
|
|
</label>
|
|
|
|
</fieldset>
|
|
|
|
`).join("")}
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<footer>
|
|
|
|
${filter_id ?
|
|
|
|
`
|
2021-03-05 12:16:41 +00:00
|
|
|
${App.FormFields.button_tag(App.FormFields.icon("delete") + " " + __("Remove"), "", {class: "pull-left alt-danger", onclick: "App.dialogOf(this).removeFilter()"})}
|
|
|
|
${App.FormFields.button_tag(App.FormFields.icon("check_circle") + " " + __("Test"), "", {class: "alt-info", onclick: "App.dialogOf(this).test()"})}
|
|
|
|
${App.FormFields.submit_tag(App.FormFields.icon("save") + " " + __("Save"), {onclick: "App.dialogOf(this).execute()"})}
|
2021-02-21 06:35:07 +00:00
|
|
|
${App.FormFields.cancel_dialog_tag(__("Cancel"))}
|
|
|
|
` : `
|
2021-03-05 12:16:41 +00:00
|
|
|
${App.FormFields.button_tag(App.FormFields.icon("check_circle") + " " + __("Test"), "", {class: "alt-info", onclick: "App.dialogOf(this).test()"})}
|
|
|
|
${App.FormFields.submit_tag(App.FormFields.icon("add") + " " + __("Create"), {onclick: "App.dialogOf(this).execute()"})}
|
2021-02-21 06:35:07 +00:00
|
|
|
${App.FormFields.cancel_dialog_tag(__("Cancel"))}
|
|
|
|
`}
|
|
|
|
</footer>
|
|
|
|
</form>
|
|
|
|
`);
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (!App.isPrefs()) {
|
|
|
|
const selectedText = App.getSelectedText();
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (selectedText != "") {
|
|
|
|
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
|
|
|
Feeds.getActive();
|
|
|
|
const rule = {reg_exp: selectedText, feed_id: [feed_id], filter_type: 1};
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
dialog.editRule(null, dojo.toJson(rule));
|
|
|
|
} else {
|
2023-10-25 09:55:09 +00:00
|
|
|
const query = {op: "Article", method: "getmetadatabyid", id: Article.getActive()};
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
xhr.json("backend.php", query, (reply) => {
|
|
|
|
let title;
|
2018-12-02 14:00:58 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (reply && reply.title) title = reply.title;
|
2018-12-03 06:33:44 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
if (title || Feeds.getActive() || Feeds.activeIsCat()) {
|
|
|
|
console.log(title + " " + Feeds.getActive());
|
|
|
|
|
|
|
|
const feed_id = Feeds.activeIsCat() ? 'CAT:' + parseInt(Feeds.getActive()) :
|
|
|
|
Feeds.getActive();
|
|
|
|
const rule = {reg_exp: title, feed_id: [feed_id], filter_type: 1};
|
2021-02-12 12:22:10 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
dialog.editRule(null, dojo.toJson(rule));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-02-12 11:31:36 +00:00
|
|
|
});
|
2021-02-20 18:48:05 +00:00
|
|
|
|
2021-02-20 18:07:28 +00:00
|
|
|
dialog.show();
|
2020-06-04 16:50:13 +00:00
|
|
|
},
|
|
|
|
};
|