[pve-devel] [PATCH widget-toolkit 2/2] add a checkbox to edit windows for advanced options

Thomas Lamprecht t.lamprecht at proxmox.com
Fri Apr 6 10:17:40 CEST 2018


Am 04/05/2018 um 04:03 PM schrieb Dominik Csapak:
> if the inputpanel has advanced options, show a checkbox to
> show/hide them
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>   window/Edit.js | 39 +++++++++++++++++++++++++++++++++++++++
>   1 file changed, 39 insertions(+)
> 
> diff --git a/window/Edit.js b/window/Edit.js
> index f72bee0..8d5aa19 100644
> --- a/window/Edit.js
> +++ b/window/Edit.js
> @@ -274,6 +274,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;
> +		    }
> +		});

Do you want to run isValid on all fields, as else only the first invalid
will be shown?

If so include this info in the comment, e.g., something like:
// tell user why the panel is invalid, show all invalid advanced items 
always

else use:
valid = advancedItems.every(function(f) { return f.isValid() });

> +
> +		if (!valid) {
> +		    inputPanel.setAdvancedVisible(true);
> +		    me.down('#advancedcb').setValue(true);
> +		}
> +	    }
>   	};
>   
>   	form.on('dirtychange', set_button_status);
> @@ -297,6 +314,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;
> 





More information about the pve-devel mailing list