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