]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - window/Edit.js
buildsys: switch upload dist over to buster
[proxmox-widget-toolkit.git] / window / Edit.js
index b736a85c1fe3c71bc59a13ef55b826183339afdd..aeb8019c7a4cb6d89daeb4dfe19061b47ad29975 100644 (file)
@@ -34,10 +34,20 @@ Ext.define('Proxmox.window.Edit', {
     defaultButton: 'submitbutton',
 
     // finds the first form field
-    defaultFocus: 'field',
+    defaultFocus: 'field[disabled=false][hidden=false]',
 
     showProgress: false,
 
+    showTaskViewer: false,
+
+    // gets called if we have a progress bar or taskview and it detected that
+    // the task finished. function(success)
+    taskDone: Ext.emptyFn,
+
+    // gets called when the api call is finished, right at the beginning
+    // function(success, response, options)
+    apiCallDone: Ext.emptyFn,
+
     // assign a reference from docs, to add a help button docked to the
     // bottom of the window. If undefined we magically fall back to the
     // onlineHelp of our first item, if set.
@@ -124,23 +134,29 @@ Ext.define('Proxmox.window.Edit', {
            method: me.method || (me.backgroundDelay ? 'POST' : 'PUT'),
            params: values,
            failure: function(response, options) {
+               me.apiCallDone(false, response, options);
+
                if (response.result && response.result.errors) {
                    form.markInvalid(response.result.errors);
                }
                Ext.Msg.alert(gettext('Error'), response.htmlStatus);
            },
            success: function(response, options) {
-               var hasProgressBar = (me.backgroundDelay || me.showProgress) &&
+               var hasProgressBar = (me.backgroundDelay || me.showProgress || me.showTaskViewer) &&
                    response.result.data ? true : false;
 
+               me.apiCallDone(true, response, options);
+
                if (hasProgressBar) {
                    // stay around so we can trigger our close events
                    // when background action is completed
                    me.hide();
 
                    var upid = response.result.data;
-                   var win = Ext.create('Proxmox.window.TaskProgress', {
+                   var viewerClass = me.showTaskViewer ? 'Viewer' : 'Progress';
+                   var win = Ext.create('Proxmox.window.Task' + viewerClass, {
                        upid: upid,
+                       taskDone: me.taskDone,
                        listeners: {
                            destroy: function () {
                                me.close();
@@ -215,9 +231,9 @@ Ext.define('Proxmox.window.Edit', {
            trackResetOnLoad: true,
            bodyPadding: 10,
            border: false,
-           defaults: {
+           defaults: Ext.apply({}, me.defaults, {
                border: false
-           },
+           }),
            fieldDefaults: Ext.apply({}, me.fieldDefaults, {
                labelWidth: 100,
                anchor: '100%'
@@ -266,6 +282,23 @@ Ext.define('Proxmox.window.Edit', {
            var dirty = form.isDirty();
            submitBtn.setDisabled(!valid || !(dirty || me.isCreate));
            resetBtn.setDisabled(!dirty);
+
+           if (inputPanel && inputPanel.hasAdvanced) {
+               // we want to show the advanced options
+               // as soon as some of it is not valid
+               var advancedItems = me.down('#advancedContainer').query('field');
+               var valid = true;
+               advancedItems.forEach(function(field) {
+                   if (!field.isValid()) {
+                       valid = false;
+                   }
+               });
+
+               if (!valid) {
+                   inputPanel.setAdvancedVisible(true);
+                   me.down('#advancedcb').setValue(true);
+               }
+           }
        };
 
        form.on('dirtychange', set_button_status);
@@ -289,6 +322,28 @@ Ext.define('Proxmox.window.Edit', {
                me.buttons = [ submitBtn, resetBtn ];
        }
 
+       if (inputPanel && inputPanel.hasAdvanced) {
+           var sp = Ext.state.Manager.getProvider();
+           var advchecked = sp.get('proxmox-advanced-cb');
+           inputPanel.setAdvancedVisible(advchecked);
+           me.buttons.unshift(
+              {
+                  xtype: 'proxmoxcheckbox',
+                  itemId: 'advancedcb',
+                  boxLabelAlign: 'before',
+                  boxLabel: gettext('Advanced'),
+                  stateId: 'proxmox-advanced-cb',
+                  value: advchecked,
+                  listeners: {
+                      change: function(cb, val) {
+                          inputPanel.setAdvancedVisible(val);
+                          sp.set('proxmox-advanced-cb', val);
+                      }
+                  }
+              }
+           );
+       }
+
        var onlineHelp = me.onlineHelp;
        if (!onlineHelp && inputPanel && inputPanel.onlineHelp) {
            onlineHelp = inputPanel.onlineHelp;