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