| 7 | | function _createPart(args, boundary){ |
| | 5 | /*===== |
| | 6 | dojox.io.__xhrContentArgs = function(){ |
| | 7 | // name: String |
| | 8 | // Name of the form value. |
| | 9 | // content: String |
| | 10 | // The contents of the value. |
| | 11 | // filename: String? |
| | 12 | // An optional filename to pass to the server, as defined by the boundary. |
| | 13 | // contentType: String? |
| | 14 | // An optional content-type (MIME) to pass to the server, if value is being |
| | 15 | // treated as a file. |
| | 16 | // charset: String? |
| | 17 | // Optional charset to pass, for the server to interpret the file correctly. |
| | 18 | // contentTransferEncoding: String? |
| | 19 | // Optional transfer encoding header value. |
| | 20 | this.name = name; |
| | 21 | this.content = content; |
| | 22 | this.filename = filename; |
| | 23 | this.contentType = contentType; |
| | 24 | this.charset = charset; |
| | 25 | this.contentTransferEncoding = contentTransferEncoding; |
| | 26 | } |
| | 27 | =====*/ |
| | 28 | function _createPart(/* dojox.io.__xhrContentArgs */args, /* String */boundary){ |
| | 29 | // summary |
| | 30 | // Assemble an array of boundary parts based on the passed values in args. |
| 34 | | function _needIframe(node){ |
| 35 | | return (!!(dojo.query("input[type=file]", node).length)); |
| | 56 | function _partsFromNode(/* DOMNode */node, /* String */boundary){ |
| | 57 | // summary |
| | 58 | // Assemble an array of boundary parts based on the passed FORM node. |
| | 59 | var o=dojo.formToObject(node), parts=[]; |
| | 60 | for(var p in o){ |
| | 61 | if(dojo.isArray(o[p])){ |
| | 62 | dojo.forEach(o[p], function(item){ |
| | 63 | parts = parts.concat(_createPart({ name: p, content: item }, boundary)); |
| | 64 | }); |
| | 65 | } else { |
| | 66 | parts = parts.concat(_createPart({ name: p, content: o[p] }, boundary)); |
| | 67 | } |
| | 68 | } |
| | 69 | return parts; // Array |
| 38 | | function _partsFromNode(node, boundary){ |
| 39 | | // TODO: write this function! |
| 40 | | var tmp = []; |
| 41 | | return tmp; |
| | 72 | /*===== |
| | 73 | dojox.io.__xhrMultiArgs = function(){ |
| | 74 | // url: String |
| | 75 | // URL to server endpoint. |
| | 76 | // content: Object? |
| | 77 | // Contains properties with string values. These |
| | 78 | // properties will be serialized using multi-part |
| | 79 | // boundaries. |
| | 80 | // file: Object? |
| | 81 | // Alias for "content". Provided for backwards compatibility. |
| | 82 | // timeout: Integer? |
| | 83 | // Milliseconds to wait for the response. If this time |
| | 84 | // passes, the then error callbacks are called. |
| | 85 | // form: DOMNode? |
| | 86 | // DOM node for a form. Used to extract the form values |
| | 87 | // and send to the server; each form value will be serialized |
| | 88 | // using multi-part boundaries. |
| | 89 | // preventCache: Boolean? |
| | 90 | // Default is false. If true, then a |
| | 91 | // "dojo.preventCache" parameter is sent in the request |
| | 92 | // with a value that changes with each request |
| | 93 | // (timestamp). Useful only with GET-type requests. |
| | 94 | // handleAs: String? |
| | 95 | // Acceptable values depend on the type of IO |
| | 96 | // transport (see specific IO calls for more information). |
| | 97 | // load: Function? |
| | 98 | // function(response, ioArgs){}. response is an Object, ioArgs |
| | 99 | // is of type dojo.__IoCallbackArgs. The load function will be |
| | 100 | // called on a successful response. |
| | 101 | // error: Function? |
| | 102 | // function(response, ioArgs){}. response is an Object, ioArgs |
| | 103 | // is of type dojo.__IoCallbackArgs. The error function will |
| | 104 | // be called in an error case. |
| | 105 | // handle: Function? |
| | 106 | // function(response, ioArgs){}. response is an Object, ioArgs |
| | 107 | // is of type dojo.__IoCallbackArgs. The handle function will |
| | 108 | // be called in either the successful or error case. |
| | 109 | this.url = url; |
| | 110 | this.content = content; |
| | 111 | this.file = file; |
| | 112 | this.timeout = timeout; |
| | 113 | this.form = form; |
| | 114 | this.preventCache = preventCache; |
| | 115 | this.handleAs = handleAs; |
| | 116 | this.load = load; |
| | 117 | this.error = error; |
| | 118 | this.handle = handle; |
| 50 | | var boundary = dojox.uuid.generateRandomUuid(); |
| 51 | | |
| 52 | | var tmp = []; |
| 53 | | var out = ""; |
| 54 | | |
| 55 | | if(args["file"]){ |
| 56 | | var d = (dojo.isArray(args.file) ? args.file : [args.file]); |
| 57 | | |
| 58 | | for(var i=0; i < d.length; i++){ |
| 59 | | tmp = tmp.concat(_createPart(d[i], boundary)); |
| | 127 | var boundary=dojox.uuid.generateRandomUuid(), tmp=[], out=""; |
| | 128 | if(args["file"] || args["content"]){ |
| | 129 | var v = args["file"] || args["content"]; |
| | 130 | dojo.forEach((dojo.isArray(v) ? v : [v]), function(item){ |
| | 131 | tmp = tmp.concat(_createPart(item, boundary)); |
| | 132 | }); |
| | 133 | } |
| | 134 | else if(args["form"]){ |
| | 135 | if(dojo.query("input[type=file]", args["form"]).length){ |
| | 136 | throw new Error("dojox.io.xhrMultiPart cannot post files that are values of an INPUT TYPE=FILE. Use dojo.io.iframe.send() instead."); |