ttrss/js/PrefLabelTree.js

98 lines
2.4 KiB
JavaScript
Raw Normal View History

/* global lib,dijit */
define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare, domConstruct) {
2010-11-18 18:04:57 +01:00
return declare("fox.PrefLabelTree", lib.CheckBoxTree, {
setNameById: function (id, name) {
const item = this.model.store._itemsByIdentity['LABEL:' + id];
2010-11-18 18:04:57 +01:00
if (item)
this.model.store.setValue(item, 'name', name);
2010-11-18 18:04:57 +01:00
},
_createTreeNode: function(args) {
const tnode = this.inherited(arguments);
2010-11-18 18:04:57 +01:00
const fg_color = this.model.store.getValue(args.item, 'fg_color');
const bg_color = this.model.store.getValue(args.item, 'bg_color');
const type = this.model.store.getValue(args.item, 'type');
const bare_id = this.model.store.getValue(args.item, 'bare_id');
2010-11-18 18:04:57 +01:00
if (type == 'label') {
const span = dojo.doc.createElement('span');
span.innerHTML = 'α';
span.className = 'labelColorIndicator';
span.id = 'LICID-' + bare_id;
2010-11-18 18:04:57 +01:00
span.setStyle({
color: fg_color,
backgroundColor: bg_color});
2010-11-18 18:04:57 +01:00
tnode._labelIconNode = span;
2010-11-18 18:04:57 +01:00
domConstruct.place(tnode._labelIconNode, tnode.labelNode, 'before');
}
2010-11-18 18:04:57 +01:00
return tnode;
},
getIconClass: function (item, opened) {
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
},
getSelectedLabels: function() {
const tree = this;
const items = tree.model.getCheckedItems();
const rv = [];
items.each(function(item) {
rv.push(tree.model.store.getValue(item, 'bare_id'));
});
return rv;
},
resetColors: function() {
const labels = this.getSelectedLabels();
if (labels.length > 0) {
if (confirm(__("Reset selected labels to default colors?"))) {
const query = {
op: "pref-labels", method: "colorreset",
ids: labels.toString()
};
xhrPost("backend.php", query, () => {
updateLabelList();
});
}
} else {
alert(__("No labels are selected."));
}
},
removeSelected: function() {
const sel_rows = this.getSelectedLabels();
if (sel_rows.length > 0) {
if (confirm(__("Remove selected labels?"))) {
notify_progress("Removing selected labels...");
const query = {
op: "pref-labels", method: "remove",
ids: sel_rows.toString()
};
xhrPost("backend.php", query, () => {
updateLabelList();
});
}
} else {
alert(__("No labels are selected."));
}
return false;
}
});
2010-11-18 18:04:57 +01:00
});