cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seb...@apache.org
Subject [25/39] Format JS
Date Thu, 18 Jul 2013 16:35:00 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ad69bc8d/ui/scripts/network.js
----------------------------------------------------------------------
diff --git a/ui/scripts/network.js b/ui/scripts/network.js
index 95a93bc..15d4b7f 100755
--- a/ui/scripts/network.js
+++ b/ui/scripts/network.js
@@ -16,2782 +16,3010 @@
 // under the License.
 
 (function(cloudStack, $) {
-  var ingressEgressDataMap = function(elem) {
-    var elemData = {
-      id: elem.ruleid,
-      protocol: elem.protocol,
-      startport: elem.startport,
-      endport: elem.endport,
-      cidr: elem.cidr ? elem.cidr : ''.concat(elem.account, ' - ', elem.securitygroupname)
+    var ingressEgressDataMap = function(elem) {
+        var elemData = {
+            id: elem.ruleid,
+            protocol: elem.protocol,
+            startport: elem.startport,
+            endport: elem.endport,
+            cidr: elem.cidr ? elem.cidr : ''.concat(elem.account, ' - ', elem.securitygroupname)
+        };
+
+        if (elemData.startport == 0 && elemData.endport) {
+            elemData.startport = '0';
+        } else if (elem.icmptype && elem.icmpcode) {
+            elemData.startport = elem.icmptype;
+            elemData.endport = elem.icmpcode;
+        }
+
+        return elemData;
     };
 
-    if (elemData.startport == 0 && elemData.endport) {
-      elemData.startport = '0';
-    } else if (elem.icmptype && elem.icmpcode) {
-      elemData.startport = elem.icmptype;
-      elemData.endport = elem.icmpcode;
-    }
+    var instanceSecondaryIPSubselect = function(args) {
+        var instance = args.context.instances[0];
+        var network = args.context.networks[0];
+        var nic = $.grep(instance.nic, function(nic) {
+            return nic.networkid == network.id;
+        })[0];
 
-    return elemData;
-  };
-
-  var instanceSecondaryIPSubselect = function(args) {
-    var instance = args.context.instances[0];
-    var network = args.context.networks[0];
-    var nic = $.grep(instance.nic, function(nic) {
-      return nic.networkid == network.id;
-    })[0];
-
-    // Get NIC IPs
-    $.ajax({
-      url: createURL('listNics'),
-      data: {
-        virtualmachineid: instance.id,
-        nicId: nic.id
-      },
-      success: function(json) {
-        var nic = json.listnicsresponse.nic[0];
-        var ips = nic.secondaryip ? nic.secondaryip : [];
-        var ipSelection = [];
-
-        // Add primary IP as default
-        ipSelection.push({ id: -1, description: nic.ipaddress + ' (Primary)' });
-
-        // Add secondary IPs
-        $(ips).map(function(index, ip) {
-          ipSelection.push({
-            id: ip.ipaddress,
-            description: ip.ipaddress
-          });
-        }); 
-
-
-        args.response.success({
-          data: ipSelection
-        });
-      }
-    })
-  };
-  
-  var ipChangeNotice = function() {
-    cloudStack.dialog.confirm({
-      message: 'message.ip.address.changed',
-      action: function() {
-        $('#browser .container').cloudBrowser('selectPanel', {
-          panel: $('#browser .panel:last').prev(),
-          complete: function() {
-            $(window).trigger('cloudStack.fullRefresh');
-          }
+        // Get NIC IPs
+        $.ajax({
+            url: createURL('listNics'),
+            data: {
+                virtualmachineid: instance.id,
+                nicId: nic.id
+            },
+            success: function(json) {
+                var nic = json.listnicsresponse.nic[0];
+                var ips = nic.secondaryip ? nic.secondaryip : [];
+                var ipSelection = [];
+
+                // Add primary IP as default
+                ipSelection.push({
+                    id: -1,
+                    description: nic.ipaddress + ' (Primary)'
+                });
+
+                // Add secondary IPs
+                $(ips).map(function(index, ip) {
+                    ipSelection.push({
+                        id: ip.ipaddress,
+                        description: ip.ipaddress
+                    });
+                });
+
+
+                args.response.success({
+                    data: ipSelection
+                });
+            }
+        })
+    };
+
+    var ipChangeNotice = function() {
+        cloudStack.dialog.confirm({
+            message: 'message.ip.address.changed',
+            action: function() {
+                $('#browser .container').cloudBrowser('selectPanel', {
+                    panel: $('#browser .panel:last').prev(),
+                    complete: function() {
+                        $(window).trigger('cloudStack.fullRefresh');
+                    }
+                });
+            }
         });
-      }
-    });
-  };
-
-  var zoneObjs = [];
-
-  var actionFilters = {
-    ipAddress: function(args) {
-      var allowedActions = args.context.actions;
-      var disallowedActions = [];
-      var item = args.context.item;
-      var status = item.state;
-
-      if (status == 'Destroyed' ||
-          status == 'Releasing' ||
-          status == 'Released' ||
-          status == 'Creating' ||
-          status == 'Allocating' ||
-          item.account == 'system' ||
-          item.issystem == true ) {
-            return [];
-          }
-
-      if(item.networkOfferingConserveMode == false) {
-        /*
+    };
+
+    var zoneObjs = [];
+
+    var actionFilters = {
+        ipAddress: function(args) {
+            var allowedActions = args.context.actions;
+            var disallowedActions = [];
+            var item = args.context.item;
+            var status = item.state;
+
+            if (status == 'Destroyed' ||
+                status == 'Releasing' ||
+                status == 'Released' ||
+                status == 'Creating' ||
+                status == 'Allocating' ||
+                item.account == 'system' ||
+                item.issystem == true) {
+                return [];
+            }
+
+            if (item.networkOfferingConserveMode == false) {
+                /*
          (1) If IP is SourceNat, no StaticNat/VPN/PortForwarding/LoadBalancer can be enabled/added.
          */
-        if (item.issourcenat == true){
-          disallowedActions.push('enableStaticNAT');
-          disallowedActions.push('enableVPN');
-        }
+                if (item.issourcenat == true) {
+                    disallowedActions.push('enableStaticNAT');
+                    disallowedActions.push('enableVPN');
+                }
 
-        /*
+                /*
          (2) If IP is non-SourceNat, show StaticNat/VPN/PortForwarding/LoadBalancer at first.
          1. Once StaticNat is enabled, hide VPN/PortForwarding/LoadBalancer.
          2. Once VPN is enabled, hide StaticNat/PortForwarding/LoadBalancer.
          3. Once a PortForwarding rule is added, hide StaticNat/VPN/LoadBalancer.
          4. Once a LoadBalancer rule is added, hide StaticNat/VPN/PortForwarding.
          */
-        else { //item.issourcenat == false
-          if (item.isstaticnat) { //1. Once StaticNat is enabled, hide VPN/PortForwarding/LoadBalancer.
-            disallowedActions.push('enableVPN');
-          }
-          if (item.vpnenabled) { //2. Once VPN is enabled, hide StaticNat/PortForwarding/LoadBalancer.
-            disallowedActions.push('enableStaticNAT');
-          }
-
-          //3. Once a PortForwarding rule is added, hide StaticNat/VPN/LoadBalancer.
-          $.ajax({
-            url: createURL('listPortForwardingRules'),
-            data: {
-              ipaddressid: item.id,
-              listAll: true
-            },
-            dataType: 'json',
-            async: false,
-            success: function(json) {
-              var rules = json.listportforwardingrulesresponse.portforwardingrule;
-              if(rules != null && rules.length > 0) {
-                disallowedActions.push('enableVPN');
-                disallowedActions.push('enableStaticNAT');
-              }
-            }
-          });
+                else { //item.issourcenat == false
+                    if (item.isstaticnat) { //1. Once StaticNat is enabled, hide VPN/PortForwarding/LoadBalancer.
+                        disallowedActions.push('enableVPN');
+                    }
+                    if (item.vpnenabled) { //2. Once VPN is enabled, hide StaticNat/PortForwarding/LoadBalancer.
+                        disallowedActions.push('enableStaticNAT');
+                    }
 
-          //4. Once a LoadBalancer rule is added, hide StaticNat/VPN/PortForwarding.
-          $.ajax({
-            url: createURL('listLoadBalancerRules'),
-            data: {
-              publicipid: item.id,
-              listAll: true
-            },
-            dataType: 'json',
-            async: false,
-            success: function(json) {
-              var rules = json.listloadbalancerrulesresponse.loadbalancerrule;
-              if(rules != null && rules.length > 0) {
-                disallowedActions.push('enableVPN');
-                disallowedActions.push('enableStaticNAT');
-              }
+                    //3. Once a PortForwarding rule is added, hide StaticNat/VPN/LoadBalancer.
+                    $.ajax({
+                        url: createURL('listPortForwardingRules'),
+                        data: {
+                            ipaddressid: item.id,
+                            listAll: true
+                        },
+                        dataType: 'json',
+                        async: false,
+                        success: function(json) {
+                            var rules = json.listportforwardingrulesresponse.portforwardingrule;
+                            if (rules != null && rules.length > 0) {
+                                disallowedActions.push('enableVPN');
+                                disallowedActions.push('enableStaticNAT');
+                            }
+                        }
+                    });
+
+                    //4. Once a LoadBalancer rule is added, hide StaticNat/VPN/PortForwarding.
+                    $.ajax({
+                        url: createURL('listLoadBalancerRules'),
+                        data: {
+                            publicipid: item.id,
+                            listAll: true
+                        },
+                        dataType: 'json',
+                        async: false,
+                        success: function(json) {
+                            var rules = json.listloadbalancerrulesresponse.loadbalancerrule;
+                            if (rules != null && rules.length > 0) {
+                                disallowedActions.push('enableVPN');
+                                disallowedActions.push('enableStaticNAT');
+                            }
+                        }
+                    });
+                }
             }
-          });
-        }
-      }
-			if(item.networkOfferingConserveMode == false) {			 
-				/*
-				(1) If IP is SourceNat, no StaticNat/VPN/PortForwarding/LoadBalancer can be enabled/added. 
+            if (item.networkOfferingConserveMode == false) {
+                /*
+				(1) If IP is SourceNat, no StaticNat/VPN/PortForwarding/LoadBalancer can be enabled/added.
 				*/
-	      if (item.issourcenat == true){
-					disallowedActions.push('enableStaticNAT');
-					disallowedActions.push('enableVPN');
-				}			
-				
-				/*
+                if (item.issourcenat == true) {
+                    disallowedActions.push('enableStaticNAT');
+                    disallowedActions.push('enableVPN');
+                }
+
+                /*
 				(2) If IP is non-SourceNat, show StaticNat/VPN/PortForwarding/LoadBalancer at first.
 				1. Once StaticNat is enabled, hide VPN/PortForwarding/LoadBalancer.
 				2. Once VPN is enabled, hide StaticNat/PortForwarding/LoadBalancer.
 				3. Once a PortForwarding rule is added, hide StaticNat/VPN/LoadBalancer.
 				4. Once a LoadBalancer rule is added, hide StaticNat/VPN/PortForwarding.
 				*/
-				else { //item.issourcenat == false				   
-					if (item.isstaticnat) { //1. Once StaticNat is enabled, hide VPN/PortForwarding/LoadBalancer.
-					  disallowedActions.push('enableVPN');
-					}
-					if (item.vpnenabled) { //2. Once VPN is enabled, hide StaticNat/PortForwarding/LoadBalancer.
-					  disallowedActions.push('enableStaticNAT');
-					}
-								 
-					//3. Once a PortForwarding rule is added, hide StaticNat/VPN/LoadBalancer.
-					$.ajax({
-						url: createURL('listPortForwardingRules'),
-						data: {
-							ipaddressid: item.id,
-							listAll: true
-						},
-						dataType: 'json',
-						async: false,
-						success: function(json) {							
-							var rules = json.listportforwardingrulesresponse.portforwardingrule;
-							if(rules != null && rules.length > 0) {
-							  disallowedActions.push('enableVPN');
-								disallowedActions.push('enableStaticNAT'); 
-							}
-						}
-					});	
-										
-					//4. Once a LoadBalancer rule is added, hide StaticNat/VPN/PortForwarding.
-					$.ajax({
-						url: createURL('listLoadBalancerRules'),
-						data: {
-							publicipid: item.id,
-							listAll: true
-						},
-						dataType: 'json',
-						async: false,
-						success: function(json) {
-							var rules = json.listloadbalancerrulesresponse.loadbalancerrule;
-							if(rules != null && rules.length > 0) {
-							  disallowedActions.push('enableVPN');
-								disallowedActions.push('enableStaticNAT'); 
-							}
-						}
-					});		
-				}			  				
-			}			
-			
-      if (item.isstaticnat) {
-        disallowedActions.push('enableStaticNAT');
-      } else {
-        disallowedActions.push('disableStaticNAT');
-      }
-
-			if(item.networkOfferingHavingVpnService == true) {      
-        if (item.vpnenabled) {
-          disallowedActions.push('enableVPN');
-        } else {
-          disallowedActions.push('disableVPN');
-        }
-      } else { //item.networkOfferingHavingVpnService == false
-        disallowedActions.push('disableVPN');
-        disallowedActions.push('enableVPN');
-      }
-
-      if (item.issourcenat){
-        disallowedActions.push('enableStaticNAT');
-        disallowedActions.push('disableStaticNAT');
-        disallowedActions.push('remove');
-      }
-
-      allowedActions = $.grep(allowedActions, function(item) {
-        return $.inArray(item, disallowedActions) == -1;
-      });
-
-      return allowedActions;
-    },
-
-    securityGroups: function(args) {
-      var allowedActions = [];
-      var isSecurityGroupOwner = isAdmin() || isDomainAdmin() ||
-            args.context.item.account == args.context.users[0].account;
-
-      if (isSecurityGroupOwner &&
-          args.context.item.state != 'Destroyed' &&
-          args.context.item.name != 'default') {
-        allowedActions.push('remove');
-      }
-
-      return allowedActions;
-    }
-  };
-
-	var networkOfferingObjs = [];  	        
-  var advZoneObjs;
-  
-  cloudStack.sections.network = {
-    title: 'label.network',
-    id: 'network',
-    sectionSelect: {
-      preFilter: function(args) {
-        var sectionsToShow = ['networks'];
-
-        $.ajax({
-          url: createURL('listZones'),
-          data: {
-            networktype: 'Advanced'
-          },
-          async: false,
-          success: function(json) {            
-            advZoneObjs = json.listzonesresponse.zone;
-            if(advZoneObjs != null && advZoneObjs.length > 0) {
-              sectionsToShow.push('vpc');
-              sectionsToShow.push('vpnCustomerGateway');
-            }
-          }
-        });
-                           
-        $.ajax({
-          url: createURL('listNetworks', { ignoreProject: true }),
-          data: {
-            supportedServices: 'SecurityGroup',
-            listAll: true,
-            details: 'min'
-          },
-          async: false,
-          success: function(json) {
-            if(json.listnetworksresponse.network != null && json.listnetworksresponse.network.length > 0) {
-              sectionsToShow.push('securityGroups');
-            }
-          }
-        });
-       
-        return sectionsToShow;
-      },
-
-      label: 'label.select-view'
-    },
-    sections: {
-      networks: {
-        id: 'networks',
-        type: 'select',
-        title: 'label.guest.networks',
-        listView: {
-          actions: {
-            add: { 
-              label: 'Add Isolated Network',
-
-              preFilter: function(args) { 
-                if(advZoneObjs != null && advZoneObjs.length > 0) {
-                  for(var i = 0; i < advZoneObjs.length; i++) {
-                    if(advZoneObjs[i].securitygroupsenabled != true) { //'Add Isolated Guest Network with SourceNat' is only supported in Advanced SG-disabled zone 
-                      return true;
+                else { //item.issourcenat == false
+                    if (item.isstaticnat) { //1. Once StaticNat is enabled, hide VPN/PortForwarding/LoadBalancer.
+                        disallowedActions.push('enableVPN');
                     }
-                  }   
-                  return false;
-                }
-                else{
-                  return false;     
-                }  			
-              },
-
-              createForm: {
-                title: 'Add Isolated Guest Network with SourceNat',               
-                fields: {
-                  name: { label: 'label.name', validation: { required: true }, docID: 'helpGuestNetworkName' },
-                  displayText: { label: 'label.display.text', validation: { required: true }, docID: 'helpGuestNetworkDisplayText'},
-                  zoneId: {
-                    label: 'label.zone',
-                    validation: { required: true },
-                    docID: 'helpGuestNetworkZone',
-
-                    select: function(args) {
-                      $.ajax({
-                        url: createURL('listZones'),
-                        success: function(json) {
-                          var zones = $.grep(json.listzonesresponse.zone, function(zone) {
-                            return (zone.networktype == 'Advanced' && zone.securitygroupsenabled	!= true); //Isolated networks can only be created in Advanced SG-disabled zone (but not in Basic zone nor Advanced SG-enabled zone)
-                          });
-
-                          args.response.success({
-                            data: $.map(zones, function(zone) {
-                              return {
-                                id: zone.id,
-                                description: zone.name
-                              };
-                            })
-                          });
-                        }
-                      });
+                    if (item.vpnenabled) { //2. Once VPN is enabled, hide StaticNat/PortForwarding/LoadBalancer.
+                        disallowedActions.push('enableStaticNAT');
                     }
-                  },
-                  networkOfferingId: {
-                    label: 'label.network.offering',
-                    validation: { required: true },
-                    dependsOn: 'zoneId',
-                    docID: 'helpGuestNetworkNetworkOffering',
-                    select: function(args) {
-                      $.ajax({
-                        url: createURL('listVPCs'),
+
+                    //3. Once a PortForwarding rule is added, hide StaticNat/VPN/LoadBalancer.
+                    $.ajax({
+                        url: createURL('listPortForwardingRules'),
                         data: {
-                          listAll: true
+                            ipaddressid: item.id,
+                            listAll: true
                         },
+                        dataType: 'json',
+                        async: false,
                         success: function(json) {
-                          var items = json.listvpcsresponse.vpc;
-                          var baseUrl = 'listNetworkOfferings&zoneid=' + args.zoneId;
-                          var listUrl;
-                          var data = {
-                            guestiptype: 'Isolated',
-                            supportedServices: 'SourceNat',
-                            state: 'Enabled',
-                          };
-                          
-                          if(items != null && items.length > 0) 
-                            listUrl = baseUrl;
-                          else
-                            listUrl = baseUrl + '&forVpc=false';
-
-                          if (args.context.vpc) {
-                            data.forVpc = true;
-                          }
-                          
-                          $.ajax({
-                            url: createURL(listUrl),
-                            data: data,
-                            success: function(json) {
-                              networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
-                              args.$select.change(function() {
-                                var $vlan = args.$select.closest('form').find('[rel=vlan]');
-                                var networkOffering = $.grep(
-                                  networkOfferingObjs, function(netoffer) {
-                                    return netoffer.id == args.$select.val();
-                                  }
-                                )[0];
-
-                                if (networkOffering.specifyvlan) {
-                                  $vlan.css('display', 'inline-block');
-                                } else {
-                                  $vlan.hide();
-                                }
-                              });
-                              
-                              args.response.success({
-                                data: $.map(networkOfferingObjs, function(zone) {
-                                  return {
-                                    id: zone.id,
-                                    description: zone.name
-                                  };
-                                })
-                              });
+                            var rules = json.listportforwardingrulesresponse.portforwardingrule;
+                            if (rules != null && rules.length > 0) {
+                                disallowedActions.push('enableVPN');
+                                disallowedActions.push('enableStaticNAT');
                             }
-                          });                            
-                        }
-                      });
-                    }
-                  },
-
-                  vlan: {
-                    label: 'VLAN',
-                    validation: { required: true },
-                    isHidden: true
-                  },
-
-                  vpcid: {
-                    label: 'label.vpc',
-                    dependsOn: 'networkOfferingId',
-                    select: function(args) {
-                      var networkOfferingObj;
-                      var $form = args.$select.closest('form');
-                      var data = {
-                        listAll: true,
-												details: 'min'
-                      };
-
-                      if (args.context.vpc) {
-                        data.id = args.context.vpc[0].id;
-                      }
-                      
-                      $(networkOfferingObjs).each(function(key, value) {
-                        if(value.id == args.networkOfferingId) {
-                          networkOfferingObj = value;
-                          return false; //break each loop
                         }
-                      });
-                      
-                      if(networkOfferingObj.forvpc == true) {
-                        args.$select.closest('.form-item').css('display', 'inline-block');
-                        $.ajax({
-                          url: createURL('listVPCs'),
-                          data: data,
-                          success: function(json) {
-                            var items = json.listvpcsresponse.vpc;
-                            var data;
-                            if(items != null && items.length > 0) {
-                              data = $.map(items, function(item) {
-                                return {
-                                  id: item.id,
-                                  description: item.name
-                                }
-                              });
-                            }
-                            args.response.success({ data: data });
-                          }
-                        });
-                        $form.find('.form-item[rel=networkDomain]').hide();
-                      }
-                      else {
-                        args.$select.closest('.form-item').hide();
-                        $form.find('.form-item[rel=networkDomain]').show();
-                        args.response.success({ data: null });
-                      }
-                    }
-                  },
-
-                  guestGateway: { label: 'label.guest.gateway', docID: 'helpGuestNetworkGateway' },
-                  guestNetmask: { label: 'label.guest.netmask', docID: 'helpGuestNetworkNetmask' },
-                  networkDomain: { label: 'label.network.domain' }
-                }
-              },
-              action: function(args) {
-                var dataObj = {
-                  zoneId: args.data.zoneId,
-                  name: args.data.name,
-                  displayText: args.data.displayText,
-                  networkOfferingId: args.data.networkOfferingId
-                };		
-		
-                if(args.data.guestGateway != null && args.data.guestGateway.length > 0) {                  
-                  $.extend(dataObj, {
-                    gateway: args.data.guestGateway
-                  });
-                }								
-                if(args.data.guestNetmask != null && args.data.guestNetmask.length > 0) {                  
-                  $.extend(dataObj, {
-                    netmask: args.data.guestNetmask
-                  });									
-                }								
-                if(args.$form.find('.form-item[rel=vpcid]').css("display") != "none") {                 
-                  $.extend(dataObj, {
-                    vpcid: args.data.vpcid
-                  });
-                }
-
-                if (args.$form.find('.form-item[rel=vlan]').css('display') != 'none') {
-                  $.extend(dataObj, { vlan: args.data.vlan });
-                }
-
-                if(args.data.networkDomain != null && args.data.networkDomain.length > 0 && args.$form.find('.form-item[rel=vpcid]').css("display") == "none") {
-                  $.extend(dataObj, {
-                    networkDomain: args.data.networkDomain
-                  });                
-                }
-
-                $.ajax({
-                  url: createURL('createNetwork'),
-									data: dataObj,
-                  success: function(json) {
-                    args.response.success({
-                      data: json.createnetworkresponse.network
                     });
-                  },
-                  error: function(json) {
-                    args.response.error(parseXMLHttpResponse(json));
-                  }
-                });
-              },
-              messages: {
-                notification: function() { return 'Add Isolated Guest Network'; }
-              }
-            },
-            
-            rootAdminAddGuestNetwork: $.extend( {}, addGuestNetworkDialog.def, {isHeader: true} )
-            
-          },
-          id: 'networks',
-          fields: {
-            name: { label: 'label.name' },
-            account: { label: 'label.account' },            
-            type: { label: 'label.type' },            
-            cidr: { label: 'label.cidr' },
-            ip6cidr: { label: 'IPv6 CIDR' }
-          },
-          
-					advSearchFields: {					 
-						zoneid: { 
-						  label: 'Zone',							
-              select: function(args) {							  					
-								$.ajax({
-									url: createURL('listZones'),
-									data: {
-									  listAll: true
-									},
-									success: function(json) {									  
-										var zones = json.listzonesresponse.zone ? json.listzonesresponse.zone : [];
-
-										args.response.success({
-											data: $.map(zones, function(zone) {
-												return {
-													id: zone.id,
-													description: zone.name
-												};
-											})
-										});
-									}
-								});
-							}						
-						},	
-            						
-						domainid: {					
-							label: 'Domain',					
-							select: function(args) {
-								if(isAdmin() || isDomainAdmin()) {
-									$.ajax({
-										url: createURL('listDomains'),
-										data: { 
-											listAll: true,
-											details: 'min'
-										},
-										success: function(json) {
-											var array1 = [{id: '', description: ''}];
-											var domains = json.listdomainsresponse.domain;
-											if(domains != null && domains.length > 0) {
-												for(var i = 0; i < domains.length; i++) {
-													array1.push({id: domains[i].id, description: domains[i].path});
-												}
-											}
-											args.response.success({
-												data: array1
-											});
-										}
-									});
-								}
-								else {
-									args.response.success({
-										data: null
-									});
-								}
-							},
-							isHidden: function(args) {
-								if(isAdmin() || isDomainAdmin())
-									return false;
-								else
-									return true;
-							}
-						},		
-						
-						account: { 
-							label: 'Account',
-							isHidden: function(args) {
-								if(isAdmin() || isDomainAdmin())
-									return false;
-								else
-									return true;
-							}			
-						},						
-						tagKey: { label: 'Tag Key' },
-						tagValue: { label: 'Tag Value' }						
-					},
-					
-					dataProvider: function(args) {
-            var data = {};
-						listViewDataProvider(args, data);		
-						
-            $.ajax({
-              url: createURL('listNetworks'),
-              data: data,			
-              async: false,
-              success: function(data) {
-                args.response.success({
-                  data: data.listnetworksresponse.network
-                });
-              },
-              error: function(data) {
-                args.response.error(parseXMLHttpResponse(data));
-              }
-            });
-          },
-
-          detailView: {
-            name: 'Guest network details',
-            viewAll: {
-              path: 'network.ipAddresses',
-              label: 'label.menu.ipaddresses',
-              preFilter: function(args) {
-                if (args.context.networks[0].state == 'Destroyed')
-                  return false;
-
-                return true;
-              }
-            },
-            actions: {
-              edit: {
-                label: 'label.edit',
-                messages: {
-                  notification: function(args) {
-                    return 'label.edit.network.details';
-                  }
-                },
-                action: function(args) {
-								  var data = {
-									  id: args.context.networks[0].id,		
-									  name: args.data.name,
-										displaytext: args.data.displaytext
-									};
-								  
-                  //args.data.networkdomain is null when networkdomain field is hidden
-                  if(args.data.networkdomain != null && args.data.networkdomain != args.context.networks[0].networkdomain) {
-									  $.extend(data, {
-										  networkdomain: args.data.networkdomain
-										});
-									} 
-                  
-                  var oldcidr;
-                  $.ajax({
-                    url: createURL("listNetworks&id=" + args.context.networks[0].id ),
-                    dataType: "json",
-                    async: false,
-                    success: function(json) {
-                      oldcidr = json.listnetworksresponse.network[0].cidr;
-                      
-                    }
-                  });
-
 
-                  if(args.data.cidr !="" && args.data.cidr != oldcidr ){
-                    $.extend(data, {
-                      guestvmcidr: args.data.cidr
-                    });
-                  }
-
-                  //args.data.networkofferingid is null when networkofferingid field is hidden
-                  if(args.data.networkofferingid != null && args.data.networkofferingid != args.context.networks[0].networkofferingid) {
-									  $.extend(data, {
-										  networkofferingid: args.data.networkofferingid
-										});
-
-                    if(args.context.networks[0].type == "Isolated") { //Isolated network
-                      cloudStack.dialog.confirm({
-                        message: 'Do you want to keep the current guest network CIDR unchanged?',
-                        action: function() { //"Yes"	button is clicked                          
-													$.extend(data, {
-													  changecidr: false
-													});
-													
-                          $.ajax({
-                            url: createURL('updateNetwork'),
-                            data: data,
-                            success: function(json) {
-                              var jid = json.updatenetworkresponse.jobid;
-                              args.response.success(
-                                {_custom:
-                                 {jobId: jid,
-                                  getUpdatedItem: function(json) {
-                                    var item = json.queryasyncjobresultresponse.jobresult.network;
-                                    return {data: item};
-                                  }
-                                 }
-                                }
-                              );
-                            }
-                          });
+                    //4. Once a LoadBalancer rule is added, hide StaticNat/VPN/PortForwarding.
+                    $.ajax({
+                        url: createURL('listLoadBalancerRules'),
+                        data: {
+                            publicipid: item.id,
+                            listAll: true
                         },
-                        cancelAction: function() { //"Cancel" button is clicked                         
-													$.extend(data, {
-													  changecidr: true
-													});
-													
-                          $.ajax({
-                            url: createURL('updateNetwork'),
-                            data: data,
-                            success: function(json) {
-                              var jid = json.updatenetworkresponse.jobid;
-                              args.response.success(
-                                {_custom:
-                                 {jobId: jid,
-                                  getUpdatedItem: function(json) {
-                                    var item = json.queryasyncjobresultresponse.jobresult.network;
-                                    return {data: item};
-                                  }
-                                 }
-                                }
-                              );
+                        dataType: 'json',
+                        async: false,
+                        success: function(json) {
+                            var rules = json.listloadbalancerrulesresponse.loadbalancerrule;
+                            if (rules != null && rules.length > 0) {
+                                disallowedActions.push('enableVPN');
+                                disallowedActions.push('enableStaticNAT');
                             }
-                          });
-                        }
-                      });
-                      return;
-                    }
-                  }
-
-                  $.ajax({
-                    url: createURL('updateNetwork'),
-                    data: data,
-                    success: function(json) {
-                      var jid = json.updatenetworkresponse.jobid;
-                      args.response.success(
-                        {_custom:
-                         {jobId: jid,
-                          getUpdatedItem: function(json) {
-                            var item = json.queryasyncjobresultresponse.jobresult.network;
-                            return {data: item};
-                          }
-                         }
-                        }
-                      );
-                    }
-                  });
-                },
-                notification: {
-                  poll: pollAsyncJobResult
-                }
-              },
-
-              'restart': {
-                label: 'label.restart.network',
-                createForm: {
-                  title: 'label.restart.network',
-                  desc: 'message.restart.network',
-                  preFilter: function(args) {									  
-										var zoneObj;
-										$.ajax({
-										  url: createURL("listZones&id=" + args.context.networks[0].zoneid),
-											dataType: "json",
-											async: false,
-											success: function(json){											  
-											  zoneObj = json.listzonesresponse.zone[0];												
-											}
-										});
-                                        args.$form.find('.form-item[rel=cleanup]').find('input').attr('checked', 'checked'); //checked
-                                        args.$form.find('.form-item[rel=cleanup]').css('display', 'inline-block'); //shown
-									},
-									fields: {
-                    cleanup: {
-                      label: 'label.clean.up',
-                      isBoolean: true
-                    }
-                  }
-                },
-                messages: {
-                  notification: function(args) {
-                    return 'label.restart.network';
-                  }
-                },
-                action: function(args) {
-                  var array1 = [];
-                  array1.push("&cleanup=" + (args.data.cleanup == "on"));
-                  $.ajax({
-                    url: createURL("restartNetwork&id=" + args.context.networks[0].id + array1.join("")),
-                    dataType: "json",
-                    async: true,
-                    success: function(json) {
-                      var jid = json.restartnetworkresponse.jobid;
-                      args.response.success(
-                        {_custom:
-                         {jobId: jid,
-                          getUpdatedItem: function(json) {
-                            return json.queryasyncjobresultresponse.jobresult.network;
-                          }
-                         }
                         }
-                      );
-                    }
-                  });
-                },
-                notification: {
-                  poll: pollAsyncJobResult
-                }
-              },
-
-              remove: {
-                label: 'label.action.delete.network',
-                messages: {
-                  confirm: function(args) {
-                    return 'message.action.delete.network';
-                  },
-                  notification: function(args) {
-                    return 'label.action.delete.network';
-                  }
-                },
-                action: function(args) {
-                  $.ajax({
-                    url: createURL("deleteNetwork&id=" + args.context.networks[0].id),
-                    dataType: "json",
-                    async: true,
-                    success: function(json) {
-                      var jid = json.deletenetworkresponse.jobid;
-                      args.response.success(
-                        {_custom:
-                         {jobId: jid
-                         }
-                        }
-                      );
-                    }
-                  });
-                },
-                notification: {
-                  poll: pollAsyncJobResult
+                    });
                 }
-              }
-            },
-
-            tabFilter: function(args) {
-              var networkOfferingHavingELB = false;
-              var hasNetworkACL = false;
-              var hasSRXFirewall = false;
-              var isVPC = false;
-              var isAdvancedSGZone = false;
-              var hiddenTabs = [];
-              var isSharedNetwork;
-
-              // Get network offering data
-              $.ajax({
-                url: createURL("listNetworkOfferings&id=" + args.context.networks[0].networkofferingid),
-                dataType: "json",
-                async: false,
-                success: function(json) {
-                  var networkoffering = json.listnetworkofferingsresponse.networkoffering[0];
-
-                  if (networkoffering.forvpc) {
-                    isVPC = true;
-                  }
-
-                  if (networkoffering.guestiptype == 'Shared') {
-                    isSharedNetwork = true;
-                  }
+            }
 
-                  $(networkoffering.service).each(function(){
-                    var thisService = this;
+            if (item.isstaticnat) {
+                disallowedActions.push('enableStaticNAT');
+            } else {
+                disallowedActions.push('disableStaticNAT');
+            }
 
-                    if (thisService.name == 'NetworkACL') {
-                      hasNetworkACL = true;
-                    } else if (thisService.name == "Lb") {
-                      $(thisService.capability).each(function(){
-                        if (this.name == "ElasticLb" && this.value == "true") {
-                          networkOfferingHavingELB = true;
-                        }
-                      });
-                    }
+            if (item.networkOfferingHavingVpnService == true) {
+                if (item.vpnenabled) {
+                    disallowedActions.push('enableVPN');
+                } else {
+                    disallowedActions.push('disableVPN');
+                }
+            } else { //item.networkOfferingHavingVpnService == false
+                disallowedActions.push('disableVPN');
+                disallowedActions.push('enableVPN');
+            }
 
-                    if (thisService.name == 'Firewall') {
-                      $(thisService.provider).each(function() {
-                        if (this.name == 'JuniperSRX') {
-                          hasSRXFirewall = true;
+            if (item.issourcenat) {
+                disallowedActions.push('enableStaticNAT');
+                disallowedActions.push('disableStaticNAT');
+                disallowedActions.push('remove');
+            }
 
-                          return false;
-                        }
+            allowedActions = $.grep(allowedActions, function(item) {
+                return $.inArray(item, disallowedActions) == -1;
+            });
 
-                        return true;
-                      });
-                    }
-                  });
-                }
-              });
+            return allowedActions;
+        },
 
-              // Get zone data
-              $.ajax({
-                url: createURL('listZones'),
-                data: {
-                  id: args.context.networks[0].zoneid
-                },
-                async: false,
-                success: function(json) {
-                  var zone = json.listzonesresponse.zone[0];
+        securityGroups: function(args) {
+            var allowedActions = [];
+            var isSecurityGroupOwner = isAdmin() || isDomainAdmin() ||
+                args.context.item.account == args.context.users[0].account;
 
-                  isAdvancedSGZone = zone.securitygroupsenabled;
-                }
-              });
+            if (isSecurityGroupOwner &&
+                args.context.item.state != 'Destroyed' &&
+                args.context.item.name != 'default') {
+                allowedActions.push('remove');
+            }
 
-              if (!networkOfferingHavingELB) {
-                hiddenTabs.push("addloadBalancer");
-              }
+            return allowedActions;
+        }
+    };
 
-              if (isVPC || isAdvancedSGZone || isSharedNetwork) {
-                 hiddenTabs.push('egressRules');
-               }
-              
-              return hiddenTabs;
-            },
+    var networkOfferingObjs = [];
+    var advZoneObjs;
 
-            isMaximized: true,
-            tabs: {
-              details: {
-                title: 'label.details',
-                preFilter: function(args) {
-                  var hiddenFields = [];
-                  var zone;
+    cloudStack.sections.network = {
+        title: 'label.network',
+        id: 'network',
+        sectionSelect: {
+            preFilter: function(args) {
+                var sectionsToShow = ['networks'];
 
-                  $.ajax({
+                $.ajax({
                     url: createURL('listZones'),
                     data: {
-                      id: args.context.networks[0].zoneid
+                        networktype: 'Advanced'
                     },
                     async: false,
                     success: function(json) {
-                      zone = json.listzonesresponse.zone[0];
-                    }
-                  });
-
-                  if(zone.networktype == "Basic") {
-                    hiddenFields.push("account");
-                    hiddenFields.push("gateway");
-                    hiddenFields.push("vlan");
-                    hiddenFields.push("cidr");
-                    //hiddenFields.push("netmask");
-                  }
-
-                  if(args.context.networks[0].type == "Isolated") {
-                    hiddenFields.push("networkofferingdisplaytext");
-                    hiddenFields.push("networkdomaintext");
-                    hiddenFields.push("gateway");
-                    hiddenFields.push("networkofferingname");
-                    //hiddenFields.push("netmask");
-                  }
-                  else { //selectedGuestNetworkObj.type == "Shared"
-                    hiddenFields.push("networkofferingid");
-                    hiddenFields.push("networkdomain");
-                  }
-									
-									if(!isAdmin()) {
-									  hiddenFields.push("vlan");
-									}
-									
-                  return hiddenFields;
-                },						
-																
-                fields: [
-                  {
-                    name: {
-                      label: 'label.name',
-                      isEditable: true
+                        advZoneObjs = json.listzonesresponse.zone;
+                        if (advZoneObjs != null && advZoneObjs.length > 0) {
+                            sectionsToShow.push('vpc');
+                            sectionsToShow.push('vpnCustomerGateway');
+                        }
                     }
-                  },
-                  {
-                    id: { label: 'label.id' },
-                    zonename: { label: 'label.zone' },
-                    displaytext: {
-                      label: 'label.description',
-                      isEditable: true
-                    },
-                    type: {
-                      label: 'label.type'
-                    },
-                    state: {
-                      label: 'label.state'
-                    },
+                });
 
-                    ispersistent:{
-                      label:'Persistent ',
-                      converter:cloudStack.converters.toBooleanText
-
-                     },
-                    restartrequired: {
-                      label: 'label.restart.required',
-                      converter: function(booleanValue) {
-                        if(booleanValue == true)
-                          return "<font color='red'>Yes</font>";
-                        else if(booleanValue == false)
-                          return "No";
-                      }
+                $.ajax({
+                    url: createURL('listNetworks', {
+                        ignoreProject: true
+                    }),
+                    data: {
+                        supportedServices: 'SecurityGroup',
+                        listAll: true,
+                        details: 'min'
                     },
-                    vlan: { label: 'label.vlan.id' },               
-
-                    networkofferingid: {
-                      label: 'label.network.offering',
-                      isEditable: true,
-                      select: function(args){
-											  if (args.context.networks[0].type == 'Shared') { //Shared network is not allowed to upgrade to a different network offering
-												  args.response.success({ data: [] });
-                          return;
-												}
-											
-                        if (args.context.networks[0].state == 'Destroyed') {
-                          args.response.success({ data: [] });
-                          return;
+                    async: false,
+                    success: function(json) {
+                        if (json.listnetworksresponse.network != null && json.listnetworksresponse.network.length > 0) {
+                            sectionsToShow.push('securityGroups');
                         }
+                    }
+                });
 
-                        var items = [];
-                        $.ajax({
-                          url: createURL("listNetworkOfferings&networkid=" + args.context.networks[0].id),
-                          dataType: "json",
-                          async: false,
-                          success: function(json) {
-                            var networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
-                            $(networkOfferingObjs).each(function() {
-                              items.push({id: this.id, description: this.displaytext});
-                            });
-                          }
-                        });
-                        $.ajax({
-                          url: createURL("listNetworkOfferings&id=" + args.context.networks[0].networkofferingid),  //include currently selected network offeirng to dropdown
-                          dataType: "json",
-                          async: false,
-                          success: function(json) {
-                            var networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
-                            $(networkOfferingObjs).each(function() {
-                              items.push({id: this.id, description: this.displaytext});
-                            });
-                          }
-                        });
-                        args.response.success({data: items});
-                      }
-                    },
+                return sectionsToShow;
+            },
 
-                    gateway: { label: 'label.gateway' },
+            label: 'label.select-view'
+        },
+        sections: {
+            networks: {
+                id: 'networks',
+                type: 'select',
+                title: 'label.guest.networks',
+                listView: {
+                    actions: {
+                        add: {
+                            label: 'Add Isolated Network',
+
+                            preFilter: function(args) {
+                                if (advZoneObjs != null && advZoneObjs.length > 0) {
+                                    for (var i = 0; i < advZoneObjs.length; i++) {
+                                        if (advZoneObjs[i].securitygroupsenabled != true) { //'Add Isolated Guest Network with SourceNat' is only supported in Advanced SG-disabled zone
+                                            return true;
+                                        }
+                                    }
+                                    return false;
+                                } else {
+                                    return false;
+                                }
+                            },
 
-                    //netmask: { label: 'label.netmask' },
-                    cidr: { label: 'label.cidr', isEditable:true },
+                            createForm: {
+                                title: 'Add Isolated Guest Network with SourceNat',
+                                fields: {
+                                    name: {
+                                        label: 'label.name',
+                                        validation: {
+                                            required: true
+                                        },
+                                        docID: 'helpGuestNetworkName'
+                                    },
+                                    displayText: {
+                                        label: 'label.display.text',
+                                        validation: {
+                                            required: true
+                                        },
+                                        docID: 'helpGuestNetworkDisplayText'
+                                    },
+                                    zoneId: {
+                                        label: 'label.zone',
+                                        validation: {
+                                            required: true
+                                        },
+                                        docID: 'helpGuestNetworkZone',
+
+                                        select: function(args) {
+                                            $.ajax({
+                                                url: createURL('listZones'),
+                                                success: function(json) {
+                                                    var zones = $.grep(json.listzonesresponse.zone, function(zone) {
+                                                        return (zone.networktype == 'Advanced' && zone.securitygroupsenabled != true); //Isolated networks can only be created in Advanced SG-disabled zone (but not in Basic zone nor Advanced SG-enabled zone)
+                                                    });
+
+                                                    args.response.success({
+                                                        data: $.map(zones, function(zone) {
+                                                            return {
+                                                                id: zone.id,
+                                                                description: zone.name
+                                                            };
+                                                        })
+                                                    });
+                                                }
+                                            });
+                                        }
+                                    },
+                                    networkOfferingId: {
+                                        label: 'label.network.offering',
+                                        validation: {
+                                            required: true
+                                        },
+                                        dependsOn: 'zoneId',
+                                        docID: 'helpGuestNetworkNetworkOffering',
+                                        select: function(args) {
+                                            $.ajax({
+                                                url: createURL('listVPCs'),
+                                                data: {
+                                                    listAll: true
+                                                },
+                                                success: function(json) {
+                                                    var items = json.listvpcsresponse.vpc;
+                                                    var baseUrl = 'listNetworkOfferings&zoneid=' + args.zoneId;
+                                                    var listUrl;
+                                                    var data = {
+                                                        guestiptype: 'Isolated',
+                                                        supportedServices: 'SourceNat',
+                                                        state: 'Enabled',
+                                                    };
+
+                                                    if (items != null && items.length > 0)
+                                                        listUrl = baseUrl;
+                                                    else
+                                                        listUrl = baseUrl + '&forVpc=false';
+
+                                                    if (args.context.vpc) {
+                                                        data.forVpc = true;
+                                                    }
+
+                                                    $.ajax({
+                                                        url: createURL(listUrl),
+                                                        data: data,
+                                                        success: function(json) {
+                                                            networkOfferingObjs = json.listnetworkofferingsresponse.networkoffering;
+                                                            args.$select.change(function() {
+                                                                var $vlan = args.$select.closest('form').find('[rel=vlan]');
+                                                                var networkOffering = $.grep(
+                                                                    networkOfferingObjs, function(netoffer) {
+                                                                        return netoffer.id == args.$select.val();
+                                                                    }
+                                                                )[0];
+
+                                                                if (networkOffering.specifyvlan) {
+                                                                    $vlan.css('display', 'inline-block');
+                                                                } else {
+                                                                    $vlan.hide();
+                                                                }
+                                                            });
+
+                                                            args.response.success({
+                                                                data: $.map(networkOfferingObjs, function(zone) {
+                                                                    return {
+                                                                        id: zone.id,
+                                                                        description: zone.name
+                                                                    };
+                                                                })
+                                                            });
+                                                        }
+                                                    });
+                                                }
+                                            });
+                                        }
+                                    },
 
-                    networkcidr:{label:'Network CIDR'},
+                                    vlan: {
+                                        label: 'VLAN',
+                                        validation: {
+                                            required: true
+                                        },
+                                        isHidden: true
+                                    },
 
-                    ip6gateway: { label: 'IPv6 Gateway' }, 
+                                    vpcid: {
+                                        label: 'label.vpc',
+                                        dependsOn: 'networkOfferingId',
+                                        select: function(args) {
+                                            var networkOfferingObj;
+                                            var $form = args.$select.closest('form');
+                                            var data = {
+                                                listAll: true,
+                                                details: 'min'
+                                            };
+
+                                            if (args.context.vpc) {
+                                                data.id = args.context.vpc[0].id;
+                                            }
 
-                    ip6cidr: { label: 'IPv6 CIDR' }, 
+                                            $(networkOfferingObjs).each(function(key, value) {
+                                                if (value.id == args.networkOfferingId) {
+                                                    networkOfferingObj = value;
+                                                    return false; //break each loop
+                                                }
+                                            });
 
+                                            if (networkOfferingObj.forvpc == true) {
+                                                args.$select.closest('.form-item').css('display', 'inline-block');
+                                                $.ajax({
+                                                    url: createURL('listVPCs'),
+                                                    data: data,
+                                                    success: function(json) {
+                                                        var items = json.listvpcsresponse.vpc;
+                                                        var data;
+                                                        if (items != null && items.length > 0) {
+                                                            data = $.map(items, function(item) {
+                                                                return {
+                                                                    id: item.id,
+                                                                    description: item.name
+                                                                }
+                                                            });
+                                                        }
+                                                        args.response.success({
+                                                            data: data
+                                                        });
+                                                    }
+                                                });
+                                                $form.find('.form-item[rel=networkDomain]').hide();
+                                            } else {
+                                                args.$select.closest('.form-item').hide();
+                                                $form.find('.form-item[rel=networkDomain]').show();
+                                                args.response.success({
+                                                    data: null
+                                                });
+                                            }
+                                        }
+                                    },
 
-                    reservediprange:{label:'Reserved IP Range'},
+                                    guestGateway: {
+                                        label: 'label.guest.gateway',
+                                        docID: 'helpGuestNetworkGateway'
+                                    },
+                                    guestNetmask: {
+                                        label: 'label.guest.netmask',
+                                        docID: 'helpGuestNetworkNetmask'
+                                    },
+                                    networkDomain: {
+                                        label: 'label.network.domain'
+                                    }
+                                }
+                            },
+                            action: function(args) {
+                                var dataObj = {
+                                    zoneId: args.data.zoneId,
+                                    name: args.data.name,
+                                    displayText: args.data.displayText,
+                                    networkOfferingId: args.data.networkOfferingId
+                                };
+
+                                if (args.data.guestGateway != null && args.data.guestGateway.length > 0) {
+                                    $.extend(dataObj, {
+                                        gateway: args.data.guestGateway
+                                    });
+                                }
+                                if (args.data.guestNetmask != null && args.data.guestNetmask.length > 0) {
+                                    $.extend(dataObj, {
+                                        netmask: args.data.guestNetmask
+                                    });
+                                }
+                                if (args.$form.find('.form-item[rel=vpcid]').css("display") != "none") {
+                                    $.extend(dataObj, {
+                                        vpcid: args.data.vpcid
+                                    });
+                                }
 
+                                if (args.$form.find('.form-item[rel=vlan]').css('display') != 'none') {
+                                    $.extend(dataObj, {
+                                        vlan: args.data.vlan
+                                    });
+                                }
 
-                    networkdomaintext: {
-                      label: 'label.network.domain.text'
-                    },
-                    networkdomain: {
-                      label: 'label.network.domain',
-                      isEditable: true
-                    },
-
-                    domain: { label: 'label.domain' },
-                    account: { label: 'label.account' },
-
-                    vpcid: {
-                      label: 'label.vpc.id',
-                      converter: function(args) {
-                        if(args != null)
-												  return args;
-												else
-												  return 'N/A';
-                      }											
-										}
-                  }
-                ],
-
-                tags: cloudStack.api.tags({ resourceType: 'Network', contextId: 'networks' }),
-
-
-                dataProvider: function(args) {
-                  $.ajax({
-                    url: createURL("listNetworks&id=" + args.context.networks[0].id + "&listAll=true"), //pass "&listAll=true" to "listNetworks&id=xxxxxxxx" for now before API gets fixed.
-                    data: { listAll: true },
-										dataType: "json",
-										async: true,
-										success: function(json) {								  
-											var jsonObj = json.listnetworksresponse.network[0];  
-                      addExtraPropertiesToGuestNetworkObject(jsonObj);												
-											args.response.success(
-												{
-													actionFilter: cloudStack.actionFilter.guestNetwork,
-													data: jsonObj
-												}
-											);		
-										}
-									});			
-                }
-              },
-                 
-              egressRules: {
-                title: 'label.egress.rules',
-                custom: function(args) {
-                  var context = args.context;
-
-                  return $('<div>').multiEdit({
-                    context: context,
-                    noSelect: true,
-                    noHeaderActionsColumn: true,
-                    fields: {
-                      'cidrlist': { edit: true, label: 'label.cidr.list', isOptional: true },
-                      'protocol': {
-                        label: 'label.protocol',
-                        select: function(args) {
-                          args.$select.change(function() {
-                            var $inputs = args.$form.find('th, td');
-                            var $icmpFields = $inputs.filter(function() {
-                              var name = $(this).attr('rel');
-
-                              return $.inArray(name, [
-                                'icmptype',
-                                'icmpcode'
-                              ]) > -1;
-                            });
-                            var $otherFields = $inputs.filter(function() {
-                              var name = $(this).attr('rel');
-
-                              return name != 'cidrlist' &&
-                                name != 'icmptype' &&
-                                name != 'icmpcode' &&
-                                name != 'protocol' &&
-                                name != 'add-rule';
-                            });
-
-                            if ($(this).val() == 'icmp') {
-                              $icmpFields.show();
-                              $otherFields.hide();
-                            } else if ($(this).val() == 'all') {
-                              $icmpFields.hide();
-                              $otherFields.hide();
-                            } else {
-                              $icmpFields.hide();
-                              $otherFields.show();
-                            }
-                          });
-                       
-                            args.response.success({
-                            data: [
-                              { name: 'tcp', description: 'TCP' },
-                              { name: 'udp', description: 'UDP' },
-                              { name: 'icmp', description: 'ICMP' },
-                              { name: 'all', description: 'All' }
-                            ]
-                          });
-                        }
-                      },
-                      'startport': { edit: true, label: 'label.start.port', isOptional: true },
-                      'endport': { edit: true, label: 'label.end.port', isOptional: true },
-                      'icmptype': { edit: true, label: 'ICMP.type', isHidden: true, isOptional: true },
-                      'icmpcode': { edit: true, label: 'ICMP.code', isHidden: true, isOptional: true },
-                      'add-rule': {
-                        label: 'label.add',
-                        addButton: true
-                      }
-                    },
-                    add: {
-                      label: 'label.add',
-                      action: function(args) {
-                        var data = {
-                          protocol: args.data.protocol,
-                          cidrlist: args.data.cidrlist,
-                          networkid: args.context.networks[0].id
-                        };
-
-                        if (args.data.icmptype && args.data.icmpcode) { // ICMP
-                          $.extend(data, {
-                            icmptype: args.data.icmptype,
-                            icmpcode: args.data.icmpcode
-                          });
-                        } else { // TCP/UDP
-                          $.extend(data, {
-                            startport: args.data.startport,
-                            endport: args.data.endport
-                          });
-                        }
+                                if (args.data.networkDomain != null && args.data.networkDomain.length > 0 && args.$form.find('.form-item[rel=vpcid]').css("display") == "none") {
+                                    $.extend(dataObj, {
+                                        networkDomain: args.data.networkDomain
+                                    });
+                                }
 
-                        $.ajax({
-                          url: createURL('createEgressFirewallRule'),
-                          data: data,
-                          dataType: 'json',
-                          async: true,
-                          success: function(json) {
-                            var jobId = json.createegressfirewallruleresponse.jobid;
-
-                            args.response.success({
-                              _custom: {
-                                jobId: jobId
-                              },
-                              notification: {
-                                label: 'label.add.egress.rule',
-                                poll: pollAsyncJobResult
-                              }
-                            });
-                          },
-                          error: function(json) {
-                            args.response.error(parseXMLHttpResponse(json));
-                          }
-                        });
-                      }
-                    },
-                    actions: {
-                      destroy: {
-                        label: 'label.remove.rule',
-                        action: function(args) {
-                          $.ajax({
-                            url: createURL('deleteEgressFirewallRule'),
-                            data: {
-                              id: args.context.multiRule[0].id
+                                $.ajax({
+                                    url: createURL('createNetwork'),
+                                    data: dataObj,
+                                    success: function(json) {
+                                        args.response.success({
+                                            data: json.createnetworkresponse.network
+                                        });
+                                    },
+                                    error: function(json) {
+                                        args.response.error(parseXMLHttpResponse(json));
+                                    }
+                                });
                             },
-                            dataType: 'json',
-                            async: true,
-                            success: function(data) {
-                              var jobID = data.deleteegressfirewallruleresponse.jobid;
-
-                              args.response.success({
-                                _custom: {
-                                  jobId: jobID
-                                },
-                                notification: {
-                                  label: 'label.remove.egress.rule',
-                                  poll: pollAsyncJobResult
+                            messages: {
+                                notification: function() {
+                                    return 'Add Isolated Guest Network';
                                 }
-                              });
-                            },
-                            error: function(json) {
-                              args.response.error(parseXMLHttpResponse(json));
                             }
-                          });
-                        }
-                      }
-                    },
-                    ignoreEmptyFields: true,
-                    dataProvider: function(args) {
-                      $.ajax({
-                        url: createURL('listEgressFirewallRules'),
-                        data: {
-                          listAll: true,
-                          networkid: args.context.networks[0].id
                         },
-                        dataType: 'json',
-                        async: true,
-                        success: function(json) {
-                          var response = json.listegressfirewallrulesresponse.firewallrule ?
-                                json.listegressfirewallrulesresponse.firewallrule : [];
-
-                          args.response.success({
-                            data: $.map(response, function(rule) {
-                              if (rule.protocol == 'all') {
-                                $.extend(rule, {
-                                  startport: 'All',
-                                  endport: 'All'
-                                });
-                              } else if (rule.protocol == 'tcp' || rule.protocol == 'udp') {
-                                if (!rule.startport) {
-                                  rule.startport = ' ';
-                                }
 
-                                if (!rule.endport) {
-                                  rule.endport = ' ';
-                                }
-                              }
+                        rootAdminAddGuestNetwork: $.extend({}, addGuestNetworkDialog.def, {
+                            isHeader: true
+                        })
 
-                              return rule;
-                            })
-                          });
+                    },
+                    id: 'networks',
+                    fields: {
+                        name: {
+                            label: 'label.name'
+                        },
+                        account: {
+                            label: 'label.account'
+                        },
+                        type: {
+                            label: 'label.type'
+                        },
+                        cidr: {
+                            label: 'label.cidr'
+                        },
+                        ip6cidr: {
+                            label: 'IPv6 CIDR'
                         }
-                       });
-                    }
-                  });
-                }
-              },
-
-               addloadBalancer: { // EIP/ELB Basic zone: Add Load Balancer tab in network detailView
-                title: 'label.add.load.balancer',
-                custom: function(args) {
-                  var context = args.context;
-
-                  return $('<div>').addClass('loadBalancer').multiEdit(
-                    {
-                      context: context,
-                      listView: $.extend(true, {}, cloudStack.sections.instances, {
-                        listView: {
-                          filters: false,
-
-                          dataProvider: function(args) {
-                            var data = {
-                              page: args.page,
-                              pageSize: pageSize,
-                                                                                                                        domainid: g_domainid,
-                              account: g_account,
-                              networkid: args.context.networks[0].id,
-                              listAll: true
-                            };
+                    },
 
-                            $.ajax({
-                              url: createURL('listVirtualMachines'),
-                              data: data,
-                              dataType: 'json',
-                              async: true,
-                              success: function(data) {
-                                args.response.success({
-                                  data: $.grep(
-                                    data.listvirtualmachinesresponse.virtualmachine ?
-                                      data.listvirtualmachinesresponse.virtualmachine : [],
-                                    function(instance) {
-                                          var nonAutoScale=0;
-                                          if(instance.displayname == null)
-                                              nonAutoScale = 1;
-                                            else{
-                                          if( instance.displayname.match(/AutoScale-LB-/)==null)
-                                             nonAutoScale =1;
-                                          else {
-                                             if(instance.displayname.match(/AutoScale-LB-/).length)
-                                               nonAutoScale =0;
-                                             }
-                                          }
-                                      var isActiveState= $.inArray(instance.state, ['Destroyed','Expunging']) == -1;
-                                      return nonAutoScale && isActiveState;
+                    advSearchFields: {
+                        zoneid: {
+                            label: 'Zone',
+                            select: function(args) {
+                                $.ajax({
+                                    url: createURL('listZones'),
+                                    data: {
+                                        listAll: true
+                                    },
+                                    success: function(json) {
+                                        var zones = json.listzonesresponse.zone ? json.listzonesresponse.zone : [];
+
+                                        args.response.success({
+                                            data: $.map(zones, function(zone) {
+                                                return {
+                                                    id: zone.id,
+                                                    description: zone.name
+                                                };
+                                            })
+                                        });
                                     }
-                                  )
                                 });
-                               },
-                              error: function(data) {
-                                args.response.error(parseXMLHttpResponse(data));
-                              }
-                            });
-                          }
-                        }
-                      }),
-                      multipleAdd: true,
-                      fields: {
-                        'name': { edit: true, label: 'label.name' },
-                        'publicport': { edit: true, label: 'label.public.port' },
-                        'privateport': { edit: true, label: 'label.private.port' },
-                        'algorithm': {
-                          label: 'label.algorithm',
-                          select: function(args) {
-                            args.response.success({
-                              data: [
-                                { name: 'roundrobin', description: _l('label.round.robin') },
-                                { name: 'leastconn', description: _l('label.least.connections') },
-                                { name: 'source', description: _l('label.source') }
-                              ]
-                            });
-                          }
+                            }
+                        },
+
+                        domainid: {
+                            label: 'Domain',
+                            select: function(args) {
+                                if (isAdmin() || isDomainAdmin()) {
+                                    $.ajax({
+                                        url: createURL('listDomains'),
+                                        data: {
+                                            listAll: true,
+                                            details: 'min'
+                                        },
+                                        success: function(json) {
+                                            var array1 = [{
+                                                id: '',
+                                                description: ''
+                                            }];
+                                            var domains = json.listdomainsresponse.domain;
+                                            if (domains != null && domains.length > 0) {
+                                                for (var i = 0; i < domains.length; i++) {
+                                                    array1.push({
+                                                        id: domains[i].id,
+                                                        description: domains[i].path
+                                                    });
+                                                }
+                                            }
+                                            args.response.success({
+                                                data: array1
+                                            });
+                                        }
+                                    });
+                                } else {
+                                    args.response.success({
+                                        data: null
+                                    });
+                                }
+                            },
+                            isHidden: function(args) {
+                                if (isAdmin() || isDomainAdmin())
+                                    return false;
+                                else
+                                    return true;
+                            }
                         },
-                        'sticky': {
-                          label: 'label.stickiness',
-                          custom: {
-                            buttonLabel: 'label.configure',
-                            action: cloudStack.lbStickyPolicy.dialog()
-                          }
+
+                        account: {
+                            label: 'Account',
+                            isHidden: function(args) {
+                                if (isAdmin() || isDomainAdmin())
+                                    return false;
+                                else
+                                    return true;
+                            }
                         },
-                        'autoScale': {
-                          label: 'AutoScale',
-                          custom: {
-                            requireValidation: true,
-                            buttonLabel: 'label.configure',
-                            action: cloudStack.uiCustom.autoscaler(cloudStack.autoscaler)
-                          }
+                        tagKey: {
+                            label: 'Tag Key'
                         },
-                        'add-vm': {
-                          label: 'label.add.vms',
-                          addButton: true
+                        tagValue: {
+                            label: 'Tag Value'
                         }
-                      },
-
-                      add: {  //basic zone - elastic IP - Add Load Balancer tab - Add VMs button
-                        label: 'label.add.vms',
-                        action: function(args) {
-                            var data = {
-                            algorithm: args.data.algorithm,
-                            name: args.data.name,
-                            privateport: args.data.privateport,
-                            publicport: args.data.publicport,
-                                                                                                                openfirewall: false,
-                                                                                                                domainid: g_domainid,
-                                                                                                                account: g_account
-                          };
-
-                                                                                                        if('vpc' in args.context) { //from VPC section
-                                                                                                                if(args.data.tier == null) {                                                         
-                                                                                                                        args.response.error('Tier is required');
-                                                                                                                        return;
-                                                                                                                }
-                                                                                                                $.extend(data, {
-                                                                                                                        networkid: args.data.tier
-                                                         

<TRUNCATED>

Mime
View raw message