all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@pve.proxmox.com
Subject: Re: [pve-devel] [PATCH widget-toolkit 2/4] add TimezonePanel for containers
Date: Tue, 11 Aug 2020 14:05:46 +0200	[thread overview]
Message-ID: <cb62cf46-4cfe-b666-9b3c-f27eb159d87d@proxmox.com> (raw)
In-Reply-To: <20200702124914.824124-3-o.bektas@proxmox.com>

aside from thomas comment about static declaration, i would like
to use a viewmodel controller style

this would make it much easier to use, e.g

you could have a viewmodel with

data: {
     tzmode: 'foo'
}
formulas: {
     tzIsSelect: function(get) {
         return get('tzmode') === 'select'
     }
}

and then you can bind the value directly (instead of using a change handler)

You have to use a 'radiogroup' in this case to be able to
two-way bind the value

{
     xtype: 'radiogroup',
     bind: {
        value: "{tzmode}",
     }
}

...

{
     xtype: 'combobox',
     ...
     bind: {
        disabled: '{!tzIsSelect}'
     }
}
etc.

this makes the code much more readable
(ofc maybe the radiogroup thing is too much effort,
that case a change handler for all radio buttons in
a controller should do the same trick; you can set a viewmodel value
manually as well)

also comments inline

On 7/2/20 2:49 PM, Oguz Bektas wrote:
> with 3 modes;
> - CT managed (no action)
> - match host (use same timezone as host)
> - select from list
> 
> also move 'UTC' to the top of the TimezoneStore for convenience
> 
> Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
> ---
> 
> v2->v3:
> * use radiofields
> 
> 
> 
>   src/Makefile               |  1 +
>   src/data/TimezoneStore.js  |  2 +-
>   src/panel/TimezonePanel.js | 91 ++++++++++++++++++++++++++++++++++++++
>   3 files changed, 93 insertions(+), 1 deletion(-)
>   create mode 100644 src/panel/TimezonePanel.js
> 
> diff --git a/src/Makefile b/src/Makefile
> index 12dda30..8bd576f 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -41,6 +41,7 @@ JSSRC=					\
>   	panel/JournalView.js		\
>   	panel/RRDChart.js		\
>   	panel/GaugeWidget.js		\
> +	panel/TimezonePanel.js		\
>   	window/Edit.js			\
>   	window/PasswordEdit.js		\
>   	window/TaskViewer.js		\
> diff --git a/src/data/TimezoneStore.js b/src/data/TimezoneStore.js
> index a67ad8b..fcaca3e 100644
> --- a/src/data/TimezoneStore.js
> +++ b/src/data/TimezoneStore.js
> @@ -7,6 +7,7 @@ Ext.define('Proxmox.data.TimezoneStore', {
>       extend: 'Ext.data.Store',
>       model: 'Timezone',
>       data: [
> +	    ['UTC'],
>   	    ['Africa/Abidjan'],
>   	    ['Africa/Accra'],
>   	    ['Africa/Addis_Ababa'],
> @@ -414,6 +415,5 @@ Ext.define('Proxmox.data.TimezoneStore', {
>   	    ['Pacific/Tongatapu'],
>   	    ['Pacific/Wake'],
>   	    ['Pacific/Wallis'],
> -	    ['UTC'],
>   	],
>   });
> diff --git a/src/panel/TimezonePanel.js b/src/panel/TimezonePanel.js
> new file mode 100644
> index 0000000..25d6423
> --- /dev/null
> +++ b/src/panel/TimezonePanel.js
> @@ -0,0 +1,91 @@
> +Ext.define('PVE.panel.TimezonePanel', {
> +    extend: 'Proxmox.panel.InputPanel',
> +    alias: 'widget.PVETimezonePanel',
> +
> +    insideWizard: false,
> +
> +    setValues: function(values) {
> +	var me = this;
> +
> +	if (!values.timezone) {
> +	    delete values.tzmode;

should that not be values.tzmode = "__default__" ?

> +	} else if (values.timezone === 'host') {
> +	    values.tzmode = 'host';
> +	} else {
> +	    values.tzmode = 'select';
> +	}
> +	return me.callParent([values]);
> +    },
> +
> +    onGetValues: function(values) {
> +	var me = this;
> +
> +	var deletes = [];
> +	if (values.tzmode === '__default__') {
> +	    deletes.push('timezone');
> +	} else if (values.tzmode === 'host') {
> +	    values.timezone = 'host';
> +	}
> +
> +	delete values.tzmode;
> +
> +	if (deletes.length) {
> +	    values.delete = deletes.join(',');

i think you do not need the join here, simply using the array should be 
enough

also, you only have one field to delete, why dont you set it directly above:

if (values.tzmode === '__default__') {
   values.delete = 'timezone';
}

?


> +	}
> +
> +	return values;
> +    },
> +
> +
> +    initComponent: function() {
> +	var me = this;
> +
> +	var items = [];
> +	items.push({
> +		   xtype: 'radiofield',
> +		   name: 'tzmode',
> +		   inputValue: '__default__',
> +		   boxLabel: gettext('Container managed'),
> +		   checked: true,
> +	});
> +	items.push({
> +		   xtype: 'radiofield',
> +		   name: 'tzmode',
> +		   inputValue: 'host',
> +		   boxLabel: gettext('Use host settings'),
> +	});
> +	items.push({
> +		   xtype: 'radiofield',
> +		   name: 'tzmode',
> +		   inputValue: 'select',
> +		   boxLabel: gettext('Select a timezone'),
> +		   listeners: {
> +		       change: function(f, value) {
> +			   if (!this.rendered) {
> +			       return;
> +			   }
> +			   let timezoneSelect = me.down('field[name=timezone]');
> +			   timezoneSelect.setDisabled(!value);
> +		       },
> +		   },
> +	});
> +	items.push({
> +		   xtype: 'combobox',
> +		   itemId: 'tzlist',
> +		   fieldLabel: gettext('Time zone'),
> +		   disabled: true,
> +		   name: 'timezone',
> +		   queryMode: 'local',
> +		   store: Ext.create('Proxmox.data.TimezoneStore'),
> +		   displayField: 'zone',
> +		   editable: true,
> +		   anyMatch: true,
> +		   forceSelection: true,
> +		   allowBlank: false,
> +	});
> +
> +	me.items = items;
> +
> +	me.callParent();
> +    },
> +});
> 





      parent reply	other threads:[~2020-08-11 12:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200702124914.824124-1-o.bektas@proxmox.com>
     [not found] ` <20200702124914.824124-2-o.bektas@proxmox.com>
2020-07-09 12:00   ` [pve-devel] applied: Re: [PATCH v3 container 1/4] fix #1423: add timezone config option Thomas Lamprecht
     [not found] ` <20200702124914.824124-3-o.bektas@proxmox.com>
2020-08-11 12:05   ` Dominik Csapak [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cb62cf46-4cfe-b666-9b3c-f27eb159d87d@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@pve.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal