]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - window/Edit.js
add the missing explanation of onlineHelp
[proxmox-widget-toolkit.git] / window / Edit.js
index 967f9d79cc18ff6002b187d6706c896ee9ff1dc4..b736a85c1fe3c71bc59a13ef55b826183339afdd 100644 (file)
@@ -3,16 +3,19 @@
 Ext.define('Proxmox.window.Edit', {
     extend: 'Ext.window.Window',
     alias: 'widget.proxmoxWindowEdit',
+
+    // autoLoad trigger a load() after component creation
+    autoLoad: false,
+
     resizable: false,
 
     // use this tio atimatically generate a title like
     // Create: <subject>
     subject: undefined,
 
-    // set create to true if you want a Create button (instead 
-    // OK and RESET) 
-    create: false, 
+    // set isCreate to true if you want a Create button (instead
+    // OK and RESET)
+    isCreate: false,
 
     // set to true if you want an Add button (instead of Create)
     isAdd: false,
@@ -20,10 +23,26 @@ Ext.define('Proxmox.window.Edit', {
     // set to true if you want an Remove button (instead of Create)
     isRemove: false,
 
+    // custom submitText
+    submitText: undefined,
+
     backgroundDelay: 0,
 
+    // needed for finding the reference to submitbutton
+    // because we do not have a controller
+    referenceHolder: true,
+    defaultButton: 'submitbutton',
+
+    // finds the first form field
+    defaultFocus: 'field',
+
     showProgress: false,
 
+    // 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.
+    onlineHelp: undefined,
+
     isValid: function() {
        var me = this;
 
@@ -65,7 +84,7 @@ Ext.define('Proxmox.window.Edit', {
                 }
             }
        });
+
        Ext.Array.each(me.query('inputpanel'), function(panel) {
            panel.setValues(values);
        });
@@ -120,7 +139,7 @@ Ext.define('Proxmox.window.Edit', {
                    me.hide();
 
                    var upid = response.result.data;
-                   var win = Ext.create('PVE.window.TaskProgress', { 
+                   var win = Ext.create('Proxmox.window.TaskProgress', {
                        upid: upid,
                        listeners: {
                            destroy: function () {
@@ -184,6 +203,8 @@ Ext.define('Proxmox.window.Edit', {
            throw "no url specified";
        }
 
+       if (me.create) {throw "deprecated parameter, use isCreate";}
+
        var items = Ext.isArray(me.items) ? me.items : [ me.items ];
 
        me.items = undefined;
@@ -204,11 +225,15 @@ Ext.define('Proxmox.window.Edit', {
            items: items
        });
 
+       var inputPanel = me.formPanel.down('inputpanel');
+
        var form = me.formPanel.getForm();
 
        var submitText;
-       if (me.create) {
-           if (me.isAdd) {
+       if (me.isCreate) {
+           if (me.submitText) {
+               submitText = me.submitText;
+           } else if (me.isAdd) {
                submitText = gettext('Add');
            } else if (me.isRemove) {
                submitText = gettext('Remove');
@@ -216,12 +241,13 @@ Ext.define('Proxmox.window.Edit', {
                submitText = gettext('Create');
            }
        } else {
-           submitText = gettext('OK');
+           submitText = me.submitText || gettext('OK');
        }
 
        var submitBtn = Ext.create('Ext.Button', {
+           reference: 'submitbutton',
            text: submitText,
-           disabled: !me.create,
+           disabled: !me.isCreate,
            handler: function() {
                me.submit();
            }
@@ -238,7 +264,7 @@ Ext.define('Proxmox.window.Edit', {
        var set_button_status = function() {
            var valid = form.isValid();
            var dirty = form.isDirty();
-           submitBtn.setDisabled(!valid || !(dirty || me.create));
+           submitBtn.setDisabled(!valid || !(dirty || me.isCreate));
            resetBtn.setDisabled(!dirty);
        };
 
@@ -249,24 +275,29 @@ Ext.define('Proxmox.window.Edit', {
        if (me.fieldDefaults && me.fieldDefaults.labelWidth) {
            colwidth += me.fieldDefaults.labelWidth - 100;
        }
-       
 
-       var twoColumn = items[0].column1 || items[0].column2;
+       var twoColumn = inputPanel &&
+           (inputPanel.column1 || inputPanel.column2);
 
        if (me.subject && !me.title) {
-           me.title = Proxmox.Utils.dialog_title(me.subject, me.create, me.isAdd);
+           me.title = Proxmox.Utils.dialog_title(me.subject, me.isCreate, me.isAdd);
        }
 
-       if (me.create) {
+       if (me.isCreate) {
                me.buttons = [ submitBtn ] ;
        } else {
                me.buttons = [ submitBtn, resetBtn ];
        }
 
-       if (items[0].onlineHelp) {
-           var helpButton = Ext.create('PVE.button.Help');
+       var onlineHelp = me.onlineHelp;
+       if (!onlineHelp && inputPanel && inputPanel.onlineHelp) {
+           onlineHelp = inputPanel.onlineHelp;
+       }
+
+       if (onlineHelp) {
+           var helpButton = Ext.create('Proxmox.button.Help');
            me.buttons.unshift(helpButton, '->');
-           Ext.GlobalEvents.fireEvent('pveShowHelp', items[0].onlineHelp);
+           Ext.GlobalEvents.fireEvent('proxmoxShowHelp', onlineHelp);
        }
 
        Ext.applyIf(me, {
@@ -289,5 +320,9 @@ Ext.define('Proxmox.window.Edit', {
            me.isValid();
            me.suspendLayout = false;
        });
+
+       if (me.autoLoad) {
+           me.load();
+       }
     }
 });