2021-02-12 16:02:09 +00:00
|
|
|
/* eslint-disable prefer-rest-params */
|
2022-06-06 06:29:16 +00:00
|
|
|
/* global __, define, lib, dijit, dojo, xhr, App, Notify, Filters */
|
2020-06-04 20:27:22 +00:00
|
|
|
|
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, {
|
2022-06-05 08:41:28 +00:00
|
|
|
postCreate: function() {
|
|
|
|
this.inherited(arguments);
|
|
|
|
|
|
|
|
dijit.byId('filterTree').hideOrShowFilterRules(
|
|
|
|
parseInt(localStorage.getItem("ttrss:hide-filter-rules"))
|
|
|
|
);
|
2022-06-06 06:29:16 +00:00
|
|
|
|
|
|
|
dojo.connect(this, 'onClick', (item) => {
|
|
|
|
const id = String(item.id);
|
|
|
|
const bare_id = id.substr(id.indexOf(':')+1);
|
|
|
|
|
|
|
|
if (id.match('FILTER:')) {
|
|
|
|
Filters.edit(bare_id);
|
|
|
|
}
|
|
|
|
});
|
2022-06-05 08:41:28 +00:00
|
|
|
},
|
2016-08-10 10:40:24 +00:00
|
|
|
_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) {
|
2021-02-12 16:02:09 +00:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
2016-08-10 10:40:24 +00:00
|
|
|
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) {
|
2021-02-12 16:02:09 +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
|
|
|
|
2021-02-18 18:51:18 +00:00
|
|
|
items.forEach(function (item) {
|
2018-12-02 09:03:28 +00:00
|
|
|
rv.push(tree.model.store.getValue(item, 'bare_id'));
|
|
|
|
});
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
},
|
2018-12-02 13:29:00 +00:00
|
|
|
reload: function() {
|
2021-02-18 18:51:18 +00:00
|
|
|
const user_search = App.byId("filter_search");
|
2018-12-02 13:29:00 +00:00
|
|
|
let search = "";
|
|
|
|
if (user_search) { search = user_search.value; }
|
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("backend.php", { op: "Pref_Filters", search: search }, (reply) => {
|
2021-02-19 10:44:56 +00:00
|
|
|
dijit.byId('filtersTab').attr('content', reply);
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.close();
|
2018-12-02 13:29:00 +00:00
|
|
|
});
|
|
|
|
},
|
2022-06-05 08:41:28 +00:00
|
|
|
hideOrShowFilterRules(hide) {
|
|
|
|
App.findAll("body")[0].setAttribute("hide-filter-rules", !!hide);
|
|
|
|
},
|
|
|
|
toggleRules: function() {
|
|
|
|
const hide = !parseInt(localStorage.getItem("ttrss:hide-filter-rules"));
|
|
|
|
|
|
|
|
this.hideOrShowFilterRules(hide);
|
|
|
|
|
|
|
|
localStorage.setItem("ttrss:hide-filter-rules", hide ? 1 : 0);
|
|
|
|
},
|
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
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("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
|
|
|
|
2023-10-25 09:55:09 +00:00
|
|
|
xhr.post("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
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
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 = {
|
2023-10-25 09:55:09 +00:00
|
|
|
op: "Pref_Filters", method: "remove",
|
2018-12-02 09:03:28 +00:00
|
|
|
ids: sel_rows.toString()
|
|
|
|
};
|
|
|
|
|
2021-02-19 08:28:14 +00:00
|
|
|
xhr.post("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
|
|
|
|