[Kimchi-devel] [PATCH] UI: change some code of storage add page

Zhou Zheng Sheng zhshzhou at linux.vnet.ibm.com
Tue Apr 1 03:15:46 UTC 2014


The original code would grow quadratic if we add more types of storage
pool. It's tedious to maintain.
The new code is smarter and easy to maintain.

on 2014/04/01 10:48, shaohef at linux.vnet.ibm.com wrote:
> From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> 
> Actually there is no bug.
> But we think, we can improve the codes.
> We can remove the reduplicate codes.
> 
> Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
> Signed-off-by: Zhou Zheng Sheng <zhshzhou at linux.vnet.ibm.com>
> ---
>  ui/js/src/kimchi.storagepool_add_main.js | 42 +++++++++-----------------------
>  1 file changed, 11 insertions(+), 31 deletions(-)
> 
> diff --git a/ui/js/src/kimchi.storagepool_add_main.js b/ui/js/src/kimchi.storagepool_add_main.js
> index ea9f68b..86dbe7f 100644
> --- a/ui/js/src/kimchi.storagepool_add_main.js
> +++ b/ui/js/src/kimchi.storagepool_add_main.js
> @@ -123,37 +123,17 @@ kimchi.initStorageAddPage = function() {
>      });
> 
>      $('#poolTypeInputId').change(function() {
> -        if ($(this).val() === 'dir') {
> -            $('.path-section').removeClass('tmpl-html');
> -            $('.logical-section').addClass('tmpl-html');
> -            $('.nfs-section').addClass('tmpl-html');
> -            $('.iscsi-section').addClass('tmpl-html');
> -            $('.scsi-section').addClass('tmpl-html');
> -        } else if ($(this).val() === 'netfs') {
> -            $('.path-section').addClass('tmpl-html');
> -            $('.logical-section').addClass('tmpl-html');
> -            $('.nfs-section').removeClass('tmpl-html');
> -            $('.iscsi-section').addClass('tmpl-html');
> -            $('.scsi-section').addClass('tmpl-html');
> -        } else if ($(this).val() === 'iscsi') {
> -            $('.path-section').addClass('tmpl-html');
> -            $('.logical-section').addClass('tmpl-html');
> -            $('.nfs-section').addClass('tmpl-html');
> -            $('.iscsi-section').removeClass('tmpl-html');
> -            $('.scsi-section').addClass('tmpl-html');
> -        } else if ($(this).val() === 'logical') {
> -            $('.path-section').addClass('tmpl-html');
> -            $('.logical-section').removeClass('tmpl-html');
> -            $('.nfs-section').addClass('tmpl-html');
> -            $('.iscsi-section').addClass('tmpl-html');
> -            $('.scsi-section').addClass('tmpl-html');
> -        } else if ($(this).val() === 'scsi') {
> -            $('.scsi-section').removeClass('tmpl-html');
> -            $('.path-section').addClass('tmpl-html');
> -            $('.logical-section').addClass('tmpl-html');
> -            $('.nfs-section').addClass('tmpl-html');
> -            $('.iscsi-section').addClass('tmpl-html');
> -        }
> +        var poolObject = {'dir': ".path-section", 'netfs': '.nfs-section',
> +                          'iscsi': '.iscsi-section', 'scsi': '.scsi-section',
> +                          'logical': '.logical-section'}
> +        var selectType = $(this).val();
> +        $.each(poolObject, function(type, value) {
> +            if(selectType == type){
> +                $(value).removeClass('tmpl-html');
> +            } else {
> +                $(value).addClass('tmpl-html');
> +            }
> +        });
>      });
>      $('#authId').click(function() {
>          if ($(this).prop("checked")) {
> 


-- 
Thanks and best regards!

Zhou Zheng Sheng / 周征晟
E-mail: zhshzhou at linux.vnet.ibm.com
Telephone: 86-10-82454397




More information about the Kimchi-devel mailing list