]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - Toolkit.js
add Realm model and RealmComboBox
[proxmox-widget-toolkit.git] / Toolkit.js
index cb37972294fe77092e1416b4858274324970b104..c30aae1fb94e0e31857bf9bad74ac0854d27a6fe 100644 (file)
@@ -3,6 +3,11 @@
  // do not send '_dc' parameter
 Ext.Ajax.disableCaching = false;
 
+// FIXME: HACK! Makes scrolling in number spinner work again. fixed in ExtJS >= 6.1
+if (Ext.isFirefox) {
+    Ext.$eventNameMap.DOMMouseScroll = 'DOMMouseScroll';
+}
+
 // custom Vtypes
 Ext.apply(Ext.form.field.VTypes, {
     IPAddress:  function(v) {
@@ -47,6 +52,22 @@ Ext.apply(Ext.form.field.VTypes, {
     IP64AddressText:  gettext('Example') + ': 192.168.1.1 2001:DB8::42',
     IP64AddressMask: /[A-Fa-f0-9\.:]/,
 
+    IP64CIDRAddress: function(v) {
+       var result = Proxmox.Utils.IP64_cidr_match.exec(v);
+       if (result === null) {
+           return false;
+       }
+       if (result[1] !== undefined) {
+           return result[1] >= 8 && result[1] <= 128;
+       } else if (result[2] !== undefined) {
+           return result[2] >= 8 && result[2] <= 32;
+       } else {
+           return false;
+       }
+    },
+    IP64CIDRAddressText: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64',
+    IP64CIDRAddressMask: /[A-Fa-f0-9\.:\/]/,
+
     MacAddress: function(v) {
        return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v);
     },
@@ -62,6 +83,14 @@ Ext.apply(Ext.form.field.VTypes, {
     BridgeName: function(v) {
         return (/^vmbr\d{1,4}$/).test(v);
     },
+    VlanName: function(v) {
+       if (Proxmox.Utils.VlanInterface_match.test(v)) {
+         return true;
+       } else if (Proxmox.Utils.Vlan_match.test(v)) {
+         return true;
+       }
+       return true;
+    },
     BridgeNameText: gettext('Format') + ': vmbr<b>N</b>, where 0 <= <b>N</b> <= 9999',
 
     BondName: function(v) {
@@ -192,6 +221,46 @@ Ext.define('EXTJS_23846.Gesture', {
     }
 });
 
+Ext.define('EXTJS_18900.Pie', {
+    override: 'Ext.chart.series.Pie',
+
+    // from 6.0.2
+    betweenAngle: function (x, a, b) {
+        var pp = Math.PI * 2,
+            offset = this.rotationOffset;
+
+        if (a === b) {
+            return false;
+        }
+
+        if (!this.getClockwise()) {
+            x *= -1;
+            a *= -1;
+            b *= -1;
+            a -= offset;
+            b -= offset;
+        } else {
+            a += offset;
+            b += offset;
+        }
+
+        x -= a;
+        b -= a;
+
+        // Normalize, so that both x and b are in the [0,360) interval.
+        x %= pp;
+        b %= pp;
+        x += pp;
+        b += pp;
+        x %= pp;
+        b %= pp;
+
+        // Because 360 * n angles will be normalized to 0,
+        // we need to treat b === 0 as a special case.
+        return x < b || b === 0;
+    },
+});
+
 // we always want the number in x.y format and never in, e.g., x,y
 Ext.define('PVE.form.field.Number', {
     override: 'Ext.form.field.Number',
@@ -264,7 +333,36 @@ Ext.define('Proxmox.form.ComboBox', {
            me.clearValue();
            me.setValue(me.originalValue);
        }
-    }
+    },
+
+    // we also want to open the trigger on editable comboboxes by default
+    initComponent: function() {
+       let me = this;
+       me.callParent();
+
+       if (me.editable) {
+           // The trigger.picker causes first a focus event on the field then
+           // toggles the selection picker. Thus skip expanding in this case,
+           // else our focus listener expands and the picker.trigger then
+           // collapses it directly afterwards.
+           Ext.override(me.triggers.picker, {
+               onMouseDown: function(e) {
+                   // copied "should we focus" check from Ext.form.trigger.Trigger
+                   if (e.pointerType !== 'touch' && !this.field.owns(Ext.Element.getActiveElement())) {
+                       me.skip_expand_on_focus = true;
+                   }
+                   this.callParent(arguments);
+               }
+           });
+
+           me.on("focus", function(combobox) {
+               if (!combobox.isExpanded && !combobox.skip_expand_on_focus) {
+                   combobox.expand();
+               }
+               combobox.skip_expand_on_focus = false;
+           });
+       }
+    },
 });
 
 // when refreshing a grid/tree view, restoring the focus moves the view back to
@@ -383,6 +481,12 @@ Ext.define(null, {
 
 });
 
+// add '@' to the valid id
+Ext.define('Proxmox.validIdReOverride', {
+    override: 'Ext.Component',
+    validIdRe: /^[a-z_][a-z0-9\-_\@]*$/i,
+});
+
 // force alert boxes to be rendered with an Error Icon
 // since Ext.Msg is an object and not a prototype, we need to override it
 // after the framework has been initiated