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

From: ShaoHe Feng <shaohef@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@linux.vnet.ibm.com> Signed-off-by: Zhou Zheng Sheng <zhshzhou@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")) { -- 1.8.5.3

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@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@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@linux.vnet.ibm.com> Signed-off-by: Zhou Zheng Sheng <zhshzhou@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@linux.vnet.ibm.com Telephone: 86-10-82454397

Reviewed-by: Aline Manera <alinefm@linux.vnet.ibm.com> On 03/31/2014 11:48 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@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@linux.vnet.ibm.com> Signed-off-by: Zhou Zheng Sheng <zhshzhou@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")) {

Reviewed-by: Rodrigo Trujillo <rodrigo.trujillo@linux.vnet.ibm.com> On 03/31/2014 11:48 PM, shaohef@linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef@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@linux.vnet.ibm.com> Signed-off-by: Zhou Zheng Sheng <zhshzhou@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")) {
participants (4)
-
Aline Manera
-
Rodrigo Trujillo
-
shaohef@linux.vnet.ibm.com
-
Zhou Zheng Sheng