Pman.Tab.CmsProduct.js
[Pman.Cms] / Pman.Tab.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
6
7 // register the module first
8 Pman.on('beforeload', function()
9 {
10     Pman.register({
11         modKey : '001-Pman.Tab.CmsProduct',
12         module : Pman.Tab.CmsProduct,
13         region : 'center',
14         parent : Pman.Tab.CmsProductMgr,
15         name : "Pman.Tab.CmsProduct",
16         disabled : false, 
17         permname: 'Cms.Products' 
18     });
19 });
20
21 Pman.Tab.CmsProduct = new Roo.util.Observable({
22
23     panel : false,
24     disabled : false,
25     parentLayout:  false,
26
27     add : function(parentLayout, region)
28     {
29
30         var _this = this;
31         this.parentLayout = parentLayout;
32
33         this.panel = parentLayout.addxtype({
34             xtype: 'GridPanel',
35             xns: Roo,
36             title : "Product",
37             fitToframe : true,
38             fitContainer : true,
39             tableName : 'Product',
40             background : true,
41             region : 'center',
42             listeners : {
43                 activate : function() {
44                     _this.panel = this;
45                     if (_this.grid) {
46                         _this.grid.footer.onClick('first');
47                     }
48                 }
49             },
50             grid : {
51                 xtype: 'Grid',
52                 xns: Roo.grid,
53                 listeners : {
54                     render : function() 
55                     {
56                         _this.grid = this; 
57                         _this.dialog = Pman.Dialog.CmsProduct;
58                         if (_this.panel.active) {
59                            this.footer.onClick('first');
60                         }
61                     },
62                     rowdblclick : function (_self, rowIndex, e)
63                     {
64                         if (!_this.dialog) return;
65                         _this.dialog.show( this.getDataSource().getAt(rowIndex), function() {
66                             _this.grid.footer.onClick('first');
67                         }); 
68                     }
69                 },
70                 autoExpandColumn : 'description',
71                 ddGroup : 'products',
72                 enableDrag : true,
73                 loadMask : true,
74                 dataSource : {
75                     xtype: 'Store',
76                     xns: Roo.data,
77                     listeners : {
78                         beforeload : function (_self, options)
79                         {
80                             if (!Pman.Tab.CmsProductCategory.panel) {
81                                 return false;
82                             }
83                             options.params['query[search]'] =  _this.searchBox.getValue();
84                             // category..
85                             var sn = Pman.Tab.CmsProductCategory.panel.tree.getSelectionModel().getSelectedNode();
86                             if (sn && !isNaN(parseInt(sn.attributes.id))) {
87                                 options.params.category_id  = sn.attributes.id;
88                             }
89                             
90                         }
91                     },
92                     remoteSort : true,
93                     sortInfo : { field : 'name', direction: 'ASC' },
94                     proxy : {
95                         xtype: 'HttpProxy',
96                         xns: Roo.data,
97                         method : 'GET',
98                         url : baseURL + '/Roo/Product.php'
99                     },
100                     reader : {
101                         xtype: 'JsonReader',
102                         xns: Roo.data,
103                         totalProperty : 'total',
104                         root : 'data',
105                         id : 'id',
106                         fields : [
107                             {
108                                 'name': 'id',
109                                 'type': 'int'
110                             },
111                             {
112                                 'name': 'name',
113                                 'type': 'string'
114                             },
115                             {
116                                 'name': 'sku',
117                                 'type': 'string'
118                             },
119                             {
120                                 'name': 'price',
121                                 'type': 'float'
122                             },
123                             {
124                                 'name': 'shortdesc',
125                                 'type': 'string'
126                             },
127                             {
128                                 'name': 'description',
129                                 'type': 'string'
130                             },
131                             {
132                                 'name': 'visible',
133                                 'type': 'int'
134                             },
135                             {
136                                 'name': 'itemtypes',
137                                 'type': 'string'
138                             },
139                             {
140                                 'name': 'category_id',
141                                 'type': 'int'
142                             },
143                             {
144                                 'name': 'currency',
145                                 'type': 'string'
146                             },
147                             {
148                                 'name': 'vender_url',
149                                 'type': 'string'
150                             },
151                             {
152                                 'name': 'supplier_id',
153                                 'type': 'int'
154                             }
155                         ]
156                     }
157                 },
158                 footer : {
159                     xtype: 'PagingToolbar',
160                     xns: Roo,
161                     pageSize : 25,
162                     displayInfo : true,
163                     displayMsg : 'Displaying Product{0} - {1} of {2}',
164                     emptyMsg : 'No Product found'
165                 },
166                 toolbar : {
167                     xtype: 'Toolbar',
168                     xns: Roo,
169                     items : [
170                         {
171                             xtype: 'TextField',
172                             xns: Roo.form,
173                             listeners : {
174                                 render : function (_self)
175                                 {
176                                     _this.searchBox = _self;
177                                 },
178                                 specialkey : function (_self, e)
179                                 {
180                                   if (e.getKey() == 13) {
181                                      _this.grid.footer.onClick( 'first' );
182                                   }
183                                 }
184                             }
185                         },
186                         {
187                             xtype: 'Button',
188                             xns: Roo.Toolbar,
189                             listeners : {
190                                 click : function (_self, e)
191                                 {
192                                 _this.grid.footer.onClick('first');
193                                 }
194                             },
195                             cls : 'x-btn-icon',
196                             icon : rootURL + '/Pman/templates/images/search.gif'
197                         },
198                         {
199                             xtype: 'Button',
200                             xns: Roo.Toolbar,
201                             listeners : {
202                                 click : function (_self, e)
203                                 {
204                                 _this.searchBox.setValue('');
205                                     _this.grid.footer.onClick('first');
206                                 }
207                             },
208                             cls : 'x-btn-icon',
209                             icon : rootURL + '/Pman/templates/images/edit-clear.gif'
210                         },
211                         {
212                             xtype: 'Fill',
213                             xns: Roo.Toolbar
214                         },
215                         {
216                             xtype: 'Button',
217                             xns: Roo.Toolbar,
218                             listeners : {
219                                 click : function()
220                                 {
221                                     if (!_this.dialog) return;
222                                     
223                                       var sel = Pman.Tab.CmsProductCategory.panel.tree.getSelectionModel().getSelectedNode();
224                                       var id =  (!sel || isNaN(parseInt(sel.attributes.id))) ? 0 : sel.attributes.id;
225                                       if (!id) {
226                                          Roo.MessageBox.alert("Error", "Select a Category to add it to");
227                                          return;
228                                      }
229                                 
230                                     
231                                     _this.dialog.show( { id : 0, category_id :id } , function(data) {
232                                         _this.searchBox.setValue(data.name);
233                                         _this.grid.footer.onClick('first');
234                                    }); 
235                                 }
236                             },
237                             cls : 'x-btn-text-icon',
238                             text : "Add",
239                             icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
240                         },
241                         {
242                             xtype: 'Button',
243                             xns: Roo.Toolbar,
244                             text : "Edit",
245                             cls : 'x-btn-text-icon',
246                             icon : Roo.rootURL + 'images/default/tree/leaf.gif',
247                             listeners : {
248                                 click : function()
249                                 {
250                                     var s = _this.grid.getSelectionModel().getSelections();
251                                     if (!s.length || (s.length > 1))  {
252                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
253                                         return;
254                                     }
255                                     if (!_this.dialog) return;
256                                     _this.dialog.show(s[0].data, function() {
257                                         _this.grid.footer.onClick('first');
258                                     }); 
259                                     
260                                 }
261                             }
262                         },
263                         {
264                             xtype: 'Button',
265                             xns: Roo.Toolbar,
266                             text : "Delete",
267                             cls : 'x-btn-text-icon',
268                             icon : rootURL + '/Pman/templates/images/trash.gif',
269                             listeners : {
270                                 click : function()
271                                 {
272                                      Pman.genericDelete(_this, 'Product'); 
273                                 }
274                             }
275                         }
276                     ]
277                 },
278                 colModel : [
279                     {
280                         xtype: 'ColumnModel',
281                         xns: Roo.grid,
282                         dataIndex : 'id',
283                         header : 'Photo',
284                         width : 100,
285                         renderer : function(v,x,r) {
286                             if (!r.json.images.length) {
287                                 return '';
288                             }
289                             
290                             return String.format('<img height="100" src="{0}/Images/Thumb/100x100/{1}/{2}">',
291                                 baseURL , r.json.images[0].id,r.json.images[0].filename ); }
292                     },
293                     {
294                         xtype: 'ColumnModel',
295                         xns: Roo.grid,
296                         dataIndex : 'category_id_title',
297                         header : 'Category',
298                         width : 75,
299                         renderer : function(v) { return String.format('{0}', v); },
300                         sortable : true
301                     },
302                     {
303                         xtype: 'ColumnModel',
304                         xns: Roo.grid,
305                         dataIndex : 'name',
306                         header : 'Name',
307                         sortable : true,
308                         width : 200,
309                         renderer : function(v) { return String.format('{0}', v); }
310                     },
311                     {
312                         xtype: 'ColumnModel',
313                         xns: Roo.grid,
314                         dataIndex : 'sku',
315                         header : 'Sku',
316                         width : 200,
317                         renderer : function(v) { return String.format('{0}', v); },
318                         sortable : true
319                     },
320                     {
321                         xtype: 'ColumnModel',
322                         xns: Roo.grid,
323                         dataIndex : 'description',
324                         header : 'Description',
325                         sortable : true,
326                         width : 200,
327                         renderer : function(v) { return String.format('{0}', v); }
328                     },
329                     {
330                         xtype: 'ColumnModel',
331                         xns: Roo.grid,
332                         dataIndex : 'visible',
333                         header : 'Visible',
334                         sortable : true,
335                         width : 75,
336                         renderer : function(v) { return String.format('{0}', v); }
337                     }
338                 ]
339             }
340         });
341         this.layout = this.panel.layout;
342
343     }
344 });