From e7924c6dacef405a6e20b41d078f4a90a210cb51 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 13 Feb 2021 13:17:34 +0300 Subject: label editor: use client dialog --- js/PrefLabelTree.js | 167 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 54 deletions(-) (limited to 'js/PrefLabelTree.js') diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 73f375f2d..88e88b669 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-rest-params */ -/* global __, define, lib, dijit, dojo, xhrPost, Notify, fox */ +/* global __, define, lib, dijit, dojo, xhrPost, Notify, fox, App */ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare, domConstruct) { @@ -61,70 +61,129 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }); }, editLabel: function(id) { - const dialog = new fox.SingleUseDialog({ - id: "labelEditDlg", - title: __("Label Editor"), - style: "width: 650px", - 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 = $("icon-label-" + id); - - if (e) { - if (bg) e.style.color = bg; - } + xhrJson("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { - const query = { - op: "pref-labels", method: "colorset", kind: kind, - ids: id, fg: fg, bg: bg, color: color - }; + console.log(reply); - xhrPost("backend.php", query, () => { - const tree = dijit.byId("filterTree"); - if (tree) tree.reload(); // maybe there's labels in there - }); + 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 = ''; - }, - 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; + if (fg && bg) { + kind = 'both'; + } else if (fg) { + kind = 'fg'; + color = fg; + } else if (bg) { + kind = 'bg'; + color = bg; + } - dijit.byId('labelTree').setNameById(id, caption); - this.setLabelColor(id, fg_color, bg_color); - this.hide(); + const e = $("icon-label-" + id); - xhrPost("backend.php", this.attr('value'), () => { + 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, () => { const tree = dijit.byId("filterTree"); if (tree) tree.reload(); // maybe there's labels in there }); - } - }, - content: __("Loading, please wait...") - }); - const tmph = dojo.connect(dialog, 'onShow', function () { - dojo.disconnect(tmph); + }, + 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: ` +
+ +
${__("Caption")}
+
+ +
+ + ${App.FormFields.hidden('id', id)} + ${App.FormFields.hidden('op', 'pref-labels')} + ${App.FormFields.hidden('method', 'save')} + + ${App.FormFields.hidden('fg_color', fg_color, 'labelEdit_fgColor')} + ${App.FormFields.hidden('bg_color', bg_color, 'labelEdit_bgColor')} + +
${__("Colors")}
+
+ + + + + + + + + +
${__("Foreground:")}${__("Background:")}
+
+ +
+
+
+ +
+
+
+ +
+ + +
+ +
+ ` + }); - xhrPost("backend.php", {op: "pref-labels", method: "edit", id: id}, (transport) => { - dialog.attr('content', transport.responseText); - }) - }); + dialog.show(); - dialog.show(); + }); }, resetColors: function() { const labels = this.getSelectedLabels(); -- cgit v1.2.3 From b16abc157ee584f4be80a537ee24ec9e5ff25496 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 17 Feb 2021 19:34:54 +0300 Subject: * App: rename hidden to hidden_tag * search: use client dialog * add some form field helpers --- js/PrefLabelTree.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/PrefLabelTree.js') diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 88e88b669..f22423091 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -133,12 +133,12 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f value="${App.escapeHtml(reply.caption)}"> - ${App.FormFields.hidden('id', id)} - ${App.FormFields.hidden('op', 'pref-labels')} - ${App.FormFields.hidden('method', 'save')} + ${App.FormFields.hidden_tag('id', id)} + ${App.FormFields.hidden_tag('op', 'pref-labels')} + ${App.FormFields.hidden_tag('method', 'save')} - ${App.FormFields.hidden('fg_color', fg_color, 'labelEdit_fgColor')} - ${App.FormFields.hidden('bg_color', bg_color, 'labelEdit_bgColor')} + ${App.FormFields.hidden_tag('fg_color', fg_color, {}, 'labelEdit_fgColor')} + ${App.FormFields.hidden_tag('bg_color', bg_color, {}, 'labelEdit_bgColor')}
${__("Colors")}
-- cgit v1.2.3 From 70fa4230268a422d0b7eef1ea223ca5cc1c14646 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 18 Feb 2021 21:51:18 +0300 Subject: initial for RIP prototype/scriptaculous --- js/PrefLabelTree.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/PrefLabelTree.js') diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index f22423091..4392dfc44 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -48,7 +48,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f const items = tree.model.getCheckedItems(); const rv = []; - items.each(function(item) { + items.forEach(function(item) { rv.push(tree.model.store.getValue(item, 'bare_id')); }); @@ -87,7 +87,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f color = bg; } - const e = $("icon-label-" + id); + const e = App.byId("icon-label-" + id); if (e) { if (bg) e.style.color = bg; -- cgit v1.2.3 From 6b43b788d909ce20f07f29f9f3ccd2f6a8715616 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 10:22:00 +0300 Subject: migrate xhrJson invocations to the new helper --- js/PrefLabelTree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/PrefLabelTree.js') diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 4392dfc44..9d16a147c 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -61,7 +61,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f }); }, editLabel: function(id) { - xhrJson("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { + xhr.json("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { console.log(reply); -- cgit v1.2.3 From bb4e4282f46824308aebc2eaeac29fa29f8687ad Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 11:28:14 +0300 Subject: migrate a bunch of xhrPost invocations --- js/PrefLabelTree.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/PrefLabelTree.js') diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 9d16a147c..5e024afde 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -1,5 +1,5 @@ /* eslint-disable prefer-rest-params */ -/* global __, define, lib, dijit, dojo, xhrPost, Notify, fox, App */ +/* global __, define, lib, dijit, dojo, xhr, Notify, fox, App */ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare, domConstruct) { @@ -98,7 +98,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f ids: id, fg: fg, bg: bg, color: color }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { const tree = dijit.byId("filterTree"); if (tree) tree.reload(); // maybe there's labels in there }); @@ -114,7 +114,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f this.setLabelColor(id, fg_color, bg_color); this.hide(); - xhrPost("backend.php", this.attr('value'), () => { + xhr.post("backend.php", this.attr('value'), () => { const tree = dijit.byId("filterTree"); if (tree) tree.reload(); // maybe there's labels in there }); @@ -196,7 +196,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f ids: labels.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } @@ -217,7 +217,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f ids: sel_rows.toString() }; - xhrPost("backend.php", query, () => { + xhr.post("backend.php", query, () => { this.reload(); }); } -- cgit v1.2.3 From 660a1bbe011fef5f0fa6bb0af43521fed7598cc7 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 13:44:56 +0300 Subject: * switch to xhr.post() almost everywhere * call App.handlerpcjson() automatically on json request (if possible) * show net/log indicators in prefs --- js/PrefLabelTree.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/PrefLabelTree.js') diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 5e024afde..627b2cfbe 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -55,8 +55,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f return rv; }, reload: function() { - xhrPost("backend.php", { op: "pref-labels" }, (transport) => { - dijit.byId('labelsTab').attr('content', transport.responseText); + xhr.post("backend.php", { op: "pref-labels" }, (reply) => { + dijit.byId('labelsTab').attr('content', reply); Notify.close(); }); }, -- cgit v1.2.3 From d9fe14a0123eb90008a1be4b6ab9bb21b42f3776 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 19 Feb 2021 15:09:53 +0300 Subject: use template strings in a bunch of places instead of id concatenation --- js/PrefLabelTree.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'js/PrefLabelTree.js') diff --git a/js/PrefLabelTree.js b/js/PrefLabelTree.js index 627b2cfbe..2b78927c2 100644 --- a/js/PrefLabelTree.js +++ b/js/PrefLabelTree.js @@ -63,8 +63,6 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f editLabel: function(id) { xhr.json("backend.php", {op: "pref-labels", method: "edit", id: id}, (reply) => { - console.log(reply); - const fg_color = reply['fg_color']; const bg_color = reply['bg_color'] ? reply['bg_color'] : '#fff7d5'; @@ -87,7 +85,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/f color = bg; } - const e = App.byId("icon-label-" + id); + const e = App.byId(`icon-label-${id}`); if (e) { if (bg) e.style.color = bg; -- cgit v1.2.3