2020-06-04 20:27:22 +00:00
|
|
|
/* global __, $$, define, lib, dijit, dojo, xhrPost, Notify, Filters, Lists */
|
|
|
|
|
2018-08-23 06:56:34 +00:00
|
|
|
define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
return declare("fox.PrefFilterTree", lib.CheckBoxTree, {
|
|
|
|
_createTreeNode: function(args) {
|
2018-11-29 18:21:06 +00:00
|
|
|
const tnode = this.inherited(arguments);
|
2016-08-10 10:40:24 +00:00
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
const enabled = this.model.store.getValue(args.item, 'enabled');
|
|
|
|
let param = this.model.store.getValue(args.item, 'param');
|
|
|
|
const rules = this.model.store.getValue(args.item, 'rules');
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
if (param) {
|
|
|
|
param = dojo.doc.createElement('span');
|
|
|
|
param.className = (enabled != false) ? 'labelParam' : 'labelParam filterDisabled';
|
|
|
|
param.innerHTML = args.item.param[0];
|
2017-01-21 17:54:36 +00:00
|
|
|
domConstruct.place(param, tnode.rowNode, 'first');
|
2016-08-10 10:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rules) {
|
2018-12-19 09:08:06 +00:00
|
|
|
param = dojo.doc.createElement('ul');
|
2016-08-10 10:40:24 +00:00
|
|
|
param.className = 'filterRules';
|
|
|
|
param.innerHTML = rules;
|
2017-01-21 17:54:36 +00:00
|
|
|
domConstruct.place(param, tnode.rowNode, 'next');
|
2016-08-10 10:40:24 +00:00
|
|
|
}
|
|
|
|
|
2018-12-05 13:48:29 +00:00
|
|
|
/* if (this.model.store.getValue(args.item, 'id') != 'root') {
|
|
|
|
const i = dojo.doc.createElement('i');
|
|
|
|
i.className = 'material-icons filter';
|
|
|
|
i.innerHTML = 'label';
|
|
|
|
tnode._filterIconNode = i;
|
2017-01-21 17:54:36 +00:00
|
|
|
domConstruct.place(tnode._filterIconNode, tnode.labelNode, 'before');
|
2018-12-05 13:48:29 +00:00
|
|
|
} */
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
return tnode;
|
|
|
|
},
|
|
|
|
|
|
|
|
getLabel: function(item) {
|
2018-12-04 13:07:24 +00:00
|
|
|
let label = String(item.name);
|
2016-08-10 10:40:24 +00:00
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
const feed = this.model.store.getValue(item, 'feed');
|
|
|
|
const inverse = this.model.store.getValue(item, 'inverse');
|
2018-12-06 16:37:20 +00:00
|
|
|
const last_triggered = this.model.store.getValue(item, 'last_triggered');
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
if (feed)
|
|
|
|
label += " (" + __("in") + " " + feed + ")";
|
|
|
|
|
|
|
|
if (inverse)
|
|
|
|
label += " (" + __("Inverse") + ")";
|
|
|
|
|
2018-12-06 16:37:20 +00:00
|
|
|
if (last_triggered)
|
|
|
|
label += " — " + last_triggered;
|
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
return label;
|
|
|
|
},
|
|
|
|
getIconClass: function (item, opened) {
|
|
|
|
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
|
|
|
|
},
|
|
|
|
getRowClass: function (item, opened) {
|
2018-12-08 12:49:52 +00:00
|
|
|
const enabled = this.model.store.getValue(item, 'enabled');
|
|
|
|
|
|
|
|
return enabled ? "dijitTreeRow" : "dijitTreeRow filterDisabled";
|
2016-08-10 10:40:24 +00:00
|
|
|
},
|
|
|
|
checkItemAcceptance: function(target, source, position) {
|
2018-11-29 18:21:06 +00:00
|
|
|
const item = dijit.getEnclosingWidget(target).item;
|
2016-08-10 10:40:24 +00:00
|
|
|
|
|
|
|
// disable copying items
|
|
|
|
source.copyState = function() { return false; };
|
|
|
|
|
|
|
|
return position != 'over';
|
|
|
|
},
|
|
|
|
onDndDrop: function() {
|
|
|
|
this.inherited(arguments);
|
|
|
|
this.tree.model.store.save();
|
|
|
|
},
|
2018-12-02 09:03:28 +00:00
|
|
|
getSelectedFilters: function() {
|
|
|
|
const tree = this;
|
|
|
|
const items = tree.model.getCheckedItems();
|
|
|
|
const rv = [];
|
2016-08-10 10:40:24 +00:00
|
|
|
|
2018-12-02 09:03:28 +00:00
|
|
|
items.each(function (item) {
|
|
|
|
rv.push(tree.model.store.getValue(item, 'bare_id'));
|
|
|
|
});
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
},
|
2018-12-02 13:29:00 +00:00
|
|
|
reload: function() {
|
|
|
|
const user_search = $("filter_search");
|
|
|
|
let search = "";
|
|
|
|
if (user_search) { search = user_search.value; }
|
|
|
|
|
|
|
|
xhrPost("backend.php", { op: "pref-filters", search: search }, (transport) => {
|
2021-02-11 12:49:32 +00:00
|
|
|
dijit.byId('filtersTab').attr('content', transport.responseText);
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 13:29:00 +00:00
|
|
|
});
|
|
|
|
},
|
2018-12-02 09:03:28 +00:00
|
|
|
resetFilterOrder: function() {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Loading, please wait...");
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-filters", method: "filtersortreset"}, () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
this.reload();
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
joinSelectedFilters: function() {
|
2018-12-08 14:01:30 +00:00
|
|
|
const rows = this.getSelectedFilters();
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
if (rows.length == 0) {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No filters selected."));
|
2018-12-02 09:03:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (confirm(__("Combine selected filters?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Joining filters...");
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", {op: "pref-filters", method: "join", ids: rows.toString()}, () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
this.reload();
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
editSelectedFilter: function() {
|
|
|
|
const rows = this.getSelectedFilters();
|
|
|
|
|
|
|
|
if (rows.length == 0) {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No filters selected."));
|
2018-12-02 09:03:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rows.length > 1) {
|
|
|
|
alert(__("Please select only one filter."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
this.editFilter(rows[0]);
|
|
|
|
},
|
|
|
|
editFilter: function(id) {
|
|
|
|
|
2018-12-02 17:07:57 +00:00
|
|
|
const query = "backend.php?op=pref-filters&method=edit&id=" + encodeURIComponent(id);
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
if (dijit.byId("feedEditDlg"))
|
|
|
|
dijit.byId("feedEditDlg").destroyRecursive();
|
|
|
|
|
|
|
|
if (dijit.byId("filterEditDlg"))
|
|
|
|
dijit.byId("filterEditDlg").destroyRecursive();
|
|
|
|
|
|
|
|
const dialog = new dijit.Dialog({
|
|
|
|
id: "filterEditDlg",
|
|
|
|
title: __("Edit Filter"),
|
|
|
|
style: "width: 600px",
|
|
|
|
|
|
|
|
test: function () {
|
2020-02-28 09:16:54 +00:00
|
|
|
Filters.editFilterTest(dojo.formToObject("filter_edit_form"));
|
2018-12-02 09:03:28 +00:00
|
|
|
},
|
|
|
|
selectRules: function (select) {
|
2018-12-06 06:52:12 +00:00
|
|
|
Lists.select("filterDlg_Matches", select);
|
2018-12-02 09:03:28 +00:00
|
|
|
},
|
|
|
|
selectActions: function (select) {
|
2018-12-06 06:52:12 +00:00
|
|
|
Lists.select("filterDlg_Actions", select);
|
2018-12-02 09:03:28 +00:00
|
|
|
},
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
removeFilter: function () {
|
2018-12-08 10:02:39 +00:00
|
|
|
const msg = __("Remove filter?");
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
if (confirm(msg)) {
|
|
|
|
this.hide();
|
|
|
|
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing filter...");
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
const query = {op: "pref-filters", method: "remove", ids: this.attr('value').id};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
dijit.byId("filterTree").reload();
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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 17:56:30 +00:00
|
|
|
Notify.progress("Saving data...", true);
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
xhrPost("backend.php", dojo.formToObject("filter_edit_form"), () => {
|
|
|
|
dialog.hide();
|
2018-12-02 13:29:00 +00:00
|
|
|
dijit.byId("filterTree").reload();
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
href: query
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
},
|
|
|
|
removeSelectedFilters: function() {
|
|
|
|
const sel_rows = this.getSelectedFilters();
|
|
|
|
|
|
|
|
if (sel_rows.length > 0) {
|
|
|
|
if (confirm(__("Remove selected filters?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing selected filters...");
|
2018-12-02 09:03:28 +00:00
|
|
|
|
|
|
|
const query = {
|
|
|
|
op: "pref-filters", method: "remove",
|
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
this.reload();
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No filters selected."));
|
2018-12-02 09:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
});
|
2010-11-18 12:49:26 +00:00
|
|
|
});
|
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
|