From fb804ac4ada82c862905a1f24069ee78c6e8fe4e Mon Sep 17 00:00:00 2001 From: Bo Wang Date: Mon, 4 Jan 2016 21:02:44 +0800 Subject: [PATCH] Fix workflow bug in "Create Network" dialog In "Subnet Info" tab, the button "Next" will hide and button "Create" will show if checked Disable Gateway. Because value of hide_tab is undefined but transformed to hide_tab = ['undefined'] in js code. Remove unused ',' which will introduce empty element in list: String(['a', 'b',]).split(,) --> ['a', 'b', ''] Switching field "address_source" should not trigger field "gateway_ip" show/disappear. Closes-Bug: #1487005 Closes-Bug: #1530729 Closes-Bug: #1569942 Change-Id: If9e417e151e11c8ee46ded50ee3ee8108ed777a4 --- horizon/static/horizon/js/horizon.forms.js | 23 ++++++++++++------- .../dashboards/project/networks/workflows.py | 4 ++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/horizon/static/horizon/js/horizon.forms.js b/horizon/static/horizon/js/horizon.forms.js index 6f1cfe4f07..cec82559ad 100644 --- a/horizon/static/horizon/js/horizon.forms.js +++ b/horizon/static/horizon/js/horizon.forms.js @@ -320,25 +320,32 @@ horizon.addInitFunction(horizon.forms.init = function () { visible = $switchable.parent().hasClass('themable-checkbox') ? $switchable.siblings('label').is(':visible') : $switchable.is(':visible'), slug = $switchable.data('slug'), checked = $switchable.prop('checked'), - hide_tab = String($switchable.data('hide-tab')).split(','), hide_on = $switchable.data('hideOnChecked'); // If checkbox is hidden then do not apply any further logic if (!visible) return; // If the checkbox has hide-tab attribute then hide/show the tab - var i, len; - for (i = 0, len = hide_tab.length; i < len; i++) { + if ($switchable.data('hide-tab')){ + var hide_tab = String($switchable.data('hide-tab')).split(','); + for (var i = 0, len = hide_tab.length; i < len; i++) { + var tab = $('*[data-target="#'+ hide_tab[i] +'"]').parent(); + if(checked == hide_on) { + // If the checkbox is not checked then hide the tab + tab.hide(); + } else if (!tab.is(':visible')) { + // If the checkbox is checked and the tab is currently hidden then show the tab again + tab.show(); + } + } + + // hide/show button-next or button-final var $btnfinal = $('.button-final'); if(checked == hide_on) { - // If the checkbox is not checked then hide the tab - $('*[data-target="#'+ hide_tab[i] +'"]').parent().hide(); $('.button-next').hide(); $btnfinal.show(); $btnfinal.data('show-on-tab', $fieldset.prop('id')); - } else if (!$('*[data-target="#'+ hide_tab[i] +'"]').parent().is(':visible')) { - // If the checkbox is checked and the tab is currently hidden then show the tab again - $('*[data-target="#'+ hide_tab[i] +'"]').parent().show(); + } else{ $btnfinal.hide(); $('.button-next').show(); $btnfinal.removeData('show-on-tab'); diff --git a/openstack_dashboard/dashboards/project/networks/workflows.py b/openstack_dashboard/dashboards/project/networks/workflows.py index bc68a18bb7..eee7b6db0d 100644 --- a/openstack_dashboard/dashboards/project/networks/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/workflows.py @@ -62,7 +62,7 @@ class CreateNetworkInfoAction(workflows.Action): 'action,' 'create_network__' 'createsubnetdetail' - 'action,', + 'action', 'data-hide-on-checked': 'false' }), initial=True, @@ -174,7 +174,7 @@ class CreateSubnetInfoAction(workflows.Action): label=_("Gateway IP"), widget=forms.TextInput(attrs={ 'class': 'switched', - 'data-switch-on': 'source gateway_ip', + 'data-switch-on': 'gateway_ip', 'data-source-manual': _("Gateway IP") }), required=False,