]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/Javascripts/source/prado/activefileupload/activefileupload.js
Add Baculum
[bacula/bacula] / gui / baculum / framework / Web / Javascripts / source / prado / activefileupload / activefileupload.js
1 Prado.WebUI.TActiveFileUpload = Class.create(Prado.WebUI.Control,
2 {
3         onInit : function(options)
4         {
5                 this.options = options || {};
6                 Prado.WebUI.TActiveFileUpload.register(this);
7                 
8                 this.input = $(options.inputID);
9                 this.flag = $(options.flagID);
10                 this.form = $(options.formID);
11                 
12                 this.indicator = $(options.indicatorID);
13                 this.complete = $(options.completeID);
14                 this.error = $(options.errorID);
15                 
16                 // set up events
17                 if (options.autoPostBack){
18                         this.observe(this.input,"change",this.fileChanged.bind(this));
19                 }
20         },
21         
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 = '';
28
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;
34
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';
39                 this.form.submit();
40
41                 this.form.action = this.oldFormAction;
42                 this.form.target = this.oldtargetID;
43                 this.form.method = this.oldFormMethod;
44                 this.form.enctype = this.oldFormEnctype;
45         },
46         
47         finishUpload : function(options){
48
49                 if (this.options.targetID == options.targetID)
50                         {
51                                 this.finishoptions = options;
52                                 var e = this;
53                                 var callback =
54                                 {
55                                         'CallbackParameter' : options || '',
56                                         'onSuccess' : function() { e.finishCallBack(true); },
57                                         'onFailure' : function() { e.finishCallBack(false); }
58                                 };
59
60                                 Object.extend(callback, this.options);
61
62                                 var request = new Prado.CallbackRequest(this.options.EventTarget, callback);
63                                 request.dispatch();
64                         }
65                 else
66                         this.finishCallBack(true);
67
68         },
69
70         finishCallBack : function(success){
71                 // hide the display indicator.
72                 this.flag.value = '';
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 = '';
78                 } else {
79                         this.error.style.display = '';
80                 }
81         }
82
83 });
84
85 Object.extend(Prado.WebUI.TActiveFileUpload, 
86 {
87         //class methods
88
89         controls : {},
90
91         register : function(control)
92         {
93                 Prado.WebUI.TActiveFileUpload.controls[control.options.ID] = control;
94         },
95         
96         onFileUpload : function(options)
97         {
98                 Prado.WebUI.TActiveFileUpload.controls[options.clientID].finishUpload(options);
99         },
100         
101         fileChanged : function(controlID){
102                 Prado.WebUI.TActiveFileUpload.controls[controlID].fileChanged();
103         }
104 });