]> git.proxmox.com Git - proxmox-backup.git/blame - www/form/NamespaceMaxDepth.js
ui: sync job: fix error if local namespace is selected first
[proxmox-backup.git] / www / form / NamespaceMaxDepth.js
CommitLineData
ad7741a2
TL
1Ext.define('PBS.form.NamespaceMaxDepth', {
2 extend: 'Proxmox.form.field.Integer',
3 alias: 'widget.pbsNamespaceMaxDepth',
4
5 allowBlank: true,
6
7 emptyText: gettext('Full'),
8 fieldLabel: gettext('Max. Depth'),
9 deleteEmpty: true,
10
11 minValue: 0,
12 maxValue: 7,
13
14 triggers: {
15 clear: {
16 cls: 'pmx-clear-trigger',
17 weight: -1,
18 hidden: true,
19 handler: function() {
20 this.triggers.clear.setVisible(false);
21 this.setValue('');
22 },
23 },
24 },
25
26 listeners: {
27 change: function(field, value) {
28 let canClear = value !== '';
29 field.triggers.clear.setVisible(canClear);
30 },
31 },
32});
33
9dde8cd6
FG
34Ext.define('PBS.form.NamespaceMaxDepthReduced', {
35 extend: 'PBS.form.NamespaceMaxDepth',
36 alias: 'widget.pbsNamespaceMaxDepthReduced',
37
f07e6601
TL
38 calcMaxPrefixLength: function(ns1, ns2) {
39 let maxPrefixLength = 0;
eff279e7 40 if (ns1 !== undefined && ns1 !== null && typeof ns1 === 'string') {
f07e6601
TL
41 maxPrefixLength = (ns1.match(/[/]/g) || []).length + (ns1 === '' ? 0 : 1);
42 }
eff279e7 43 if (ns2 !== undefined && ns2 !== null && typeof ns2 === 'string') {
f07e6601
TL
44 let ns2PrefixLength = (ns2.match(/[/]/g) || []).length + (ns2 === '' ? 0 : 1);
45 if (ns2PrefixLength > maxPrefixLength) {
46 maxPrefixLength = ns2PrefixLength;
47 }
48 }
49 return maxPrefixLength;
50 },
51
52 setLimit: function(ns1, ns2) {
53 let me = this;
54 let maxPrefixLength = me.calcMaxPrefixLength(ns1, ns2);
55 if (maxPrefixLength !== undefined) {
56 me.maxValue = 7 - maxPrefixLength;
57 } else {
58 me.maxValue = 7;
59 }
60 },
9dde8cd6 61});