You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2013/04/25 20:08:35 UTC

[17/43] git commit: updated refs/heads/master to 5ce2890

CLOUDSTACK-2074: cloudstack UI - Affinity - (1) populate listView by API call. (2) implement Add Affinity Group action.


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

Branch: refs/heads/master
Commit: df15ceac265e2b088515c7b7c7bdb02f637f8fb9
Parents: 5d235f6
Author: Jessica Wang <je...@citrix.com>
Authored: Wed Apr 17 16:27:20 2013 -0700
Committer: Jessica Wang <je...@citrix.com>
Committed: Wed Apr 17 16:27:20 2013 -0700

----------------------------------------------------------------------
 ui/scripts/affinity.js |  139 +++++++++++++++++++++++++++++++-----------
 1 files changed, 102 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/df15ceac/ui/scripts/affinity.js
----------------------------------------------------------------------
diff --git a/ui/scripts/affinity.js b/ui/scripts/affinity.js
index 8bfd844..7a15533 100644
--- a/ui/scripts/affinity.js
+++ b/ui/scripts/affinity.js
@@ -21,25 +21,22 @@
       id: 'affinityGroups',
       fields: {
         name: { label: 'label.name' },
-        type: { label: 'label.type' }
+        description: { label: 'label.description' }
       },
       dataProvider: function(args) {
-        args.response.success({
-          data: [
-            { id: 1, name: 'Affinity Group 1', type: 'Affinity' },
-            { id: 2, name: 'Affinity Group 2', type: 'Anti-affinity' },
-            { id: 3, name: 'Anti-affinity Group', type: 'Anti-affinity' }
-          ]
-        });
+        $.ajax({
+				  url: createURL('listAffinityGroups'),
+					success: function(json) {					 
+					  var items = json.listaffinitygroupsresponse.affinitygroup;
+						args.response.success({data: items});
+					}
+				});				
       },
       actions: {
         add: {
           label: 'label.add.affinity.group',
 
-          messages: {
-            confirm: function(args) {
-              return 'message.add.volume';
-            },
+          messages: {            
             notification: function(args) {
               return 'label.add.affinity.group';
             }
@@ -52,40 +49,108 @@
                 label: 'label.name',
                 validation: { required: true }
               },
+							description: {
+                label: 'label.description'                
+              },
               type: {
-                label: 'label.availability.zone',
+                label: 'label.type',
                 select: function(args) {
-                  args.response.success({
-                    data: [
-                      { id: 'Affinity', description: 'Affinity' },
-                      { id: 'AntiAffinity', description: 'Anti-Affinity' }
-                    ]
-                  });
+								  $.ajax({
+									  url: createURL('listAffinityGroupTypes'),
+										success: function(json) {
+										  var types = [];											
+											var items = json.listaffinitygrouptypesresponse.affinityGroupType;
+											if(items != null) {
+											  for(var i = 0; i < items.length; i++) {
+												  types.push({id: items[i].type, description: items[i].type});
+												}												
+											}
+											args.response.success({data: types})
+										}
+									});								
                 }
-              },              
-              availabilityZone: {
-                label: 'label.availability.zone',
-                select: function(args) {
-                  $.ajax({
-                    url: createURL("listZones&available=true"),
-                    dataType: "json",
-                    async: true,
-                    success: function(json) {
-                      var items = json.listzonesresponse.zone;
-                      args.response.success({descriptionField: 'name', data: items});
-                    }
-                  });
-                }
-              },
+              },             
+						  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;
+								}			
+							}						 
             }
           },
 
-          action: function(args) {
-            args.response.success();
+          action: function(args) {					 
+						var data = {
+						  name: args.data.name,
+							type: args.data.type							
+						};						
+						if(args.data.description != null && args.data.description.length > 0)
+						  $.extend(data, {description: args.data.description});
+						if(args.data.domainid != null && args.data.domainid.length > 0)
+							$.extend(data, { domainid: args.data.domainid });  								  		
+						if(args.data.account != null && args.data.account.length > 0)
+							$.extend(data, { account: args.data.account });   
+					
+					  $.ajax({
+						  url: createURL('createAffinityGroup'),
+							data: data,
+							success: function(json) {							 							
+								var jid = json.createaffinitygroupresponse.jobid;
+								args.response.success(
+									{_custom:
+									 {jobId: jid,
+										getUpdatedItem: function(json) {												  
+											return json.queryasyncjobresultresponse.jobresult.affinitygroup;
+										}
+									 }
+									}
+								);								
+							}						
+						});            
           },
 
           notification: {
-            poll: function(args) { args.complete(); }
+            poll: pollAsyncJobResult
           }
         }
       },