0061610c069bf63e9dfefb47088728ec35888f66
[Pman.Core] / Pman.Dialog.ImageUpload.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.ImageUpload = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             listeners : {
34                 keydown : function (_self, e)
35                 {
36                     Roo.log(e);
37                 }
38             },
39             closable : false,
40             collapsible : false,
41             haveProgress : false,
42             height : 140,
43             modal : true,
44             resizable : true,
45             title : "Upload an Image or File",
46             uploadProgress : false,
47             width : 500,
48             shadow : true,
49             uploadProgres : function()
50             {
51                 var dlg = this;
52                if (!dlg.haveProgress) {
53                     Roo.MessageBox.progress("Uploading", "Uploading");
54                 }
55                 if (dlg.uploadComplete) {
56                     Roo.MessageBox.hide();
57                     return;
58                 }
59                 dlg.haveProgress = true;
60             
61                 var uid = _this.form.findField('UPLOAD_IDENTIFIER').getValue();
62                 Pman.request({
63                     url : baseURL + '/Core/UploadProgress.php',
64                     params: {
65                         id : uid
66                     },
67                     method: 'GET',
68                     success : function(data){
69                         //console.log(data);
70                         if (dlg.uploadComplete) {
71                             Roo.MessageBox.hide();
72                             return;
73                         }
74                             
75                         if (data){
76                             Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
77                                 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
78                             );
79                         }
80                         dlg.uploadProgress.defer(2000,dlg);
81                     },
82                     failure: function(data) {
83                       //  console.log('fail');
84                      //   console.log(data);
85                     }
86                 })
87                 
88             },
89             items : [
90                 {
91                     xtype: 'ContentPanel',
92                     xns: Roo,
93                     fitToFrame : true,
94                     region : 'center',
95                     items : [
96                         {
97                             xtype: 'Form',
98                             xns: Roo.form,
99                             listeners : {
100                                 actioncomplete : function(_self,act)
101                                 {
102                                        _this.dialog.uploadComplete = true;
103                                         _this.dialog.el.unmask();
104                                          
105                                           if (act.type == 'setdata') { 
106                                          
107                                               this.findField('UPLOAD_IDENTIFIER').setValue(
108                                                 (new Date() * 1) + '' + Math.random());
109                                             return;
110                                          }
111                                          
112                                        
113                                         if (act.type == 'load') {
114                                           // should this happen?  
115                                             _this.data = act.result.data;
116                                            // _this.loaded();
117                                             return;
118                                         }
119                                         
120                                         
121                                         if (act.type == 'submit') { // only submitted here if we are 
122                                             _this.dialog.hide();
123                                             //console.log(act);
124                                             if (_this.callback) {
125                                                 _this.callback.call(this, act.result.data);
126                                             }
127                                             return; 
128                                         }
129                                 },
130                                 rendered : function (form)
131                                 {
132                                     _this.form= form;
133                                 },
134                                 actionfailed : function (_self, act)
135                                 {
136                                     _this.dialog.uploadComplete = true;
137                                     _this.dialog.el.unmask();
138                                     // error msg???
139                                     
140                                     if (act.type == 'submit') {
141                                         Ext.MessageBox.alert("Error", "Saving failed = fix errors and try again");
142                                         return;
143                                     }
144                                     
145                                     // what about load failing..
146                                     Ext.MessageBox.alert("Error", "Error loading details"); 
147                                 }
148                             },
149                             labelWidth : 140,
150                             method : 'POST',
151                             style : 'margin:10px;',
152                             url : baseURL + '/Roo/Images.php',
153                             items : [
154                                 {
155                                     xtype: 'Hidden',
156                                     xns: Roo.form,
157                                     name : 'UPLOAD_IDENTIFIER'
158                                 },
159                                 {
160                                     xtype: 'TextField',
161                                     xns: Roo.form,
162                                     fieldLabel : 'Upload Image or File',
163                                     inputType : 'file',
164                                     name : 'image',
165                                     width : 200
166                                 },
167                                 {
168                                     xtype: 'Hidden',
169                                     xns: Roo.form,
170                                     name : 'ontable'
171                                 },
172                                 {
173                                     xtype: 'Hidden',
174                                     xns: Roo.form,
175                                     name : 'onid'
176                                 },
177                                 {
178                                     xtype: 'Hidden',
179                                     xns: Roo.form,
180                                     name : 'imgtype'
181                                 },
182                                 {
183                                     xtype: 'Hidden',
184                                     xns: Roo.form,
185                                     name : 'post_max_size',
186                                     value : "32M"
187                                 },
188                                 {
189                                     xtype: 'Hidden',
190                                     xns: Roo.form,
191                                     name : 'upload_max_filesize',
192                                     value : "32M"
193                                 }
194                             ]
195                         }
196                     ]
197                 }
198             ],
199             center : {
200                 xtype: 'LayoutRegion',
201                 xns: Roo
202             },
203             buttons : [
204                 {
205                     xtype: 'Button',
206                     xns: Roo,
207                     listeners : {
208                         click : function (_self, e)
209                         {
210                             _this.dialog.hide();
211                         }
212                     },
213                     text : "Cancel"
214                 },
215                 {
216                     xtype: 'Button',
217                     xns: Roo,
218                     listeners : {
219                         click : function (_self, e)
220                         {
221                             // do some checks?
222                              
223                             _this.dialog.el.mask("Sending");
224                             _this.dialog.uploadComplete = false;
225                             _this.form.doAction('submit', {
226                                 url: baseURL + '/Roo/Images.html',
227                                 method: 'POST',
228                                 params: {
229                                  //   _id: 0 ,
230                                     ts : Math.random()
231                                 } 
232                             });
233                             _this.dialog.haveProgress = false,
234                             _this.dialog.uploadProgress.defer(1000, _this.dialog);
235                         
236                         }
237                     },
238                     text : "Post"
239                 }
240             ]
241         });
242     }
243 };