]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/Javascripts/source/prado/activefileupload/activefileupload.js
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / Javascripts / source / prado / activefileupload / activefileupload.js
1 Prado.WebUI.TActiveFileUpload = jQuery.klass(Prado.WebUI.Control,
2 {
3         onInit : function(options)
4         {
5                 this.options = options || {};
6                 Prado.WebUI.TActiveFileUpload.register(this);
7
8                 this.input = jQuery('#'+options.inputID).get(0);
9                 this.flag = jQuery('#'+options.flagID).get(0);
10                 this.form = jQuery('#'+options.formID).get(0);
11
12                 this.indicator = jQuery('#'+options.indicatorID).get(0);
13                 this.complete = jQuery('#'+options.completeID).get(0);
14                 this.error = jQuery('#'+options.errorID).get(0);
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                 // ie11 fix
24                 if(this.input.value=='') return;
25                 // show the upload indicator, and hide the complete and error indicators (if they areSn't already).
26                 this.flag.value = '1';
27                 this.complete.style.display = 'none';
28                 this.error.style.display = 'none';
29                 this.indicator.style.display = '';
30
31                 // set the form to submit in the iframe, submit it, and then reset it.
32                 this.oldtargetID = this.form.target;
33                 this.oldFormAction = this.form.action;
34                 this.oldFormMethod = this.form.method;
35                 this.oldFormEnctype = this.form.enctype;
36
37                 this.form.action += (this.form.action.indexOf('?')!=-1 ? '&' : '?')+'TActiveFileUpload_InputId='+this.options.inputID+'&TActiveFileUpload_TargetId='+this.options.targetID;
38                 this.form.target = this.options.targetID;
39                 this.form.method = 'POST';
40                 this.form.enctype = 'multipart/form-data';
41                 this.form.submit();
42
43                 this.form.action = this.oldFormAction;
44                 this.form.target = this.oldtargetID;
45                 this.form.method = this.oldFormMethod;
46                 this.form.enctype = this.oldFormEnctype;
47         },
48
49         finishUpload : function(options){
50
51                 if (this.options.targetID == options.targetID)
52                 {
53                         this.finishoptions = options;
54                         var e = this;
55                         var callback =
56                         {
57                                 'CallbackParameter' : options || '',
58                                 'onSuccess' : function() { e.finishCallBack(true); },
59                                 'onFailure' : function() { e.finishCallBack(false); }
60                         };
61
62                         jQuery.extend(callback, this.options);
63
64                         var request = new Prado.CallbackRequest(this.options.EventTarget, callback);
65                         request.dispatch();
66                 }
67                 else
68                         this.finishCallBack(true);
69
70         },
71
72         finishCallBack : function(success){
73                 // hide the display indicator.
74                 this.flag.value = '';
75                 this.indicator.style.display = 'none';
76                         // show the complete indicator.
77                         if ((this.finishoptions.errorCode == 0) && (success)) {
78                                 this.complete.style.display = '';
79                                 this.input.value = '';
80                         } else {
81                                 this.error.style.display = '';
82                         }
83         }
84
85 });
86
87 jQuery.extend(Prado.WebUI.TActiveFileUpload,
88 {
89         //class methods
90
91         controls : {},
92
93         register : function(control)
94         {
95                 Prado.WebUI.TActiveFileUpload.controls[control.options.ID] = control;
96         },
97
98         onFileUpload : function(options)
99         {
100                 Prado.WebUI.TActiveFileUpload.controls[options.clientID].finishUpload(options);
101         },
102
103         fileChanged : function(controlID){
104                 Prado.WebUI.TActiveFileUpload.controls[controlID].fileChanged();
105         }
106 });