]> git.proxmox.com Git - pve-manager.git/commitdiff
ui: backup job: refactor preparation of form values into own function
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 21 Apr 2024 14:15:39 +0000 (16:15 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 22 Apr 2024 09:27:17 +0000 (11:27 +0200)
The indentation level was rather deep here so move the preparation of
the API response for getting set to the UI form into a separate
function.

No semantic change intended.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
www/manager6/dc/Backup.js

index 39b85d80e2204110ad320d39a1a2c740b101f194..cd4ece3358af527a7aaeec94c9111685855ecb9e 100644 (file)
@@ -158,63 +158,67 @@ Ext.define('PVE.dc.BackupEdit', {
            this.getView().lookup('backupAdvanced').updateCompression(f.getValue(), false);
        },
 
-       init: function(view) {
+       prepareValues: function(data) {
            let me = this;
-           if (view.isCreate) {
-               me.lookup('modeSelector').setValue('include');
-           } else {
-               view.load({
-                   success: function(response, _options) {
-                       let data = response.result.data;
-
-                       // Migrate 'new'-old notification-policy back to
-                       // old-old mailnotification. Only should affect
-                       // users who used pve-manager from pvetest.
-                       // This was a remnant of notifications before the
-                       // overhaul.
-                       let policy = data['notification-policy'];
-                       if (policy === 'always' || policy === 'failure') {
-                           data.mailnotification = policy;
-                       }
+           let viewModel = me.getViewModel();
+
+           // Migrate 'new'-old notification-policy back to old-old mailnotification.
+           // Only should affect users who used pve-manager from pvetest. This was a remnant of
+           // notifications before the  overhaul.
+           let policy = data['notification-policy'];
+           if (policy === 'always' || policy === 'failure') {
+               data.mailnotification = policy;
+           }
 
-                       if (data.exclude) {
-                           data.vmid = data.exclude;
-                           data.selMode = 'exclude';
-                       } else if (data.all) {
-                           data.vmid = '';
-                           data.selMode = 'all';
-                       } else if (data.pool) {
-                           data.selMode = 'pool';
-                           data.selPool = data.pool;
-                       } else {
-                           data.selMode = 'include';
-                       }
+           if (data.exclude) {
+               data.vmid = data.exclude;
+               data.selMode = 'exclude';
+           } else if (data.all) {
+               data.vmid = '';
+               data.selMode = 'all';
+           } else if (data.pool) {
+               data.selMode = 'pool';
+               data.selPool = data.pool;
+           } else {
+               data.selMode = 'include';
+           }
+           viewModel.set('selMode', data.selMode);
+
+           if (data['prune-backups']) {
+               Object.assign(data, data['prune-backups']);
+               delete data['prune-backups'];
+           } else if (data.maxfiles !== undefined) {
+               if (data.maxfiles > 0) {
+                   data['keep-last'] = data.maxfiles;
+               } else {
+                   data['keep-all'] = 1;
+               }
+               delete data.maxfiles;
+           }
 
-                       me.getViewModel().set('selMode', data.selMode);
+           if (data['notes-template']) {
+               data['notes-template'] =
+                   PVE.Utils.unEscapeNotesTemplate(data['notes-template']);
+           }
 
-                       if (data['prune-backups']) {
-                           Object.assign(data, data['prune-backups']);
-                           delete data['prune-backups'];
-                       } else if (data.maxfiles !== undefined) {
-                           if (data.maxfiles > 0) {
-                               data['keep-last'] = data.maxfiles;
-                           } else {
-                               data['keep-all'] = 1;
-                           }
-                           delete data.maxfiles;
-                       }
+           if (data.performance) {
+               Object.assign(data, data.performance);
+               delete data.performance;
+           }
 
-                       if (data['notes-template']) {
-                           data['notes-template'] =
-                               PVE.Utils.unEscapeNotesTemplate(data['notes-template']);
-                       }
+           return data;
+       },
 
-                       if (data.performance) {
-                           Object.assign(data, data.performance);
-                           delete data.performance;
-                       }
+       init: function(view) {
+           let me = this;
 
-                       view.setValues(data);
+           if (view.isCreate) {
+               me.lookup('modeSelector').setValue('include');
+           } else {
+               view.load({
+                   success: function(response, _options) {
+                       let values = me.prepareValues(response.result.data);
+                       view.setValues(values);
                    },
                });
            }