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