]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/form/GuestIDSelector.js
ui: iso selector: fix layout, stretch items again to full space
[pve-manager.git] / www / manager6 / form / GuestIDSelector.js
index 819cef90172fc28014e4381813722593e652c571..e24c01c948b0171e6fec52970590dcecc88d8eef 100644 (file)
@@ -14,62 +14,78 @@ Ext.define('PVE.form.GuestIDSelector', {
 
     guestType: undefined,
 
+    validator: function(value) {
+       var me = this;
+
+       if (!Ext.isNumeric(value) ||
+           value < me.minValue ||
+           value > me.maxValue) {
+           // check is done by ExtJS
+           return true;
+       }
+
+       if (me.validateExists === true && !me.exists) {
+           return me.unknownID;
+       }
+
+       if (me.validateExists === false && me.exists) {
+           return me.inUseID;
+       }
+
+       return true;
+    },
+
     initComponent: function() {
        var me = this;
        var label = '{0} ID';
-       var unknownID = 'This {0} ID does not exists';
-       var inUseID = 'This {0} ID is already in use';
+       var unknownID = gettext('This {0} ID does not exist');
+       var inUseID = gettext('This {0} ID is already in use');
+       var type = 'CT/VM';
 
        if (me.guestType === 'lxc') {
-           label = Ext.String.format(label, 'CT');
-           unknownID = Ext.String.format(gettext(unknownID), 'CT');
-           inUseID = Ext.String.format(gettext(inUseID), 'CT');
+           type = 'CT';
        } else if (me.guestType === 'qemu') {
-           label = Ext.String.format(label, 'VM');
-           unknownID = Ext.String.format(gettext(unknownID), 'VM');
-           inUseID = Ext.String.format(gettext(inUseID), 'VM');
-       } else {
-           label = Ext.String.format(label, 'CT/VM');
-           unknownID = Ext.String.format(gettext(unknownID), 'CT/VM');
-           inUseID = Ext.String.format(gettext(inUseID), 'CT/VM');
+           type = 'VM';
        }
 
+       me.label = Ext.String.format(label, type);
+       me.unknownID = Ext.String.format(unknownID, type);
+       me.inUseID = Ext.String.format(inUseID, type);
+
        Ext.apply(me, {
-           fieldLabel: label,
+           fieldLabel: me.label,
            listeners: {
                'change': function(field, newValue, oldValue) {
                    if (!Ext.isDefined(me.validateExists)) {
                        return;
                    }
-                   PVE.Utils.API2Request({
+                   Proxmox.Utils.API2Request({
                        params: { vmid: newValue },
                        url: '/cluster/nextid',
                        method: 'GET',
                        success: function(response, opts) {
-                           if (me.validateExists === true) {
-                               me.markInvalid(unknownID);
-                           }
+                           me.exists = false;
+                           me.validate();
                        },
                        failure: function(response, opts) {
-                           if (me.validateExists === false) {
-                               me.markInvalid(inUseID);
-                           }
-                       }
+                           me.exists = true;
+                           me.validate();
+                       },
                    });
-               }
-           }
+               },
+           },
        });
 
         me.callParent();
 
        if (me.loadNextFreeID) {
-           PVE.Utils.API2Request({
+           Proxmox.Utils.API2Request({
                url: '/cluster/nextid',
                method: 'GET',
                success: function(response, opts) {
                    me.setRawValue(response.result.data);
-               }
+               },
            });
        }
-    }
+    },
 });