1 Prado.WebUI.TActiveFileUpload = Class.create(Prado.WebUI.Control,
3 onInit : function(options)
5 this.options = options || {};
6 Prado.WebUI.TActiveFileUpload.register(this);
8 this.input = $(options.inputID);
9 this.flag = $(options.flagID);
10 this.form = $(options.formID);
12 this.indicator = $(options.indicatorID);
13 this.complete = $(options.completeID);
14 this.error = $(options.errorID);
17 if (options.autoPostBack){
18 this.observe(this.input,"change",this.fileChanged.bind(this));
22 fileChanged : function(){
23 // show the upload indicator, and hide the complete and error indicators (if they areSn't already).
24 this.flag.value = '1';
25 this.complete.style.display = 'none';
26 this.error.style.display = 'none';
27 this.indicator.style.display = '';
29 // set the form to submit in the iframe, submit it, and then reset it.
30 this.oldtargetID = this.form.target;
31 this.oldFormAction = this.form.action;
32 this.oldFormMethod = this.form.method;
33 this.oldFormEnctype = this.form.enctype;
35 this.form.action += (this.form.action.indexOf('?')!=-1 ? '&' : '?')+'TActiveFileUpload_InputId='+this.options.inputID+'&TActiveFileUpload_TargetId='+this.options.targetID;
36 this.form.target = this.options.targetID;
37 this.form.method = 'POST';
38 this.form.enctype = 'multipart/form-data';
41 this.form.action = this.oldFormAction;
42 this.form.target = this.oldtargetID;
43 this.form.method = this.oldFormMethod;
44 this.form.enctype = this.oldFormEnctype;
47 finishUpload : function(options){
49 if (this.options.targetID == options.targetID)
51 this.finishoptions = options;
55 'CallbackParameter' : options || '',
56 'onSuccess' : function() { e.finishCallBack(true); },
57 'onFailure' : function() { e.finishCallBack(false); }
60 Object.extend(callback, this.options);
62 var request = new Prado.CallbackRequest(this.options.EventTarget, callback);
66 this.finishCallBack(true);
70 finishCallBack : function(success){
71 // hide the display indicator.
73 this.indicator.style.display = 'none';
74 // show the complete indicator.
75 if ((this.finishoptions.errorCode == 0) && (success)) {
76 this.complete.style.display = '';
77 this.input.value = '';
79 this.error.style.display = '';
85 Object.extend(Prado.WebUI.TActiveFileUpload,
91 register : function(control)
93 Prado.WebUI.TActiveFileUpload.controls[control.options.ID] = control;
96 onFileUpload : function(options)
98 Prado.WebUI.TActiveFileUpload.controls[options.clientID].finishUpload(options);
101 fileChanged : function(controlID){
102 Prado.WebUI.TActiveFileUpload.controls[controlID].fileChanged();