fix batch tags dialogue box #6971

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Apr 15, 2025 at 21:12 UTC 2b1129fb132e8394deda65c2dc22160d8814d099
2 files changed +23 -23
translate/translate.json
+2 -2
@@ -29883,7 +29883,7 @@
29883 "zh-cht": "編輯裝置標籤",
29884 "xloc": [
29885 "default.handlebars->47->776",
29886 - "default3.handlebars->35->773"
29886 + "default3.handlebars->35->772"
29887 ]
29888 },
29889 {
@@ -81445,7 +81445,7 @@
81445 "default.handlebars->47->1380",
81446 "default.handlebars->47->775",
81447 "default3.handlebars->35->1366",
81448 - "default3.handlebars->35->772"
81448 + "default3.handlebars->35->773"
81449 ]
81450 },
81451 {
views/default3.handlebars
+21 -21
@@ -6628,17 +6628,29 @@
6628 } else if (op == 107) {
6629 // Edit tags
6630 var x = "Perform batch device tag operation" + '<br /><br />';
6631 - x += addHtmlFormFloating("Operation", '<select id=d2deviceop class="form-select-sm me-2"><option value=1>' + "Add tags" + '</option><option value=2>' + "Set tags" + '</option><option value=3>' + "Remove tags" + '</option></select>');
6632 - x += addHtmlFormFloating("Tags", '<input id=dp10devicevalue class="form-control" maxlength=4096 placeholder="' + "Tag1, Tag2, Tag3" + '" />');
6631 + x += addHtmlFormFloating("Operation", '<select id=d2deviceop class="form-select"><option value=1>' + "Add tags" + '</option><option value=2>' + "Set tags" + '</option><option value=3>' + "Remove tags" + '</option></select>');
6632 + x += addHtmlFormFloating("Tags", '<select id=dp10devicevalue multiple class="form-control" maxlength=4096>');
6633 // Get a list of all possible device tags
6634 var allTags = [], y = '';
6635 for (var i in nodes) { if (nodes[i].tags) { for (var j in nodes[i].tags) { if (allTags.indexOf(nodes[i].tags[j]) == -1) { allTags.push(nodes[i].tags[j]); } } } }
6636 if (allTags.length > 0) {
6637 allTags.sort();
6638 - for (var i in allTags) { y += '<span style=padding:4px;background-color:#BBB;border-radius:3px;cursor:pointer onclick=showEditNodeValueDialogAddTag("' + encodeURIComponentEx(allTags[i]) + '")>' + EscapeHtml(allTags[i]) + '</span> '; }
6639 - x += '<div style=margin-top:8px;width:370px;line-height:26px;max-height:160px;overflow-y:auto>' + y + '</div>';
6638 + for (var i in allTags) {
6639 + var tag = EscapeHtml(allTags[i]);
6640 + y += '<option>' + EscapeHtml(allTags[i]) + '</option>';
6641 + }
6642 }
6643 + x += y + '</select>'
6644 setModalContent('xxAddAgent', "Edit Device Tags", x);
6645 + $('#dp10devicevalue').select2({
6646 + theme: 'bootstrap-5',
6647 + width: $( this ).data( 'width' ) ? $( this ).data( 'width' ) : $( this ).hasClass( 'w-100' ) ? '100%' : 'style',
6648 + placeholder: "Tag1, Tag2, Tag3",
6649 + closeOnSelect: false,
6650 + allowClear: true,
6651 + tokenSeparators: [','],
6652 + tags: true
6653 + });
6654 showModal('xxAddAgentModal', 'idx_dlgOkButton', () => d2groupActionFunctionTagsExec());
6655 } else if (op == 108) {
6656 // Device notification
@@ -6718,12 +6730,13 @@
6730 }
6731
6732 function d2groupActionFunctionTagsExec() {
6721 - var chkNodeIds = getCheckedDevices(), op = Q('d2deviceop').value, optags = Q('dp10devicevalue').value;
6733 + var chkNodeIds = getCheckedDevices(), op = Q('d2deviceop').value, optags = [];
6734 + var tt = $('#dp10devicevalue').select2('data');
6735 + for (var i in tt) { optags.push(tt[i]['text'].trim()); }
6736 if (op == 2) { // Set tags
6723 - for (var i in chkNodeIds) { meshserver.send({ action: 'changedevice', nodeid: chkNodeIds[i], tags: optags }); }
6737 + for (var i in chkNodeIds) { meshserver.send({ action: 'changedevice', nodeid: chkNodeIds[i], tags: optags.join(',') }); }
6738 } else {
6739 var taggroup = [];
6726 - optags = optags.split(',');
6740 for (var i in optags) { var tname = optags[i].trim(); if ((tname.length > 0) && (tname.length < 64) && (taggroup.indexOf(tname) == -1)) { taggroup.push(tname); } }
6741 for (var i in chkNodeIds) {
6742 var nodeTags = null, tagChanges = false, n = getNodeFromId(chkNodeIds[i]);
@@ -9826,13 +9839,12 @@
9839 if (v == null) v = '';
9840 if (mode == 3) {
9841 // Get a list of all possible device tags
9829 - x = '<select id=dp10devicevalue multiple class="form-control" maxlength=' + showEditNodeValueDialog_modes4[mode] + ' class=form-control>';
9842 + x = '<select id=dp10devicevalue multiple maxlength=' + showEditNodeValueDialog_modes4[mode] + ' class=form-control>';
9843 var allTags = [];
9844 for (var i in nodes) { if (nodes[i].tags) { for (var j in nodes[i].tags) { if (allTags.indexOf(nodes[i].tags[j]) == -1) { allTags.push(nodes[i].tags[j]); } } } }
9845 if (allTags.length > 0) {
9846 allTags.sort();
9847 for (var i in allTags) {
9835 - var tag = EscapeHtml(allTags[i]);
9848 y += Array.isArray(v) && v.indexOf(allTags[i]) !== -1 ? '<option selected=selected>' + EscapeHtml(allTags[i]) + '</option>' : '<option>' + EscapeHtml(allTags[i]) + '</option>';
9849 }
9850 }
@@ -9852,24 +9864,12 @@
9864 setModalContent('xxAddAgent', "Edit Device", x);
9865 if (Array.isArray(v)) { v = v.join(', '); }
9866 Q('dp10devicevalue').value = v;
9855 - showModal('xxAddAgentModal', 'idx_dlgOkButton', function () {
9856 - showEditNodeValueDialogEx(3, mode);
9857 - });
9867 }
9868 p10editdevicevalueValidate();
9869 showModal('xxAddAgentModal', 'idx_dlgOkButton', function () { showEditNodeValueDialogEx(3, mode); });
9870 Q('dp10devicevalue').focus();
9871 }
9872
9864 - function showEditNodeValueDialogAddTag(t) {
9865 - var tt = Q('dp10devicevalue').value.split(','), t2 = [];
9866 - for (var i in tt) { t2.push(tt[i].trim()); }
9867 - if (t2.indexOf(t) >= 0) return;
9868 - Q('dp10devicevalue').value += ((Q('dp10devicevalue').value.length == 0) ? '' : ', ') + decodeURIComponent(t);
9869 - setTimeout(function () { Q('dp10devicevalue').selectionStart = Q('dp10devicevalue').selectionEnd = 90000; }, 0);
9870 - p10editdevicevalueValidate();
9871 - }
9872 -
9873 function showEditNodeValueDialogEx(button, mode) {
9874 var tags = '';
9875 var x = { action: 'changedevice', nodeid: currentNode._id };