]> 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 517f1a13a5df447a157513b481fdb71829a96e0d..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,14 +121,24 @@ 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);
     },
     DnsNameText: gettext('This is not a valid DNS name'),
 
-    // workaround for https://www.sencha.com/forum/showthread.php?302150
+    DnsNameOrWildcard: function(v) {
+       return Proxmox.Utils.DnsName_or_Wildcard_match.test(v);
+    },
+    DnsNameOrWildcardText: gettext('This is not a valid DNS name'),
+
+    // 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",
 
@@ -184,95 +194,22 @@ Ext.apply(Ext.form.field.VTypes, {
     },
 });
 
-// Firefox 52+ Touchscreen bug
-// see https://www.sencha.com/forum/showthread.php?336762-Examples-don-t-work-in-Firefox-52-touchscreen/page2
-// and https://bugzilla.proxmox.com/show_bug.cgi?id=1223
-Ext.define('EXTJS_23846.Element', {
-    override: 'Ext.dom.Element',
-}, function(Element) {
-    let supports = Ext.supports,
-        proto = Element.prototype,
-        eventMap = proto.eventMap,
-        additiveEvents = proto.additiveEvents;
-
-    if (Ext.os.is.Desktop && supports.TouchEvents && !supports.PointerEvents) {
-        eventMap.touchstart = 'mousedown';
-        eventMap.touchmove = 'mousemove';
-        eventMap.touchend = 'mouseup';
-        eventMap.touchcancel = 'mouseup';
-
-        additiveEvents.mousedown = 'mousedown';
-        additiveEvents.mousemove = 'mousemove';
-        additiveEvents.mouseup = 'mouseup';
-        additiveEvents.touchstart = 'touchstart';
-        additiveEvents.touchmove = 'touchmove';
-        additiveEvents.touchend = 'touchend';
-        additiveEvents.touchcancel = 'touchcancel';
-
-        additiveEvents.pointerdown = 'mousedown';
-        additiveEvents.pointermove = 'mousemove';
-        additiveEvents.pointerup = 'mouseup';
-        additiveEvents.pointercancel = 'mouseup';
-    }
-});
-
-Ext.define('EXTJS_23846.Gesture', {
-    override: 'Ext.event.publisher.Gesture',
-}, function(Gesture) {
-    let gestures = Gesture.instance;
-
-    if (Ext.supports.TouchEvents && !Ext.isWebKit && Ext.os.is.Desktop) {
-        gestures.handledDomEvents.push('mousedown', 'mousemove', 'mouseup');
-        gestures.registerEvents();
-    }
-});
-
-Ext.define('EXTJS_18900.Pie', {
-    override: 'Ext.chart.series.Pie',
-
-    // from 6.0.2
-    betweenAngle: function(x, a, b) {
-        let 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',
     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', {
@@ -306,20 +243,6 @@ Ext.define('Proxmox.UnderlayPool', {
     },
 });
 
-// 'Enter' in Textareas and aria multiline fields should not activate the
-// defaultbutton, fixed in extjs 6.0.2
-Ext.define('PVE.panel.Panel', {
-    override: 'Ext.panel.Panel',
-
-    fireDefaultButton: function(e) {
-       if (e.target.getAttribute('aria-multiline') === 'true' ||
-           e.target.tagName === "TEXTAREA") {
-           return true;
-       }
-       return this.callParent(arguments);
-    },
-});
-
 // if the order of the values are not the same in originalValue and value
 // extjs will not overwrite value, but marks the field dirty and thus
 // the reset button will be enabled (but clicking it changes nothing)
@@ -380,58 +303,105 @@ Ext.define(null, {
     jumpToFocus: false,
 
     saveFocusState: function() {
-       let me = this,
+       var me = this,
            store = me.dataSource,
            actionableMode = me.actionableMode,
            navModel = me.getNavigationModel(),
            focusPosition = actionableMode ? me.actionPosition : navModel.getPosition(true),
-           refocusRow, refocusCol;
-
-       if (focusPosition) {
+           activeElement = Ext.fly(Ext.Element.getActiveElement()),
+           focusCell = focusPosition && focusPosition.view === me &&
+           Ext.fly(focusPosition.getCell(true)),
+           refocusRow, refocusCol, record;
+
+       // The navModel may return a position that is in a locked partner, so check that
+       // the focusPosition's cell contains the focus before going forward.
+       // The skipSaveFocusState is set by Actionables which actively control
+       // focus destination. See CellEditing#activateCell.
+       if (!me.skipSaveFocusState && focusCell && focusCell.contains(activeElement)) {
            // Separate this from the instance that the nav model is using.
            focusPosition = focusPosition.clone();
 
-           // Exit actionable mode.
-           // We must inform any Actionables that they must relinquish control.
-           // Tabbability must be reset.
-           if (actionableMode) {
-               me.ownerGrid.setActionableMode(false);
+           // While we deactivate the focused element, suspend focus processing on it.
+           activeElement.suspendFocusEvents();
+
+           // Suspend actionable mode.
+           // Each Actionable must silently save its state ready to resume when focus
+           // can be restored but should only do that if the activeElement is not the cell itself,
+           // this happens when the grid is refreshed while one of the actionables is being
+           // deactivated (e.g. Calling  view refresh inside CellEditor 'edit' event listener).
+           if (actionableMode && focusCell.dom !== activeElement.dom) {
+               me.suspendActionableMode();
+           } else {
+               // Clear position, otherwise the setPosition on the other side
+               // will be rejected as a no-op if the resumption position is logically
+               // equivalent.
+               actionableMode = false;
+               navModel.setPosition();
            }
 
-           // Blur the focused descendant, but do not trigger focusLeave.
-           me.el.dom.focus();
+           // Do not leave the element in that state in case refresh fails, and restoration
+           // closure not called.
+           activeElement.resumeFocusEvents();
 
-           // Exiting actionable mode navigates to the owning cell, so in either focus mode we must
-           // clear the navigation position
-           navModel.setPosition();
+           // if the store is expanding or collapsing, we should never scroll the view.
+           if (store.isExpandingOrCollapsing) {
+               return Ext.emptyFn;
+           }
 
            // The following function will attempt to refocus back in the same mode to the same cell
-           // as it was at before based upon the previous record (if it's still inthe store), or the row index.
+           // as it was at before based upon the previous record (if it's still in the store),
+           // or the row index.
            return function() {
+               var all;
+
+               // May have changed due to reconfigure
+               store = me.dataSource;
+
                // If we still have data, attempt to refocus in the same mode.
                if (store.getCount()) {
-                   // Adjust expectations of where we are able to refocus according to what kind of destruction
-                   // might have been wrought on this view's DOM during focus save.
-                   refocusRow = Math.min(focusPosition.rowIdx, me.all.getCount() - 1);
-                   refocusCol = Math.min(focusPosition.colIdx,
-                                         me.getVisibleColumnManager().getColumns().length - 1);
-                   refocusRow = store.contains(focusPosition.record) ? focusPosition.record : refocusRow;
-                   focusPosition = new Ext.grid.CellContext(me).setPosition(refocusRow, refocusCol);
-
-                   if (actionableMode) {
-                       me.ownerGrid.setActionableMode(true, focusPosition);
-                   } else {
-                       me.cellFocused = true;
-
-                       // we sometimes want to scroll back to where we were
-                       let x = me.getScrollX();
-                       let y = me.getScrollY();
-
-                       // Pass "preventNavigation" as true so that that does not cause selection.
-                       navModel.setPosition(focusPosition, null, null, null, true);
-
-                       if (!me.jumpToFocus) {
-                           me.scrollTo(x, y);
+                   all = me.all;
+
+                   // Adjust expectations of where we are able to refocus according to
+                   // what kind of destruction might have been wrought on this view's DOM
+                   // during focus save.
+                   refocusRow =
+                       Math.min(Math.max(focusPosition.rowIdx, all.startIndex), all.endIndex);
+
+                   refocusCol = Math.min(
+                       focusPosition.colIdx,
+                       me.getVisibleColumnManager().getColumns().length - 1,
+                   );
+
+                   record = focusPosition.record;
+
+                   focusPosition = new Ext.grid.CellContext(me).setPosition(
+                       record && store.contains(record) && !record.isCollapsedPlaceholder
+                       ? record
+                       : refocusRow,
+                       refocusCol,
+                   );
+
+                   // Maybe there are no cells. eg: all groups collapsed.
+                   if (focusPosition.getCell(true)) {
+                       if (actionableMode) {
+                           me.resumeActionableMode(focusPosition);
+                       } else {
+                           // we sometimes want to scroll back to where we are
+
+                           let x = me.getScrollX();
+                           let y = me.getScrollY();
+
+                           // Pass "preventNavigation" as true
+                           // so that that does not cause selection.
+                           navModel.setPosition(focusPosition, null, null, null, true);
+
+                           if (!navModel.getPosition()) {
+                               focusPosition.column.focus();
+                           }
+
+                           if (!me.jumpToFocus) {
+                               me.scrollTo(x, y);
+                           }
                        }
                    }
                } else { // No rows - focus associated column header
@@ -443,13 +413,6 @@ Ext.define(null, {
     },
 });
 
-// should be fixed with ExtJS 6.0.2, see:
-// https://www.sencha.com/forum/showthread.php?307244-Bug-with-datefield-in-window-with-scroll
-Ext.define('Proxmox.Datepicker', {
-    override: 'Ext.picker.Date',
-    hideMode: 'visibility',
-});
-
 // ExtJS 6.0.1 has no setSubmitValue() (although you find it in the docs).
 // Note: this.submitValue is a boolean flag, whereas getSubmitValue() returns
 // data to be submitted.
@@ -501,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) {
@@ -721,15 +666,42 @@ Ext.define('Proxmox.selection.CheckboxModel', {
     },
 });
 
-// override the download server url globally, for privacy reasons
-Ext.draw.Container.prototype.defaultDownloadServerUrl = "-";
-
 // stop nulling of properties
 Ext.define('Proxmox.Component', {
     override: 'Ext.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