]> git.proxmox.com Git - pve-manager.git/commitdiff
ui: qemu: change logic to use ViewModel instead of listener function
authorMarkus Frank <m.frank@proxmox.com>
Mon, 22 Apr 2024 10:27:55 +0000 (12:27 +0200)
committerDominik Csapak <d.csapak@proxmox.com>
Mon, 22 Apr 2024 12:49:35 +0000 (14:49 +0200)
Signed-off-by: Markus Frank <m.frank@proxmox.com>
Reviewed-by: Dominik Csapak <d.csapak@proxmox.com>
Tested-by: Dominik Csapak <d.csapak@proxmox.com>
www/manager6/qemu/DisplayEdit.js

index 9bb1763ece1fd8b5b20704a49c1d3b25a4882421..f2649c1c998cb1ca8809bf9c0c8f76082ff2dd4e 100644 (file)
@@ -11,6 +11,33 @@ Ext.define('PVE.qemu.DisplayInputPanel', {
        return { vga: ret };
     },
 
+    viewModel: {
+       data: {
+           type: '__default__',
+           clipboard: '__default__',
+       },
+       formulas: {
+           matchNonGUIOption: function(get) {
+               return get('type').match(/^(serial\d|none)$/);
+           },
+           memoryEmptyText: function(get) {
+               let val = get('type');
+               if (val === "cirrus") {
+                   return "4";
+               } else if (val === "std" || val.match(/^qxl\d?$/) || val === "vmware") {
+                   return "16";
+               } else if (val.match(/^virtio/)) {
+                   return "256";
+               } else if (get('matchNonGUIOption')) {
+                   return "N/A";
+               } else {
+                   console.debug("unexpected display type", val);
+                   return Proxmox.Utils.defaultText;
+               }
+           },
+       },
+    },
+
     items: [{
        name: 'type',
        xtype: 'proxmoxKVComboBox',
@@ -27,29 +54,8 @@ Ext.define('PVE.qemu.DisplayInputPanel', {
            }
            return true;
        },
-       listeners: {
-           change: function(cb, val) {
-               if (!val) {
-                   return;
-               }
-               let memoryfield = this.up('panel').down('field[name=memory]');
-               let disableMemoryField = false;
-
-               if (val === "cirrus") {
-                   memoryfield.setEmptyText("4");
-               } else if (val === "std" || val.match(/^qxl\d?$/) || val === "vmware") {
-                   memoryfield.setEmptyText("16");
-               } else if (val.match(/^virtio/)) {
-                   memoryfield.setEmptyText("256");
-               } else if (val.match(/^(serial\d|none)$/)) {
-                   memoryfield.setEmptyText("N/A");
-                   disableMemoryField = true;
-               } else {
-                   console.debug("unexpected display type", val);
-                   memoryfield.setEmptyText(Proxmox.Utils.defaultText);
-               }
-               memoryfield.setDisabled(disableMemoryField);
-           },
+       bind: {
+           value: '{type}',
        },
     },
     {
@@ -60,6 +66,10 @@ Ext.define('PVE.qemu.DisplayInputPanel', {
        maxValue: 512,
        step: 4,
        name: 'memory',
+       bind: {
+           emptyText: '{memoryEmptyText}',
+           disabled: '{matchNonGUIOption}',
+       },
     }],
 });