Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / io / xhrMultiPart.js @ 12

History | View | Annotate | Download (1.93 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

    
8
if(!dojo._hasResource["dojox.io.xhrMultiPart"]){
9
dojo._hasResource["dojox.io.xhrMultiPart"]=true;
10
dojo.provide("dojox.io.xhrMultiPart");
11
dojo.require("dojox.uuid.generateRandomUuid");
12
(function(){
13
function _1(_2,_3){
14
if(!_2["name"]&&!_2["content"]){
15
throw new Error("Each part of a multi-part request requires 'name' and 'content'.");
16
}
17
var _4=[];
18
_4.push("--"+_3,"Content-Disposition: form-data; name=\""+_2.name+"\""+(_2["filename"]?"; filename=\""+_2.filename+"\"":""));
19
if(_2["contentType"]){
20
var ct="Content-Type: "+_2.contentType;
21
if(_2["charset"]){
22
ct+="; Charset="+_2.charset;
23
}
24
_4.push(ct);
25
}
26
if(_2["contentTransferEncoding"]){
27
_4.push("Content-Transfer-Encoding: "+_2.contentTransferEncoding);
28
}
29
_4.push("",_2.content);
30
return _4;
31
};
32
function _5(_6,_7){
33
var o=dojo.formToObject(_6),_8=[];
34
for(var p in o){
35
if(dojo.isArray(o[p])){
36
dojo.forEach(o[p],function(_9){
37
_8=_8.concat(_1({name:p,content:_9},_7));
38
});
39
}else{
40
_8=_8.concat(_1({name:p,content:o[p]},_7));
41
}
42
}
43
return _8;
44
};
45
dojox.io.xhrMultiPart=function(_a){
46
if(!_a["file"]&&!_a["content"]&&!_a["form"]){
47
throw new Error("content, file or form must be provided to dojox.io.xhrMultiPart's arguments");
48
}
49
var _b=dojox.uuid.generateRandomUuid(),_c=[],_d="";
50
if(_a["file"]||_a["content"]){
51
var v=_a["file"]||_a["content"];
52
dojo.forEach((dojo.isArray(v)?v:[v]),function(_e){
53
_c=_c.concat(_1(_e,_b));
54
});
55
}else{
56
if(_a["form"]){
57
if(dojo.query("input[type=file]",_a["form"]).length){
58
throw new Error("dojox.io.xhrMultiPart cannot post files that are values of an INPUT TYPE=FILE.  Use dojo.io.iframe.send() instead.");
59
}
60
_c=_5(_a["form"],_b);
61
}
62
}
63
if(_c.length){
64
_c.push("--"+_b+"--","");
65
_d=_c.join("\r\n");
66
}
67
return dojo.rawXhrPost(dojo.mixin(_a,{contentType:"multipart/form-data; boundary="+_b,postData:_d}));
68
};
69
})();
70
}