cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jessicaw...@apache.org
Subject [02/39] Format JS
Date Fri, 19 Jul 2013 17:01:15 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f766a9e5/ui/scripts/vpc.js
----------------------------------------------------------------------
diff --git a/ui/scripts/vpc.js b/ui/scripts/vpc.js
index 358237b..0b670dd 100644
--- a/ui/scripts/vpc.js
+++ b/ui/scripts/vpc.js
@@ -15,759 +15,883 @@
 // specific language governing permissions and limitations
 // under the License.
 (function($, cloudStack) {
-  var aclMultiEdit = {
-    noSelect: true,
-    fieldPreFilter: function(args) {
-      var context = args.context;
-      var hiddenFields = [];
-
-      if (context.networks) { // from tier detail view
-        hiddenFields.push('networkid');
-      }
-
-      return hiddenFields; // Returns fields to be hidden
-    },     
-    reorder: {
-      moveDrag: {
-        action: function(args) {
-          var rule = args.context.multiRule[0];
-          var index = args.targetIndex;
-
-          $.ajax({
-            url: createURL('updateNetworkACLItem'),
-            data: {
-              id: rule.id,
-              number: index + 1
-            },
-            success: function(json) {
-              var pollTimer = setInterval(function() {
-                pollAsyncJobResult({
-                  _custom: { jobId: json.createnetworkaclresponse.jobid },
-                  complete: function() {
-                    clearInterval(pollTimer);
-                    args.response.success();
-                  },
-                  error: function(errorMsg) {
-                    clearInterval(pollTimer);
-                    args.response.error(errorMsg);
-                  }
-                });
-              }, 1000);               
+    var aclMultiEdit = {
+        noSelect: true,
+        fieldPreFilter: function(args) {
+            var context = args.context;
+            var hiddenFields = [];
+
+            if (context.networks) { // from tier detail view
+                hiddenFields.push('networkid');
             }
-          });
-        }
-      }
-    },
-    fields: {
-
-       'number':{
-           label:'Rule Number',
-           edit:true,
-         isEditable: true
-
-       },
-
-      'cidrlist': { edit: true, label: 'label.cidr', isEditable: true },
-      action: {
-        label: 'Action',
-        isEditable: true,
-        select: function(args) {
-          args.response.success({
-            data: [
-              { name: 'Allow', description: 'Allow' },
-              { name: 'Deny', description: 'Deny' }
-            ]
-          });
-        }
-      },
-      'protocol': {
-        label: 'label.protocol',
-        isEditable: true,
-        select: function(args) {
-          var isEditDialog = args.type === 'createForm';
-          
-          args.$select.change(function() {
-            var $inputs, $icmpFields, $otherFields, $portFields, $protocolFields, $protocolinput;
-            
-            //
-            // Editing existing rules in createForm dialog
-            //
-            if (isEditDialog) {
-              $inputs = args.$form.find('.form-item');
-              $icmpFields = $inputs.filter(function() {
-                var name = $(this).attr('rel');
-
-                return $.inArray(name, [
-                  'icmptype',
-                  'icmpcode'
-                ]) > -1;
-              });
-              $otherFields = $inputs.filter(function() {
-                var name = $(this).attr('rel');
-
-                return name != 'protocolnumber' &&
-                  name != 'icmptype' &&
-                  name != 'icmpcode' &&
-                  name != 'cidrlist';
-              });
-              $portFields = $inputs.filter(function() {
-                var name = $(this).attr('rel');
-                return $.inArray(name, [
-                  'startport',
-                  'endport'
-                ]) > -1;
-              });
-              $protocolFields = $inputs.filter(function(){
-                var name = $(this).attr('rel');
-
-                return $.inArray(name,['protocolnumber']) > -1;
-              });
-
-              if ($(this).val() == 'protocolnumber' ){
-                $icmpFields.hide();
-                $portFields.show();
-                $protocolFields.show();
-              } else if ($(this).val() == 'icmp') {
-                $icmpFields.show();
-                $protocolFields.hide();
-                $portFields.hide();
-              } else {
-                $otherFields.show();
-                $icmpFields.hide();
-                $protocolFields.hide();
-                
-                if ($(this).val() == 'all') {
-                  $portFields.hide();
-                }
-              }              
-            } else {
-              //
-              // Add new form
-              //
-              $inputs = args.$form.find('input');
-              $icmpFields = $inputs.filter(function() {
-                var name = $(this).attr('name');
-
-                return $.inArray(name, [
-                  'icmptype',
-                  'icmpcode'
-                ]) > -1;
-              });
-              $otherFields = $inputs.filter(function() {
-                var name = $(this).attr('name');
-
-                return name != 'protocolnumber' &&
-                  name != 'icmptype' &&
-                  name != 'icmpcode' &&
-                  name != 'cidrlist' &&
-                  name != 'number';
-              });
-              $portFields = $inputs.filter(function() {
-                var name = $(this).attr('name');
-                return $.inArray(name, [
-                  'startport',
-                  'endport'
-                ]) > -1;
-              });
-
-              $protocolinput = args.$form.find('td input');
-              $protocolFields = $protocolinput.filter(function(){
-                var name = $(this).attr('name');
-
-                return  $.inArray(name,['protocolnumber']) > -1;
-              });
-
-              if ($(this).val() == 'protocolnumber' ){
-                $icmpFields.hide();
-                $otherFields.hide();
-                $protocolFields.show().addClass('required');
-                $inputs.filter('[name=startport],[name=endport]').show().attr('disabled', false);
-              } else if ($(this).val() == 'icmp') {
-                $icmpFields.show();
-                $icmpFields.attr('disabled', false);
-                $protocolFields.hide().removeClass('required');
-                $otherFields.attr('disabled', 'disabled');
-                $otherFields.hide();
-                $otherFields.parent().find('label.error').hide();
-              } else {
-                $otherFields.show();
-                $otherFields.parent().find('label.error').hide();
-                $otherFields.attr('disabled', false);
-                $icmpFields.attr('disabled', 'disabled');
-                $icmpFields.hide();
-                $icmpFields.parent().find('label.error').hide();
-                $protocolFields.hide().removeClass('required');
-                if ($(this).val() == 'all'){
-                  $portFields.attr('disabled', 'disabled');
-                  $portFields.hide();
+
+            return hiddenFields; // Returns fields to be hidden
+        },
+        reorder: {
+            moveDrag: {
+                action: function(args) {
+                    var rule = args.context.multiRule[0];
+                    var index = args.targetIndex;
+
+                    $.ajax({
+                        url: createURL('updateNetworkACLItem'),
+                        data: {
+                            id: rule.id,
+                            number: index + 1
+                        },
+                        success: function(json) {
+                            var pollTimer = setInterval(function() {
+                                pollAsyncJobResult({
+                                    _custom: {
+                                        jobId: json.createnetworkaclresponse.jobid
+                                    },
+                                    complete: function() {
+                                        clearInterval(pollTimer);
+                                        args.response.success();
+                                    },
+                                    error: function(errorMsg) {
+                                        clearInterval(pollTimer);
+                                        args.response.error(errorMsg);
+                                    }
+                                });
+                            }, 1000);
+                        }
+                    });
                 }
-              }              
             }
-          });
+        },
+        fields: {
 
-          args.response.success({
-            data: [
-              { name: 'tcp', description: 'TCP' },
-              { name: 'udp', description: 'UDP' },
-              { name: 'icmp', description: 'ICMP' },
-              { name: 'all', description: 'ALL'},
-              { name: 'protocolnumber', description: 'Protocol Number'}
+            'number': {
+                label: 'Rule Number',
+                edit: true,
+                isEditable: true
 
-            ]
-          });
+            },
 
-          setTimeout(function() { args.$select.trigger('change'); }, 100);
-        }
-      },
-
-      'protocolnumber': {label:'Protocol Number',edit:true, isEditable: true},
-      'startport': { edit: true, label: 'label.start.port', isOptional: true, isEditable: true },
-      'endport': { edit: true, label: 'label.end.port', isOptional: true, isEditable: true },
-      'networkid': {
-        label: 'Select Tier',
-        select: function(args) {
-          var data = {
-            listAll: true,
-            vpcid: args.context.vpc[0].id
-          };
-
-          // Only show selected tier, if viewing from detail view
-          if (args.context.networks &&
-              args.context.networks[0] &&
-              args.context.networks[0].vpcid) {
-            $.extend(data, {
-              id: args.context.networks[0].id
-            });
-          }
-          
-          //  Ajax Call to display the Tiers
-          $.ajax({
-            url: createURL('listNetworks'),
-            data: data,
-            success: function(json) {
-              var networks = json.listnetworksresponse.network;
-              
-              args.response.success({
-                data: $(networks).map(function(index, network) {
-                  return {
-                    name: network.id,
-                    description: network.name
-                  };
-                })
-              });
-            }
-          });
-        }
-      },
-      'icmptype': { edit: true, label: 'ICMP.type', isDisabled: true, desc:'Please specify -1 if you want to allow all ICMP types', defaultValue:'-1', isEditable: true },
-      'icmpcode': { edit: true, label: 'ICMP.code', isDisabled: true, desc:'Please specify -1 if you want to allow all ICMP codes', defaultValue:'-1', isEditable: true },
-      'traffictype' : {
-        label: 'label.traffic.type',
-        isEditable: true,
-        select: function(args) {
-          args.response.success({
-            data: [
-              { name: 'Ingress', description: 'Ingress' },
-              { name: 'Egress', description: 'Egress' }
-            ]
-          });
-        }
-      },
-      'add-rule': {
-        label: 'label.add.rule',
-        addButton: true
-      }
-    },
-
-    tags: cloudStack.api.tags({ resourceType: 'NetworkACL', contextId: 'multiRule' }),
-
-    add: {
-      label: 'label.add',
-      action: function(args) {
-        var $multi = args.$multi;
-        //Support for Protocol Number between 0 to 255
-        if (args.data.protocol === 'protocolnumber'){
-          $.extend(args.data,{protocol:args.data.protocolnumber});
-          delete args.data.protocolnumber;
-          delete args.data.startport;
-          delete args.data.endport;
-          delete args.data.icmptype;
-          delete args.data.icmpcode;
-        } else {
-          delete args.data.protocolnumber;
-        }
+            'cidrlist': {
+                edit: true,
+                label: 'label.cidr',
+                isEditable: true
+            },
+            action: {
+                label: 'Action',
+                isEditable: true,
+                select: function(args) {
+                    args.response.success({
+                        data: [{
+                            name: 'Allow',
+                            description: 'Allow'
+                        }, {
+                            name: 'Deny',
+                            description: 'Deny'
+                        }]
+                    });
+                }
+            },
+            'protocol': {
+                label: 'label.protocol',
+                isEditable: true,
+                select: function(args) {
+                    var isEditDialog = args.type === 'createForm';
+
+                    args.$select.change(function() {
+                        var $inputs, $icmpFields, $otherFields, $portFields, $protocolFields, $protocolinput;
+
+                        //
+                        // Editing existing rules in createForm dialog
+                        //
+                        if (isEditDialog) {
+                            $inputs = args.$form.find('.form-item');
+                            $icmpFields = $inputs.filter(function() {
+                                var name = $(this).attr('rel');
+
+                                return $.inArray(name, [
+                                    'icmptype',
+                                    'icmpcode'
+                                ]) > -1;
+                            });
+                            $otherFields = $inputs.filter(function() {
+                                var name = $(this).attr('rel');
+
+                                return name != 'protocolnumber' &&
+                                    name != 'icmptype' &&
+                                    name != 'icmpcode' &&
+                                    name != 'cidrlist' &&
+                                    name != 'number';
+                            });
+                            $portFields = $inputs.filter(function() {
+                                var name = $(this).attr('rel');
+                                return $.inArray(name, [
+                                    'startport',
+                                    'endport'
+                                ]) > -1;
+                            });
+                            $protocolFields = $inputs.filter(function() {
+                                var name = $(this).attr('rel');
 
-        if ((args.data.protocol == 'tcp' || args.data.protocol == 'udp') && (args.data.startport=="" || args.data.startport == undefined)){
-          cloudStack.dialog.notice({message:_l('Start Port or End Port value should not be blank')});
-          $(window).trigger('cloudStack.fullRefresh');
-        }
-        else if ((args.data.protocol == 'tcp' || args.data.protocol == 'udp')  && (args.data.endport=="" || args.data.endport == undefined)){
-          cloudStack.dialog.notice({message:_l('Start Port or End Port value should not be blank')});
-          $(window).trigger('cloudStack.fullRefresh');
-        }
+                                return $.inArray(name, ['protocolnumber']) > -1;
+                            });
 
-        else {
-          $.ajax({
-            url: createURL('createNetworkACL'),
-            data: $.extend(args.data, {
-              aclid: args.context.aclLists[0].id
-            }),
-            dataType: 'json',
-            success: function(data) {
-              args.response.success({
-                _custom: {
-                  jobId: data.createnetworkaclresponse.jobid,
-                  getUpdatedItem: function(json) {
-                    $(window).trigger('cloudStack.fullRefresh');
+                            if ($(this).val() == 'protocolnumber') {
+                                $icmpFields.hide();
+                                $portFields.show();
+                                $protocolFields.show();
+                                $portFields.show();
+                            } else if ($(this).val() == 'icmp') {
+                                $icmpFields.show();
+                                $protocolFields.hide();
+                                $portFields.hide();
+                            } else if ($(this).val() == 'all') {
+                                $portFields.hide();
+                            } else {
+                                $otherFields.show();
+                                $icmpFields.hide();
+                                $protocolFields.hide();
 
-                    return data;
-                  }
-                },
-                notification: {
-                  label: 'label.add.ACL',
-                  poll: pollAsyncJobResult
+                            }
+                        } else {
+                            //
+                            // Add new form
+                            //
+                            $inputs = args.$form.find('input');
+                            $icmpFields = $inputs.filter(function() {
+                                var name = $(this).attr('name');
+
+                                return $.inArray(name, [
+                                    'icmptype',
+                                    'icmpcode'
+                                ]) > -1;
+                            });
+                            $otherFields = $inputs.filter(function() {
+                                var name = $(this).attr('name');
+
+                                return name != 'protocolnumber' &&
+                                    name != 'icmptype' &&
+                                    name != 'icmpcode' &&
+                                    name != 'cidrlist' &&
+                                    name != 'number';
+                            });
+                            $portFields = $inputs.filter(function() {
+                                var name = $(this).attr('name');
+                                return $.inArray(name, [
+                                    'startport',
+                                    'endport'
+                                ]) > -1;
+                            });
+
+                            $protocolinput = args.$form.find('td input');
+                            $protocolFields = $protocolinput.filter(function() {
+                                var name = $(this).attr('name');
+
+                                return $.inArray(name, ['protocolnumber']) > -1;
+                            });
+
+                            if ($(this).val() == 'protocolnumber') {
+                                $icmpFields.hide();
+                                $otherFields.hide();
+                                $protocolFields.show().addClass('required');
+                                $inputs.filter('[name=startport],[name=endport]').show().attr('disabled', false);
+                            } else if ($(this).val() == 'icmp') {
+                                $icmpFields.show();
+                                $icmpFields.attr('disabled', false);
+                                $protocolFields.hide().removeClass('required');
+                                $otherFields.attr('disabled', 'disabled');
+                                $otherFields.hide();
+                                $otherFields.parent().find('label.error').hide();
+                            } else if ($(this).val() == 'all') {
+                                $portFields.attr('disabled', 'disabled');
+                                $portFields.hide();
+                            } else {
+                                $otherFields.show();
+                                $otherFields.parent().find('label.error').hide();
+                                $otherFields.attr('disabled', false);
+                                $icmpFields.attr('disabled', 'disabled');
+                                $icmpFields.hide();
+                                $icmpFields.parent().find('label.error').hide();
+                                $protocolFields.hide().removeClass('required');
+                            }
+                        }
+                    });
+
+                    args.response.success({
+                        data: [{
+                                name: 'tcp',
+                                description: 'TCP'
+                            }, {
+                                name: 'udp',
+                                description: 'UDP'
+                            }, {
+                                name: 'icmp',
+                                description: 'ICMP'
+                            }, {
+                                name: 'all',
+                                description: 'ALL'
+                            }, {
+                                name: 'protocolnumber',
+                                description: 'Protocol Number'
+                            }
+
+                        ]
+                    });
+
+                    setTimeout(function() {
+                        args.$select.trigger('change');
+                    }, 100);
                 }
-              });
             },
-            error: function(data) {
-              args.response.error(parseXMLHttpResponse(data));
-            }
-          });
-        }
-      }
-    },
-    actions: {
-      edit: {
-        label: 'label.edit',
-        action: function(args) {
-          var data = {
-            id: args.context.multiRule[0].id,
-            cidrlist: args.data.cidrlist,
-            number: args.data.number,
-            protocol: args.data.protocol,
-            traffictype: args.data.traffictype,
-            action: args.data.action
-          };
-
-          if (data.protocol === 'tcp' || data.protocol === 'udp') {
-            $.extend(data, {
-              startport: args.data.startport,
-              endport: args.data.endport
-            });
-          } else if (data.protocol === 'icmp') {
-            $.extend(data, {
-              icmptype: args.data.icmptype,
-              icmpcode: args.data.icmpcode
-            });
-          } else if (data.protocol === 'protocolnumber') {
-            $.extend(data, {
-              protocol: args.data.protocolnumber,
-              startport: args.data.startport,
-              endport: args.data.endport
-            });
-
-            delete args.data.protocolnumber;
-          }
-
-          $.ajax({
-            url: createURL('updateNetworkACLItem'),
-            data: data,
-            success: function(json) {
-              args.response.success({
-                _custom: { jobId: json.createnetworkaclresponse.jobid }, // API response obj name needs to be fixed
-                notification: {
-                  label: 'Edit ACL rule',
-                  poll: pollAsyncJobResult
-                }
-              });
+
+            'protocolnumber': {
+                label: 'Protocol Number',
+                edit: true,
+                isEditable: true
             },
-            error: function(error) {
-              args.response.error(parseXMLHttpResponse(error));
-            }
-          });         
-        }
-      },
-      destroy: {
-        label: 'label.remove.ACL',
-        action: function(args) {
-          $.ajax({
-            url: createURL('deleteNetworkACL'),
-            data: {
-              id: args.context.multiRule[0].id
+            'startport': {
+                edit: true,
+                label: 'label.start.port',
+                isOptional: true,
+                isEditable: true
             },
-            dataType: 'json',
-            async: true,
-            success: function(data) {
-              var jobID = data.deletenetworkaclresponse.jobid;
-              args.response.success({
-                _custom: {
-                  jobId: jobID,
-                  getUpdateIdtem: function() {
-                    $(window).trigger('cloudStack.fullRefresh');
-                  }
-                },
-                notification: {
-                  label: 'label.remove.ACL',
-                  poll: pollAsyncJobResult
-                }
-              });
+            'endport': {
+                edit: true,
+                label: 'label.end.port',
+                isOptional: true,
+                isEditable: true
             },
-            error: function(data) {
-              args.response.error(parseXMLHttpResponse(data));
-            }
-          });
-        }
-      }
-    },
-    dataProvider: function(args) {
-      var $multi = args.$multi;
-      var data = {
-        vpcid: args.context.vpc[0].id,
-        listAll: true
-      };
-
-      if (!$multi.data('acl-rules')) {
-        $multi.data('acl-rules', []);
-      }
-
-      if (args.context.networks &&
-          args.context.networks[0] &&
-          args.context.networks[0].vpcid) {
-        data.networkid = args.context.networks[0].id;
-
-        $.ajax({
-          url: createURL('listNetworkACLs'),
-          data: data,
-          dataType: 'json',
-          async: true,
-          success: function(json) {
-            args.response.success({
-              data: $(json.listnetworkaclsresponse.networkacl).map(function(index, acl) {
-                return $.extend(acl, {
-                  networkid: args.context.networks[0].name
-                });
-              })
-            });
-          },
-          error: function(XMLHttpResponse) {
-            args.response.error(parseXMLHttpResponse(XMLHttpResponse));
-          }
-        });
-      } else {
-        args.response.success({ data: $multi.data('acl-rules') });
-      }
-    }
-  };
-
-  cloudStack.vpc = {
-    // nTier sections
-    sections: {
-      tierVMs: function() {
-        var list = $.extend(true, {}, cloudStack.sections.instances);
-
-        list.listView.actions.add.action.custom = cloudStack.uiCustom.instanceWizard(
-          $.extend(true, {}, cloudStack.instanceWizard, {
-            pluginForm: { name: 'vpcTierInstanceWizard' }
-          })
-        );
-        
-        return list;
-      },
-
-      tierPortForwarders: function() {
-        return cloudStack.vpc.ipAddresses.listView();
-      },
-
-      tierStaticNATs: function() {
-        return cloudStack.vpc.staticNatIpAddresses.listView();
-      },
-      
-      // Internal load balancers
-      internalLoadBalancers: {
-        title: 'Internal LB',
-        listView: {
-          id: 'internalLoadBalancers',
-          fields: {
-            name: { label: 'label.name' },
-            sourceipaddress: { label: 'Source IP Address' },
-            sourceport: { label: 'Source Port' },
-            instanceport: { label: 'Instance Port' },
-            algorithm: { label: 'label.algorithm' }   
-          },
-          dataProvider: function(args) {                
-            $.ajax({
-              url: createURL('listLoadBalancers'),
-              data: {
-                networkid: args.context.networks[0].id
-              },
-              success: function(json) {                    
-                var items = json.listloadbalancerssresponse.loadbalancer;
-                if(items != null) {
-                  for(var i = 0; i < items.length; i++) {
-                    var item = items[i];                    
-                    //there is only one element in loadbalancerrul array property.
-                    item.sourceport = item.loadbalancerrule[0].sourceport;
-                    item.instanceport = item.loadbalancerrule[0].instanceport;
-                  }
-                }                
-                args.response.success({ data: items });                
-              }
-            });                
-          },
-          actions: {
-            add: {
-              label: 'Add Internal LB',
-              createForm: {
-                title: 'Add Internal LB',                
-                fields: {                                   
-                  name: { label: 'label.name', validation: { required: true } },
-                  description: { label: 'label.description', validation: { required: false } },
-                  sourceipaddress: { label: 'Source IP Address', validation: { required: false } },
-                  sourceport: { label: 'Source Port', validation: { required: true } },
-                  instanceport: { label: 'Instance Port', validation: { required: true } },
-                  algorithm: { 
-                    label: 'label.algorithm',
-                    validation: { required: true },
-                    select: function(args) {
-                      args.response.success({
-                        data: [
-                          { id: 'source', description: 'source' },
-                          { id: 'roundrobin', description: 'roundrobin' },
-                          { id: 'leastconn', description: 'leastconn' }
-                        ]
-                      });
+            'networkid': {
+                label: 'Select Tier',
+                select: function(args) {
+                    var data = {
+                        listAll: true,
+                        vpcid: args.context.vpc[0].id
+                    };
+
+                    // Only show selected tier, if viewing from detail view
+                    if (args.context.networks &&
+                        args.context.networks[0] &&
+                        args.context.networks[0].vpcid) {
+                        $.extend(data, {
+                            id: args.context.networks[0].id
+                        });
                     }
-                  }                  
+
+                    //  Ajax Call to display the Tiers
+                    $.ajax({
+                        url: createURL('listNetworks'),
+                        data: data,
+                        success: function(json) {
+                            var networks = json.listnetworksresponse.network;
+
+                            args.response.success({
+                                data: $(networks).map(function(index, network) {
+                                    return {
+                                        name: network.id,
+                                        description: network.name
+                                    };
+                                })
+                            });
+                        }
+                    });
                 }
-              },
-              messages: {
-                notification: function(args) {
-                  return 'Add Internal LB';
+            },
+            'icmptype': {
+                edit: true,
+                label: 'ICMP.type',
+                isDisabled: true,
+                desc: 'Please specify -1 if you want to allow all ICMP types',
+                defaultValue: '-1',
+                isEditable: true
+            },
+            'icmpcode': {
+                edit: true,
+                label: 'ICMP.code',
+                isDisabled: true,
+                desc: 'Please specify -1 if you want to allow all ICMP codes',
+                defaultValue: '-1',
+                isEditable: true
+            },
+            'traffictype': {
+                label: 'label.traffic.type',
+                isEditable: true,
+                select: function(args) {
+                    args.response.success({
+                        data: [{
+                            name: 'Ingress',
+                            description: 'Ingress'
+                        }, {
+                            name: 'Egress',
+                            description: 'Egress'
+                        }]
+                    });
                 }
-              },
-              action: function(args) {               
-                var data = {
-                  name: args.data.name,
-                  sourceport: args.data.sourceport,
-                  instanceport: args.data.instanceport,
-                  algorithm: args.data.algorithm,
-                  networkid: args.context.networks[0].id,
-                  sourceipaddressnetworkid: args.context.networks[0].id,
-                  scheme: 'Internal'
-                };
-                if(args.data.description != null && args.data.description.length > 0){
-                  $.extend(data, {
-                    description: args.data.description
-                  });                  
+            },
+            'add-rule': {
+                label: 'label.add.rule',
+                addButton: true
+            }
+        },
+
+        tags: cloudStack.api.tags({
+            resourceType: 'NetworkACL',
+            contextId: 'multiRule'
+        }),
+
+        add: {
+            label: 'label.add',
+            action: function(args) {
+                var $multi = args.$multi;
+                //Support for Protocol Number between 0 to 255
+                if (args.data.protocol === 'protocolnumber') {
+                    $.extend(args.data, {
+                        protocol: args.data.protocolnumber
+                    });
+                    delete args.data.protocolnumber;
+                    delete args.data.startport;
+                    delete args.data.endport;
+                    delete args.data.icmptype;
+                    delete args.data.icmpcode;
+                } else {
+                    delete args.data.protocolnumber;
                 }
-                if(args.data.sourceipaddress != null && args.data.sourceipaddress.length > 0){
-                  $.extend(data, {
-                    sourceipaddress: args.data.sourceipaddress
-                  });                  
-                }                
-                $.ajax({
-                  url: createURL('createLoadBalancer'),
-                  data: data,
-                  success: function(json){                    
-                    var jid = json.createloadbalancerresponse.jobid;   
-                    args.response.success(
-                      {_custom:
-                       {jobId: jid,
-                        getUpdatedItem: function(json) {    
-                          return json.queryasyncjobresultresponse.jobresult.loadbalancer;
+
+                if ((args.data.protocol == 'tcp' || args.data.protocol == 'udp') && (args.data.startport == "" || args.data.startport == undefined)) {
+                    cloudStack.dialog.notice({
+                        message: _l('Start Port or End Port value should not be blank')
+                    });
+                    $(window).trigger('cloudStack.fullRefresh');
+                } else if ((args.data.protocol == 'tcp' || args.data.protocol == 'udp') && (args.data.endport == "" || args.data.endport == undefined)) {
+                    cloudStack.dialog.notice({
+                        message: _l('Start Port or End Port value should not be blank')
+                    });
+                    $(window).trigger('cloudStack.fullRefresh');
+                } else {
+                    $.ajax({
+                        url: createURL('createNetworkACL'),
+                        data: $.extend(args.data, {
+                            aclid: args.context.aclLists[0].id
+                        }),
+                        dataType: 'json',
+                        success: function(data) {
+                            args.response.success({
+                                _custom: {
+                                    jobId: data.createnetworkaclresponse.jobid,
+                                    getUpdatedItem: function(json) {
+                                        $(window).trigger('cloudStack.fullRefresh');
+
+                                        return data;
+                                    }
+                                },
+                                notification: {
+                                    label: 'label.add.ACL',
+                                    poll: pollAsyncJobResult
+                                }
+                            });
+                        },
+                        error: function(data) {
+                            args.response.error(parseXMLHttpResponse(data));
                         }
-                       }
-                      }
-                    );    
-                  }
-                });        
-              },
-              notification: {
-                poll: pollAsyncJobResult
-              }
+                    });
+                }
             }
-          },
-          
-          detailView: {
-            isMaximized: true,
-            name: 'Internal LB details',
-            actions: {                
-              assignVMs: {
-                label: 'Assign VMs',
-                messages: {
-                  notification: function(args) { return 'Assign VMs'; }
-                },
-                needsRefresh: true,
-                listView: $.extend(true, {}, cloudStack.sections.instances.listView, {
-                  type: 'checkbox',
-                  filters: false,
-                  dataProvider: function(args) {       
-                    var assignedInstances;
-                    $.ajax({
-                      url: createURL('listLoadBalancers'),
-                      data: {
-                        id: args.context.internalLoadBalancers[0].id
-                      },
-                      async: false,
-                      success: function(json) {    
-                        assignedInstances = json.listloadbalancerssresponse.loadbalancer[0].loadbalancerinstance;         
-                        if(assignedInstances == null)
-                          assignedInstances = []; 
-                      }
-                    });                     
-                    
-                    $.ajax({
-                      url: createURL('listVirtualMachines'),
-                      data: {
-                        networkid: args.context.networks[0].id,
-                        listAll: true
-                      },
-                      success: function(json) {
-                        var instances = json.listvirtualmachinesresponse.virtualmachine;
-
-                        // Pre-select existing instances in LB rule
-                        $(instances).map(function(index, instance) {
-                          instance._isSelected = $.grep(assignedInstances,                                  
-                            function(assignedInstance) {
-                              return assignedInstance.id == instance.id;
-                            }
-                          ).length ? true : false;
+        },
+        actions: {
+            edit: {
+                label: 'label.edit',
+                action: function(args) {
+                    var data = {
+                        id: args.context.multiRule[0].id,
+                        cidrlist: args.data.cidrlist,
+                        number: args.data.number,
+                        protocol: args.data.protocol,
+                        traffictype: args.data.traffictype,
+                        action: args.data.action
+                    };
+
+                    if (data.protocol === 'tcp' || data.protocol === 'udp') {
+                        $.extend(data, {
+                            startport: args.data.startport,
+                            endport: args.data.endport
                         });
-                        
-                        //remove assigned VMs (i.e. instance._isSelected == true)
-                        var items = [];
-                        if(instances != null) {
-                          for(var i = 0; i < instances.length; i++) {
-                            if(instances[i]._isSelected == true)
-                              continue;
-                            else
-                              items.push(instances[i]);
-                          }
-                        }
-                        
-                        args.response.success({
-                          data: items
+                    } else if (data.protocol === 'icmp') {
+                        $.extend(data, {
+                            icmptype: args.data.icmptype,
+                            icmpcode: args.data.icmpcode
                         });
-                      }
-                    });
-                  }
-                }),
-                action: function(args) {                          
-                  var vms = args.context.instances;
-                  var array1 = [];
-                  for(var i = 0; i < vms.length; i++) {
-                    array1.push(vms[i].id);
-                  }
-                  var virtualmachineids = array1.join(',');
-                  
-                  $.ajax({
-                    url: createURL('assignToLoadBalancerRule'),
-                    data: {
-                      id: args.context.internalLoadBalancers[0].id,
-                      virtualmachineids: virtualmachineids
-                    },
-                    dataType: 'json',
-                    async: true,
-                    success: function(data) {                          
-                      var jid = data.assigntoloadbalancerruleresponse.jobid;                                                   
-                      args.response.success({
-                        _custom: { 
-                          jobId: jid
-                        }
-                      });
+                    } else if (data.protocol === 'protocolnumber') {
+                        $.extend(data, {
+                            protocol: args.data.protocolnumber,
+                            startport: args.data.startport,
+                            endport: args.data.endport
+                        });
+
+                        delete args.data.protocolnumber;
                     }
-                  });
-                },
-                notification: {
-                  poll: pollAsyncJobResult
-                }                      
-              },
-                            
-              remove: {
-                label: 'Delete Internal LB',
-                messages: {
-                  confirm: function(args) {
-                    return 'Please confirm you want to delete Internal LB';
-                  },
-                  notification: function(args) {
-                    return 'Delete Internal LB';
-                  }
-                },
+
+                    $.ajax({
+                        url: createURL('updateNetworkACLItem'),
+                        data: data,
+                        success: function(json) {
+                            args.response.success({
+                                _custom: {
+                                    jobId: json.createnetworkaclresponse.jobid
+                                }, // API response obj name needs to be fixed
+                                notification: {
+                                    label: 'Edit ACL rule',
+                                    poll: pollAsyncJobResult
+                                }
+                            });
+                        },
+                        error: function(error) {
+                            args.response.error(parseXMLHttpResponse(error));
+                        }
+                    });
+                }
+            },
+            destroy: {
+                label: 'label.remove.ACL',
                 action: function(args) {
-                  var data = {
-                    id: args.context.internalLoadBalancers[0].id
-                  };                
-                  $.ajax({
-                    url: createURL('deleteLoadBalancer'),
+                    $.ajax({
+                        url: createURL('deleteNetworkACL'),
+                        data: {
+                            id: args.context.multiRule[0].id
+                        },
+                        dataType: 'json',
+                        async: true,
+                        success: function(data) {
+                            var jobID = data.deletenetworkaclresponse.jobid;
+                            args.response.success({
+                                _custom: {
+                                    jobId: jobID,
+                                    getUpdateIdtem: function() {
+                                        $(window).trigger('cloudStack.fullRefresh');
+                                    }
+                                },
+                                notification: {
+                                    label: 'label.remove.ACL',
+                                    poll: pollAsyncJobResult
+                                }
+                            });
+                        },
+                        error: function(data) {
+                            args.response.error(parseXMLHttpResponse(data));
+                        }
+                    });
+                }
+            }
+        },
+        dataProvider: function(args) {
+            var $multi = args.$multi;
+            var data = {
+                vpcid: args.context.vpc[0].id,
+                listAll: true
+            };
+
+            if (!$multi.data('acl-rules')) {
+                $multi.data('acl-rules', []);
+            }
+
+            if (args.context.networks &&
+                args.context.networks[0] &&
+                args.context.networks[0].vpcid) {
+                data.networkid = args.context.networks[0].id;
+
+                $.ajax({
+                    url: createURL('listNetworkACLs'),
                     data: data,
+                    dataType: 'json',
                     async: true,
                     success: function(json) {
-                      var jid = json.deleteloadbalancerresponse.jobid;                                                   
-                      args.response.success({
-                        _custom: { jobId: jid }
-                      });                      
+                        args.response.success({
+                            data: $(json.listnetworkaclsresponse.networkacl).map(function(index, acl) {
+                                return $.extend(acl, {
+                                    networkid: args.context.networks[0].name
+                                });
+                            })
+                        });
                     },
-                    error: function(data) {
-                      args.response.error(parseXMLHttpResponse(data));
-                    }
-                  });
-                },
-                notification: {
-                  poll: pollAsyncJobResult
-                }
-              }              
-            },                
-            tabs: {
-              details: {
-                title: 'label.details',
-                fields: [
-                  {
-                    name: { label: 'label.name' }
-                  },
-                  {
-                    id: { label: 'label.id' },      
-                    description: { label: 'label.description' },
-                    sourceipaddress: { label: 'Source IP Address' },
-                    sourceport: { label: 'Source Port' },
-                    instanceport: { label: 'Instance Port' },
-                    algorithm: { label: 'label.algorithm' },
-                    loadbalancerinstance: { 
-                      label: 'Assigned VMs',
-                      converter: function(objArray) {                       
-                        var s = '';
-                        if(objArray != null) {
-                          for(var i = 0; i < objArray.length; i++) {
-                            if(i > 0) {
-                              s += ', ';      
-                            }                                                    
-                            s += objArray[i].name + ' ('+ objArray[i].ipaddress + ')';
-                          }
-                        }                        
-                        return s;                     
-                      }
+                    error: function(XMLHttpResponse) {
+                        args.response.error(parseXMLHttpResponse(XMLHttpResponse));
                     }
-                  }
-                ],                    
-                dataProvider: function(args) {      
-                  $.ajax({
-                    url: createURL('listLoadBalancers'),
-                    data: {
-                      id: args.context.internalLoadBalancers[0].id
+                });
+            } else {
+                args.response.success({
+                    data: $multi.data('acl-rules')
+                });
+            }
+        }
+    };
+
+    cloudStack.vpc = {
+        // nTier sections
+        sections: {
+            tierVMs: function() {
+                var list = $.extend(true, {}, cloudStack.sections.instances);
+
+                list.listView.actions.add.action.custom = cloudStack.uiCustom.instanceWizard(
+                    $.extend(true, {}, cloudStack.instanceWizard, {
+                        pluginForm: {
+                            name: 'vpcTierInstanceWizard'
+                        }
+                    })
+                );
+
+                return list;
+            },
+
+            tierPortForwarders: function() {
+                return cloudStack.vpc.ipAddresses.listView();
+            },
+
+            tierStaticNATs: function() {
+                return cloudStack.vpc.staticNatIpAddresses.listView();
+            },
+
+            // Internal load balancers
+            internalLoadBalancers: {
+                title: 'Internal LB',
+                listView: {
+                    id: 'internalLoadBalancers',
+                    fields: {
+                        name: {
+                            label: 'label.name'
+                        },
+                        sourceipaddress: {
+                            label: 'Source IP Address'
+                        },
+                        sourceport: {
+                            label: 'Source Port'
+                        },
+                        instanceport: {
+                            label: 'Instance Port'
+                        },
+                        algorithm: {
+                            label: 'label.algorithm'
+                        }
                     },
-                    success: function(json) {     
-                      var item = json.listloadbalancerssresponse.loadbalancer[0];
-                      
-                      //remove Rules tab and add sourceport, instanceport at Details tab because there is only one element in loadbalancerrul array property.
-                      item.sourceport = item.loadbalancerrule[0].sourceport;
-                      item.instanceport = item.loadbalancerrule[0].instanceport;
-                      
-                      args.response.success({ data: item });                          
-                    }
-                  });                        
-                }
-              },  
-              
-              /*
+                    dataProvider: function(args) {
+                        $.ajax({
+                            url: createURL('listLoadBalancers'),
+                            data: {
+                                networkid: args.context.networks[0].id
+                            },
+                            success: function(json) {
+                                var items = json.listloadbalancerssresponse.loadbalancer;
+                                if (items != null) {
+                                    for (var i = 0; i < items.length; i++) {
+                                        var item = items[i];
+                                        //there is only one element in loadbalancerrul array property.
+                                        item.sourceport = item.loadbalancerrule[0].sourceport;
+                                        item.instanceport = item.loadbalancerrule[0].instanceport;
+                                    }
+                                }
+                                args.response.success({
+                                    data: items
+                                });
+                            }
+                        });
+                    },
+                    actions: {
+                        add: {
+                            label: 'Add Internal LB',
+                            createForm: {
+                                title: 'Add Internal LB',
+                                fields: {
+                                    name: {
+                                        label: 'label.name',
+                                        validation: {
+                                            required: true
+                                        }
+                                    },
+                                    description: {
+                                        label: 'label.description',
+                                        validation: {
+                                            required: false
+                                        }
+                                    },
+                                    sourceipaddress: {
+                                        label: 'Source IP Address',
+                                        validation: {
+                                            required: false
+                                        }
+                                    },
+                                    sourceport: {
+                                        label: 'Source Port',
+                                        validation: {
+                                            required: true
+                                        }
+                                    },
+                                    instanceport: {
+                                        label: 'Instance Port',
+                                        validation: {
+                                            required: true
+                                        }
+                                    },
+                                    algorithm: {
+                                        label: 'label.algorithm',
+                                        validation: {
+                                            required: true
+                                        },
+                                        select: function(args) {
+                                            args.response.success({
+                                                data: [{
+                                                    id: 'source',
+                                                    description: 'source'
+                                                }, {
+                                                    id: 'roundrobin',
+                                                    description: 'roundrobin'
+                                                }, {
+                                                    id: 'leastconn',
+                                                    description: 'leastconn'
+                                                }]
+                                            });
+                                        }
+                                    }
+                                }
+                            },
+                            messages: {
+                                notification: function(args) {
+                                    return 'Add Internal LB';
+                                }
+                            },
+                            action: function(args) {
+                                var data = {
+                                    name: args.data.name,
+                                    sourceport: args.data.sourceport,
+                                    instanceport: args.data.instanceport,
+                                    algorithm: args.data.algorithm,
+                                    networkid: args.context.networks[0].id,
+                                    sourceipaddressnetworkid: args.context.networks[0].id,
+                                    scheme: 'Internal'
+                                };
+                                if (args.data.description != null && args.data.description.length > 0) {
+                                    $.extend(data, {
+                                        description: args.data.description
+                                    });
+                                }
+                                if (args.data.sourceipaddress != null && args.data.sourceipaddress.length > 0) {
+                                    $.extend(data, {
+                                        sourceipaddress: args.data.sourceipaddress
+                                    });
+                                }
+                                $.ajax({
+                                    url: createURL('createLoadBalancer'),
+                                    data: data,
+                                    success: function(json) {
+                                        var jid = json.createloadbalancerresponse.jobid;
+                                        args.response.success({
+                                            _custom: {
+                                                jobId: jid,
+                                                getUpdatedItem: function(json) {
+                                                    return json.queryasyncjobresultresponse.jobresult.loadbalancer;
+                                                }
+                                            }
+                                        });
+                                    }
+                                });
+                            },
+                            notification: {
+                                poll: pollAsyncJobResult
+                            }
+                        }
+                    },
+
+                    detailView: {
+                        isMaximized: true,
+                        name: 'Internal LB details',
+                        actions: {
+                            assignVMs: {
+                                label: 'Assign VMs',
+                                messages: {
+                                    notification: function(args) {
+                                        return 'Assign VMs';
+                                    }
+                                },
+                                needsRefresh: true,
+                                listView: $.extend(true, {}, cloudStack.sections.instances.listView, {
+                                    type: 'checkbox',
+                                    filters: false,
+                                    dataProvider: function(args) {
+                                        var assignedInstances;
+                                        $.ajax({
+                                            url: createURL('listLoadBalancers'),
+                                            data: {
+                                                id: args.context.internalLoadBalancers[0].id
+                                            },
+                                            async: false,
+                                            success: function(json) {
+                                                assignedInstances = json.listloadbalancerssresponse.loadbalancer[0].loadbalancerinstance;
+                                                if (assignedInstances == null)
+                                                    assignedInstances = [];
+                                            }
+                                        });
+
+                                        $.ajax({
+                                            url: createURL('listVirtualMachines'),
+                                            data: {
+                                                networkid: args.context.networks[0].id,
+                                                listAll: true
+                                            },
+                                            success: function(json) {
+                                                var instances = json.listvirtualmachinesresponse.virtualmachine;
+
+                                                // Pre-select existing instances in LB rule
+                                                $(instances).map(function(index, instance) {
+                                                    instance._isSelected = $.grep(assignedInstances,
+                                                        function(assignedInstance) {
+                                                            return assignedInstance.id == instance.id;
+                                                        }
+                                                    ).length ? true : false;
+                                                });
+
+                                                //remove assigned VMs (i.e. instance._isSelected == true)
+                                                var items = [];
+                                                if (instances != null) {
+                                                    for (var i = 0; i < instances.length; i++) {
+                                                        if (instances[i]._isSelected == true)
+                                                            continue;
+                                                        else
+                                                            items.push(instances[i]);
+                                                    }
+                                                }
+
+                                                args.response.success({
+                                                    data: items
+                                                });
+                                            }
+                                        });
+                                    }
+                                }),
+                                action: function(args) {
+                                    var vms = args.context.instances;
+                                    var array1 = [];
+                                    for (var i = 0; i < vms.length; i++) {
+                                        array1.push(vms[i].id);
+                                    }
+                                    var virtualmachineids = array1.join(',');
+
+                                    $.ajax({
+                                        url: createURL('assignToLoadBalancerRule'),
+                                        data: {
+                                            id: args.context.internalLoadBalancers[0].id,
+                                            virtualmachineids: virtualmachineids
+                                        },
+                                        dataType: 'json',
+                                        async: true,
+                                        success: function(data) {
+                                            var jid = data.assigntoloadbalancerruleresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid
+                                                }
+                                            });
+                                        }
+                                    });
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
+                            },
+
+                            remove: {
+                                label: 'Delete Internal LB',
+                                messages: {
+                                    confirm: function(args) {
+                                        return 'Please confirm you want to delete Internal LB';
+                                    },
+                                    notification: function(args) {
+                                        return 'Delete Internal LB';
+                                    }
+                                },
+                                action: function(args) {
+                                    var data = {
+                                        id: args.context.internalLoadBalancers[0].id
+                                    };
+                                    $.ajax({
+                                        url: createURL('deleteLoadBalancer'),
+                                        data: data,
+                                        async: true,
+                                        success: function(json) {
+                                            var jid = json.deleteloadbalancerresponse.jobid;
+                                            args.response.success({
+                                                _custom: {
+                                                    jobId: jid
+                                                }
+                                            });
+                                        },
+                                        error: function(data) {
+                                            args.response.error(parseXMLHttpResponse(data));
+                                        }
+                                    });
+                                },
+                                notification: {
+                                    poll: pollAsyncJobResult
+                                }
+                            }
+                        },
+                        tabs: {
+                            details: {
+                                title: 'label.details',
+                                fields: [{
+                                    name: {
+                                        label: 'label.name'
+                                    }
+                                }, {
+                                    id: {
+                                        label: 'label.id'
+                                    },
+                                    description: {
+                                        label: 'label.description'
+                                    },
+                                    sourceipaddress: {
+                                        label: 'Source IP Address'
+                                    },
+                                    sourceport: {
+                                        label: 'Source Port'
+                                    },
+                                    instanceport: {
+                                        label: 'Instance Port'
+                                    },
+                                    algorithm: {
+                                        label: 'label.algorithm'
+                                    },
+                                    loadbalancerinstance: {
+                                        label: 'Assigned VMs',
+                                        converter: function(objArray) {
+                                            var s = '';
+                                            if (objArray != null) {
+                                                for (var i = 0; i < objArray.length; i++) {
+                                                    if (i > 0) {
+                                                        s += ', ';
+                                                    }
+                                                    s += objArray[i].name + ' (' + objArray[i].ipaddress + ')';
+                                                }
+                                            }
+                                            return s;
+                                        }
+                                    }
+                                }],
+                                dataProvider: function(args) {
+                                    $.ajax({
+                                        url: createURL('listLoadBalancers'),
+                                        data: {
+                                            id: args.context.internalLoadBalancers[0].id
+                                        },
+                                        success: function(json) {
+                                            var item = json.listloadbalancerssresponse.loadbalancer[0];
+
+                                            //remove Rules tab and add sourceport, instanceport at Details tab because there is only one element in loadbalancerrul array property.
+                                            item.sourceport = item.loadbalancerrule[0].sourceport;
+                                            item.instanceport = item.loadbalancerrule[0].instanceport;
+
+                                            args.response.success({
+                                                data: item
+                                            });
+                                        }
+                                    });
+                                }
+                            },
+
+                            /*
               rules: {
                 title: 'label.rules',
                 multiple: true,
@@ -783,2798 +907,3068 @@
                     data: {
                       id: args.context.internalLoadBalancers[0].id
                     },
-                    success: function(json) {     
+                    success: function(json) {
                       var item = json.listloadbalancerssresponse.loadbalancer[0];
-                      args.response.success({ data: item.loadbalancerrule });                          
+                      args.response.success({ data: item.loadbalancerrule });
                     }
-                  }); 
+                  });
                 }
-              },    
+              },
               */
-              
-              assignedVms: {
-                title: 'Assigned VMs',
-                listView: {  
-                  id: 'assignedVms',
-                  fields: {
-                    name: { label: 'label.name' },
-                    ipaddress: { label: 'label.ip.address' }
-                  },
-                  dataProvider: function(args) {
-                    $.ajax({
-                      url: createURL('listLoadBalancers'),
-                      data: {
-                        id: args.context.internalLoadBalancers[0].id
-                      },
-                      success: function(json) {     
-                        var item = json.listloadbalancerssresponse.loadbalancer[0];
-                        args.response.success({ data: item.loadbalancerinstance });                          
-                      }
-                    }); 
-                  },
-                  actions: {
-                    add: {
-                      label: 'Assign VMs',
-                      messages: {
-                        notification: function(args) { return 'Assign VMs'; }
-                      },
-                      needsRefresh: true,
-                      listView: $.extend(true, {}, cloudStack.sections.instances.listView, {
-                        type: 'checkbox',
-                        filters: false,
-                        dataProvider: function(args) {       
-                          var assignedInstances;
-                          $.ajax({
-                            url: createURL('listLoadBalancers'),
-                            data: {
-                              id: args.context.internalLoadBalancers[0].id
+
+                            assignedVms: {
+                                title: 'Assigned VMs',
+                                listView: {
+                                    id: 'assignedVms',
+                                    fields: {
+                                        name: {
+                                            label: 'label.name'
+                                        },
+                                        ipaddress: {
+                                            label: 'label.ip.address'
+                                        }
+                                    },
+                                    dataProvider: function(args) {
+                                        $.ajax({
+                                            url: createURL('listLoadBalancers'),
+                                            data: {
+                                                id: args.context.internalLoadBalancers[0].id
+                                            },
+                                            success: function(json) {
+                                                var item = json.listloadbalancerssresponse.loadbalancer[0];
+                                                args.response.success({
+                                                    data: item.loadbalancerinstance
+                                                });
+                                            }
+                                        });
+                                    },
+                                    actions: {
+                                        add: {
+                                            label: 'Assign VMs',
+                                            messages: {
+                                                notification: function(args) {
+                                                    return 'Assign VMs';
+                                                }
+                                            },
+                                            needsRefresh: true,
+                                            listView: $.extend(true, {}, cloudStack.sections.instances.listView, {
+                                                type: 'checkbox',
+                                                filters: false,
+                                                dataProvider: function(args) {
+                                                    var assignedInstances;
+                                                    $.ajax({
+                                                        url: createURL('listLoadBalancers'),
+                                                        data: {
+                                                            id: args.context.internalLoadBalancers[0].id
+                                                        },
+                                                        async: false,
+                                                        success: function(json) {
+                                                            assignedInstances = json.listloadbalancerssresponse.loadbalancer[0].loadbalancerinstance;
+                                                            if (assignedInstances == null)
+                                                                assignedInstances = [];
+                                                        }
+                                                    });
+
+                                                    $.ajax({
+                                                        url: createURL('listVirtualMachines'),
+                                                        data: {
+                                                            networkid: args.context.networks[0].id,
+                                                            listAll: true
+                                                        },
+                                                        success: function(json) {
+                                                            var instances = json.listvirtualmachinesresponse.virtualmachine;
+
+                                                            // Pre-select existing instances in LB rule
+                                                            $(instances).map(function(index, instance) {
+                                                                instance._isSelected = $.grep(assignedInstances,
+                                                                    function(assignedInstance) {
+                                                                        return assignedInstance.id == instance.id;
+                                                                    }
+                                                                ).length ? true : false;
+                                                            });
+
+                                                            //remove assigned VMs (i.e. instance._isSelected == true)
+                                                            var items = [];
+                                                            if (instances != null) {
+                                                                for (var i = 0; i < instances.length; i++) {
+                                                                    if (instances[i]._isSelected == true)
+                                                                        continue;
+                                                                    else
+                                                                        items.push(instances[i]);
+                                                                }
+                                                            }
+
+                                                            args.response.success({
+                                                                data: items
+                                                            });
+                                                        }
+                                                    });
+                                                }
+                                            }),
+                                            action: function(args) {
+                                                var vms = args.context.instances;
+                                                var array1 = [];
+                                                for (var i = 0; i < vms.length; i++) {
+                                                    array1.push(vms[i].id);
+                                                }
+                                                var virtualmachineids = array1.join(',');
+
+                                                $.ajax({
+                                                    url: createURL('assignToLoadBalancerRule'),
+                                                    data: {
+                                                        id: args.context.internalLoadBalancers[0].id,
+                                                        virtualmachineids: virtualmachineids
+                                                    },
+                                                    dataType: 'json',
+                                                    async: true,
+                                                    success: function(data) {
+                                                        var jid = data.assigntoloadbalancerruleresponse.jobid;
+                                                        args.response.success({
+                                                            _custom: {
+                                                                jobId: jid
+                                                            }
+                                                        });
+                                                    }
+                                                });
+                                            },
+                                            notification: {
+                                                poll: pollAsyncJobResult
+                                            }
+                                        }
+                                    },
+                                    detailView: {
+                                        actions: {
+                                            remove: {
+                                                label: 'remove VM from load balancer',
+                                                addRow: 'false',
+                                                messages: {
+                                                    confirm: function(args) {
+                                                        return 'Please confirm you want to remove VM from load balancer';
+                                                    },
+                                                    notification: function(args) {
+                                                        return 'remove VM from load balancer';
+                                                    }
+                                                },
+                                                action: function(args) {
+                                                    $.ajax({
+                                                        url: createURL('removeFromLoadBalancerRule'),
+                                                        data: {
+                                                            id: args.context.internalLoadBalancers[0].id,
+                                                            virtualmachineids: args.context.assignedVms[0].id
+                                                        },
+                                                        success: function(json) {
+                                                            var jid = json.removefromloadbalancerruleresponse.jobid;
+                                                            args.response.success({
+                                                                _custom: {
+                                                                    jobId: jid
+                                                                }
+                                                            });
+                                                        }
+                                                    });
+                                                },
+                                                notification: {
+                                                    poll: pollAsyncJobResult
+                                                }
+                                            }
+                                        },
+                                        tabs: {
+                                            details: {
+                                                title: 'label.details',
+                                                fields: [{
+                                                    name: {
+                                                        label: 'label.name'
+                                                    }
+                                                }, {
+                                                    ipaddress: {
+                                                        label: 'label.ip.address'
+                                                    }
+                                                }],
+                                                dataProvider: function(args) {
+                                                    setTimeout(function() {
+                                                        args.response.success({
+                                                            data: args.context.assignedVms[0]
+                                                        });
+                                                    });
+                                                }
+                                            }
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            },
+            publicLbIps: {
+                title: 'Public LB',
+                listView: {
+                    id: 'publicLbIps',
+                    fields: {
+                        ipaddress: {
+                            label: 'label.ips',
+                            converter: function(text, item) {
+                                if (item.issourcenat) {
+                                    return text + ' [' + _l('label.source.nat') + ']';
+                                }
+
+                                return text;
+                            }
+                        },
+                        zonename: {
+                            label: 'label.zone'
+                        },
+                        virtualmachinedisplayname: {
+                            label: 'label.vm.name'
+                        },
+                        state: {
+                            converter: function(str) {
+                                // For localization
+                                return str;
                             },
-                            async: false,
-                            success: function(json) {    
-                              assignedInstances = json.listloadbalancerssresponse.loadbalancer[0].loadbalancerinstance;         
-                              if(assignedInstances == null)
-                                assignedInstances = []; 
+                            label: 'label.state',
+                            indicator: {
+                                'Allocated': 'on',
+                                'Released': 'off'
                             }
-                          });                     
-                          
-                          $.ajax({
-                            url: createURL('listVirtualMachines'),
+                        }
+                    },
+                    dataProvider: function(args) {
+                        $.ajax({
+                            url: createURL('listPublicIpAddresses'),
+                            async: false,
                             data: {
-                              networkid: args.context.networks[0].id,
-                              listAll: true
+                                associatednetworkid: args.context.networks[0].id,
+                                forloadbalancing: true
+                            },
+                            success: function(json) {
+                                var items = json.listpublicipaddressesresponse;
+                                args.response.success({
+                                    data: items
+                                });
+                            }
+                        });
+                    }
+                }
+            },
+
+            // Private gateways
+            privateGateways: function() {
+                return cloudStack.vpc.gateways.listView()
+            },
+
+            // Public IP Addresses
+            publicIPs: function() {
+                return cloudStack.vpc.ipAddresses.listView()
+            },
+
+            // Network ACL lists
+            networkACLLists: {
+                listView: {
+                    id: 'aclLists',
+                    fields: {
+                        name: {
+                            label: 'label.name'
+                        },
+                        description: {
+                            label: 'Description'
+                        },
+                        id: {
+                            label: 'id'
+                        }
+                    },
+                    dataProvider: function(args) {
+                        $.ajax({
+                            url: createURL('listNetworkACLLists&vpcid=' + args.context.vpc[0].id),
+                            success: function(json) {
+                                var items = json.listnetworkacllistsresponse.networkacllist;
+
+                                args.response.success({
+                                    data: items
+                                });
+                            }
+                        });
+                    },
+
+                    actions: {
+                        add: {
+                            label: 'Add ACL List',
+                            createForm: {
+                                label: 'Add ACL List',
+                                fields: {
+                                    name: {
+       

<TRUNCATED>

Mime
View raw message