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