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