DataObjects/Core_person_signup.php
[Pman.Core] / Pman.Dialog.Image.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Roo.namespace('Pman.Dialog');
6
7 Pman.Dialog.Image = {
8
9     dialog : false,
10     callback:  false,
11
12     show : function(data, cb)
13     {
14         if (!this.dialog) {
15             this.create();
16         }
17
18         this.callback = cb;
19         this.data = data;
20         this.dialog.show(this.data._el);
21         if (this.form) {
22            this.form.reset();
23            this.form.setValues(data);
24            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
25         }
26
27     },
28
29     create : function()
30     {
31         var _this = this;
32         this.dialog = Roo.factory({
33             center : {
34                 '|xns' : 'Roo',
35                 xtype : 'LayoutRegion',
36                 xns : Roo
37             },
38             '|xns' : 'Roo',
39             modal : true,
40             shadow : true,
41             collapsible : false,
42             title : "Upload an Image or File",
43             xtype : 'LayoutDialog',
44             uploadComplete : false,
45             width : 500,
46             xns : Roo,
47             closable : false,
48             resizable : false,
49             haveProgress : false,
50             height : 140,
51             uploadProgress : function()
52             {
53                 var dlg = this;
54                if (!dlg.haveProgress) {
55                     Roo.MessageBox.progress("Uploading", "Uploading");
56                 }
57                 
58                 if (dlg.haveProgress == 2) {
59                     // it's been closed elsewhere..
60                     return;
61                 }
62                 if (dlg.uploadComplete) {
63                     Roo.MessageBox.hide();
64                     return;
65                 }
66                 
67                 dlg.haveProgress = 1;
68             
69                 var uid = _this.form.findField('UPLOAD_IDENTIFIER').getValue();
70                 new Pman.Request({
71                     url : baseURL + '/Core/UploadProgress.php',
72                     params: {
73                         id : uid
74                     },
75                     method: 'GET',
76                     success : function(res){
77                         //console.log(data);
78                         var data = res.data;
79                         if (dlg.haveProgress == 2) {
80                             // it's been closed elsewhere..
81                             return;
82                         }
83                         
84                         if (dlg.uploadComplete) {
85                             Roo.MessageBox.hide();
86                             return;
87                         }
88                             
89                         if (data){
90                             Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
91                                 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
92                             );
93                         } else {
94                             Roo.MessageBox.updateProgress(1,
95                                 "Upload Complete - processing"
96                             );
97                             return;
98                         }
99                         dlg.uploadProgress.defer(2000,dlg);
100                     },
101                     failure: function(data) {
102                       //  console.log('fail');
103                      //   console.log(data);
104                     }
105                 })
106                 
107             },
108             buttons : [
109                  {
110                         '|xns' : 'Roo',
111                         text : "Cancel",
112                         xtype : 'Button',
113                         xns : Roo,
114                         listeners : {
115                                 click : function (_self, e)
116                                    {
117                                        _this.dialog.hide();
118                                    }
119                         }
120                     },
121 {
122                         '|xns' : 'Roo',
123                         text : "Upload",
124                         xtype : 'Button',
125                         xns : Roo,
126                         listeners : {
127                                 click : function (_self, e)
128                                    {
129                                        // do some checks?
130                                         
131                                        //_this.dialog.el.mask("Sending");
132                                        _this.dialog.uploadComplete = false;
133                                        _this.form.doAction('submit', {
134                                            params: {
135                                                ts : Math.random()
136                                            } 
137                                        });
138                                        _this.dialog.haveProgress = 0; // set to show..
139                                        _this.dialog.uploadProgress.defer(1000, _this.dialog);
140                                    
141                                    }
142                         }
143                     }
144             ],
145             listeners : {
146                 show : function (_self)
147                    {
148                    
149                        // this does not really work - escape on the borders works..
150                        // resize to fit.. if we have styled stuff...
151                        
152                        
153                        
154                        
155                        var d = this;
156                        
157                        var pad =     d.el.getSize().height - (d.header.getSize().height +
158                            d.footer.getSize().height +        
159                            d.layout.getRegion('center').getPanel(0).el.getSize().height
160                            );
161                        
162                        var height = (
163                            pad + 
164                            d.header.getSize().height +
165                            d.footer.getSize().height +        
166                            d.layout.getRegion('center').getPanel(0).el.child('div').getSize().height
167                        );
168                        this.resizeTo(d.el.getSize().width, height);
169                        
170                        if (this.keylistener) {
171                            return;
172                        }
173                        this.keylistener = this.addKeyListener(27, this.hide, this);
174                        
175                    }
176             },
177             items : [
178                 {
179                     '|xns' : 'Roo',
180                     fitToFrame : true,
181                     region : 'center',
182                     xtype : 'ContentPanel',
183                     xns : Roo,
184                     items : [
185                         {
186                             '|xns' : 'Roo.form',
187                             url : baseURL + '/Roo/Images.php',
188                             fileUpload : true,
189                             method : 'POST',
190                             style : 'margin:10px;',
191                             xtype : 'Form',
192                             labelWidth : 140,
193                             timeout : 300,
194                             xns : Roo.form,
195                             listeners : {
196                                 actionfailed : function (_self, act)
197                                    {
198                                       
199                                       
200                                        _this.dialog.uploadComplete = true;
201                                       // _this.dialog.el.unmask();
202                                        // error msg???
203                                         _this.dialog.haveProgress = 2; 
204                                        if (act.type == 'submit') {
205                                            Roo.log("Upload error");
206                                            Roo.log(act);
207                                            
208                                            try {
209                                                Roo.MessageBox.alert("Error", act.result.errorMsg.split(/\n/).join('<BR/>'));
210                                            } catch(e) {
211                                              //  Roo.log(e);
212                                                Roo.MessageBox.alert("Error", "Saving failed = fix errors and try again");        
213                                            }
214                                            return;
215                                        }
216                                        
217                                        // what about load failing..
218                                        Roo.MessageBox.alert("Error", "Error loading details"); 
219                                    },
220                                 actioncomplete : function(_self,act)
221                                    {
222                                        _this.dialog.uploadComplete = true;
223                                        _this.dialog.haveProgress = 2; 
224                                        Roo.MessageBox.hide(); // force hiding
225                                        //_this.dialog.el.unmask();
226                                         
227                                        if (act.type == 'setdata') { 
228                                            this.url = _this.data._url ? _this.data._url : baseURL + '/Roo/Images.php';
229                                            this.el.dom.action = this.url;
230                                            if (typeof(_this.data.timeout) != 'undefined') {
231                                                this.timeout = _this.data.timeout;
232                                            }
233                                            
234                                            this.findField('UPLOAD_IDENTIFIER').setValue(
235                                                (new Date() * 1) + '' + Math.random());
236                                                
237                                            return;
238                                        }
239                                         
240                                       
241                                        if (act.type == 'load') {
242                                          // should this happen?  
243                                            _this.data = act.result.data;
244                                           // _this.loaded();
245                                            return;
246                                        }
247                                        
248                                        
249                                        if (act.type == 'submit') { // only submitted here if we are 
250                                            _this.dialog.hide();
251                                            Roo.log("Upload success");
252                                            Roo.log(act);
253                                            //console.log(act);
254                                            if (_this.callback) {
255                                                _this.callback.call(this, act.result.data, act.result.extra);
256                                            }
257                                            return; 
258                                        }
259                                        
260                                    
261                                        
262                                    },
263                                 rendered : function (form)
264                                    {
265                                        _this.form= form;
266                                    }
267                             },
268                             items : [
269                                 {
270                                     '|xns' : 'Roo.form',
271                                     xtype : 'Hidden',
272                                     xns : Roo.form,
273                                     name : 'UPLOAD_IDENTIFIER'
274                                 },
275                                 {
276                                     '|xns' : 'Roo.form',
277                                     xtype : 'Hidden',
278                                     value : "32M",
279                                     xns : Roo.form,
280                                     name : 'post_max_size'
281                                 },
282                                 {
283                                     '|xns' : 'Roo.form',
284                                     xtype : 'Hidden',
285                                     value : "32M",
286                                     xns : Roo.form,
287                                     name : 'upload_max_filesize'
288                                 },
289                                 {
290                                     '|xns' : 'Roo.form',
291                                     inputType : 'file',
292                                     fieldLabel : 'Upload Image or File',
293                                     xtype : 'TextField',
294                                     width : 200,
295                                     xns : Roo.form,
296                                     name : 'imageUpload'
297                                 },
298                                 {
299                                     '|xns' : 'Roo.form',
300                                     xtype : 'Hidden',
301                                     xns : Roo.form,
302                                     name : 'ontable'
303                                 },
304                                 {
305                                     '|xns' : 'Roo.form',
306                                     xtype : 'Hidden',
307                                     xns : Roo.form,
308                                     name : 'onid'
309                                 },
310                                 {
311                                     '|xns' : 'Roo.form',
312                                     xtype : 'Hidden',
313                                     xns : Roo.form,
314                                     name : 'id'
315                                 },
316                                 {
317                                     '|xns' : 'Roo.form',
318                                     xtype : 'Hidden',
319                                     xns : Roo.form,
320                                     name : 'imgtype'
321                                 }
322                             ]
323
324                         }
325                     ]
326
327                 }
328             ]
329
330         });
331     }
332 };