[pve-devel] [RFC manager 2/5] GUI: Utils: add comment renderer and field provider

Matthias Heiserer m.heiserer at proxmox.com
Mon Feb 14 15:01:40 CET 2022


These render functions are used when displaying comments in a
separate column.
The `commentField` utility simplifies creation of comments.

Signed-off-by: Matthias Heiserer <m.heiserer at proxmox.com>
---
 www/manager6/Utils.js | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index aafe359a..2d03f611 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1803,6 +1803,45 @@ Ext.define('PVE.Utils', {
 
 	return undefined;
     },
+
+    renderComment: function(key, metaData, rec, rowIndex, colIndex, store, pending) {
+	if (rec && rec.data && rec.data.value) {
+	    let properties = PVE.Parser.parsePropertyString(rec.data.value, rec.data.key);
+	    if (properties && properties.comment) {
+		return properties.comment;
+	    }
+	}
+	// Try to extract a comment from the separate fields
+	// This is needed for single value fields like bios and memory
+	if (rec && rec.id) {
+	    let hw_name = rec.id;
+	    let comment = this.getObjectValue(`${hw_name}_comment`, undefined);
+	    if (comment) {
+		return comment;
+	    }
+	}
+	return PVE.Utils.noneText;
+    },
+
+    renderValueWithoutComment: function(context) {
+	return function(value, ...args) {
+	    if (value && typeof value === "string") {
+		value = value.replace(/comment=[^,]*(,|$)/, "");
+	    }
+	    return this.renderValue(value, ...args);
+	}.bind(context);
+    },
+
+    commentField: function(name = 'comment') {
+	return {
+	    xtype: 'textfield',
+	    name: name,
+	    fieldLabel: gettext('comment'),
+	    allowBlank: true,
+	    emptyText: '',
+	    defaultValue: '',
+	};
+    },
 },
 
     singleton: true,
-- 
2.30.2






More information about the pve-devel mailing list