]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
use validator for GuestIDSelector and optimize labels
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 21 Feb 2017 09:53:15 +0000 (10:53 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 9 Mar 2017 09:55:31 +0000 (10:55 +0100)
instead of using markInvalid, use a validator, which also marks the
field dirty and marks the form correctly invalid.

also optimize the label/error message assignments

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
www/manager6/form/GuestIDSelector.js

index 298988dd741ec1f1e67151034d0f4900f887d32c..0d4b85c3feb83fd48712da96cc8f2521d4c3196d 100644 (file)
@@ -14,28 +14,46 @@ 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;
+       }
+
+       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 = gettext('This {0} ID does not exists');
        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(unknownID, 'CT');
-           inUseID = Ext.String.format(inUseID, 'CT');
+           type = 'CT';
        } else if (me.guestType === 'qemu') {
-           label = Ext.String.format(label, 'VM');
-           unknownID = Ext.String.format(unknownID, 'VM');
-           inUseID = Ext.String.format(inUseID, 'VM');
-       } else {
-           label = Ext.String.format(label, 'CT/VM');
-           unknownID = Ext.String.format(unknownID, 'CT/VM');
-           inUseID = Ext.String.format(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)) {
@@ -46,14 +64,12 @@ Ext.define('PVE.form.GuestIDSelector', {
                        url: '/cluster/nextid',
                        method: 'GET',
                        success: function(response, opts) {
-                           if (me.validateExists === true) {
-                               me.markInvalid(unknownID);
-                           }
+                           me.exists = false;
+                           me.isValid();
                        },
                        failure: function(response, opts) {
-                           if (me.validateExists === false) {
-                               me.markInvalid(inUseID);
-                           }
+                           me.exists = true;
+                           me.isValid();
                        }
                    });
                }