Index: trunk/zoo-project/zoo-api/js/ZOO-api.js
===================================================================
--- trunk/zoo-project/zoo-api/js/ZOO-api.js	(revision 828)
+++ trunk/zoo-project/zoo-api/js/ZOO-api.js	(revision 917)
@@ -3686,12 +3686,32 @@
 	}
 	var builder = this.parseData[data.localName().toLowerCase()];
-	if (builder)
+	if (builder){
 	  res.push(builder.apply(this,[data]));
+	}
 	else
 	  res.push(null);
+	data=null;
       }
       return res.length>1?res:res[0];
-    } else
-      return null;
+    }
+    else{
+      var hasPercentCompleted=true;
+      var status = node.*::Status.*::ProcessStarted;
+      var msg = node.*::Status.*::ProcessStarted.*::*[0];
+      if(!status || !msg){
+        status = node.*::Status.*::ProcessAccepted;
+	msg = node.*::Status.*::ProcessAccepted.*::*[0];
+	msg=msg.toString();
+        hasPercentCompleted=false;
+      }else
+	  msg=msg.toString();
+      if(status!=null && node.@statusLocation){
+        var res={"status": node.@statusLocation.toXMLString(), "message": msg};
+	if(hasPercentCompleted)
+	  res["percentCompleted"]=status.@percentCompleted.toXMLString();
+        return res;
+      }else
+	return null;
+    }
   },
   /**
@@ -3748,6 +3768,8 @@
      * {Object} A WPS reference response.
      */
-    'reference': function(node) {
-      var result = {type:'reference',value:node.@href};
+    'reference': function(lnode) {
+      var lhref=lnode.@href;
+      var lmimeType=lnode.@mimeType;
+      var result = {type:'reference',value:lhref.toXMLString(),mimeType:lmimeType.toXMLString()};
       return result;
     }
@@ -6147,4 +6169,9 @@
   identifier: null,
   /**
+   * Property: async
+   * {Bool} Define if the process should run asyncrhonously (true) or not (false, default).
+   */
+  async: null,
+  /**
    * Constructor: ZOO.Process
    * Create a new Process
@@ -6158,4 +6185,5 @@
     this.url = url;
     this.identifier = identifier;
+    this.async = (arguments.length>2?arguments[2]:false);
   },
   /**
@@ -6173,10 +6201,10 @@
     if (this.identifier == null)
       return null;
-    var body = new XML('<wps:Execute service="WPS" version="1.0.0" xmlns:wps="'+this.namespaces['wps']+'" xmlns:ows="'+this.namespaces['ows']+'" xmlns:xlink="'+this.namespaces['xlink']+'" xmlns:xsi="'+this.namespaces['xsi']+'" xsi:schemaLocation="'+this.schemaLocation+'"><ows:Identifier>'+this.identifier+'</ows:Identifier>'+this.buildDataInputsNode(inputs)+this.buildDataOutputsNode(outputs)+'</wps:Execute>');
+      var body = new XML('<wps:Execute service="WPS" version="1.0.0" xmlns:wps="'+this.namespaces['wps']+'" xmlns:ows="'+this.namespaces['ows']+'" xmlns:xlink="'+this.namespaces['xlink']+'" xmlns:xsi="'+this.namespaces['xsi']+'" xsi:schemaLocation="'+this.schemaLocation+'"><ows:Identifier>'+this.identifier+'</ows:Identifier>'+this.buildDataInputsNode(inputs)+this.buildDataOutputsNode(outputs)+'</wps:Execute>');
     body = body.toXMLString();
     var headers=['Content-Type: text/xml; charset=UTF-8'];
-      if(arguments.length>2){
-	headers[headers.length]=arguments[2];
-      }
+    if(arguments.length>2){
+      headers[headers.length]=arguments[2];
+    }
     var response = ZOO.Request.Post(this.url,body,headers);
     return response;
@@ -6195,5 +6223,10 @@
      */
     'ResponseDocument': function(identifier,obj) {
-      var output = new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'"><wps:ResponseDocument><wps:Output'+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+(obj["asReference"]?' asReference="'+obj["asReference"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:Output></wps:ResponseDocument></wps:ResponseForm>');
+      var output = new XML('<wps:Output xmlns:wps="'+this.namespaces['wps']+'" '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+(obj["asReference"]?' asReference="'+obj["asReference"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:Output>');
+      output = output.toXMLString();
+      return output;
+    },
+    'RawDataOutput': function(identifier,obj) {
+      var output = new XML('<wps:RawDataOutput xmlns:wps="'+this.namespaces['wps']+'" '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:RawDataOutput>');
       if (obj.encoding)
         output.*::Data.*::ComplexData.@encoding = obj.encoding;
@@ -6202,13 +6235,4 @@
       output = output.toXMLString();
       return output;
-    },
-    'RawDataOutput': function(identifier,obj) {
-      var output = new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'"><wps:RawDataOutput '+(obj["mimeType"]?' mimeType="'+obj["mimeType"]+'" ':'')+(obj["encoding"]?' encoding="'+obj["encoding"]+'" ':'')+'><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier></wps:RawDataOutput></wps:ResponseForm>');
-      if (obj.encoding)
-        output.*::Data.*::ComplexData.@encoding = obj.encoding;
-      if (obj.schema)
-        output.*::Data.*::ComplexData.@schema = obj.schema;
-      output = output.toXMLString();
-      return output;
     }
 
@@ -6231,9 +6255,9 @@
      */
     'complex': function(identifier,data) {
-      var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>');
+      var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData '+(data.mimeType?'mimeType="'+data.mimeType+'"':"")+'><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>');
       if(data.xlink)
-	input.*::Reference.@mimeType = data.mimetype ? data.mimetype : 'application/json';
+        input.*::Reference.@mimeType = data.mimetype ? data.mimetype : 'application/json';
       else
-	input.*::Data.*::ComplexData.@mimeType = data.mimetype ? data.mimetype : 'application/json';
+        input.*::Data.*::ComplexData.@mimeType = data.mimetype ? data.mimetype : 'application/json';
       if (data.encoding)
         input.*::Data.*::ComplexData.@encoding = data.encoding;
@@ -6241,5 +6265,8 @@
         input.*::Data.*::ComplexData.@schema = data.schema;
       input = input.toXMLString();
-      return input;
+      if(data.value)
+        return (('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier>'+(data.value?'<wps:Data><wps:ComplexData '+(data.mimeType?'mimeType="'+data.mimeType+'"':"")+'><![CDATA['+data.value+']]></wps:ComplexData></wps:Data>':(data.xlink?'<wps:Reference xmlns:xlink="'+this.namespaces['xlink']+'" xlink:href="'+data.xlink+'" mimeType="'+data.mimeType+'" />':''))+'</wps:Input>'));
+      else
+        return input;
     },
     /**
@@ -6269,25 +6296,24 @@
      */
     'literal': function(identifier,data) {
-	if(data && !eval(data["isArray"])){
-	    var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
-      if (data.type)
-        input.*::Data.*::LiteralData.@dataType = data.type;
-      if (data.uom)
-        input.*::Data.*::LiteralData.@uom = data.uom;
-      input = input.toXMLString();
-      return input;
-	}else if(data){
-	    var inputf="";
-	    for(i=0;i<parseInt(data["length"]);i++){
-		var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>');
-		if (data.type)
-		    input.*::Data.*::LiteralData.@dataType = data.type;
-		if (data.uom)
-		    input.*::Data.*::LiteralData.@uom = data.uom;
-		inputf += input.toXMLString();
-	    }
-	    return inputf;
+      if(data && !eval(data["isArray"])){
+        var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value+'</wps:LiteralData></wps:Data></wps:Input>');
+        if (data.type)
+	  input.*::Data.*::LiteralData.@dataType = data.type;
+        if (data.uom)
+	  input.*::Data.*::LiteralData.@uom = data.uom;
+        input = input.toXMLString();
+        return input;
+      }else if(data){
+        var inputf="";
+        for(i=0;i<parseInt(data["length"]);i++){
+	  var input = new XML('<wps:Input xmlns:wps="'+this.namespaces['wps']+'"><ows:Identifier xmlns:ows="'+this.namespaces['ows']+'">'+identifier+'</ows:Identifier><wps:Data><wps:LiteralData>'+data.value[i]+'</wps:LiteralData></wps:Data></wps:Input>');
+	  if (data.type)
+	    input.*::Data.*::LiteralData.@dataType = data.type;
+	  if (data.uom)
+	    input.*::Data.*::LiteralData.@uom = data.uom;
+	  inputf += input.toXMLString();
 	}
-	
+        return inputf;
+      }	
     }
   },
@@ -6318,11 +6344,28 @@
 
   buildDataOutputsNode:function(outputs){
-    var data, builder, outputsArray=[];
+    var data, builder, outputsArray=[[],[]];
     for (var attr in outputs) {
       data = outputs[attr];
       builder = this.buildOutput[data.type];
-      outputsArray.push(builder.apply(this,[attr,data]));
-    }
-    return outputsArray.join('\n');
+      if(data.type=="ResponseDocument")
+        outputsArray[0].push(builder.apply(this,[attr,data]));
+      else
+        outputsArray[1].push(builder.apply(this,[attr,data]));	    
+    }
+    var responseDocuments=(outputsArray[0].length>0?
+			   new XML('<wps:ResponseDocument  '+(this.async?'storeExecuteResponse="true" status="true"':'')+' xmlns:wps="'+this.namespaces['wps']+'">'+
+				   outputsArray[0].join('\n')+
+				   '</wps:ResponseDocument>')
+			   :
+			   null);
+    var rawDataOutputs=(outputsArray[1].length>0?
+			outputsArray[1].join('\n')
+			:
+			null);
+    var res=new XML('<wps:ResponseForm xmlns:wps="'+this.namespaces['wps']+'">'+
+		    (responseDocuments!=null?responseDocuments.toXMLString():"")+
+		    (rawDataOutputs!=null?rawDataOutputs:"")+
+		    '</wps:ResponseForm>');
+    return res.toXMLString();
   },
 
