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