ui: move max NS prefix length logic to reduced max-depth selector
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>
This commit is contained in:
parent
addcb7803e
commit
f07e660153
|
@ -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,
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue