]>
Commit | Line | Data |
---|---|---|
1bc75c2f FE |
1 | /* |
2 | * Input panel for prune settings with a keep-all option intended to be used as | |
3 | * part of an edit/create window. | |
4 | */ | |
57513f76 | 5 | Ext.define('PVE.panel.BackupJobPrune', { |
1bc75c2f | 6 | extend: 'Proxmox.panel.PruneInputPanel', |
57513f76 | 7 | xtype: 'pveBackupJobPrunePanel', |
1bc75c2f FE |
8 | mixins: ['Proxmox.Mixin.CBind'], |
9 | ||
10 | onlineHelp: 'vzdump_retention', | |
11 | ||
12 | onGetValues: function(formValues) { | |
13 | if (this.needMask) { // isMasked() may not yet be true if not rendered once | |
14 | return {}; | |
15 | } else if (this.isCreate && !this.rendered) { | |
9c4c5797 | 16 | return this.keepAllDefaultForCreate ? { 'prune-backups': 'keep-all=1' } : {}; |
1bc75c2f | 17 | } |
4981660f FE |
18 | |
19 | let options = { 'delete': [] }; | |
20 | ||
21 | if ('max-protected-backups' in formValues) { | |
22 | options['max-protected-backups'] = formValues['max-protected-backups']; | |
23 | } else if (this.hasMaxProtected) { | |
24 | options.delete.push('max-protected-backups'); | |
25 | } | |
26 | ||
27 | delete formValues['max-protected-backups']; | |
1bc75c2f | 28 | delete formValues.delete; |
4981660f | 29 | |
1bc75c2f FE |
30 | let retention = PVE.Parser.printPropertyString(formValues); |
31 | if (retention === '') { | |
4981660f FE |
32 | options.delete.push('prune-backups'); |
33 | } else { | |
34 | options['prune-backups'] = retention; | |
1bc75c2f | 35 | } |
4981660f | 36 | |
1bc75c2f | 37 | if (!this.isCreate) { |
4981660f FE |
38 | // always delete old 'maxfiles' on edit, we map it to keep-last on window load |
39 | options.delete.push('maxfiles'); | |
40 | } else { | |
41 | delete options.delete; | |
1bc75c2f | 42 | } |
4981660f | 43 | |
1bc75c2f FE |
44 | return options; |
45 | }, | |
46 | ||
47 | updateComponents: function() { | |
48 | let me = this; | |
49 | ||
50 | let keepAll = me.down('proxmoxcheckbox[name=keep-all]').getValue(); | |
51 | let anyValue = false; | |
52 | me.query('pmxPruneKeepField').forEach(field => { | |
53 | anyValue = anyValue || field.getValue() !== null; | |
54 | field.setDisabled(keepAll); | |
55 | }); | |
56 | me.down('component[name=no-keeps-hint]').setHidden(anyValue || keepAll); | |
57 | }, | |
58 | ||
59 | listeners: { | |
60 | afterrender: function(panel) { | |
61 | if (panel.needMask) { | |
62 | panel.down('component[name=no-keeps-hint]').setHtml(''); | |
63 | panel.mask( | |
64 | gettext('Backup content type not available for this storage.'), | |
65 | ); | |
9c4c5797 | 66 | } else if (panel.isCreate && panel.keepAllDefaultForCreate) { |
1bc75c2f FE |
67 | panel.down('proxmoxcheckbox[name=keep-all]').setValue(true); |
68 | } | |
9c4c5797 | 69 | panel.down('component[name=pbs-hint]').setHidden(!panel.showPBSHint); |
1bc75c2f | 70 | |
4981660f FE |
71 | let maxProtected = panel.down('proxmoxintegerfield[name=max-protected-backups]'); |
72 | maxProtected.setDisabled(!panel.hasMaxProtected); | |
73 | maxProtected.setHidden(!panel.hasMaxProtected); | |
74 | ||
1bc75c2f FE |
75 | panel.query('pmxPruneKeepField').forEach(field => { |
76 | field.on('change', panel.updateComponents, panel); | |
77 | }); | |
78 | panel.updateComponents(); | |
79 | }, | |
80 | }, | |
81 | ||
82 | columnT: { | |
83 | xtype: 'proxmoxcheckbox', | |
84 | name: 'keep-all', | |
85 | boxLabel: gettext('Keep all backups'), | |
86 | listeners: { | |
87 | change: function(field, newValue) { | |
57513f76 | 88 | let panel = field.up('pveBackupJobPrunePanel'); |
1bc75c2f FE |
89 | panel.updateComponents(); |
90 | }, | |
91 | }, | |
92 | }, | |
93 | ||
94 | columnB: [ | |
95 | { | |
96 | xtype: 'component', | |
97 | userCls: 'pmx-hint', | |
98 | name: 'no-keeps-hint', | |
99 | hidden: true, | |
100 | padding: '5 1', | |
9c4c5797 FE |
101 | cbind: { |
102 | html: '{fallbackHintHtml}', | |
103 | }, | |
1bc75c2f FE |
104 | }, |
105 | { | |
106 | xtype: 'component', | |
107 | userCls: 'pmx-hint', | |
108 | name: 'pbs-hint', | |
109 | hidden: true, | |
110 | padding: '5 1', | |
111 | html: gettext("It's preferred to configure backup retention directly on the Proxmox Backup Server."), | |
112 | }, | |
4981660f FE |
113 | { |
114 | xtype: 'proxmoxintegerfield', | |
115 | name: 'max-protected-backups', | |
116 | fieldLabel: gettext('Maximum Protected'), | |
117 | minValue: -1, | |
118 | hidden: true, | |
119 | disabled: true, | |
120 | emptyText: 'unlimited with Datastore.Allocate privilege, 5 otherwise', | |
121 | deleteEmpty: true, | |
122 | autoEl: { | |
123 | tag: 'div', | |
124 | 'data-qtip': Ext.String.format(gettext('Use {0} for unlimited'), -1), | |
125 | }, | |
126 | }, | |
1bc75c2f FE |
127 | ], |
128 | }); |