Updated Branches:
  refs/heads/vpc 75242b49c -> 26a4132b1

CS-15841: Better add VPC gateway flow

- Because only 1 gateway can exist per VPC, remove 'add' button from
  list view and immediately show create form on click if no gateway is
  present; show list view on successful creation. If there is a
  gateway, go to list view immediately.

- Rename "Gateways" -> "Private Gateway"


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/26a4132b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/26a4132b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/26a4132b

Branch: refs/heads/vpc
Commit: 26a4132b112111044e8c3fb5f2c0afac8a4399a4
Parents: 75242b4
Author: Brian Federle <[email protected]>
Authored: Fri Aug 3 12:26:12 2012 -0700
Committer: Brian Federle <[email protected]>
Committed: Fri Aug 3 12:26:34 2012 -0700

----------------------------------------------------------------------
 ui/scripts/ui-custom/vpc.js |   71 ++++++++++++++++++---
 ui/scripts/vpc.js           |  126 +++++++++++++++++++++-----------------
 2 files changed, 130 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/26a4132b/ui/scripts/ui-custom/vpc.js
----------------------------------------------------------------------
diff --git a/ui/scripts/ui-custom/vpc.js b/ui/scripts/ui-custom/vpc.js
index b97b06e..debf635 100644
--- a/ui/scripts/ui-custom/vpc.js
+++ b/ui/scripts/ui-custom/vpc.js
@@ -24,7 +24,7 @@
       var siteToSiteVPN = args.siteToSiteVPN;
       var links = {
         'ip-addresses': 'IP Addresses',
-        'gateways': 'Gateways',
+        'gateways': 'Private Gateway',
         'site-to-site-vpn': 'Site-to-site VPN'
       };
       var $links = $('<ul>').addClass('links');
@@ -54,14 +54,62 @@
             });
             break;
           case 'gateways':
-            $browser.cloudBrowser('addPanel', {
-              title: 'Gateways',
-              maximizeIfSelected: true,
-              complete: function($panel) {
-                //ipAddresses.listView is a function
-                $panel.listView(gateways.listView(), {context: 
gateways.context});
-              }
-            });
+            //siteToSiteVPN is an object
+            var addAction = gateways.add;
+            var isGatewayPresent = addAction.preCheck({ context: 
gateways.context });
+            var showGatewayListView = function() {
+              $browser.cloudBrowser('addPanel', {
+                title: 'Private Gateway',
+                maximizeIfSelected: true,
+                complete: function($panel) {
+                  $panel.listView(gateways.listView(), { context: 
gateways.context });
+                }
+              });
+            };
+
+            if (isGatewayPresent) {
+              showGatewayListView();
+            } else {
+              cloudStack.dialog.createForm({
+                form: addAction.createForm,
+                after: function(args) {
+                  var data = args.data;
+                  var $loading = 
$('<div>').addClass('loading-overlay').appendTo($chart);
+                  var error = function(message) {
+                    $loading.remove();
+                    cloudStack.dialog.notice({ message: message });
+                  };
+
+                  addAction.action({
+                    data: data,
+                    context: gateways.context,
+                    response: {
+                      success: function(args) {
+                        var _custom = args._custom;
+                        var notification = {
+                          poll: addAction.notification.poll,
+                          _custom: _custom,
+                          desc: addAction.messages.notification()
+                        };
+                        var success = function(args) {
+                          if (!$chart.is(':visible')) return;
+                          
+                          $loading.remove();
+                          showGatewayListView();
+                        };
+                        
+                        cloudStack.ui.notifications.add(
+                          notification,
+                          success, {},
+                          error, {}
+                        );
+                      },
+                      error: error
+                    }
+                  });
+                }
+              });
+            }
             break;
           case 'site-to-site-vpn':
             //siteToSiteVPN is an object
@@ -69,7 +117,7 @@
             var isVPNPresent = addAction.preCheck({ context: 
siteToSiteVPN.context });
             var showVPNListView = function() {
               $browser.cloudBrowser('addPanel', {
-                title: 'Site-to-site VPNs',
+                title: 'Site-to-site VPN',
                 maximizeIfSelected: true,
                 complete: function($panel) {
                   $panel.listView(siteToSiteVPN, {context: 
siteToSiteVPN.context});
@@ -111,7 +159,8 @@
                           success, {},
                           error, {}
                         );
-                      }
+                      },
+                      error: error
                     }
                   });
                 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/26a4132b/ui/scripts/vpc.js
----------------------------------------------------------------------
diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js
index e4029f1..19e34e4 100644
--- a/ui/scripts/vpc.js
+++ b/ui/scripts/vpc.js
@@ -443,6 +443,76 @@
       }
     },
     gateways: {
+      add: {
+        preCheck: function(args) {
+          var items;
+          
+          $.ajax({
+            url: createURL('listPrivateGateways'),
+            async: false,
+            data: {
+              vpcid: args.context.vpc[0].id,
+              listAll: true
+            },
+            success: function(json) {
+              items = json.listprivategatewaysresponse.privategateway;
+              args.response.success({ data: items });
+            }
+          });
+
+          if (items && items.length) {
+            return true;
+          }
+
+          return false;
+        },
+        label: 'Add new gateway',
+        messages: {
+          notification: function(args) {
+            return 'Add new gateway';
+          }
+        },
+        createForm: {
+          title: 'Add new gateway',
+          desc: 'Please specify the information to add a new gateway to this 
VPC.',
+          fields: {
+            ipaddress: { label: 'label.ip.address', validation: { required: 
true }},
+            gateway: { label: 'label.gateway', validation: { required: true }},
+            netmask: { label: 'label.netmask', validation: { required: true }},
+            vlan: { label: 'label.vlan', validation: { required: true }}
+          }
+        },
+        action: function(args) {
+          $.ajax({
+            url: createURL('createPrivateGateway'),
+            data: {
+              vpcid: args.context.vpc[0].id,
+              ipaddress: args.data.ipaddress,
+              gateway: args.data.gateway,
+              netmask: args.data.netmask,
+              vlan: args.data.vlan
+            },
+            success: function(json) {
+              var jid = json.createprivategatewayresponse.jobid;
+              args.response.success(
+                {_custom:
+                 {jobId: jid,
+                  getUpdatedItem: function(json) {
+                    return 
json.queryasyncjobresultresponse.jobresult.privategateway;
+                  }
+                 }
+                }
+              );
+            },
+            error: function(json) {
+              args.response.error(parseXMLHttpResponse(json));
+            }
+          });
+        },
+        notification: {
+          poll: pollAsyncJobResult
+        }
+      },
       listView: function() {
         return {
           listView: {
@@ -453,62 +523,6 @@
               netmask: { label: 'label.netmask', validation: { required: true 
}},
               vlan: { label: 'label.vlan', validation: { required: true }}
             },
-            actions: {
-              add: {
-                label: 'Add new gateway',
-                preFilter: function(args) {
-                  if(isAdmin())
-                    return true;
-                  else
-                    return false;
-                },
-                messages: {
-                  notification: function(args) {
-                    return 'Add new gateway';
-                  }
-                },
-                createForm: {
-                  title: 'Add new gateway',
-                  desc: 'Please specify the information to add a new gateway 
to this VPC.',
-                  fields: {
-                    ipaddress: { label: 'label.ip.address', validation: { 
required: true }},
-                    gateway: { label: 'label.gateway', validation: { required: 
true }},
-                    netmask: { label: 'label.netmask', validation: { required: 
true }},
-                    vlan: { label: 'label.vlan', validation: { required: true 
}}
-                  }
-                },
-                action: function(args) {
-                  $.ajax({
-                    url: createURL('createPrivateGateway'),
-                    data: {
-                      vpcid: args.context.vpc[0].id,
-                      ipaddress: args.data.ipaddress,
-                      gateway: args.data.gateway,
-                      netmask: args.data.netmask,
-                      vlan: args.data.vlan
-                    },
-                    success: function(json) {
-                      var jid = json.createprivategatewayresponse.jobid;
-                      args.response.success(
-                        {_custom:
-                         {jobId: jid,
-                          getUpdatedItem: function(json) {
-                            return 
json.queryasyncjobresultresponse.jobresult.privategateway;
-                          }
-                         }
-                        }
-                      );
-                    },
-                    error: function(json) {
-                      args.response.error(parseXMLHttpResponse(json));
-                    }
-                  });
-                },
-                notification: {
-                  poll: pollAsyncJobResult
-                }
-              }
-            },
             dataProvider: function(args) {
               $.ajax({
                 url: createURL('listPrivateGateways'),

Reply via email to