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