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