public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH widget-toolkit 2/2] window: edit: added `convertNewlines` config
Date: Fri, 15 Sep 2023 11:46:35 +0200	[thread overview]
Message-ID: <20230915094635.61759-3-g.goller@proxmox.com> (raw)
In-Reply-To: <20230915094635.61759-1-g.goller@proxmox.com>

When setting `convertNewlines` to true, all the '\n' will
be converted to '<br>' tags and vice-versa. This means we
can press enter in a `textfieldarea`, save the config and
we get a '<br>' in the config file. When editing the value,
the '<br>' will be converted back to a '\n'.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---

Note: Implemented to close #4589 (support multi-line comments)

 src/window/Edit.js | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/window/Edit.js b/src/window/Edit.js
index 7f94e30..97cd4d2 100644
--- a/src/window/Edit.js
+++ b/src/window/Edit.js
@@ -66,6 +66,9 @@ Ext.define('Proxmox.window.Edit', {
     // onlineHelp of our first item, if set.
     onlineHelp: undefined,
 
+    // converts newlines '\n' to html '<br>' tags and vice-versa
+    convertNewlines: false,
+
     isValid: function() {
 	let me = this;
 
@@ -83,7 +86,15 @@ Ext.define('Proxmox.window.Edit', {
 
 	form.getFields().each(function(field) {
 	    if (!field.up('inputpanel') && (!dirtyOnly || field.isDirty())) {
-		Proxmox.Utils.assemble_field_data(values, field.getSubmitData());
+		let fieldData = field.getSubmitData();
+		if (me.convertNewlines) {
+		    for (let key in fieldData) {
+			if (typeof fieldData[key] === 'string' || fieldData[key] instanceof String) {
+			    fieldData[key] = fieldData[key].replaceAll('\n', '<br>');
+			}
+		    }
+		}
+		Proxmox.Utils.assemble_field_data(values, fieldData);
 	    }
 	});
 
@@ -105,7 +116,13 @@ Ext.define('Proxmox.window.Edit', {
 	        (f.id === id || f.name === id || f.dataIndex === id) && !f.up('inputpanel'),
 	    );
 	    fields.each((field) => {
+		if (me.convertNewlines) {
+		    if (typeof val === 'string' || val instanceof String) {
+			val = val.replaceAll('<br>', '\n');
+		    }
+		}
 		field.setValue(val);
+
 		if (form.trackResetOnLoad) {
 		    field.resetOriginalValue();
 		}
-- 
2.39.2





      parent reply	other threads:[~2023-09-15  9:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-15  9:46 [pbs-devel] [PATCH proxmox-backup 0/2] support multi-line comments in Gabriel Goller
2023-09-15  9:46 ` [pbs-devel] [PATCH proxmox-backup 1/2] close #4589: allow multi-line comments in datastore notes Gabriel Goller
2023-09-15  9:46 ` Gabriel Goller [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230915094635.61759-3-g.goller@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal