2021-02-12 16:02:09 +00:00
|
|
|
/* eslint-disable prefer-rest-params */
|
2021-02-13 10:17:34 +00:00
|
|
|
/* global __, define, lib, dijit, dojo, xhrPost, Notify, fox, App */
|
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", "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
|
|
|
|
2021-02-12 15:38:26 +00:00
|
|
|
//const fg_color = this.model.store.getValue(args.item, 'fg_color');
|
|
|
|
//const bg_color = this.model.store.getValue(args.item, 'bg_color');
|
2018-11-29 18:21:06 +00:00
|
|
|
const type = this.model.store.getValue(args.item, 'type');
|
2021-02-12 15:38:26 +00:00
|
|
|
//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-12-06 05:26:52 +00:00
|
|
|
const label = dojo.doc.createElement('i');
|
|
|
|
//const fg_color = args.item.fg_color[0];
|
2018-12-06 05:35:02 +00:00
|
|
|
const bg_color = String(args.item.bg_color);
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2018-12-06 05:26:52 +00:00
|
|
|
label.className = "material-icons icon-label";
|
2018-12-06 05:35:02 +00:00
|
|
|
label.id = 'icon-label-' + String(args.item.bare_id);
|
2018-12-06 05:26:52 +00:00
|
|
|
label.innerHTML = "label";
|
|
|
|
label.setStyle({
|
|
|
|
color: bg_color,
|
|
|
|
});
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2018-12-06 05:26:52 +00:00
|
|
|
domConstruct.place(label, tnode.iconNode, 'before');
|
2010-11-18 17:04:57 +00:00
|
|
|
|
2018-12-06 05:26:52 +00:00
|
|
|
//tnode._labelIconNode = span;
|
|
|
|
//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) {
|
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";
|
|
|
|
},
|
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) => {
|
2021-02-11 12:49:32 +00:00
|
|
|
dijit.byId('labelsTab').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
|
|
|
editLabel: function(id) {
|
2021-02-13 10:17:34 +00:00
|
|
|
xhrJson("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => {
|
2018-12-02 09:03:28 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
console.log(reply);
|
2018-12-02 09:03:28 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
const fg_color = reply['fg_color'];
|
|
|
|
const bg_color = reply['bg_color'] ? reply['bg_color'] : '#fff7d5';
|
|
|
|
|
|
|
|
const dialog = new fox.SingleUseDialog({
|
|
|
|
id: "labelEditDlg",
|
|
|
|
title: __("Label Editor"),
|
|
|
|
style: "width: 650px",
|
|
|
|
setLabelColor: function (id, fg, bg) {
|
|
|
|
|
|
|
|
let kind = '';
|
|
|
|
let color = '';
|
2018-12-02 09:03:28 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
if (fg && bg) {
|
|
|
|
kind = 'both';
|
|
|
|
} else if (fg) {
|
|
|
|
kind = 'fg';
|
|
|
|
color = fg;
|
|
|
|
} else if (bg) {
|
|
|
|
kind = 'bg';
|
|
|
|
color = bg;
|
|
|
|
}
|
2018-12-02 09:03:28 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
const e = $("icon-label-" + id);
|
2018-12-02 09:03:28 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
if (e) {
|
|
|
|
if (bg) e.style.color = bg;
|
|
|
|
}
|
|
|
|
|
|
|
|
const query = {
|
|
|
|
op: "pref-labels", method: "colorset", kind: kind,
|
|
|
|
ids: id, fg: fg, bg: bg, color: color
|
|
|
|
};
|
|
|
|
|
|
|
|
xhrPost("backend.php", query, () => {
|
2021-02-12 11:31:36 +00:00
|
|
|
const tree = dijit.byId("filterTree");
|
|
|
|
if (tree) tree.reload(); // maybe there's labels in there
|
2018-12-02 09:03:28 +00:00
|
|
|
});
|
2021-02-12 15:38:26 +00:00
|
|
|
|
2021-02-13 10:17:34 +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'), () => {
|
|
|
|
const tree = dijit.byId("filterTree");
|
|
|
|
if (tree) tree.reload(); // maybe there's labels in there
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
content: `
|
|
|
|
<form onsubmit='return false'>
|
|
|
|
|
|
|
|
<header>${__("Caption")}</header>
|
|
|
|
<section>
|
|
|
|
<input style='font-size : 16px; color : ${fg_color}; background : ${bg_color}; transition : background 0.1s linear'
|
|
|
|
id='labelEdit_caption'
|
|
|
|
name='caption'
|
|
|
|
dojoType='dijit.form.ValidationTextBox'
|
|
|
|
required='true'
|
|
|
|
value="${App.escapeHtml(reply.caption)}">
|
|
|
|
</section>
|
|
|
|
|
2021-02-17 16:34:54 +00:00
|
|
|
${App.FormFields.hidden_tag('id', id)}
|
|
|
|
${App.FormFields.hidden_tag('op', 'pref-labels')}
|
|
|
|
${App.FormFields.hidden_tag('method', 'save')}
|
2021-02-13 10:17:34 +00:00
|
|
|
|
2021-02-17 16:34:54 +00:00
|
|
|
${App.FormFields.hidden_tag('fg_color', fg_color, {}, 'labelEdit_fgColor')}
|
|
|
|
${App.FormFields.hidden_tag('bg_color', bg_color, {}, 'labelEdit_bgColor')}
|
2021-02-13 10:17:34 +00:00
|
|
|
|
|
|
|
<header>${__("Colors")}</header>
|
|
|
|
<section>
|
|
|
|
<table width='100%'>
|
|
|
|
<tr>
|
|
|
|
<th>${__("Foreground:")}</th>
|
|
|
|
<th>${__("Background:")}</th>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td class='text-center'>
|
|
|
|
<div dojoType='dijit.ColorPalette'>
|
|
|
|
<script type='dojo/method' event='onChange' args='fg_color'>
|
|
|
|
dijit.byId('labelEdit_fgColor').attr('value', fg_color);
|
|
|
|
dijit.byId('labelEdit_caption').domNode.setStyle({color: fg_color});
|
|
|
|
</script>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td class='text-center'>
|
|
|
|
<div dojoType='dijit.ColorPalette'>
|
|
|
|
<script type='dojo/method' event='onChange' args='bg_color'>
|
|
|
|
dijit.byId('labelEdit_bgColor').attr('value', bg_color);
|
|
|
|
dijit.byId('labelEdit_caption').domNode.setStyle({backgroundColor: bg_color});
|
|
|
|
</script>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<footer>
|
|
|
|
<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick='App.dialogOf(this).execute()'>
|
|
|
|
${__('Save')}
|
|
|
|
</button>
|
|
|
|
<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>
|
|
|
|
${__('Cancel')}
|
|
|
|
</button>
|
|
|
|
</footer>
|
|
|
|
|
|
|
|
</form>
|
|
|
|
`
|
|
|
|
});
|
2021-02-12 15:38:26 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
dialog.show();
|
2018-12-02 09:03:28 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
});
|
2018-12-02 09:03:28 +00:00
|
|
|
},
|
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?"))) {
|
2018-12-02 17:56:30 +00:00
|
|
|
Notify.progress("Removing selected labels...");
|
2018-12-02 08:34:57 +00:00
|
|
|
|
|
|
|
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
|
|
|
|