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