2018-11-29 18:21:06 +00:00
|
|
|
/* global lib,dijit */
|
2018-08-23 06:56:34 +00:00
|
|
|
define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare, domConstruct) {
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
return declare("fox.PrefLabelTree", lib.CheckBoxTree, {
|
|
|
|
setNameById: function (id, name) {
|
2018-11-29 18:21:06 +00:00
|
|
|
const item = this.model.store._itemsByIdentity['LABEL:' + id];
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
if (item)
|
|
|
|
this.model.store.setValue(item, 'name', name);
|
2010-11-18 17:04:57 +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);
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2018-11-29 18:21:06 +00: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 17:04:57 +00:00
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
if (type == 'label') {
|
2018-11-29 18:21:06 +00:00
|
|
|
const span = dojo.doc.createElement('span');
|
2016-08-10 10:40:24 +00:00
|
|
|
span.innerHTML = 'α';
|
|
|
|
span.className = 'labelColorIndicator';
|
|
|
|
span.id = 'LICID-' + bare_id;
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
span.setStyle({
|
|
|
|
color: fg_color,
|
|
|
|
backgroundColor: bg_color});
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
tnode._labelIconNode = span;
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2017-01-21 17:54:36 +00:00
|
|
|
domConstruct.place(tnode._labelIconNode, tnode.labelNode, 'before');
|
2016-08-10 10:40:24 +00:00
|
|
|
}
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
return tnode;
|
|
|
|
},
|
|
|
|
getIconClass: function (item, opened) {
|
|
|
|
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
|
|
|
|
},
|
2018-12-02 08:34:57 +00:00
|
|
|
getSelectedLabels: function() {
|
2018-12-02 08:50:53 +00:00
|
|
|
const tree = this;
|
2018-12-02 08:34:57 +00:00
|
|
|
const items = tree.model.getCheckedItems();
|
|
|
|
const rv = [];
|
|
|
|
|
|
|
|
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() {
|
|
|
|
xhrPost("backend.php", { op: "pref-labels" }, (transport) => {
|
|
|
|
dijit.byId('labelConfigTab').attr('content', transport.responseText);
|
|
|
|
notify("");
|
|
|
|
});
|
|
|
|
},
|
2018-12-02 09:03:28 +00:00
|
|
|
editLabel: function(id) {
|
|
|
|
const query = "backend.php?op=pref-labels&method=edit&id=" +
|
|
|
|
param_escape(id);
|
|
|
|
|
|
|
|
if (dijit.byId("labelEditDlg"))
|
|
|
|
dijit.byId("labelEditDlg").destroyRecursive();
|
|
|
|
|
|
|
|
const dialog = new dijit.Dialog({
|
|
|
|
id: "labelEditDlg",
|
|
|
|
title: __("Label Editor"),
|
|
|
|
style: "width: 600px",
|
|
|
|
setLabelColor: function (id, fg, bg) {
|
|
|
|
|
|
|
|
let kind = '';
|
|
|
|
let color = '';
|
|
|
|
|
|
|
|
if (fg && bg) {
|
|
|
|
kind = 'both';
|
|
|
|
} else if (fg) {
|
|
|
|
kind = 'fg';
|
|
|
|
color = fg;
|
|
|
|
} else if (bg) {
|
|
|
|
kind = 'bg';
|
|
|
|
color = bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
const e = $("LICID-" + id);
|
|
|
|
|
|
|
|
if (e) {
|
|
|
|
if (fg) e.style.color = fg;
|
|
|
|
if (bg) e.style.backgroundColor = bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
op: "pref-labels", method: "colorset", kind: kind,
|
|
|
|
ids: id, fg: fg, bg: bg, color: color
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
dijit.byId("filterTree").reload(); // maybe there's labels in there
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
execute: function () {
|
|
|
|
if (this.validate()) {
|
|
|
|
const caption = this.attr('value').caption;
|
|
|
|
const fg_color = this.attr('value').fg_color;
|
|
|
|
const bg_color = this.attr('value').bg_color;
|
|
|
|
|
|
|
|
dijit.byId('labelTree').setNameById(id, caption);
|
|
|
|
this.setLabelColor(id, fg_color, bg_color);
|
|
|
|
this.hide();
|
|
|
|
|
|
|
|
xhrPost("backend.php", this.attr('value'), () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
dijit.byId("filterTree").reload(); // maybe there's labels in there
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
href: query
|
|
|
|
});
|
|
|
|
|
|
|
|
dialog.show();
|
|
|
|
},
|
2018-12-02 08:34:57 +00:00
|
|
|
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, () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
this.reload();
|
2018-12-02 08:34:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No labels selected."));
|
2018-12-02 08:34:57 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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, () => {
|
2018-12-02 13:29:00 +00:00
|
|
|
this.reload();
|
2018-12-02 08:34:57 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-02 13:30:32 +00:00
|
|
|
alert(__("No labels selected."));
|
2018-12-02 08:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2010-11-18 17:04:57 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2016-08-10 10:40:24 +00:00
|
|
|
|