Pman.Dialog.CmsCategory.js
[Pman.Cms] / Pman.Dialog.CmsCategory.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.CmsCategory = {
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             background : true,
34             width : 800,
35             height : 500,
36             title : "Edit Category",
37             modal : true,
38             resizable : false,
39             collapsible : false,
40             closable : false,
41             items : [
42                 {
43                     xtype: 'ContentPanel',
44                     xns: Roo,
45                     background : true,
46                     fitToFrame : true,
47                     region : 'center',
48                     items : [
49                         {
50                             xtype: 'Form',
51                             xns: Roo.form,
52                             listeners : {
53                                 actionfailed : function (_self, action)
54                                 {
55                                     _this.dialog.el.unmask();
56                                     Pman.standardActionFailed(_self, action);
57                                 },
58                                 actioncomplete : function (_self, action)
59                                 {
60                                    
61                                    if (action.type =='submit') {
62                                        
63                                        _this.dialog.el.unmask();
64                                        _this.dialog.hide();
65                                        
66                                         if (_this.callback) {
67                                            _this.callback.call(_this, _this.form.getValues());
68                                         }
69                                         _this.form.reset();
70                                         return;
71                                     }
72                                      if (action.type == 'setdata') {
73                                          if (_this.data.id) {
74                                            _this.dialog.el.mask("Loading");
75                                            this.load({ method: 'GET', params: { '_id' : _this.data.id }});
76                                             return;
77                                        }
78                                       _this.grid.getDataSource().load();
79                                        return;
80                                     }
81                                     if (action.type == 'load') {
82                                        _this.grid.getDataSource().load();
83                                         _this.dialog.el.unmask();
84                                         return;
85                                     }
86                                     
87                                   
88                                     
89                                 },
90                                 rendered : function (_self)
91                                 {
92                                     _this.form = _self;
93                                 }
94                             },
95                             method : 'POST',
96                             style : 'margin: 5px',
97                             url : baseURL + '/Roo/Category.php',
98                             items : [
99                                 {
100                                     xtype: 'TextField',
101                                     xns: Roo.form,
102                                     fieldLabel : 'Parent',
103                                     name : 'parent_id_title',
104                                     readOnly : true,
105                                     width : 450
106                                 },
107                                 {
108                                     xtype: 'NumberField',
109                                     xns: Roo.form,
110                                     decimalPrecision : 2,
111                                     fieldLabel : 'Order (1 first)',
112                                     name : 'display_order'
113                                 },
114                                 {
115                                     xtype: 'TextField',
116                                     xns: Roo.form,
117                                     name : 'title',
118                                     fieldLabel : 'Title',
119                                     width : 450
120                                 },
121                                 {
122                                     xtype: 'ComboBox',
123                                     xns: Roo.form,
124                                     allowBlank : true,
125                                     displayField : 'name',
126                                     editable : 'false',
127                                     emptyText : "Select Type",
128                                     fieldLabel : 'Type',
129                                     forceSelection : true,
130                                     hiddenName : 'category_type_id',
131                                     listWidth : 200,
132                                     loadingText : "Searching...",
133                                     minChars : 2,
134                                     name : 'category_type_id_name',
135                                     pageSize : 20,
136                                     qtip : "Select cms_category_type",
137                                     selectOnFocus : true,
138                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{name}</b> </div>',
139                                     triggerAction : 'all',
140                                     typeAhead : true,
141                                     valueField : 'id',
142                                     width : 200,
143                                     store : {
144                                         xtype: 'Store',
145                                         xns: Roo.data,
146                                         remoteSort : true,
147                                         sortInfo : { direction : 'ASC', field: 'id' },
148                                         listeners : {
149                                             beforeload : function (_self, o){
150                                                 o.params = o.params || {};
151                                                 // set more here
152                                             }
153                                         },
154                                         proxy : {
155                                             xtype: 'HttpProxy',
156                                             xns: Roo.data,
157                                             method : 'GET',
158                                             url : baseURL + '/Roo/cms_category_type.php'
159                                         },
160                                         reader : {
161                                             xtype: 'JsonReader',
162                                             xns: Roo.data,
163                                             id : 'id',
164                                             root : 'data',
165                                             totalProperty : 'total',
166                                             fields : [{"name":"id","type":"int"},{"name":"name","type":"string"}]
167                                         }
168                                     }
169                                 },
170                                 {
171                                     xtype: 'Checkbox',
172                                     xns: Roo.form,
173                                     fieldLabel : 'Visible',
174                                     name : 'visible'
175                                 },
176                                 {
177                                     xtype: 'Hidden',
178                                     xns: Roo.form,
179                                     name : 'parent_id'
180                                 },
181                                 {
182                                     xtype: 'Hidden',
183                                     xns: Roo.form,
184                                     name : 'id'
185                                 }
186                             ]
187                         }
188                     ]
189                 },
190                 {
191                     xtype: 'GridPanel',
192                     xns: Roo,
193                     title : "Images",
194                     fitToframe : true,
195                     fitContainer : true,
196                     tableName : 'Images',
197                     background : false,
198                     listeners : {
199                         activate : function() {
200                             _this.panel = this;
201                             if (_this.grid) {
202                                 //_this.grid.footer.onClick('first');
203                             }
204                         }
205                     },
206                     region : 'east',
207                     grid : {
208                         xtype: 'Grid',
209                         xns: Roo.grid,
210                         autoExpandColumn : 'filename',
211                         loadMask : true,
212                         listeners : {
213                             render : function() { 
214                                 _this.grid = this; 
215                                 //_this.dialog = Pman.Dialog.FILL_IN
216                                 if (_this.panel.active) {
217                                    //this.footer.onClick('first');
218                                 }
219                             }
220                         },
221                         dataSource : {
222                             xtype: 'Store',
223                             xns: Roo.data,
224                             reader : Pman.Readers.Images,
225                             listeners : {
226                                 beforeload : function (_self, o)
227                                 {
228                                   if (!_this.data.id) {
229                                        return false;
230                                     }               
231                                     o.params = o.params || {};
232                                     o.params.onid = _this.data.id;
233                                     o.params.ontable = 'Category';
234                                 }
235                             },
236                             proxy : {
237                                 xtype: 'HttpProxy',
238                                 xns: Roo.data,
239                                 method : 'GET',
240                                 url : baseURL + '/Roo/Images.php'
241                             }
242                         },
243                         toolbar : {
244                             xtype: 'Toolbar',
245                             xns: Roo,
246                             items : [
247                                 {
248                                     xtype: 'Button',
249                                     xns: Roo,
250                                     text : "Add",
251                                     cls : 'x-btn-text-icon',
252                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
253                                     listeners : {
254                                         click : function()
255                                                 {
256                                                     Pman.Dialog.Image.show( { id : 0, onid: _this.data.id, ontable: 'Category' }, function(data) {
257                                                         _this.grid.getDataSource().load();
258                                                          Pman.Dialog.CmsImage.show(data, function() {
259                                                            _this.grid.getDataSource().load();
260                                                        }); 
261                                             
262                                                         
263                                                     }); 
264                                         
265                                                 }
266                                     }
267                                 },
268                                 {
269                                     xtype: 'Button',
270                                     xns: Roo,
271                                     text : "Edit",
272                                     cls : 'x-btn-text-icon',
273                                     icon : Roo.rootURL + 'images/default/tree/leaf.gif',
274                                     listeners : {
275                                         click : function()
276                                                 {
277                                                     var s = _this.grid.getSelectionModel().getSelections();
278                                                     if (!s.length || (s.length > 1))  {
279                                                         Roo.MessageBox.alert("Error", s.length ? "Select only one Row" : "Select a Row");
280                                                         return;
281                                                     }
282                                                     var data = _this.grid.getDataSource().getById(s[0].data.id).data;
283                                                     Pman.Dialog.CmsImage.show(data, function() {
284                                                         _this.grid.getDataSource().load();
285                                                        }); 
286                                                     
287                                                 }
288                                     }
289                                 },
290                                 {
291                                     xtype: 'Button',
292                                     xns: Roo,
293                                     text : "Delete",
294                                     cls : 'x-btn-text-icon',
295                                     icon : rootURL + '/Pman/templates/images/trash.gif',
296                                     listeners : {
297                                         click : function()
298                                                 {
299                                                 Pman.genericDelete(_this, _this.panel.tableName); 
300                                                 }
301                                     }
302                                 }
303                             ]
304                         },
305                         colModel : [
306                             {
307                                 xtype: 'ColumnModel',
308                                 xns: Roo.grid,
309                                 header : '',
310                                 width : 110,
311                                 dataIndex : 'id',
312                                 renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}">', baseURL, v, r.data.filename); }
313                             },
314                             {
315                                 xtype: 'ColumnModel',
316                                 xns: Roo.grid,
317                                 header : 'Filename',
318                                 width : 100,
319                                 dataIndex : 'filename',
320                                 renderer : function(v,x,r) { return String.format('{0}<br/><i qtip="{1}">{1}</i>', v, r.data.linkurl); }
321                             }
322                         ]
323                     }
324                 }
325             ],
326             center : {
327                 xtype: 'LayoutRegion',
328                 xns: Roo,
329                 titlebar : false
330             },
331             east : {
332                 xtype: 'LayoutRegion',
333                 xns: Roo,
334                 titlebar : false,
335                 split : 'true',
336                 fitToFrame : 'true',
337                 width : 200
338             },
339             buttons : [
340                 {
341                     xtype: 'Button',
342                     xns: Roo,
343                     text : "Cancel",
344                     listeners : {
345                         click : function() {
346                         
347                                                             _this.form.reset();
348                         
349                                                             _this.dialog.hide();
350                         
351                                                         }
352                     }
353                 },
354                 {
355                     xtype: 'Button',
356                     xns: Roo,
357                     text : "OK",
358                     listeners : {
359                         click : function() {
360                         
361                                                             _this.dialog.el.mask("Saving");
362                         
363                                                             _this.form.doAction("submit");
364                         
365                                                         }
366                     }
367                 }
368             ]
369         });
370     }
371 };