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                                     var cb = _this.callback;
169                                     _this.callback = function() {
170                                         _this.uploadSending = false;
171                                         _this.callback = cb;
172                                         
173                                     }
174                                     _this.uploadSending = true;
175                                     _this.form.submit();
176                                 }
177                                 
178                                  _this.uploadSending =true;
179                                 _this.uploadForm.findField('onid').setValue(_this.data.id);
180                                 _this.uploadForm.el.mask("Sending");
181                                 _this.uploadForm.submit.defer(100, _this.uploadForm);
182                            
183                           }, 1000)  
184                            
185                         }
186                     },
187                     region : 'east',
188                     title : "Images / PDF",
189                     layout : {
190                         xtype: 'BorderLayout',
191                         xns: Roo,
192                         items : [
193                             {
194                                 xtype: 'ContentPanel',
195                                 xns: Roo,
196                                 autoScroll : true,
197                                 fitContainer : true,
198                                 fitToFrame : true,
199                                 region : 'center',
200                                 items : [
201                                     {
202                                         xtype: 'JsonView',
203                                         xns: Roo,
204                                         listeners : {
205                                             beforerender : function (_self, data)
206                                             {
207                                                _this.imageView = _self;
208                                                
209                                                if (this.stylesheet) {
210                                                   return;
211                                                }
212                                                this.el.addClass('thumb-browser');
213                                             
214                                                
215                                                this.stylesheet = Roo.util.CSS.createStyleSheet(
216                                                     {
217                                                       '.thumb-browser .thumb-wrap' : {
218                                                             border:'3px solid #EEE',
219                                                             'float':'left',
220                                                             height:'160px',
221                                                             margin:'2px',
222                                                             'padding-left':'5px',
223                                                             'padding-top':'5px',
224                                                             width:'160px'
225                                                         },
226                                                         '.thumb-browser .x-view-selected' : {
227                                                           border:'3px solid #333'
228                                                       
229                                                         }
230                                             
231                                             
232                                                     }, Roo.id()
233                                                     );
234                                                
235                                             }
236                                         },
237                                         jsonRoot : 'data',
238                                         singleSelect : true,
239                                         loadImages : function() {
240                                             if (!_this.data.id) {return; } 
241                                         
242                                            this.load({
243                                                 url : baseURL + '/Roo/Images.php',
244                                                 method : 'GET',
245                                                 params : {
246                                                    ontable : 'Product',
247                                                    onid : _this.data.id,
248                                                    'query[imagesize]' : 150
249                                                 },
250                                                 text : 'Loading'
251                                            });
252                                            
253                                         },
254                                         tpl : {
255                                             xtype: 'Template',
256                                             xns: Roo,
257                                             html : '<div class="thumb-wrap"> ' + 
258                                               '<div class="thumb"><img  src="'+ baseURL + '/Images/Thumb/150/{id}/{filename}" class="thumb-img"></div>' + 
259                                             '</div>'
260                                         }
261                                     }
262                                 ],
263                                 toolbar : {
264                                     xtype: 'Toolbar',
265                                     xns: Roo,
266                                     items : [
267                                         {
268                                             xtype: 'Button',
269                                             xns: Roo.Toolbar,
270                                             listeners : {
271                                                 click : function (_self, e)
272                                                 {
273                                                  
274                                                    if (!_this.imageView.getSelectedNodes().length) {
275                                                      Roo.MessageBox.alert("Error", "Select an Image");
276                                                      return;
277                                                    }
278                                                    var n = _this.imageView.getNodeData(_this.imageView.getSelectedNodes()[0]);
279                                                 
280                                                    // open a new window with this file in..
281                                                    Pman.download( {
282                                                        url: baseURL + '/Images/Download/' + n.id  + '/' + n.filename
283                                                    });
284                                                 }
285                                             },
286                                             text : "Download"
287                                         },
288                                         {
289                                             xtype: 'Fill',
290                                             xns: Roo.Toolbar
291                                         },
292                                         {
293                                             xtype: 'Button',
294                                             xns: Roo.Toolbar,
295                                             listeners : {
296                                                 click : function (_self, e)
297                                                 {
298                                                     if (!_this.imageView.getSelectedNodes().length) {
299                                                      Roo.MessageBox.alert("Error", "Select an Image");
300                                                      return;
301                                                    }
302                                                    var id  = _this.imageView.getNodeData(_this.imageView.getSelectedNodes()[0]).id;
303                                                    _this.imageView.el.mask('Deleting');
304                                                    
305                                                    Roo.Ajax.request({
306                                                       url : baseURL + '/Roo/Images.php',
307                                                       params : {
308                                                          _delete : id
309                                                       },
310                                                       method : 'GET',
311                                                       success : function() {
312                                                           _this.imageView.el.unmask();
313                                                            _this.imageView.loadImages();
314                                                       },
315                                                       failure : function() {
316                                                            _this.imageView.el.unmask();
317                                                            Roo.MessageBox.alert("Error", "Error deleting image");
318                                                            return;
319                                                       }
320                                                   });
321                                                  }
322                                             },
323                                             text : "Delete File/Image"
324                                         }
325                                     ]
326                                 }
327                             },
328                             {
329                                 xtype: 'ContentPanel',
330                                 xns: Roo,
331                                 region : 'south',
332                                 items : [
333                                     {
334                                         xtype: 'Form',
335                                         xns: Roo.form,
336                                         listeners : {
337                                             actioncomplete : function (_self, action)
338                                             {
339                                             // only action this will handle is submit?
340                                             // should test for errors..
341                                                 if (action.failureType) {
342                                                       _this.uploadForm.el.unmask();
343                                                       _this.uploadSending = false;
344                                                     Roo.MessageBox.alert("Error", "Upload Failed");
345                                                     return false;
346                                                 
347                                                 }
348                                                   
349                                                 
350                                                 if (action.type =='submit') {
351                                                      _this.uploadForm.reset();
352                                                        _this.uploadSending = false;
353                                                       _this.uploadForm.el.unmask();         
354                                                      _this.imageView.loadImages();
355                                                      return;
356                                                 }
357                                                  
358                                             },
359                                             rendered : function (form)
360                                             {
361                                               _this.uploadForm = form;
362                                             }
363                                         },
364                                         fileUpload : true,
365                                         labelAlign : 'top',
366                                         labelWidth : 150,
367                                         style : 'margin: 10px;',
368                                         url : baseURL + '/Roo/Images.php',
369                                         items : [
370                                             {
371                                                 xtype: 'Row',
372                                                 xns: Roo.form,
373                                                 items : [
374                                                     {
375                                                         xtype: 'TextField',
376                                                         xns: Roo.form,
377                                                         allowBlank : false,
378                                                         fieldLabel : 'Upload Image or File',
379                                                         inputType : 'file',
380                                                         name : 'imageUpload',
381                                                         width : 250
382                                                     }
383                                                 ]
384                                             },
385                                             {
386                                                 xtype: 'Hidden',
387                                                 xns: Roo.form,
388                                                 name : 'onid'
389                                             },
390                                             {
391                                                 xtype: 'Hidden',
392                                                 xns: Roo.form,
393                                                 name : 'ontable',
394                                                 value : "Product"
395                                             }
396                                         ]
397                                     }
398                                 ]
399                             }
400                         ],
401                         center : {
402                             xtype: 'LayoutRegion',
403                             xns: Roo
404                         },
405                         south : {
406                             xtype: 'LayoutRegion',
407                             xns: Roo,
408                             height : 60
409                         }
410                     }
411                 }
412             ],
413             center : {
414                 xtype: 'LayoutRegion',
415                 xns: Roo
416             },
417             east : {
418                 xtype: 'LayoutRegion',
419                 xns: Roo,
420                 width : 300
421             },
422             buttons : [
423                 {
424                     xtype: 'Button',
425                     xns: Roo,
426                     listeners : {
427                         click : function (_self, e)
428                         {
429                             _this.dialog.hide();
430                         }
431                     },
432                     text : "Cancel"
433                 },
434                 {
435                     xtype: 'Button',
436                     xns: Roo,
437                     listeners : {
438                         click : function (_self, e)
439                         {
440                             // do some checks?
441                              
442                             
443                             _this.dialog.el.mask("Saving");
444                             _this.form.doAction("submit");
445                         
446                         }
447                     },
448                     text : "Save"
449                 }
450             ]
451         });
452     }
453 };