diff options
Diffstat (limited to 'js/PrefLabelTree.js')
-rw-r--r-- | js/PrefLabelTree.js | 124 |
1 files changed, 123 insertions, 1 deletions
diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 7321b80d8..f808e987b 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -37,7 +37,129 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f 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; + }, + reload: function() { + xhrPost("backend.php", { op: "pref-labels" }, (transport) => { + dijit.byId('labelConfigTab').attr('content', transport.responseText); + Notify.close(); + }); + }, + editLabel: function(id) { + const query = "backend.php?op=pref-labels&method=edit&id=" + + encodeURIComponent(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, () => { + dijit.byId("filterTree").reload(); // maybe there's labels in there + }); + + }, + 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'), () => { + dijit.byId("filterTree").reload(); // maybe there's labels in there + }); + } + }, + href: query + }); + + dialog.show(); + }, + 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, () => { + this.reload(); + }); + } + + } else { + alert(__("No labels 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, () => { + this.reload(); + }); + } + } else { + alert(__("No labels selected.")); + } + + return false; + } +}); }); |