Pman.Dialog.CmsProduct.js
[Pman.Cms] / Pman.Dialog.CmsProduct.js
1 //<script type="text/javascript">
2
3 // Auto generated file - created by app.Builder.js- do not edit directly (at present!)
4
5 Pman.Dialog.CmsProduct = {
6
7     dialog : false,
8     callback:  false,
9
10     show : function(data, cb)
11     {
12         if (!this.dialog) {
13             this.create();
14         }
15
16         this.callback = cb;
17         this.data = data;
18         this.dialog.show(this.data._el);
19         if (this.form) {
20            this.form.reset();
21            this.form.setValues(data);
22            this.form.fireEvent('actioncomplete', this.form,  { type: 'setdata', data: data });
23         }
24
25     },
26
27     create : function()
28     {
29         var _this = this;
30         this.dialog = Roo.factory({
31             xtype: 'LayoutDialog',
32             xns: Roo,
33             closable : false,
34             collapsible : false,
35             height : 380,
36             resizable : false,
37             title : "Edit / Create Product",
38             width : 700,
39             items : [
40                 {
41                     xtype: 'ContentPanel',
42                     xns: Roo,
43                     region : 'center',
44                     items : [
45                         {
46                             xtype: 'Form',
47                             xns: Roo.form,
48                             listeners : {
49                                 actioncomplete : function(_self,action)
50                                 {
51                                     if (action.type == 'setdata') {
52                                        _this.dialog.el.mask("Loading");
53                                        if (_this.data.id) {
54                                            _this.dialog.el.mask("Loading");
55                                            this.load({ method: 'GET', params: { '_id' : _this.data.id }});
56                                             return;
57                                        }
58                                        _this.imageView.loadImages();
59                                        return;
60                                     }
61                                     if (action.type == 'load') {
62                                        _this.imageView.loadImages();
63                                         _this.dialog.el.unmask();
64                                         return;
65                                     }
66                                     if (action.type =='submit') {
67                                     
68                                         _this.dialog.el.unmask();
69                                         _this.dialog.hide();
70                                     
71                                          if (_this.callback) {
72                                             _this.callback.call(_this, _this.form.getValues());
73                                          }
74                                          _this.form.reset();
75                                          return;
76                                     }
77                                 },
78                                 rendered : function (form)
79                                 {
80                                     _this.form= form;
81                                 }
82                             },
83                             method : 'POST',
84                             style : 'margin:10px;',
85                             url : baseURL + '/Roo/Product.php',
86                             items : [
87                                 {
88                                     xtype: 'TextField',
89                                     xns: Roo.form,
90                                     fieldLabel : 'Name',
91                                     name : 'name',
92                                     width : 200
93                                 },
94                                 {
95                                     xtype: 'TextField',
96                                     xns: Roo.form,
97                                     fieldLabel : 'Sku',
98                                     name : 'sku',
99                                     width : 200
100                                 },
101                                 {
102                                     xtype: 'Checkbox',
103                                     xns: Roo.form,
104                                     listeners : {
105                                         valid : function (_self)
106                                         {
107                                         
108                                         }
109                                     },
110                                     fieldLabel : 'Visible',
111                                     name : 'visible',
112                                     width : 75
113                                 },
114                                 {
115                                     xtype: 'Column',
116                                     xns: Roo.form,
117                                     labelAlign : 'top',
118                                     width : 360,
119                                     items : [
120                                         {
121                                             xtype: 'TextArea',
122                                             xns: Roo.form,
123                                             fieldLabel : 'Description',
124                                             height : 180,
125                                             name : 'description',
126                                             width : 350
127                                         }
128                                     ]
129                                 },
130                                 {
131                                     xtype: 'Hidden',
132                                     xns: Roo.form,
133                                     name : 'id'
134                                 }
135                             ]
136                         }
137                     ]
138                 },
139                 {
140                     xtype: 'NestedLayoutPanel',
141                     xns: Roo,
142                     listeners : {
143                         activate : function (_self)
144                         {
145                            //console.log('activate');
146                            if ( _this.imageView ){ 
147                               _this.imageView.loadImages();
148                            }
149                         
150                            if (_this.hasUploadWatch) {
151                              return;
152                            }
153                            _this.hasUploadWatch =true;
154                            _this.uploadSending =false;
155                            window.setInterval( function()
156                             {
157                                 var val = _this.uploadForm.findField('imageUpload').getValue();
158                                 if (!val || !val.length) {
159                                     return;
160                                 }
161                                 
162                                 if (_this.uploadSending) {
163                                     return;
164                                 }
165                                 
166                                 if (_this.data.id) {
167                                     // trigger a save..
168                                     va
169                                     _this.form.submit();
170                                 }
171                                 
172                                  _this.uploadSending =true;
173                                 _this.uploadForm.findField('onid').setValue(_this.data.id);
174                                 _this.uploadForm.el.mask("Sending");
175                                 _this.uploadForm.submit.defer(100, _this.uploadForm);
176                            
177                           }, 1000)  
178                            
179                         }
180                     },
181                     region : 'east',
182                     title : "Images / PDF",
183                     layout : {
184                         xtype: 'BorderLayout',
185                         xns: Roo,
186                         items : [
187                             {
188                                 xtype: 'ContentPanel',
189                                 xns: Roo,
190                                 autoScroll : true,
191                                 fitContainer : true,
192                                 fitToFrame : true,
193                                 region : 'center',
194                                 items : [
195                                     {
196                                         xtype: 'JsonView',
197                                         xns: Roo,
198                                         listeners : {
199                                             beforerender : function (_self, data)
200                                             {
201                                                _this.imageView = _self;
202                                                
203                                                if (this.stylesheet) {
204                                                   return;
205                                                }
206                                                this.el.addClass('thumb-browser');
207                                             
208                                                
209                                                this.stylesheet = Roo.util.CSS.createStyleSheet(
210                                                     {
211                                                       '.thumb-browser .thumb-wrap' : {
212                                                             border:'3px solid #EEE',
213                                                             'float':'left',
214                                                             height:'160px',
215                                                             margin:'2px',
216                                                             'padding-left':'5px',
217                                                             'padding-top':'5px',
218                                                             width:'160px'
219                                                         },
220                                                         '.thumb-browser .x-view-selected' : {
221                                                           border:'3px solid #333'
222                                                       
223                                                         }
224                                             
225                                             
226                                                     }, Roo.id()
227                                                     );
228                                                
229                                             }
230                                         },
231                                         jsonRoot : 'data',
232                                         singleSelect : true,
233                                         loadImages : function() {
234                                             if (!_this.data.id) {return; } 
235                                         
236                                            this.load({
237                                                 url : baseURL + '/Roo/Images.php',
238                                                 method : 'GET',
239                                                 params : {
240                                                    ontable : 'Product',
241                                                    onid : _this.data.id,
242                                                    'query[imagesize]' : 150
243                                                 },
244                                                 text : 'Loading'
245                                            });
246                                            
247                                         },
248                                         tpl : {
249                                             xtype: 'Template',
250                                             xns: Roo,
251                                             html : '<div class="thumb-wrap"> ' + 
252                                               '<div class="thumb"><img  src="'+ baseURL + '/Images/Thumb/150/{id}/{filename}" class="thumb-img"></div>' + 
253                                             '</div>'
254                                         }
255                                     }
256                                 ],
257                                 toolbar : {
258                                     xtype: 'Toolbar',
259                                     xns: Roo,
260                                     items : [
261                                         {
262                                             xtype: 'Button',
263                                             xns: Roo.Toolbar,
264                                             listeners : {
265                                                 click : function (_self, e)
266                                                 {
267                                                  
268                                                    if (!_this.imageView.getSelectedNodes().length) {
269                                                      Roo.MessageBox.alert("Error", "Select an Image");
270                                                      return;
271                                                    }
272                                                    var n = _this.imageView.getNodeData(_this.imageView.getSelectedNodes()[0]);
273                                                 
274                                                    // open a new window with this file in..
275                                                    Pman.download( {
276                                                        url: baseURL + '/Images/Download/' + n.id  + '/' + n.filename
277                                                    });
278                                                 }
279                                             },
280                                             text : "Download"
281                                         },
282                                         {
283                                             xtype: 'Fill',
284                                             xns: Roo.Toolbar
285                                         },
286                                         {
287                                             xtype: 'Button',
288                                             xns: Roo.Toolbar,
289                                             listeners : {
290                                                 click : function (_self, e)
291                                                 {
292                                                     if (!_this.imageView.getSelectedNodes().length) {
293                                                      Roo.MessageBox.alert("Error", "Select an Image");
294                                                      return;
295                                                    }
296                                                    var id  = _this.imageView.getNodeData(_this.imageView.getSelectedNodes()[0]).id;
297                                                    _this.imageView.el.mask('Deleting');
298                                                    
299                                                    Roo.Ajax.request({
300                                                       url : baseURL + '/Roo/Images.php',
301                                                       params : {
302                                                          _delete : id
303                                                       },
304                                                       method : 'GET',
305                                                       success : function() {
306                                                           _this.imageView.el.unmask();
307                                                            _this.imageView.loadImages();
308                                                       },
309                                                       failure : function() {
310                                                            _this.imageView.el.unmask();
311                                                            Roo.MessageBox.alert("Error", "Error deleting image");
312                                                            return;
313                                                       }
314                                                   });
315                                                  }
316                                             },
317                                             text : "Delete File/Image"
318                                         }
319                                     ]
320                                 }
321                             },
322                             {
323                                 xtype: 'ContentPanel',
324                                 xns: Roo,
325                                 region : 'south',
326                                 items : [
327                                     {
328                                         xtype: 'Form',
329                                         xns: Roo.form,
330                                         listeners : {
331                                             actioncomplete : function (_self, action)
332                                             {
333                                             // only action this will handle is submit?
334                                             // should test for errors..
335                                                 if (action.failureType) {
336                                                       _this.uploadForm.el.unmask();
337                                                       _this.uploadSending = false;
338                                                     Roo.MessageBox.alert("Error", "Upload Failed");
339                                                     return false;
340                                                 
341                                                 }
342                                                   
343                                                 
344                                                 if (action.type =='submit') {
345                                                      _this.uploadForm.reset();
346                                                        _this.uploadSending = false;
347                                                       _this.uploadForm.el.unmask();         
348                                                      _this.imageView.loadImages();
349                                                      return;
350                                                 }
351                                                  
352                                             },
353                                             rendered : function (form)
354                                             {
355                                               _this.uploadForm = form;
356                                             }
357                                         },
358                                         fileUpload : true,
359                                         labelAlign : 'top',
360                                         labelWidth : 150,
361                                         style : 'margin: 10px;',
362                                         url : baseURL + '/Roo/Images.php',
363                                         items : [
364                                             {
365                                                 xtype: 'Row',
366                                                 xns: Roo.form,
367                                                 items : [
368                                                     {
369                                                         xtype: 'TextField',
370                                                         xns: Roo.form,
371                                                         allowBlank : false,
372                                                         fieldLabel : 'Upload Image or File',
373                                                         inputType : 'file',
374                                                         name : 'imageUpload',
375                                                         width : 250
376                                                     }
377                                                 ]
378                                             },
379                                             {
380                                                 xtype: 'Hidden',
381                                                 xns: Roo.form,
382                                                 name : 'onid'
383                                             },
384                                             {
385                                                 xtype: 'Hidden',
386                                                 xns: Roo.form,
387                                                 name : 'ontable',
388                                                 value : "Product"
389                                             }
390                                         ]
391                                     }
392                                 ]
393                             }
394                         ],
395                         center : {
396                             xtype: 'LayoutRegion',
397                             xns: Roo
398                         },
399                         south : {
400                             xtype: 'LayoutRegion',
401                             xns: Roo,
402                             height : 60
403                         }
404                     }
405                 }
406             ],
407             center : {
408                 xtype: 'LayoutRegion',
409                 xns: Roo
410             },
411             east : {
412                 xtype: 'LayoutRegion',
413                 xns: Roo,
414                 width : 300
415             },
416             buttons : [
417                 {
418                     xtype: 'Button',
419                     xns: Roo,
420                     listeners : {
421                         click : function (_self, e)
422                         {
423                             _this.dialog.hide();
424                         }
425                     },
426                     text : "Cancel"
427                 },
428                 {
429                     xtype: 'Button',
430                     xns: Roo,
431                     listeners : {
432                         click : function (_self, e)
433                         {
434                             // do some checks?
435                              
436                             
437                             _this.dialog.el.mask("Saving");
438                             _this.form.doAction("submit");
439                         
440                         }
441                     },
442                     text : "Save"
443                 }
444             ]
445         });
446     }
447 };