Updated Branches:
  refs/heads/master 5e451f899 -> ef83621c5

CS-16573: cloudstack UI - update template - encode data passed to API call.


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

Branch: refs/heads/master
Commit: ef83621c5b7ccde8614e68e96af841331cba538f
Parents: 5e451f8
Author: Jessica Wang <[email protected]>
Authored: Wed Oct 24 15:56:20 2012 -0700
Committer: Jessica Wang <[email protected]>
Committed: Thu Oct 25 11:05:04 2012 -0700

----------------------------------------------------------------------
 ui/scripts/templates.js |   93 +++++++++++++++++++++++++++--------------
 1 files changed, 61 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ef83621c/ui/scripts/templates.js
----------------------------------------------------------------------
diff --git a/ui/scripts/templates.js b/ui/scripts/templates.js
index c3c82c8..35cabfa 100644
--- a/ui/scripts/templates.js
+++ b/ui/scripts/templates.js
@@ -414,54 +414,83 @@
               edit: {
                 label: 'label.edit',
                 action: function(args) {
-                  var array1 = [];
-                  array1.push("&name=" + todb(args.data.name));
-                  array1.push("&displaytext=" + todb(args.data.displaytext));
-                  array1.push("&ostypeid=" + args.data.ostypeid);
-                  array1.push("&passwordenabled=" + 
(args.data.passwordenabled=="on"));
+                                                                 //***** 
updateTemplate *****
+                                                                 var data = {
+                                                                         id: 
args.context.templates[0].id,
+                                                                               
zoneid: args.context.templates[0].zoneid,                                       
                                
+                                                                         name: 
args.data.name,
+                                                                               
displaytext: args.data.displaytext,
+                                                                               
ostypeid: args.data.ostypeid,
+                                                                               
passwordenabled: (args.data.passwordenabled=="on")                              
                                                
+                                                                       };      
   
                   $.ajax({
-                    url: createURL("updateTemplate&id=" + 
args.context.templates[0].id + "&zoneid=" + args.context.templates[0].zoneid + 
array1.join("")),
-                    dataType: "json",
+                    url: createURL('updateTemplate'),
+                    data: data,
                     async: false,
                     success: function(json) {
                       //API returns an incomplete embedded object  (some 
properties are missing in the embedded template object)
                     }
-                  });
-
-                  var array2 = [];
-                  
-                                                                       
//array2.push("&ispublic=" + (args.data.ispublic=="on"));
-                                                                       
if(args.data.ispublic == "on")
-                    array2.push("&ispublic=true");
-                                                                       else 
if(args.data.ispublic == "off")
-                    array2.push("&ispublic=false");    
-                                                                       //if 
args.data.ispublic is undefined, do not pass ispublic to API call.
+                  });                                                          
+                                                                       
                                                                        
-                                                                       
if(args.data.isfeatured == "on")
-                    array2.push("&isfeatured=true");
-                                                                       else 
if(args.data.isfeatured == "off")
-                    array2.push("&isfeatured=false");  
+                                                                       //***** 
updateTemplatePermissions *****
+                  var data = {
+                                                                         id: 
args.context.templates[0].id,
+                                                                               
zoneid: args.context.templates[0].zoneid
+                                                                       };     
+                                                                       
+                                                                       //if 
args.data.ispublic is undefined, do not pass ispublic to API call.
+                                                                       
if(args.data.ispublic == "on") {
+                                                                         
$.extend(data, {
+                                                                               
  ispublic: true
+                                                                               
});                                     
+                  }                                                            
                
+                                                                       else 
if(args.data.ispublic == "off") {
+                                                                         
$.extend(data, {
+                                                                               
  ispublic: false
+                                                                               
});
+                                                                       }       
                                                                                
                                                        
                                                                        //if 
args.data.isfeatured is undefined, do not pass isfeatured to API call.
-                                                                               
          
-                                                                       
if(args.data.isextractable == "on")
-                    array2.push("&isextractable=true");
-                                                                       else 
if(args.data.isextractable == "off")
-                    array2.push("&isextractable=false");       
-                                                                       //if 
args.data.isextractable is undefined, do not pass isextractable to API call.
-                                                                               
                                                                
+                                                                       
if(args.data.isfeatured == "on") {
+                                                                         
$.extend(data, {
+                                                                               
  isfeatured: true
+                                                                               
});
+                                                                       }
+                                                                       else 
if(args.data.isfeatured == "off") {
+                                                                         
$.extend(data, {
+                                                                               
  isfeatured: false
+                                                                               
});                                                                     }       
                                                                
+                                                                       //if 
args.data.isextractable is undefined, do not pass isextractable to API call.    
              
+                                                                       
if(args.data.isextractable == "on") {
+                                                                         
$.extend(data, {
+                                                                               
  isextractable: true
+                                                                               
});                     
+                                                                       }
+                                                                       else 
if(args.data.isextractable == "off") {
+                                                                         
$.extend(data, {
+                                                                               
  isextractable: false
+                                                                               
});
+                  }                                                            
                   $.ajax({
-                    url: createURL("updateTemplatePermissions&id=" + 
args.context.templates[0].id + "&zoneid=" + args.context.templates[0].zoneid + 
array2.join("")),
-                    dataType: "json",
+                    url: createURL('updateTemplatePermissions'),
+                    data: data,
                     async: false,
                     success: function(json) {
                       //API doesn't return an embedded object
                     }
                   });
 
+                                                                       
+                                                                       //***** 
listTemplates *****
                   //So, we call listTemplates API to get a complete template 
object
+                                                                       var 
data = {
+                                                                         id: 
args.context.templates[0].id,
+                                                                               
zoneid: args.context.templates[0].zoneid,
+                                                                               
templatefilter: 'self'
+                                                                       };
                   $.ajax({
-                    url: createURL("listTemplates&id=" + 
args.context.templates[0].id + "&zoneid=" + args.context.templates[0].zoneid + 
"&templatefilter=self"),
-                    dataType: "json",
+                    url: createURL('listTemplates'),
+                    data: data,
                     async: false,
                     success: function(json){
                       var item = json.listtemplatesresponse.template;

Reply via email to