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