]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - src/window/Edit.js
disk smart: fix layout, enable autoscroll
[proxmox-widget-toolkit.git] / src / window / Edit.js
index f548196ba26ed4d095be5cbceaa4c66292077968..53d0e73abf8d7479bdbb090fffa94538a03c8764 100644 (file)
@@ -25,11 +25,22 @@ Ext.define('Proxmox.window.Edit', {
     // set to true if you want an Remove button (instead of Create)
     isRemove: false,
 
+    // set to false, if you don't want the reset button present
+    showReset: true,
+
     // custom submitText
     submitText: undefined,
 
     backgroundDelay: 0,
 
+    // string or function, called as (url, values) - useful if the ID of the
+    // new object is part of the URL, or that URL differs from GET/PUT URL
+    submitUrl: Ext.identityFn,
+
+    // string or function, called as (url, initialConfig) - mostly for
+    // consistency with submitUrl existing. If both are set `url` gets optional
+    loadUrl: Ext.identityFn,
+
     // needed for finding the reference to submitbutton
     // because we do not have a controller
     referenceHolder: true,
@@ -132,7 +143,9 @@ Ext.define('Proxmox.window.Edit', {
            values.background_delay = me.backgroundDelay;
        }
 
-       let url = me.url;
+       let url = Ext.isFunction(me.submitUrl)
+           ? me.submitUrl(me.url, values)
+           : me.submitUrl || me.url;
        if (me.method === 'DELETE') {
            url = url + "?" + Ext.Object.toQueryString(values);
            values = undefined;
@@ -199,9 +212,13 @@ Ext.define('Proxmox.window.Edit', {
            newopts.params = params;
        }
 
+       let url = Ext.isFunction(me.loadUrl)
+           ? me.loadUrl(me.url, me.initialConfig)
+           : me.loadUrl || me.url;
+
        let createWrapper = function(successFn) {
            Ext.apply(newopts, {
-               url: me.url,
+               url: url,
                method: 'GET',
                success: function(response, opts) {
                    form.clearInvalid();
@@ -232,8 +249,12 @@ Ext.define('Proxmox.window.Edit', {
     initComponent: function() {
        let me = this;
 
-       if (!me.url) {
-           throw "no url specified";
+       if (!me.url && (
+               !me.submitUrl || !me.loadUrl || me.submitUrl === Ext.identityFn ||
+               me.loadUrl === Ext.identityFn
+           )
+       ) {
+           throw "neither 'url' nor both, submitUrl and loadUrl specified";
        }
 
        if (me.create) {throw "deprecated parameter, use isCreate";}
@@ -243,7 +264,7 @@ Ext.define('Proxmox.window.Edit', {
        me.items = undefined;
 
        me.formPanel = Ext.create('Ext.form.Panel', {
-           url: me.url,
+           url: me.url, // FIXME: not in 'form' class, safe to remove??
            method: me.method || 'PUT',
            trackResetOnLoad: true,
            bodyPadding: me.bodyPadding !== undefined ? me.bodyPadding : 10,
@@ -313,7 +334,6 @@ Ext.define('Proxmox.window.Edit', {
 
                if (!allAdvancedValid) {
                    inputPanel.setAdvancedVisible(true);
-                   me.down('#advancedcb').setValue(true);
                }
            }
        };
@@ -332,7 +352,7 @@ Ext.define('Proxmox.window.Edit', {
            me.title = Proxmox.Utils.dialog_title(me.subject, me.isCreate, me.isAdd);
        }
 
-       if (me.isCreate) {
+       if (me.isCreate || !me.showReset) {
                me.buttons = [submitBtn];
        } else {
                me.buttons = [submitBtn, resetBtn];