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