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