From 33466283cf03aaad57f074da8c565ce05a3db51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Wed, 8 Oct 2014 18:14:01 +0200 Subject: [PATCH] Feature #3175: Move vnet creation wizard to new window model --- src/sunstone/public/js/plugins/vnets-tab.js | 313 ++++++++------------ 1 file changed, 124 insertions(+), 189 deletions(-) diff --git a/src/sunstone/public/js/plugins/vnets-tab.js b/src/sunstone/public/js/plugins/vnets-tab.js index bf025ff2e8..39124ec14c 100644 --- a/src/sunstone/public/js/plugins/vnets-tab.js +++ b/src/sunstone/public/js/plugins/vnets-tab.js @@ -17,21 +17,8 @@ var addresses_vnets = 0; var last_selected_row_ar; -var create_vn_tmpl = -'
'+ - '
'+ - '

'+tr("Create Virtual Network")+'

'+ - '
'+ - '\ -
\ -
\ -
\ -
\ +var create_vnet_wizard_html = + '\
\
\

'+tr("General")+'
\ @@ -191,84 +178,24 @@ var create_vn_tmpl =
\
\
\ -
\ - \ - \ -
\ - \ - \ -
\ -
\ -
\ -
\ -

'+tr("Write the Virtual Network template here")+'

\ -
\ -
\ -
\ -
\ - \ -
\ -
\ -
\ - \ - \ -
\ -
\ -
\ -\ -×'; + '; -var update_vnet_tmpl = - '
\ -

'+tr("Please, choose and modify the virtual network you want to update")+':

\ -
\ - \ - \ -
\ -
\ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ - \ -
'+tr("Permissions")+':'+tr("Use")+''+tr("Manage")+''+tr("Admin")+'
'+tr("Owner")+'
'+tr("Group")+'
'+tr("Other")+'
\ -
\ - \ -
\ - \ -
\ -
\ -
\ - \ -
\ -
\ -
'; + +var create_vnet_advanced_html = + '
' + + '
' + + '
' + + '

'+tr("Write the Virtual Network template here")+'

' + + '
' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
'; var dataTable_vNetworks; -var $create_vn_dialog; var $lease_vn_dialog; //Setup actions @@ -278,10 +205,8 @@ var vnet_actions = { type: "create", call: OpenNebula.Network.create, callback: function(request, response) { - // Reset the create wizard - $create_vn_dialog.foundation('reveal', 'close'); - $create_vn_dialog.empty(); - setupCreateVNetDialog(); + $("a[href=back]", $("#vnets-tab")).trigger("click"); + popFormDialog("create_vnet_form", $("#vnets-tab")); addVNetworkElement(request, response); notifyCustom(tr("Virtual Network created"), " ID: " + response.VNET.ID, false); @@ -291,7 +216,13 @@ var vnet_actions = { "Network.create_dialog" : { type: "custom", - call: popUpCreateVnetDialog + call: function(){ + Sunstone.popUpFormPanel("create_vnet_form", "vnets-tab", "create", false, function(context){ + refreshSecurityGroupTableSelect(context, "vnet_create"); + + $("input#name",context).focus(); + }); + } }, "Network.list" : { @@ -631,7 +562,24 @@ var vnets_tab = { \ \ \ - ' + ', + forms: { + "create_vnet_form": { + actions: { + create: { + title: tr("Create Virtual Network"), + submit_text: tr("Create") + }, + update: { + title: tr("Update Virtual Network"), + submit_text: tr("Update") + } + }, + wizard_html: create_vnet_wizard_html, + advanced_html: create_vnet_advanced_html, + setup: initialize_create_vnet_dialog + } + } } Sunstone.addActions(vnet_actions); @@ -1261,14 +1209,7 @@ function printLeases(vn_info){ return html; } -//Prepares the vnet creation dialog -function setupCreateVNetDialog() { - dialogs_context.append('
'); - $create_vn_dialog = $('#create_vn_dialog',dialogs_context) - var dialog = $create_vn_dialog; - dialog.html(create_vn_tmpl); - - dialog.addClass("reveal-modal medium").attr("data-reveal", ""); +function initialize_create_vnet_dialog(dialog) { var number_of_ar = 0; @@ -1303,49 +1244,49 @@ function setupCreateVNetDialog() { $('input', $(this).parent()).val(""); switch ($(this).val()) { case "default": - $('input#bridge,label[for="bridge"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('input#phydev,label[for="phydev"]',$create_vn_dialog).hide().prop('wizard_field_disabled', true); - $('select#vlan,label[for="vlan"]',$create_vn_dialog).hide().prop('wizard_field_disabled', true); - $('input#vlan_id,label[for="vlan_id"]',$create_vn_dialog).hide().prop('wizard_field_disabled', true); + $('input#bridge,label[for="bridge"]',dialog).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]',dialog).hide().prop('wizard_field_disabled', true); + $('select#vlan,label[for="vlan"]',dialog).hide().prop('wizard_field_disabled', true); + $('input#vlan_id,label[for="vlan_id"]',dialog).hide().prop('wizard_field_disabled', true); - $('input#phydev',$create_vn_dialog).removeAttr('required'); - $('input#bridge',$create_vn_dialog).attr('required', ''); + $('input#phydev',dialog).removeAttr('required'); + $('input#bridge',dialog).attr('required', ''); break; case "802.1Q": - $('input#bridge,label[for="bridge"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('input#phydev,label[for="phydev"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('select#vlan,label[for="vlan"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('input#vlan_id,label[for="vlan_id"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); + $('input#bridge,label[for="bridge"]',dialog).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]',dialog).show().prop('wizard_field_disabled', false); + $('select#vlan,label[for="vlan"]',dialog).show().prop('wizard_field_disabled', false); + $('input#vlan_id,label[for="vlan_id"]',dialog).show().prop('wizard_field_disabled', false); - $('input#phydev',$create_vn_dialog).attr('required', ''); - $('input#bridge',$create_vn_dialog).removeAttr('required'); + $('input#phydev',dialog).attr('required', ''); + $('input#bridge',dialog).removeAttr('required'); break; case "ebtables": - $('input#bridge,label[for="bridge"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('input#phydev,label[for="phydev"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('select#vlan,label[for="vlan"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('input#vlan_id,label[for="vlan_id"]',$create_vn_dialog).hide().prop('wizard_field_disabled', true); + $('input#bridge,label[for="bridge"]',dialog).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]',dialog).show().prop('wizard_field_disabled', false); + $('select#vlan,label[for="vlan"]',dialog).show().prop('wizard_field_disabled', false); + $('input#vlan_id,label[for="vlan_id"]',dialog).hide().prop('wizard_field_disabled', true); - $('input#phydev',$create_vn_dialog).removeAttr('required'); - $('input#bridge',$create_vn_dialog).attr('required', ''); + $('input#phydev',dialog).removeAttr('required'); + $('input#bridge',dialog).attr('required', ''); break; case "openvswitch": - $('input#bridge,label[for="bridge"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('input#phydev,label[for="phydev"]',$create_vn_dialog).hide().prop('wizard_field_disabled', true); - $('select#vlan,label[for="vlan"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); - $('input#vlan_id,label[for="vlan_id"]',$create_vn_dialog).show().prop('wizard_field_disabled', false); + $('input#bridge,label[for="bridge"]',dialog).show().prop('wizard_field_disabled', false); + $('input#phydev,label[for="phydev"]',dialog).hide().prop('wizard_field_disabled', true); + $('select#vlan,label[for="vlan"]',dialog).show().prop('wizard_field_disabled', false); + $('input#vlan_id,label[for="vlan_id"]',dialog).show().prop('wizard_field_disabled', false); - $('input#phydev',$create_vn_dialog).removeAttr('required'); - $('input#bridge',$create_vn_dialog).attr('required', ''); + $('input#phydev',dialog).removeAttr('required'); + $('input#bridge',dialog).attr('required', ''); break; case "vmware": - $('input#bridge,label[for="bridge"]',$create_vn_dialog).show(); - $('input#phydev,label[for="phydev"]',$create_vn_dialog).hide(); - $('select#vlan,label[for="vlan"]',$create_vn_dialog).show(); - $('input#vlan_id,label[for="vlan_id"]',$create_vn_dialog).show(); + $('input#bridge,label[for="bridge"]',dialog).show(); + $('input#phydev,label[for="phydev"]',dialog).hide(); + $('select#vlan,label[for="vlan"]',dialog).show(); + $('input#vlan_id,label[for="vlan_id"]',dialog).show(); - $('input#phydev',$create_vn_dialog).removeAttr('required'); - $('input#bridge',$create_vn_dialog).attr('required', ''); + $('input#phydev',dialog).removeAttr('required'); + $('input#bridge',dialog).attr('required', ''); break; }; @@ -1360,81 +1301,76 @@ function setupCreateVNetDialog() { setupCustomTags($("#vnetCreateContextTab", dialog)); - //Handle submission of the easy mode - $('#create_vn_form_easy',dialog).on('invalid', function () { - notifyError(tr("One or more required fields are missing.")); - }).on('valid', function () { - //Fetch values - var network_json = {}; + dialog.foundation(); - retrieveWizardFields($("#vnetCreateGeneralTab", dialog), network_json); - retrieveWizardFields($("#vnetCreateBridgeTab", dialog), network_json); - retrieveWizardFields($("#vnetCreateContextTab", dialog), network_json); + //Process form + $('#create_vnet_form_wizard',dialog).on('invalid.fndtn.abide', function () { + notifyError(tr("One or more required fields are missing or malformed.")); + popFormDialog("create_vnet_form", $("#vnets-tab")); + }).on('valid.fndtn.abide', function() { + if ($('#create_vnet_form_wizard',dialog).attr("action") == "create") { + //Fetch values + var network_json = {}; - var secgroups = retrieveSecurityGroupTableSelect(dialog, "vnet_create"); - network_json["SECURITY_GROUPS"] = secgroups.join(","); + retrieveWizardFields($("#vnetCreateGeneralTab", dialog), network_json); + retrieveWizardFields($("#vnetCreateBridgeTab", dialog), network_json); + retrieveWizardFields($("#vnetCreateContextTab", dialog), network_json); - retrieveCustomTags($("#vnetCreateContextTab", dialog), network_json); + var secgroups = retrieveSecurityGroupTableSelect(dialog, "vnet_create"); + network_json["SECURITY_GROUPS"] = secgroups.join(","); - $('.ar_tab',dialog).each(function(){ - hash = retrieve_ar_tab_data(this); + retrieveCustomTags($("#vnetCreateContextTab", dialog), network_json); - if (!$.isEmptyObject(hash)) { - if(!network_json["AR"]) - network_json["AR"] = []; + $('.ar_tab',dialog).each(function(){ + hash = retrieve_ar_tab_data(this); - network_json["AR"].push(hash); - } - }); + if (!$.isEmptyObject(hash)) { + if(!network_json["AR"]) + network_json["AR"] = []; - //Create the VNetwork. + network_json["AR"].push(hash); + } + }); - network_json = { - "vnet" : network_json - }; + //Create the VNetwork. - Sunstone.runAction("Network.create",network_json); - return false; + network_json = { + "vnet" : network_json + }; + + Sunstone.runAction("Network.create",network_json); + return false; + } else if ($('#create_template_form_wizard',dialog).attr("action") == "update") { + // TODO + console.log("update called") + return false; + } }); - $('#create_vn_submit_manual',dialog).click(function(){ - var template=$('#template',dialog).val(); - var vnet_json = {vnet: {vnet_raw: template}}; - Sunstone.runAction("Network.create",vnet_json); - return false; - }); + $('#create_vnet_form_advanced',dialog).on('invalid.fndtn.abide', function () { + notifyError(tr("One or more required fields are missing or malformed.")); + popFormDialog("create_vnet_form", $("#vnets-tab")); + }).on('valid.fndtn.abide', function() { + if ($('#create_vnet_form_advanced',dialog).attr("action") == "create") { - $('#wizard_vnet_reset_button').click(function(){ - $create_vn_dialog.html(""); - setupCreateVNetDialog(); + var template = $('textarea#template',dialog).val(); + var vnet_json = {vnet: {vnet_raw: template}}; + Sunstone.runAction("Network.create",vnet_json); + return false; - popUpCreateVnetDialog(); - }); - - $('#advanced_vnet_reset_button').click(function(){ - $create_vn_dialog.html(""); - setupCreateVNetDialog(); - - popUpCreateVnetDialog(); - $("a[href='#vnet_advanced']").click(); + } else if ($('#create_vnet_form_advanced',dialog).attr("action") == "update") { + // TODO + console.log("update called") + return false; + } }); setupTips(dialog); - dialog.foundation(); - // Add first AR $("#vnet_wizard_ar_btn", dialog).trigger("click"); } -function popUpCreateVnetDialog() { - $create_vn_dialog.foundation().foundation('reveal', 'open'); - - refreshSecurityGroupTableSelect($create_vn_dialog, "vnet_create"); - - $("input#name",$create_vn_dialog).focus(); -} - function add_ar_tab(ar_id, dialog) { var str_ar_tab_id = 'ar' + ar_id; @@ -2172,7 +2108,6 @@ $(document).ready(function(){ Sunstone.runAction("Network.list"); - setupCreateVNetDialog(); setupLeasesOps(); setupAddARDialog();