]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - src/Toolkit.js
language selector: increase only picker list view
[proxmox-widget-toolkit.git] / src / Toolkit.js
index 33b701596bc568ef045837a7b9eda1ab77ad7e79..4314fb4ab6164660510a501e1eb9e5a72d639662 100644 (file)
@@ -110,7 +110,7 @@ Ext.apply(Ext.form.field.VTypes, {
                   gettext("Must end with") + ": 'A-Z', 'a-z', '0-9'<br />",
 
     ConfigId: function(v) {
-        return (/^[a-z][a-z0-9_]+$/i).test(v);
+        return (/^[a-z][a-z0-9_-]+$/i).test(v);
     },
     ConfigIdText: gettext("Allowed characters") + ": 'A-Z', 'a-z', '0-9', '_'<br />" +
                  gettext("Minimum characters") + ": 2<br />" +
@@ -121,6 +121,11 @@ Ext.apply(Ext.form.field.VTypes, {
     },
     HttpProxyText: gettext('Example') + ": http://username:password&#64;host:port/",
 
+    CpuSet: function(v) {
+       return Proxmox.Utils.CpuSet_match.test(v);
+    },
+    CpuSetText: gettext('This is not a valid CpuSet'),
+
     DnsName: function(v) {
        return Proxmox.Utils.DnsName_match.test(v);
     },
@@ -131,9 +136,9 @@ Ext.apply(Ext.form.field.VTypes, {
     },
     DnsNameOrWildcardText: gettext('This is not a valid DNS name'),
 
-    // workaround for https://www.sencha.com/forum/showthread.php?302150
+    // email regex used by pve-common
     proxmoxMail: function(v) {
-        return (/^(\w+)([-+.][\w]+)*@(\w[-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v);
+        return (/^[\w+-~]+(\.[\w+-~]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*$/).test(v);
     },
     proxmoxMailText: gettext('Example') + ": user@example.com",
 
@@ -195,6 +200,16 @@ Ext.define('PVE.form.field.Number', {
     submitLocaleSeparator: false,
 });
 
+// avois spamming the console and if we ever use this avoid a CORS block error too
+Ext.define('PVE.draw.Container', {
+    override: 'Ext.draw.Container',
+    defaultDownloadServerUrl: document.location.origin, // avoid that pointing to http://svg.sencha.io
+    applyDownloadServerUrl: function(url) { // avoid noisy warning, we don't really use that anyway
+       url = url || this.defaultDownloadServerUrl;
+       return url;
+    },
+});
+
 // ExtJs 5-6 has an issue with caching
 // see https://www.sencha.com/forum/showthread.php?308989
 Ext.define('Proxmox.UnderlayPool', {
@@ -324,7 +339,7 @@ Ext.define(null, {
                navModel.setPosition();
            }
 
-           // Do not leave the element in tht state in case refresh fails, and restoration
+           // Do not leave the element in that state in case refresh fails, and restoration
            // closure not called.
            activeElement.resumeFocusEvents();
 
@@ -449,40 +464,22 @@ Ext.define(null, {
 
 // extj 6.7 reversed mousewheel direction... (fixed in 7.3)
 // https://forum.sencha.com/forum/showthread.php?472517-Mousewheel-scroll-direction-in-numberfield-with-spinners
-// alse use the 'wheel' event instead of 'mousewheel' (fixed in 7.3)
+// also use the 'wheel' event instead of 'mousewheel' (fixed in 7.3)
 Ext.define('Proxmox.form.field.Spinner', {
     override: 'Ext.form.field.Spinner',
 
     onRender: function() {
-       var me = this,
-           spinnerTrigger = me.getTrigger('spinner');
+       let me = this;
 
        me.callParent();
 
-       // Init up/down arrow keys
-       if (me.keyNavEnabled) {
-           me.spinnerKeyNav = new Ext.util.KeyNav({
-               target: me.inputEl,
-               scope: me,
-               up: me.spinUp,
-               down: me.spinDown,
-           });
-
-           me.inputEl.on({
-               keyup: me.onInputElKeyUp,
-               scope: me,
-           });
-       }
-
        // Init mouse wheel
        if (me.mouseWheelEnabled) {
+           // Unlisten Ext generated listener ('mousewheel' is deprecated anyway)
+           me.mun(me.bodyEl, 'mousewheel', me.onMouseWheel, me);
+
            me.mon(me.bodyEl, 'wheel', me.onMouseWheel, me);
        }
-
-       // in v4 spinUpEl/spinDownEl were childEls, now they are children of the trigger.
-       // create references for compatibility
-       me.spinUpEl = spinnerTrigger.upEl;
-       me.spinDownEl = spinnerTrigger.downEl;
     },
 
     onMouseWheel: function(e) {
@@ -675,6 +672,36 @@ Ext.define('Proxmox.Component', {
     clearPropertiesOnDestroy: false,
 });
 
+// Fix drag&drop for vms and desktops that detect 'pen' pointerType
+// NOTE: this part has been rewritten in ExtJS 7.4, so re-check once we can upgrade
+Ext.define('Proxmox.view.DragZone', {
+    override: 'Ext.view.DragZone',
+
+    onItemMouseDown: function(view, record, item, index, e) {
+        // Ignore touchstart.
+        // For touch events, we use longpress.
+        if (e.pointerType !== 'touch') {
+            this.onTriggerGesture(view, record, item, index, e);
+        }
+    },
+});
+
+// Fix text selection on drag when using DragZone,
+// see https://forum.sencha.com/forum/showthread.php?335100
+Ext.define('Proxmox.dd.DragDropManager', {
+    override: 'Ext.dd.DragDropManager',
+
+    stopEvent: function(e) {
+       if (this.stopPropagation) {
+           e.stopPropagation();
+       }
+
+       if (this.preventDefault) {
+           e.preventDefault();
+       }
+    },
+});
+
 // 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