cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jessicaw...@apache.org
Subject git commit: updated refs/heads/4.2 to f37877d
Date Tue, 16 Jul 2013 20:39:23 GMT
Updated Branches:
  refs/heads/4.2 25b0f58a6 -> f37877dc9


CLOUDSTACK-3563: UI > Network menu > Guest Netework section > provide "Add Guest
Network" option where root-admin can create shared networks from.


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

Branch: refs/heads/4.2
Commit: f37877dc9ba619e36398d194c35c3c9b2cf2de00
Parents: 25b0f58
Author: Jessica Wang <jessicawang@apache.org>
Authored: Tue Jul 16 13:28:16 2013 -0700
Committer: Jessica Wang <jessicawang@apache.org>
Committed: Tue Jul 16 13:39:13 2013 -0700

----------------------------------------------------------------------
 ui/scripts/network.js         |   5 +-
 ui/scripts/sharedFunctions.js | 512 +++++++++++++++++++++++++++++++++++++
 ui/scripts/system.js          | 414 +-----------------------------
 3 files changed, 517 insertions(+), 414 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f37877dc/ui/scripts/network.js
----------------------------------------------------------------------
diff --git a/ui/scripts/network.js b/ui/scripts/network.js
index c52b85a..0822d44 100755
--- a/ui/scripts/network.js
+++ b/ui/scripts/network.js
@@ -550,7 +550,10 @@
               messages: {
                 notification: function() { return 'Add Isolated Guest Network'; }
               }
-            }
+            },
+            
+            rootAdminAddGuestNetwork: $.extend( {}, addGuestNetworkDialog.def, {isHeader:
true} )
+            
           },
           id: 'networks',
           fields: {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f37877dc/ui/scripts/sharedFunctions.js
----------------------------------------------------------------------
diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js
index bf6464c..a9f833c 100644
--- a/ui/scripts/sharedFunctions.js
+++ b/ui/scripts/sharedFunctions.js
@@ -134,6 +134,518 @@ var lbProviderMap = {
   }
 };
 
+//Add Guest Network in Advanced zone (for root-admin only)
+var addGuestNetworkDialog = {
+  zoneObjs: [],   
+  physicalNetworkObjs: [],
+  networkOfferingObjs: [],
+  def: {
+    label: 'label.add.guest.network',
+
+    messages: {     
+      notification: function(args) {
+        return 'label.add.guest.network';
+      }
+    },
+
+    preFilter: function(args) {      
+      if(isAdmin()) 
+        return true;     
+      else
+        return false;      
+    },
+    
+    createForm: {
+      title: 'label.add.guest.network',  //Add Shared Network in advanced zone
+
+      preFilter: function(args) {   
+        if('zones' in args.context) {//Infrastructure menu > zone detail > guest traffic
type > network tab (only shown in advanced zone) > add guest network dialog
+          args.$form.find('.form-item[rel=zoneId]').hide();
+          args.$form.find('.form-item[rel=physicalNetworkId]').hide();
+        }
+        else {//Network menu > guest network section > add guest network dialog
+          args.$form.find('.form-item[rel=zoneId]').css('display', 'inline-block');
+          args.$form.find('.form-item[rel=physicalNetworkId]').css('display', 'inline-block');
+        }  
+      },
+      
+      fields: {
+        name: {
+          docID: 'helpGuestNetworkZoneName',
+          label: 'label.name',
+          validation: { required: true }
+        },
+        description: {
+          label: 'label.description',
+          docID: 'helpGuestNetworkZoneDescription',
+          validation: { required: true }
+        },        
+        
+        zoneId: {
+          label: 'label.zone',
+          validation: { required: true },
+          docID: 'helpGuestNetworkZone',
+          select: function(args) {   
+            if('zones' in args.context) {//Infrastructure menu > zone detail > guest
traffic type > network tab (only shown in advanced zone) > add guest network dialog
+              addGuestNetworkDialog.zoneObjs = args.context.zones; //i.e. only one zone entry
+            }
+            else {//Network menu > guest network section > add guest network dialog
+              $.ajax({
+                url: createURL('listZones'),
+                async: false,
+                success: function(json) {
+                  addGuestNetworkDialog.zoneObjs = []; //reset                   
+                  var items = json.listzonesresponse.zone;
+                  if(items != null) {
+                    for(var i = 0; i < items.length; i++) {
+                      if(items[i].networktype == 'Advanced') {
+                        addGuestNetworkDialog.zoneObjs.push(items[i]);
+                      }
+                    }
+                  }                     
+                }
+              });
+            }              
+            args.response.success({
+              data: $.map(addGuestNetworkDialog.zoneObjs, function(zone) {
+                return {
+                  id: zone.id,
+                  description: zone.name
+                };
+              })
+            });    
+          },
+          isHidden: true
+        },   
+        
+        physicalNetworkId: {
+          label: 'label.physical.network',
+          dependsOn: 'zoneId',
+          select: function(args) {   
+            if('physicalNetworks' in args.context) {
+              addGuestNetworkDialog.physicalNetworkObjs = args.context.physicalNetworks;
+            }
+            else {
+              var selectedZoneId = args.$form.find('.form-item[rel=zoneId]').find('select').val();
+              $.ajax({
+                url: createURL('listPhysicalNetworks'),
+                data: {
+                  zoneid: selectedZoneId
+                },
+                async: false,
+                success: function(json) {               
+                  addGuestNetworkDialog.physicalNetworkObjs = json.listphysicalnetworksresponse.physicalnetwork;
                 
+                }
+              });
+            }        
+            var items = [];
+            if(addGuestNetworkDialog.physicalNetworkObjs != null) {
+              for(var i = 0; i < addGuestNetworkDialog.physicalNetworkObjs.length; i++)
{
+                items.push({ id: addGuestNetworkDialog.physicalNetworkObjs[i].id, description:
addGuestNetworkDialog.physicalNetworkObjs[i].name });
+              }
+            }
+            args.response.success({data: items});            
+          },
+          isHidden: true
+        },
+        
+        vlanId: {
+          label: 'label.vlan.id',
+          docID: 'helpGuestNetworkZoneVLANID'
+        },
+        isolatedpvlanId: {
+          label: 'Secondary Isolated VLAN ID'                           
+        },
+        
+        scope: {
+          label: 'label.scope',
+          docID: 'helpGuestNetworkZoneScope',
+          select: function(args) {
+            var selectedZoneId = args.$form.find('.form-item[rel=zoneId]').find('select').val();
+            var selectedZoneObj = {};
+            if(addGuestNetworkDialog.zoneObjs != null && selectedZoneId != "") {
+              for(var i = 0; i < addGuestNetworkDialog.zoneObjs.length; i++) {
+                if(addGuestNetworkDialog.zoneObjs[i].id == selectedZoneId) {
+                  selectedZoneObj = addGuestNetworkDialog.zoneObjs[i];
+                  break;
+                }
+              }
+            }      
+                        
+            var array1 = [];                              
+            if(selectedZoneObj.networktype == "Advanced" && selectedZoneObj.securitygroupsenabled
== true) {                                
+              array1.push({id: 'zone-wide', description: 'All'});
+            }
+            else {                              
+              array1.push({id: 'zone-wide', description: 'All'});
+              array1.push({id: 'domain-specific', description: 'Domain'});
+              array1.push({id: 'account-specific', description: 'Account'});
+              array1.push({id: 'project-specific', description: 'Project'});
+            }
+            args.response.success({data: array1});
+
+            args.$select.change(function() {
+              var $form = $(this).closest('form');
+              if($(this).val() == "zone-wide") {
+                $form.find('.form-item[rel=domainId]').hide();
+                $form.find('.form-item[rel=subdomainaccess]').hide();
+                $form.find('.form-item[rel=account]').hide();
+                $form.find('.form-item[rel=projectId]').hide();
+              }
+              else if ($(this).val() == "domain-specific") {
+                $form.find('.form-item[rel=domainId]').css('display', 'inline-block');
+                $form.find('.form-item[rel=subdomainaccess]').css('display', 'inline-block');
+                $form.find('.form-item[rel=account]').hide();
+                $form.find('.form-item[rel=projectId]').hide();
+              }
+              else if($(this).val() == "account-specific") {
+                $form.find('.form-item[rel=domainId]').css('display', 'inline-block');
+                $form.find('.form-item[rel=subdomainaccess]').hide();
+                $form.find('.form-item[rel=account]').css('display', 'inline-block');
+                $form.find('.form-item[rel=projectId]').hide();
+              }
+              else if($(this).val() == "project-specific") {
+                $form.find('.form-item[rel=domainId]').css('display', 'inline-block');
+                $form.find('.form-item[rel=subdomainaccess]').hide();
+                $form.find('.form-item[rel=account]').hide();
+                $form.find('.form-item[rel=projectId]').css('display', 'inline-block');
+              }
+            });
+          }
+        },
+        domainId: {
+          label: 'label.domain',
+          validation: { required: true },
+          select: function(args) {
+            var items = [];
+            var selectedZoneId = args.$form.find('.form-item[rel=zoneId]').find('select').val();
+            var selectedZoneObj = {};
+            if(addGuestNetworkDialog.zoneObjs != null && selectedZoneId != "") {
+              for(var i = 0; i < addGuestNetworkDialog.zoneObjs.length; i++) {
+                if(addGuestNetworkDialog.zoneObjs[i].id == selectedZoneId) {
+                  selectedZoneObj = addGuestNetworkDialog.zoneObjs[i];
+                  break;
+                }
+              }
+            }            
+            if(selectedZoneObj.domainid != null) { //list only domains under selectedZoneObj.domainid
+              $.ajax({
+                url: createURL("listDomainChildren&id=" + selectedZoneObj.domainid +
"&isrecursive=true"),
+                dataType: "json",
+                async: false,
+                success: function(json) {
+                  var domainObjs = json.listdomainchildrenresponse.domain;
+                  $(domainObjs).each(function() {
+                    items.push({id: this.id, description: this.path});
+                  });
+                }
+              });
+              $.ajax({
+                url: createURL("listDomains&id=" + selectedZoneObj.domainid),
+                dataType: "json",
+                async: false,
+                success: function(json) {
+                  var domainObjs = json.listdomainsresponse.domain;
+                  $(domainObjs).each(function() {
+                    items.push({id: this.id, description: this.path});
+                  });
+                }
+              });
+            }
+            else { //list all domains
+              $.ajax({
+                url: createURL("listDomains&listAll=true"),
+                dataType: "json",
+                async: false,
+                success: function(json) {
+                  var domainObjs = json.listdomainsresponse.domain;
+                  $(domainObjs).each(function() {
+                    items.push({id: this.id, description: this.path});
+                  });
+                }
+              });
+            }
+            args.response.success({data: items});
+          }
+        },
+        subdomainaccess: {
+          label: 'label.subdomain.access', isBoolean: true, isHidden: true,
+        },
+        account: { label: 'label.account' },
+
+        projectId: {
+          label: 'label.project',
+          validation: { required: true },
+          select: function(args) {
+            var items = [];
+            $.ajax({
+              url: createURL("listProjects&listAll=true"),
+              dataType: "json",
+              async: false,
+              success: function(json) {
+                projectObjs = json.listprojectsresponse.project;
+                $(projectObjs).each(function() {
+                  items.push({id: this.id, description: this.name});
+                });
+              }
+            });
+            args.response.success({data: items});
+          }
+        },
+        
+        networkOfferingId: {
+          label: 'label.network.offering',
+          docID: 'helpGuestNetworkZoneNetworkOffering',
+          dependsOn: 'scope',
+          select: function(args) {   
+            var data = {
+              state: 'Enabled',
+              zoneid: args.$form.find('.form-item[rel=zoneId]').find('select').val()
+            };
+                        
+            var selectedPhysicalNetworkObj = [];
+            var selectedPhysicalNetworkId = args.$form.find('.form-item[rel=physicalNetworkId]').find('select').val();
+            if(addGuestNetworkDialog.physicalNetworkObjs != null) {
+              for(var i = 0; i < addGuestNetworkDialog.physicalNetworkObjs.length; i++)
{
+                if(addGuestNetworkDialog.physicalNetworkObjs[i].id == selectedPhysicalNetworkId)
{
+                  selectedPhysicalNetworkObj = addGuestNetworkDialog.physicalNetworkObjs[i];
+                  break;
+                }
+              }
+            }     
+            if(selectedPhysicalNetworkObj.tags != null && selectedPhysicalNetworkObj.tags.length
> 0) {
+              $.extend(data, {
+                tags: selectedPhysicalNetworkObj.tags
+              });              
+            }            
+            
+            //Network tab in Guest Traffic Type in Infrastructure menu is only available
when it's under Advanced zone.
+            //zone dropdown in add guest network dialog includes only Advanced zones.  
+            if(args.scope == "zone-wide" || args.scope == "domain-specific") {
+              $.extend(data, {
+                guestiptype: 'Shared'
+              });
+            }
+
+            var items= [];             
+            $.ajax({
+              url: createURL('listNetworkOfferings'),
+              data: data,
+              async: false,
+              success: function(json) {        
+                addGuestNetworkDialog.networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
+                if (addGuestNetworkDialog.networkOfferingObjs != null && addGuestNetworkDialog.networkOfferingObjs.length
> 0) {                  
+                  var selectedZoneId = args.$form.find('.form-item[rel=zoneId]').find('select').val();
+                  var selectedZoneObj = {};
+                  if(addGuestNetworkDialog.zoneObjs != null && selectedZoneId !=
"") {
+                    for(var i = 0; i < addGuestNetworkDialog.zoneObjs.length; i++) {
+                      if(addGuestNetworkDialog.zoneObjs[i].id == selectedZoneId) {
+                        selectedZoneObj = addGuestNetworkDialog.zoneObjs[i];
+                        break;
+                      }
+                    }
+                  }     
+                  for (var i = 0; i < addGuestNetworkDialog.networkOfferingObjs.length;
i++) {    
+                    //for zone-wide network in Advanced SG-enabled zone, list only SG network
offerings 
+                    if(selectedZoneObj.networktype == 'Advanced' && selectedZoneObj.securitygroupsenabled
== true) {                                    
+                      if(args.scope == "zone-wide") { 
+                        var includingSecurityGroup = false;
+                        var serviceObjArray = addGuestNetworkDialog.networkOfferingObjs[i].service;
+                        for(var k = 0; k < serviceObjArray.length; k++) {            
                              
+                          if(serviceObjArray[k].name == "SecurityGroup") {
+                            includingSecurityGroup = true;
+                            break;
+                          }
+                        }
+                        if(includingSecurityGroup == false)
+                          continue; //skip to next network offering
+                      }
+                    }                    
+                    items.push({id: addGuestNetworkDialog.networkOfferingObjs[i].id, description:
addGuestNetworkDialog.networkOfferingObjs[i].displaytext});
+                  }
+                }
+              }
+            });            
+            args.response.success({data: items});
+
+            args.$select.change(function(){
+              var $form = $(this).closest("form");
+              var selectedNetworkOfferingId = $(this).val();
+              $(addGuestNetworkDialog.networkOfferingObjs).each(function(){
+                if(this.id == selectedNetworkOfferingId) {                              
     
+                  if(this.specifyvlan == false) {
+                    $form.find('.form-item[rel=vlanId]').hide();
+                    cloudStack.dialog.createFormField.validation.required.remove($form.find('.form-item[rel=vlanId]'));
//make vlanId optional  
+                    
+                    $form.find('.form-item[rel=isolatedpvlanId]').hide();
+                  }
+                  else {
+                    $form.find('.form-item[rel=vlanId]').css('display', 'inline-block');
                                     
+                    cloudStack.dialog.createFormField.validation.required.add($form.find('.form-item[rel=vlanId]'));
   //make vlanId required  
+                    
+                    $form.find('.form-item[rel=isolatedpvlanId]').css('display', 'inline-block');
            
+                  }
+                  return false; //break each loop
+                }
+              });
+            });
+          }
+        },
+
+        //IPv4 (begin)
+        ip4gateway: {
+          label: 'IPv4 Gateway',
+          docID: 'helpGuestNetworkZoneGateway'
+        },
+        ip4Netmask: {
+          label: 'IPv4 Netmask',
+          docID: 'helpGuestNetworkZoneNetmask'
+        },
+        startipv4: { 
+          label: 'IPv4 Start IP',               
+          docID: 'helpGuestNetworkZoneStartIP'
+        },
+        endipv4: { 
+          label: 'IPv4 End IP',               
+          docID: 'helpGuestNetworkZoneEndIP'
+        },
+        //IPv4 (end)
+        
+        //IPv6 (begin)
+        ip6gateway: {
+          label: 'IPv6 Gateway',
+          docID: 'helpGuestNetworkZoneGateway'
+        },
+        ip6cidr: {
+          label: 'IPv6 CIDR'
+        },
+        startipv6: { 
+          label: 'IPv6 Start IP',               
+          docID: 'helpGuestNetworkZoneStartIP'
+        },
+        endipv6: { 
+          label: 'IPv6 End IP',               
+          docID: 'helpGuestNetworkZoneEndIP'
+        },
+        //IPv6 (end)
+
+        networkdomain: {
+          label: 'label.network.domain',
+          docID: 'helpGuestNetworkZoneNetworkDomain'
+        }
+      }
+    },
+
+    action: function(args) { //Add guest network in advanced zone                       
+      if (
+        ((args.data.ip4gateway.length == 0) && (args.data.ip4Netmask.length == 0)
&& (args.data.startipv4.length == 0) && (args.data.endipv4.length == 0))
+        && 
+        ((args.data.ip6gateway.length == 0) && (args.data.ip6cidr.length == 0) &&
(args.data.startipv6.length == 0) && (args.data.endipv6.length == 0))
+      )
+      {
+        args.response.error("Either IPv4 fields or IPv6 fields need to be filled when adding
a guest network");
+        return;
+      }
+    
+      var $form = args.$form;
+
+      var array1 = [];  
+      array1.push("&zoneId=" + args.data.zoneId);
+      array1.push("&networkOfferingId=" + args.data.networkOfferingId);
+
+      //Pass physical network ID to createNetwork API only when network offering's guestiptype
is Shared.
+      var selectedNetworkOfferingObj;
+      if(addGuestNetworkDialog.networkOfferingObjs != null) {
+        for(var i = 0; i < addGuestNetworkDialog.networkOfferingObjs.length; i++) {
+          if(addGuestNetworkDialog.networkOfferingObjs[i].id == args.data.networkOfferingId)
{
+            selectedNetworkOfferingObj = addGuestNetworkDialog.networkOfferingObjs[i]
+            break;
+          }
+        }
+      }
+      
+      if(selectedNetworkOfferingObj.guestiptype == "Shared")
+        array1.push("&physicalnetworkid=" + args.data.physicalNetworkId);
+
+      array1.push("&name=" + todb(args.data.name));
+      array1.push("&displayText=" + todb(args.data.description));
+
+      if(($form.find('.form-item[rel=vlanId]').css("display") != "none") && (args.data.vlanId
!= null && args.data.vlanId.length > 0))
+        array1.push("&vlan=" + todb(args.data.vlanId));
+      
+      if(($form.find('.form-item[rel=isolatedpvlanId]').css("display") != "none") &&
(args.data.isolatedpvlanId != null && args.data.isolatedpvlanId.length > 0))
+        array1.push("&isolatedpvlan=" + todb(args.data.isolatedpvlanId));
+                              
+      if($form.find('.form-item[rel=domainId]').css("display") != "none") {
+        array1.push("&domainId=" + args.data.domainId);
+
+        if($form.find('.form-item[rel=account]').css("display") != "none") {  //account-specific
+          array1.push("&account=" + args.data.account);
+          array1.push("&acltype=account");
+        }
+        else if($form.find('.form-item[rel=projectId]').css("display") != "none") {  //project-specific
+          array1.push("&projectid=" + args.data.projectId);
+          array1.push("&acltype=account");                            
+        }
+        else {  //domain-specific
+          array1.push("&acltype=domain");
+
+          if ($form.find('.form-item[rel=subdomainaccess]:visible input:checked').size())
+            array1.push("&subdomainaccess=true");
+          else
+            array1.push("&subdomainaccess=false");
+        }
+      }
+      else { //zone-wide
+        array1.push("&acltype=domain"); //server-side will make it Root domain (i.e.
domainid=1)
+      }
+
+      //IPv4 (begin)
+      if(args.data.ip4gateway != null && args.data.ip4gateway.length > 0)
+        array1.push("&gateway=" + args.data.ip4gateway);
+      if(args.data.ip4Netmask != null && args.data.ip4Netmask.length > 0)
+        array1.push("&netmask=" + args.data.ip4Netmask);
+      if(($form.find('.form-item[rel=startipv4]').css("display") != "none") && (args.data.startipv4
!= null && args.data.startipv4.length > 0))
+        array1.push("&startip=" + args.data.startipv4);
+      if(($form.find('.form-item[rel=endipv4]').css("display") != "none") && (args.data.endipv4
!= null && args.data.endipv4.length > 0))
+        array1.push("&endip=" + args.data.endipv4);
+      //IPv4 (end)
+      
+      //IPv6 (begin)
+      if(args.data.ip6gateway != null && args.data.ip6gateway.length > 0)
+        array1.push("&ip6gateway=" + args.data.ip6gateway);
+      if(args.data.ip6cidr != null && args.data.ip6cidr.length > 0)
+        array1.push("&ip6cidr=" + args.data.ip6cidr);
+      if(($form.find('.form-item[rel=startipv6]').css("display") != "none") && (args.data.startipv6
!= null && args.data.startipv6.length > 0))
+        array1.push("&startipv6=" + args.data.startipv6);
+      if(($form.find('.form-item[rel=endipv6]').css("display") != "none") && (args.data.endipv6
!= null && args.data.endipv6.length > 0))
+        array1.push("&endipv6=" + args.data.endipv6);
+      //IPv6 (end)
+      
+      if(args.data.networkdomain != null && args.data.networkdomain.length > 0)
+        array1.push("&networkdomain=" + todb(args.data.networkdomain));
+
+      $.ajax({
+        url: createURL("createNetwork" + array1.join("")),
+        dataType: "json",
+        success: function(json) {
+          var item = json.createnetworkresponse.network;
+          args.response.success({data:item});
+        },
+        error: function(XMLHttpResponse) {
+          var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
+          args.response.error(errorMsg);
+        }
+      });
+    },
+    notification: {
+      poll: function(args) {
+        args.complete();
+      }
+    }
+  }    
+}
+  
 
 // Role Functions
 function isAdmin() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f37877dc/ui/scripts/system.js
----------------------------------------------------------------------
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index ebb2117..89b9d6e 100644
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -1309,419 +1309,7 @@
                     //scope: { label: 'label.scope' }
                   },
                   actions: {
-                    add: {
-                      label: 'label.add.guest.network',
-
-                      messages: {
-                        confirm: function(args) {
-                          return 'message.add.guest.network';
-                        },
-                        notification: function(args) {
-                          return 'label.add.guest.network';
-                        }
-                      },
-
-                      createForm: {
-                        title: 'label.add.guest.network',  //Add guest network in advanced
zone
-
-                        fields: {
-                          name: {
-                            docID: 'helpGuestNetworkZoneName',
-                            label: 'label.name',
-                            validation: { required: true }
-                          },
-                          description: {
-                            label: 'label.description',
-                            docID: 'helpGuestNetworkZoneDescription',
-                            validation: { required: true }
-                          },
-                          vlanId: {
-                            label: 'label.vlan.id',
-                            docID: 'helpGuestNetworkZoneVLANID'
-                          },
-                          isolatedpvlanId: {
-                            label: 'Secondary Isolated VLAN ID'                         
 
-                          },
-                          
-                          scope: {
-                            label: 'label.scope',
-                            docID: 'helpGuestNetworkZoneScope',
-                            select: function(args) {
-                              var array1 = [];															
-															if(args.context.zones[0].networktype == "Advanced" && args.context.zones[0].securitygroupsenabled
== true) {															  
-																array1.push({id: 'zone-wide', description: 'All'});
-															}
-															else {															
-																array1.push({id: 'zone-wide', description: 'All'});
-																array1.push({id: 'domain-specific', description: 'Domain'});
-																array1.push({id: 'account-specific', description: 'Account'});
-																array1.push({id: 'project-specific', description: 'Project'});
-															}
-                              args.response.success({data: array1});
-
-                              args.$select.change(function() {
-                                var $form = $(this).closest('form');
-                                if($(this).val() == "zone-wide") {
-                                  $form.find('.form-item[rel=domainId]').hide();
-                                  $form.find('.form-item[rel=subdomainaccess]').hide();
-                                  $form.find('.form-item[rel=account]').hide();
-																	$form.find('.form-item[rel=projectId]').hide();
-                                }
-                                else if ($(this).val() == "domain-specific") {
-                                  $form.find('.form-item[rel=domainId]').css('display', 'inline-block');
-                                  $form.find('.form-item[rel=subdomainaccess]').css('display',
'inline-block');
-                                  $form.find('.form-item[rel=account]').hide();
-																	$form.find('.form-item[rel=projectId]').hide();
-                                }
-                                else if($(this).val() == "account-specific") {
-                                  $form.find('.form-item[rel=domainId]').css('display', 'inline-block');
-                                  $form.find('.form-item[rel=subdomainaccess]').hide();
-                                  $form.find('.form-item[rel=account]').css('display', 'inline-block');
-																	$form.find('.form-item[rel=projectId]').hide();
-                                }
-																else if($(this).val() == "project-specific") {
-                                  $form.find('.form-item[rel=domainId]').css('display', 'inline-block');
-                                  $form.find('.form-item[rel=subdomainaccess]').hide();
-                                  $form.find('.form-item[rel=account]').hide();
-																	$form.find('.form-item[rel=projectId]').css('display', 'inline-block');
-                                }
-                              });
-                            }
-                          },
-                          domainId: {
-                            label: 'label.domain',
-                            validation: { required: true },
-                            select: function(args) {
-                              var items = [];
-                              if(selectedZoneObj.domainid != null) { //list only domains
under selectedZoneObj.domainid
-                                $.ajax({
-                                  url: createURL("listDomainChildren&id=" + selectedZoneObj.domainid
+ "&isrecursive=true"),
-                                  dataType: "json",
-                                  async: false,
-                                  success: function(json) {
-                                    var domainObjs = json.listdomainchildrenresponse.domain;
-                                    $(domainObjs).each(function() {
-                                      items.push({id: this.id, description: this.path});
-                                    });
-                                  }
-                                });
-                                $.ajax({
-                                  url: createURL("listDomains&id=" + selectedZoneObj.domainid),
-                                  dataType: "json",
-                                  async: false,
-                                  success: function(json) {
-                                    var domainObjs = json.listdomainsresponse.domain;
-                                    $(domainObjs).each(function() {
-                                      items.push({id: this.id, description: this.path});
-                                    });
-                                  }
-                                });
-                              }
-                              else { //list all domains
-                                $.ajax({
-                                  url: createURL("listDomains&listAll=true"),
-                                  dataType: "json",
-                                  async: false,
-                                  success: function(json) {
-                                    var domainObjs = json.listdomainsresponse.domain;
-                                    $(domainObjs).each(function() {
-                                      items.push({id: this.id, description: this.path});
-                                    });
-                                  }
-                                });
-                              }
-                              args.response.success({data: items});
-                            }
-                          },
-                          subdomainaccess: {
-                            label: 'label.subdomain.access', isBoolean: true, isHidden: true,
-                          },
-                          account: { label: 'label.account' },
-
-													projectId: {
-                            label: 'label.project',
-                            validation: { required: true },
-                            select: function(args) {
-                              var items = [];
-                              $.ajax({
-															  url: createURL("listProjects&listAll=true"),
-																dataType: "json",
-																async: false,
-																success: function(json) {
-																  projectObjs = json.listprojectsresponse.project;
-																  $(projectObjs).each(function() {
-                                    items.push({id: this.id, description: this.name});
-                                  });
-																}
-															});
-                              args.response.success({data: items});
-                            }
-                          },
-
-                          networkOfferingId: {
-                            label: 'label.network.offering',
-                            docID: 'helpGuestNetworkZoneNetworkOffering',
-                            dependsOn: 'scope',
-                            select: function(args) {
-															$.ajax({
-																url: createURL('listPhysicalNetworks'),
-																data: {
-																	id: args.context.physicalNetworks[0].id
-																},
-																async: false,
-																success: function(json) {
-																	args.context.physicalNetworks[0] = json.listphysicalnetworksresponse.physicalnetwork[0];
-																}
-															});
-
-                              var apiCmd = "listNetworkOfferings&state=Enabled&zoneid="
+ selectedZoneObj.id;
-															var array1 = [];
-
-															if(physicalNetworkObjs.length > 1) { //multiple physical networks
-															  var guestTrafficTypeTotal = 0;
-															  for(var i = 0; i < physicalNetworkObjs.length; i++) {
-																  if(guestTrafficTypeTotal > 1) //as long as guestTrafficTypeTotal >
1, break for loop, don't need to continue to count. It doesn't matter whether guestTrafficTypeTotal
is 2 or 3 or 4 or 5 or more. We only care whether guestTrafficTypeTotal is greater than 1.
-																	  break;
-																  $.ajax({
-																	  url: createURL("listTrafficTypes&physicalnetworkid=" + physicalNetworkObjs[i].id),
-																		dataType: "json",
-																		async: false,
-																		success: function(json) {
-																			var items = json.listtraffictypesresponse.traffictype;
-																			for(var k = 0; k < items.length; k++) {
-																			  if(items[k].traffictype == "Guest") {
-																				  guestTrafficTypeTotal++;
-																				  break;
-																				}
-																			}
-																		}
-																	});
-																}
-
-															  if(guestTrafficTypeTotal > 1) {
-																	if(args.context.physicalNetworks[0].tags != null && args.context.physicalNetworks[0].tags.length
> 0) {
-																		array1.push("&tags=" + args.context.physicalNetworks[0].tags);
-																	}
-																	else {
-																		alert(dictionary['error.please.specify.physical.network.tags']);
-																		return;
-																	}
-																}
-															}
-
-                              //this tab (Network tab in guest network) only shows when it's
under an Advanced zone
-															if(args.scope == "zone-wide" || args.scope == "domain-specific") {
-																array1.push("&guestiptype=Shared");
-															}
-
-															var networkOfferingArray = [];
-															
-                              $.ajax({
-                                url: createURL(apiCmd + array1.join("")),
-                                dataType: "json",
-                                async: false,
-                                success: function(json) {																  
-                                  networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
-                                  if (networkOfferingObjs != null && networkOfferingObjs.length
> 0) {
-                                    for (var i = 0; i < networkOfferingObjs.length; i++)
{    
-																			//for zone-wide network in Advanced SG-enabled zone, list only SG network
offerings 
-																			if(args.context.zones[0].networktype == 'Advanced' && args.context.zones[0].securitygroupsenabled
== true) {																		
-																				if(args.scope == "zone-wide") { 
-																					var includingSecurityGroup = false;
-																					var serviceObjArray = networkOfferingObjs[i].service;
-																					for(var k = 0; k < serviceObjArray.length; k++) {															
					  
-																						if(serviceObjArray[k].name == "SecurityGroup") {
-																							includingSecurityGroup = true;
-																							break;
-																						}
-																					}
-																					if(includingSecurityGroup == false)
-																						continue; //skip to next network offering
-																				}
-																			}
-																			
-                                      networkOfferingArray.push({id: networkOfferingObjs[i].id,
description: networkOfferingObjs[i].displaytext});
-                                    }
-                                  }
-                                }
-                              });
-
-                              args.response.success({data: networkOfferingArray});
-
-
-															args.$select.change(function(){
-															  var $form = $(this).closest("form");
-																var selectedNetworkOfferingId = $(this).val();
-																$(networkOfferingObjs).each(function(){
-																  if(this.id == selectedNetworkOfferingId) {																		
-																		if(this.specifyvlan == false) {
-																		  $form.find('.form-item[rel=vlanId]').hide();
-																			cloudStack.dialog.createFormField.validation.required.remove($form.find('.form-item[rel=vlanId]'));
//make vlanId optional 	
-																			
-																			$form.find('.form-item[rel=isolatedpvlanId]').hide();
-																		}
-																		else {
-																		  $form.find('.form-item[rel=vlanId]').css('display', 'inline-block');
																		
-																			cloudStack.dialog.createFormField.validation.required.add($form.find('.form-item[rel=vlanId]'));
	//make vlanId required	
-																			
-																			$form.find('.form-item[rel=isolatedpvlanId]').css('display', 'inline-block');
            
-																		}
-																		return false; //break each loop
-																	}
-																});
-															});
-                            }
-                          },
-
-                          //IPv4 (begin)
-                          ip4gateway: {
-                            label: 'IPv4 Gateway',
-                            docID: 'helpGuestNetworkZoneGateway'
-                          },
-                          ip4Netmask: {
-                            label: 'IPv4 Netmask',
-                            docID: 'helpGuestNetworkZoneNetmask'
-                          },
-                          startipv4: { 
-							label: 'IPv4 Start IP', 							
-                            docID: 'helpGuestNetworkZoneStartIP'
-						  },
-                          endipv4: { 
-							label: 'IPv4 End IP', 							
-                            docID: 'helpGuestNetworkZoneEndIP'
-						  },
-						//IPv4 (end)
-						  
-						//IPv6 (begin)
-                          ip6gateway: {
-                            label: 'IPv6 Gateway',
-                            docID: 'helpGuestNetworkZoneGateway'
-                          },
-                          ip6cidr: {
-                            label: 'IPv6 CIDR'
-                          },
-                          startipv6: { 
-							label: 'IPv6 Start IP', 							
-                            docID: 'helpGuestNetworkZoneStartIP'
-						  },
-                          endipv6: { 
-							label: 'IPv6 End IP', 							
-                            docID: 'helpGuestNetworkZoneEndIP'
-						  },
-						//IPv6 (end)
-						  
-                          networkdomain: {
-                            label: 'label.network.domain',
-                            docID: 'helpGuestNetworkZoneNetworkDomain'
-                          }
-                        }
-                      },
-
-                      action: function(args) { //Add guest network in advanced zone					
					  
-												if (
-													((args.data.ip4gateway.length == 0) && (args.data.ip4Netmask.length
== 0) && (args.data.startipv4.length == 0) && (args.data.endipv4.length ==
0))
-													&& 
-													((args.data.ip6gateway.length == 0) && (args.data.ip6cidr.length ==
0) && (args.data.startipv6.length == 0) && (args.data.endipv6.length == 0))
-												)
-												{
-												  args.response.error("Either IPv4 fields or IPv6 fields need to be filled when
adding a guest network");
-													return;
-												}
-											
-                        var $form = args.$form;
-
-												var array1 = [];
-                        array1.push("&zoneId=" + selectedZoneObj.id);
-												array1.push("&networkOfferingId=" + args.data.networkOfferingId);
-
-												//Pass physical network ID to createNetwork API only when network offering's
guestiptype is Shared.
-												var selectedNetworkOfferingObj;
-												$(networkOfferingObjs).each(function(){
-													if(this.id == args.data.networkOfferingId) {
-													  selectedNetworkOfferingObj = this;
-														return false; //break each loop
-													}
-												});
-												if(selectedNetworkOfferingObj.guestiptype == "Shared")
-												  array1.push("&physicalnetworkid=" + selectedPhysicalNetworkObj.id);
-
-                        array1.push("&name=" + todb(args.data.name));
-                        array1.push("&displayText=" + todb(args.data.description));
-
-											  if(($form.find('.form-item[rel=vlanId]').css("display") != "none") &&
(args.data.vlanId != null && args.data.vlanId.length > 0))
-												  array1.push("&vlan=" + todb(args.data.vlanId));
-											  
-											  if(($form.find('.form-item[rel=isolatedpvlanId]').css("display") != "none")
&& (args.data.isolatedpvlanId != null && args.data.isolatedpvlanId.length
> 0))
-                          array1.push("&isolatedpvlan=" + todb(args.data.isolatedpvlanId));
-											  											  
-												if($form.find('.form-item[rel=domainId]').css("display") != "none") {
-												  array1.push("&domainId=" + args.data.domainId);
-
-													if($form.find('.form-item[rel=account]').css("display") != "none") {  //account-specific
-														array1.push("&account=" + args.data.account);
-														array1.push("&acltype=account");
-													}
-													else if($form.find('.form-item[rel=projectId]').css("display") != "none") {
 //project-specific
-														array1.push("&projectid=" + args.data.projectId);
-														array1.push("&acltype=account");														
-													}
-													else {  //domain-specific
-														array1.push("&acltype=domain");
-
-                            if ($form.find('.form-item[rel=subdomainaccess]:visible input:checked').size())
-															array1.push("&subdomainaccess=true");
-														else
-															array1.push("&subdomainaccess=false");
-													}
-												}
-												else { //zone-wide
-													array1.push("&acltype=domain"); //server-side will make it Root domain (i.e.
domainid=1)
-												}
-
-												//IPv4 (begin)
-											    if(args.data.ip4gateway != null && args.data.ip4gateway.length >
0)
-												  array1.push("&gateway=" + args.data.ip4gateway);
-												if(args.data.ip4Netmask != null && args.data.ip4Netmask.length > 0)
-												  array1.push("&netmask=" + args.data.ip4Netmask);
-												if(($form.find('.form-item[rel=startipv4]').css("display") != "none") &&
(args.data.startipv4 != null && args.data.startipv4.length > 0))
-												  array1.push("&startip=" + args.data.startipv4);
-												if(($form.find('.form-item[rel=endipv4]').css("display") != "none") &&
(args.data.endipv4 != null && args.data.endipv4.length > 0))
-												  array1.push("&endip=" + args.data.endipv4);
-												//IPv4 (end)
-												
-												//IPv6 (begin)
-											    if(args.data.ip6gateway != null && args.data.ip6gateway.length >
0)
-												  array1.push("&ip6gateway=" + args.data.ip6gateway);
-												if(args.data.ip6cidr != null && args.data.ip6cidr.length > 0)
-												  array1.push("&ip6cidr=" + args.data.ip6cidr);
-												if(($form.find('.form-item[rel=startipv6]').css("display") != "none") &&
(args.data.startipv6 != null && args.data.startipv6.length > 0))
-												  array1.push("&startipv6=" + args.data.startipv6);
-												if(($form.find('.form-item[rel=endipv6]').css("display") != "none") &&
(args.data.endipv6 != null && args.data.endipv6.length > 0))
-												  array1.push("&endipv6=" + args.data.endipv6);
-												//IPv6 (end)
-												
-												if(args.data.networkdomain != null && args.data.networkdomain.length
> 0)
-													array1.push("&networkdomain=" + todb(args.data.networkdomain));
-
-                        $.ajax({
-                          url: createURL("createNetwork" + array1.join("")),
-                          dataType: "json",
-                          success: function(json) {
-                            var item = json.createnetworkresponse.network;
-                            args.response.success({data:item});
-                          },
-                          error: function(XMLHttpResponse) {
-                            var errorMsg = parseXMLHttpResponse(XMLHttpResponse);
-                            args.response.error(errorMsg);
-                          }
-                        });
-                      },
-                      notification: {
-                        poll: function(args) {
-                          args.complete();
-                        }
-                      }
-                    }
+                    add: addGuestNetworkDialog.def
                   },
 
                   dataProvider: function(args) {


Mime
View raw message