From 8be76699e1fb8056405c402fb6921bb4115a88dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 12 Sep 2014 16:47:25 +0200 Subject: [PATCH] Feature #3175: Migrate the sec group wizard to new non-modal mechanism --- .../public/js/plugins/secgroups-tab.js | 91 +++++++++---------- 1 file changed, 42 insertions(+), 49 deletions(-) diff --git a/src/sunstone/public/js/plugins/secgroups-tab.js b/src/sunstone/public/js/plugins/secgroups-tab.js index f8f4274267..fe6d11d9a3 100644 --- a/src/sunstone/public/js/plugins/secgroups-tab.js +++ b/src/sunstone/public/js/plugins/secgroups-tab.js @@ -18,30 +18,22 @@ //Prepares the dialog to create -function setupCreateSecurityGroupDialog(){ - if ($('#create_security_group_dialog').length == 0) { - dialogs_context.append('
'); - } +function initialize_create_security_group_dialog(dialog){ + setupTips(dialog); - $create_security_group_dialog = $('#create_security_group_dialog',dialogs_context); - var dialog = $create_security_group_dialog; - - dialog.html(create_security_group_tmpl); - dialog.addClass("reveal-modal").attr("data-reveal", ""); - - $('#create_security_group_form',dialog).submit(function(){ - var name=$('#security_groupname',this).val(); - var security_group_json = { "security_group" : { "name" : name}}; - Sunstone.runAction("SecurityGroup.create",security_group_json); - return false; + $('#create_security_group_form_wizard',dialog).on('invalid', function () { + notifyError(tr("One or more required fields are missing or malformed.")); + popFormDialog("create_security_group_form", $("#secgroup-tab")); + }).on('valid', function() { + if ($('#create_security_group_form_wizard',dialog).attr("action") == "create") { + var name=$('#security_groupname',this).val(); + var security_group_json = { "security_group" : { "name" : name}}; + Sunstone.runAction("SecurityGroup.create",security_group_json); + return false; + } }); -} - -function popUpCreateSecurityGroupDialog(){ - $create_security_group_dialog.foundation().foundation('reveal', 'open'); - $("input#name",$create_security_group_dialog).focus(); - return false; + dialog.foundation(); } // Security Group clone dialog @@ -124,23 +116,14 @@ function popUpSecurityGroupCloneDialog(){ } -var create_security_group_tmpl = -'
\ -
\ -

'+tr("Create Security Group")+'

\ -
\ -
\ -
\ +var create_security_group_wizard_html = +'\
\
\ \ \
\
\ -
\ - \ -
\ - ×\
'; var dataTable_security_groups; @@ -153,18 +136,23 @@ var security_group_actions = { type: "create", call: OpenNebula.SecurityGroup.create, callback: function(request, response){ - $create_security_group_dialog.foundation('reveal', 'close'); - $("form", $create_security_group_dialog)[0].reset(); + $("a[href=back]", $("#secgroups-tab")).trigger("click"); + popFormDialog("create_security_group_form", $("#secgroups-tab")); - Sunstone.runAction('SecurityGroup.list'); + addSecurityGroupElement(request, response); + notifyCustom(tr("Security Group created"), " ID: " + response.SECURITY_GROUP.ID, false); }, - error: onError, - notify: true + error: function(request, response){ + popFormDialog("create_security_group_form", $("#secgroups-tab")); + onError(request, response); + } }, "SecurityGroup.create_dialog" : { type: "custom", - call: popUpCreateSecurityGroupDialog + call: function(){ + Sunstone.popUpFormPanel("create_security_group_form", "secgroups-tab", "create", false); + } }, "SecurityGroup.list" : { @@ -191,13 +179,6 @@ var security_group_actions = { error: onError }, - "SecurityGroup.show_to_update" : { - type: "single", - call: OpenNebula.SecurityGroup.show, - callback: fillPopPup, - error: onError - }, - "SecurityGroup.refresh" : { type: "custom", call: function(){ @@ -329,8 +310,8 @@ var security_groups_tab = { tabClass: "subTab", parentTab: "infra-tab", search_input: '', - list_header: ' '+tr("Security Groups"), - info_header: ' '+tr("Security Group"), + list_header: ' '+tr("Security Groups"), + info_header: ' '+tr("Security Group"), subheader: '  ', table: '\ \ @@ -344,7 +325,20 @@ var security_groups_tab = { \ \ \ -
' + ', + forms: { + "create_security_group_form": { + actions: { + create: { + title: tr("Create Security Group"), + submit_text: tr("Create") + } + }, + wizard_html: create_security_group_wizard_html, +// advanced_html: create_security_group_advanced_html, + setup: initialize_create_security_group_dialog + } + } }; var security_group_info_panel = { @@ -495,7 +489,6 @@ $(document).ready(function(){ Sunstone.runAction("SecurityGroup.list"); - setupCreateSecurityGroupDialog(); setupSecurityGroupCloneDialog(); dialogs_context.append('
');