Debian Codegraph @

dojox/form/uploader/_IFrame.js

raw symbols SCIP
1 define([
2 "dojo/query",
3 "dojo/dom-construct",
4 "dojo/_base/declare",
5 "dojo/_base/lang",
6 "dojo/_base/array",
7 "dojo/dom-form",
8 "dojo/request/iframe"
9 ],function(query, domConstruct, declare, lang, arrayUtil, domForm, request){
10
11
12 return declare("dojox.form.uploader._IFrame", [], {
13 // summary:
14 // A mixin for dojox/form/Uploader that adds Ajax upload capabilities via an iframe.
15 //
16 // description:
17 // Only supported by IE, due to the specific iFrame hack used. Progress events are not
18 // supported.
19 //
20 //
21
22 postMixInProperties: function(){
23 this.inherited(arguments);
24 if(this.uploadType === "iframe"){
25 this.uploadType = "iframe";
26 this.upload = this.uploadIFrame;
27 }
28 },
29
30 uploadIFrame: function(data){
31 // summary:
32 // Internal. You could use this, but you should use upload() or submit();
33 // which can also handle the post data.
34
35 var
36 formObject = {},
37 sendForm,
38 form = this.getForm(),
39 url = this.getUrl(),
40 self = this;
41 data = data || {};
42 data.uploadType = this.uploadType;
43
44 // create a temp form for which to send data
45 //enctype can't be changed once a form element is created
46 sendForm = domConstruct.place('<form enctype="multipart/form-data" method="post"></form>', this.domNode);
47 arrayUtil.forEach(this._inputs, function(n, i){
48 // don't send blank inputs
49 if(n.value !== ''){
50 sendForm.appendChild(n);
51 formObject[n.name] = n.value;
52 }
53 }, this);
54
55
56 // add any extra data as form inputs
57 if(data){
58 //formObject = domForm.toObject(form);
59 for(nm in data){
60 if(formObject[nm] === undefined){
61 domConstruct.create('input', {name:nm, value:data[nm], type:'hidden'}, sendForm);
62 }
63 }
64 }
65
66
67 request.post(url, {
68 form: sendForm,
69 handleAs: "json",
70 content: data
71 }).then(function(result){
72 domConstruct.destroy(sendForm);
73 if(result["ERROR"] || result["error"]){
74 self.onError(result);
75 }else{
76 self.onComplete(result);
77 }
78 }, function(err){
79 console.error('error parsing server result', err);
80 domConstruct.destroy(sendForm);
81 self.onError(err);
82 });
83 }
84 });
85 });