From b5d62b73c9f2141b020df17416dfd164f3246a31 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Wed, 9 Sep 2026 08:08:31 +1000 Subject: [PATCH] FE: Easier icon add in Settings #1773 --- front/js/settings_utils.js | 50 ++++++++++++++++++++----- server/plugins/custom_props/config.json | 5 ++- server/plugins/ui_settings/config.json | 5 ++- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/front/js/settings_utils.js b/front/js/settings_utils.js index 615f25b9..5ed2e5ee 100755 --- a/front/js/settings_utils.js +++ b/front/js/settings_utils.js @@ -351,6 +351,26 @@ function addViaPopupForm(element) { settingsChanged(); } +// --------------------------------------------------------- +// Commit a value as a new interactive option on a target select, +// shared by addList (typed value) and addIconViaModal (pasted/encoded value) +function appendListOption(toId, value, label = value) { + const newOption = $("") + .attr("value", value) + .text(label); + + // add new option + $(`#${toId}`).append(newOption); + + // Initialize interaction options only for the newly added option + initListInteractionOptions(newOption); + + // flag something changes to prevent navigating from page + settingsChanged(); + + return newOption; +} + // --------------------------------------------------------- // Add item to list function addList(element, clearInput = true) { @@ -361,23 +381,33 @@ function addList(element, clearInput = true) { console.log(`fromId | toId | input : ${fromId} | ${toId} | ${input}`); - const newOption = $("") - .attr("value", input) - .text(input); - - // add new option - $(`#${toId}`).append(newOption); + appendListOption(toId, input); // clear input if (clearInput) { $(`#${fromId}`).val(""); } +} - // Initialize interaction options only for the newly added option - initListInteractionOptions(newOption); +// --------------------------------------------------------- +// Add a new icon to a target select by pasting raw SVG/Font-Awesome HTML +// in a modal and base64-encoding it automatically, instead of requiring +// the value to already be base64-encoded in the (hidden) input. +function addIconViaModal(button) { + const toId = $(button).attr("my-input-to"); - // flag something changes to prevent navigating from page - settingsChanged(); + showModalInput( + ' ' + getString('DevDetail_button_AddIcon'), + getString('DevDetail_button_AddIcon_Help'), + getString('Gen_Cancel'), + getString('Gen_Okay'), + () => { + const raw = $('#modal-input-textarea').val(); + const encoded = btoa(raw.replace(/"/g, "'")); + appendListOption(toId, encoded); + }, + null + ); } // --------------------------------------------------------- diff --git a/server/plugins/custom_props/config.json b/server/plugins/custom_props/config.json index 5d053f00..c3361c73 100755 --- a/server/plugins/custom_props/config.json +++ b/server/plugins/custom_props/config.json @@ -40,7 +40,8 @@ { "placeholder": "Enter value" }, { "suffix": "_in" }, { "cssClasses": "col-sm-10" }, - { "prefillValue": "null" } + { "prefillValue": "null" }, + { "type": "hidden" } ], "transformers": [] }, @@ -50,7 +51,7 @@ { "sourceSuffixes": ["_in"] }, { "separator": "" }, { "cssClasses": "col-xs-12" }, - { "onClick": "addList(this,false)" }, + { "onClick": "addIconViaModal(this)" }, { "getStringKey": "Gen_Add" } ], "transformers": [] diff --git a/server/plugins/ui_settings/config.json b/server/plugins/ui_settings/config.json index ac71ded2..165dd5ef 100755 --- a/server/plugins/ui_settings/config.json +++ b/server/plugins/ui_settings/config.json @@ -140,7 +140,8 @@ { "placeholder": "Enter value" }, { "suffix": "_in" }, { "cssClasses": "col-sm-10" }, - { "prefillValue": "null" } + { "prefillValue": "null" }, + { "type": "hidden" } ], "transformers": [] }, @@ -150,7 +151,7 @@ { "sourceSuffixes": ["_in"] }, { "separator": "" }, { "cssClasses": "col-xs-12" }, - { "onClick": "addList(this,false)" }, + { "onClick": "addIconViaModal(this)" }, { "getStringKey": "Gen_Add" } ], "transformers": []