]> git.proxmox.com Git - proxmox-backup.git/commitdiff
ui: move max NS prefix length logic to reduced max-depth selector
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 13 May 2022 11:14:53 +0000 (13:14 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 13 May 2022 11:15:02 +0000 (13:15 +0200)
for better re-usability in the future and it felt a bit odd to have
such specific logic in the sync job edit directly

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
www/form/GroupSelector.js
www/form/NamespaceMaxDepth.js
www/window/SyncJobEdit.js

index 4bf511040ba8561ee9f1310375042ca537e9c297..6feb2878eb9c37adb1c866cc94fd2c99efacbdb7 100644 (file)
@@ -22,6 +22,7 @@ Ext.define('pbs-groups', {
 Ext.define('PBS.form.GroupSelector', {
     extend: 'Proxmox.form.ComboGrid',
     alias: 'widget.pbsGroupSelector',
+    mixins: ['Proxmox.Mixin.CBind'],
 
     allowBlank: false,
     autoSelect: false,
index 6304b6884ef1a85fe498e13d52e0013ca694dec9..cfe80de050ff5459069f15c2f35a06fc8280dec4 100644 (file)
@@ -35,12 +35,27 @@ Ext.define('PBS.form.NamespaceMaxDepthReduced', {
     extend: 'PBS.form.NamespaceMaxDepth',
     alias: 'widget.pbsNamespaceMaxDepthReduced',
 
-       setLimit: function(maxPrefixLength) {
-               let me = this;
-               if (maxPrefixLength !== undefined) {
-                       me.maxValue = 7-maxPrefixLength;
-               } else {
-                       me.maxValue = 7;
-               }
-       },
+    calcMaxPrefixLength: function(ns1, ns2) {
+       let maxPrefixLength = 0;
+       if (ns1 !== undefined && ns1 !== null) {
+           maxPrefixLength = (ns1.match(/[/]/g) || []).length + (ns1 === '' ? 0 : 1);
+       }
+       if (ns2 !== undefined && ns2 !== null) {
+           let ns2PrefixLength = (ns2.match(/[/]/g) || []).length + (ns2 === '' ? 0 : 1);
+           if (ns2PrefixLength > maxPrefixLength) {
+               maxPrefixLength = ns2PrefixLength;
+           }
+       }
+       return maxPrefixLength;
+    },
+
+    setLimit: function(ns1, ns2) {
+       let me = this;
+       let maxPrefixLength = me.calcMaxPrefixLength(ns1, ns2);
+       if (maxPrefixLength !== undefined) {
+           me.maxValue = 7 - maxPrefixLength;
+       } else {
+           me.maxValue = 7;
+       }
+    },
 });
index 632a602e778e5d390f6a4767c98e9e5f4cde5626..7657b7bc9441e3652baa588ec4c02ad3e95a7c24 100644 (file)
@@ -32,28 +32,6 @@ Ext.define('PBS.window.SyncJobEdit', {
        return { };
     },
 
-       calcMaxDepthLimit: function() {
-               let maxPrefixLength = 0;
-               let view = this.controller.getView();
-           let nsSelector = view.down('pbsNamespaceSelector[name=ns]');
-               let ns = nsSelector.getValue();
-               if (ns !== undefined && ns !== null) {
-                       maxPrefixLength = (ns.match(/\//g) || []).length + 1;
-               }
-
-               let remoteNsSelector = view.down('pbsRemoteNamespaceSelector[name=remote-ns]');
-               let remoteNs = remoteNsSelector.getValue();
-
-               if (remoteNs !== undefined && remoteNs !== null) {
-                       let remotePrefixLength = (remoteNs.match(/\//g) || []).length + 1;
-                       if (remotePrefixLength > maxPrefixLength) {
-                               maxPrefixLength = remotePrefixLength;
-                       }
-               }
-
-               return maxPrefixLength;
-       },
-
     controller: {
        xclass: 'Ext.app.ViewController',
        control: {
@@ -115,10 +93,13 @@ Ext.define('PBS.window.SyncJobEdit', {
                            datastore: '{datastore}',
                        },
                        listeners: {
-                           change: function(field, value) {
+                           change: function(field, localNs) {
                                let me = this;
-                               let maxDepthField = me.up('pbsSyncJobEdit').down('field[name=max-depth]');
-                               maxDepthField.setLimit(me.up('pbsSyncJobEdit').calcMaxDepthLimit());
+                               let view = me.up('pbsSyncJobEdit');
+
+                               let remoteNs = view.down('pbsRemoteNamespaceSelector[name=remote-ns]').getValue();
+                               let maxDepthField = view.down('field[name=max-depth]');
+                               maxDepthField.setLimit(localNs, remoteNs);
                                maxDepthField.validate();
                            },
                        },
@@ -195,15 +176,17 @@ Ext.define('PBS.window.SyncJobEdit', {
                        name: 'remote-ns',
                        disabled: true,
                        listeners: {
-                           change: function(field, value) {
+                           change: function(field, remoteNs) {
                                let me = this;
-                               let remoteField = me.up('pbsSyncJobEdit').down('field[name=remote]');
-                               let remote = remoteField.getValue();
-                               let remoteStoreField = me.up('pbsSyncJobEdit').down('field[name=remote-store]');
-                               let remoteStore = remoteStoreField.getValue();
-                               me.up('tabpanel').down('pbsGroupFilter').setRemoteNamespace(remote, remoteStore, value);
-                               let maxDepthField = me.up('pbsSyncJobEdit').down('field[name=max-depth]');
-                               maxDepthField.setLimit(me.up('pbsSyncJobEdit').calcMaxDepthLimit());
+                               let view = me.up('pbsSyncJobEdit');
+
+                               let remote = view.down('field[name=remote]').getValue();
+                               let remoteStore = view.down('field[name=remote-store]').getValue();
+                               me.up('tabpanel').down('pbsGroupFilter').setRemoteNamespace(remote, remoteStore, remoteNs);
+
+                               let localNs = view.down('pbsNamespaceSelector[name=ns]').getValue();
+                               let maxDepthField = view.down('field[name=max-depth]');
+                               maxDepthField.setLimit(localNs, remoteNs);
                                maxDepthField.validate();
                            },
                        },