[pve-devel] [PATCH manager v2 2/3] Fix #1526: Use 'detach' instead of 'remove' when the disk is used

Dominik Csapak d.csapak at proxmox.com
Mon Nov 27 09:48:40 CET 2017


comment inline:

On 11/15/2017 11:54 AM, Emmanuel Kasper wrote:
> Signed-off-by: Emmanuel Kasper <e.kasper at proxmox.com>
> ---
>   www/manager6/qemu/HardwareView.js | 28 +++++++++++++++++++++++-----
>   1 file changed, 23 insertions(+), 5 deletions(-)
> 
> diff --git a/www/manager6/qemu/HardwareView.js b/www/manager6/qemu/HardwareView.js
> index 43337c36..2cd0c940 100644
> --- a/www/manager6/qemu/HardwareView.js
> +++ b/www/manager6/qemu/HardwareView.js
> @@ -396,6 +396,8 @@ Ext.define('PVE.qemu.HardwareView', {
>   
>   	var remove_btn = new PVE.button.Button({
>   	    text: gettext('Remove'),
> +	    defaultText: gettext('Remove'),
> +	    altText: gettext('Detach'),
>   	    selModel: sm,
>   	    disabled: true,
>   	    dangerous: true,
> @@ -423,6 +425,22 @@ Ext.define('PVE.qemu.HardwareView', {
>   			Ext.Msg.alert('Error', response.htmlStatus);
>   		    }
>   		});
> +	    },
> +	    listeners: {
> +		render: function(btn) {
> +		    // hack: calculate an optimal button width on first display
> +		    // to prevent the whole toolbar to move when we switch
> +		    // between the "Remove" and "Detach" labels
> +		    var def = btn.getSize().width;
> +
> +		    btn.setText(btn.altText);
> +		    var alt = btn.getSize().width;
> +
> +		    btn.setText(btn.defaultText);
> +
> +		    btn.optimal = alt > def ? alt : def;
> +		    btn.setSize({ width: btn.optimal});

it is not really necessary to save the width, you can use the "> ? :" 
statement directly, since you do not reuse it anyway

> +		}
>   	    }
>   	});
>   
> @@ -504,22 +522,22 @@ Ext.define('PVE.qemu.HardwareView', {
>   	    var rowdef = rows[key];
>   
>   	    var pending = rec.data['delete'] || me.hasPendingChanges(key);
> -	    var isDisk = !key.match(/^unused\d+/) &&
> +	    var isUsedDisk = !key.match(/^unused\d+/) &&
>   		rowdef.tdCls == 'pve-itype-icon-storage' &&
>   		(value && !value.match(/media=cdrom/));
>   
>   	    var isEfi = (key === 'efidisk0');
>   
> -
>   	    remove_btn.setDisabled(rec.data['delete'] || (rowdef.never_delete === true));
> +	    remove_btn.setText(isUsedDisk ? remove_btn.altText : remove_btn.defaultText);
>   
>   	    edit_btn.setDisabled(rec.data['delete'] || !rowdef.editor);
>   
> -	    resize_btn.setDisabled(pending || !isDisk);
> +	    resize_btn.setDisabled(pending || !isUsedDisk);
>   
> -	    move_btn.setDisabled(pending || !isDisk);
> +	    move_btn.setDisabled(pending || !isUsedDisk);
>   
> -	    diskthrottle_btn.setDisabled(pending || !isDisk || isEfi);
> +	    diskthrottle_btn.setDisabled(pending || !isUsedDisk || isEfi);
>   
>   	    revert_btn.setDisabled(!pending);
>   
> 





More information about the pve-devel mailing list