Pman.Dialog.CmsPage.js
[Pman.Cms] / Pman.Dialog.CmsPage.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.CmsPage = {
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             closable : false,
35             collapsible : false,
36             height : 600,
37             modal : true,
38             resizable : false,
39             title : "Edit Page",
40             width : 800,
41             items : [
42                 {
43                     xtype: 'ContentPanel',
44                     xns: Roo,
45                     autoScroll : true,
46                     background : true,
47                     fitToFrame : true,
48                     region : 'center',
49                     items : [
50                         {
51                             xtype: 'Form',
52                             xns: Roo.form,
53                             listeners : {
54                                 actionfailed : function (_self, action)
55                                 {
56                                     _this.dialog.el.unmask();
57                                     Pman.standardActionFailed(_self, action);
58                                 },
59                                 actioncomplete : function (_self, action)
60                                 {
61                                 
62                                    if (action.type =='submit') {
63                                        
64                                        _this.dialog.el.unmask();
65                                        _this.dialog.hide();
66                                        
67                                         if (_this.callback) {
68                                            _this.callback.call(_this, _this.form.getValues());
69                                         }
70                                         _this.form.reset();
71                                         return;
72                                     }
73                                     if (action.type == 'setdata') {    
74                                           _this.loaded = false;
75                                           
76                                   //      _this.dialog.getLayout().showPanel(0);
77                                     //   _this.form.addForm(_this.form1);
78                                           if ( _this.data.id) {
79                                                 _this.dialog.el.mask("Loading");
80                                                 this.load({ method: 'GET', params: { '_id' : _this.data.id }});
81                                            } else {
82                                                 _this.loaded = true;
83                                                 //disable image upload!
84                                               _this.form.findField('publish_status').setValue(-1);
85                                           }
86                                 
87                                        return;
88                                       
89                                     }
90                                     
91                                     if (action.type == 'load') {
92                                         _this.dialog.el.unmask();
93                                        _this.grid.getDataSource().load();
94                                         return;
95                                     }
96                                 },
97                                 rendered : function (_self)
98                                 {
99                                     _this.form = _self;
100                                 }
101                             },
102                             method : 'POST',
103                             style : 'margin: 5px',
104                             url : baseURL + '/Roo/Page.php',
105                             items : [
106                                 {
107                                     xtype: 'TextField',
108                                     xns: Roo.form,
109                                     fieldLabel : 'Replaces',
110                                     name : 'replaces_id',
111                                     width : 75
112                                 },
113                                 {
114                                     xtype: 'TextField',
115                                     xns: Roo.form,
116                                     fieldLabel : 'Parent',
117                                     name : 'parent_id',
118                                     width : 75
119                                 },
120                                 {
121                                     xtype: 'TextField',
122                                     xns: Roo.form,
123                                     fieldLabel : 'Page link',
124                                     name : 'page_link',
125                                     width : 200
126                                 },
127                                 {
128                                     xtype: 'Checkbox',
129                                     xns: Roo.form,
130                                     fieldLabel : 'Display in RSS',
131                                     name : 'in_rss',
132                                     width : 75
133                                 },
134                                 {
135                                     xtype: 'ComboBox',
136                                     xns: Roo.form,
137                                     allowBlank : true,
138                                     displayField : 'title',
139                                     editable : false,
140                                     emptyText : "Select Category ",
141                                     fieldLabel : 'Category ',
142                                     forceSelection : true,
143                                     hiddenName : 'category_id',
144                                     listWidth : 390,
145                                     loadingText : "Searching...",
146                                     minChars : 2,
147                                     name : 'category_id_title',
148                                     pageSize : 20,
149                                     qtip : "Select Category ",
150                                     queryParam : 'query[title]',
151                                     selectOnFocus : true,
152                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b> </div>',
153                                     triggerAction : 'all',
154                                     typeAhead : true,
155                                     valueField : 'id',
156                                     width : 450,
157                                     store : {
158                                         xtype: 'Store',
159                                         xns: Roo.data,
160                                         reader : Pman.Readers.Category,
161                                         proxy : {
162                                             xtype: 'HttpProxy',
163                                             xns: Roo.data,
164                                             url : baseURL + '/Roo/Category.php',
165                                             method : 'GET'
166                                         }
167                                     }
168                                 },
169                                 {
170                                     xtype: 'TextField',
171                                     xns: Roo.form,
172                                     fieldLabel : 'Title',
173                                     name : 'title',
174                                     width : 390
175                                 },
176                                 {
177                                     xtype: 'Column',
178                                     xns: Roo.form,
179                                     width : '570',
180                                     labelAlign : 'top',
181                                     items : [
182                                         {
183                                             xtype: 'HtmlEditor',
184                                             xns: Roo.form,
185                                             fieldLabel : 'Contents',
186                                             height : 240,
187                                             name : 'contents',
188                                             width : 550
189                                         }
190                                     ]
191                                 },
192                                 {
193                                     xtype: 'Row',
194                                     xns: Roo.form,
195                                     labelWidth : 300,
196                                     items : [
197                                         {
198                                             xtype: 'Checkbox',
199                                             xns: Roo.form,
200                                             fieldLabel : 'Use Extended Contents?',
201                                             inputValue : 1,
202                                             name : 'extended',
203                                             width : 200
204                                         }
205                                     ]
206                                 },
207                                 {
208                                     xtype: 'Column',
209                                     xns: Roo.form,
210                                     width : '570',
211                                     labelAlign : 'top',
212                                     items : [
213                                         {
214                                             xtype: 'HtmlEditor',
215                                             xns: Roo.form,
216                                             fieldLabel : 'Extended Contents',
217                                             height : 340,
218                                             name : 'extended',
219                                             width : 550
220                                         }
221                                     ]
222                                 },
223                                 {
224                                     xtype: 'Hidden',
225                                     xns: Roo.form,
226                                     name : 'id'
227                                 },
228                                 {
229                                     xtype: 'Checkbox',
230                                     xns: Roo.form,
231                                     fieldLabel : 'Visible',
232                                     name : 'visible',
233                                     width : 75
234                                 },
235                                 {
236                                     xtype: 'TextField',
237                                     xns: Roo.form,
238                                     fieldLabel : 'Has extended',
239                                     name : 'has_extended',
240                                     width : 75
241                                 },
242                                 {
243                                     xtype: 'DateField',
244                                     xns: Roo.form,
245                                     fieldLabel : 'Date to Publish',
246                                     name : 'published',
247                                     width : 200
248                                 }
249                             ]
250                         }
251                     ]
252                 },
253                 {
254                     xtype: 'GridPanel',
255                     xns: Roo,
256                     title : "Images",
257                     fitToframe : true,
258                     fitContainer : true,
259                     tableName : 'Images',
260                     background : false,
261                     listeners : {
262                         activate : function() {
263                             _this.panel = this;
264                             if (_this.grid) {
265                                 _this.grid.footer.onClick('first');
266                             }
267                         }
268                     },
269                     region : 'east',
270                     grid : {
271                         xtype: 'Grid',
272                         xns: Roo.grid,
273                         autoExpandColumn : 'filename',
274                         loadMask : true,
275                         listeners : {
276                             render : function() { 
277                                 _this.grid = this; 
278                                 //_this.dialog = Pman.Dialog.FILL_IN
279                                 if (_this.panel.active) {
280                                    //this.footer.onClick('first');
281                                 }
282                             },
283                             rowdblclick : function (_self, rowIndex, e)
284                             {
285                                 var rd = _this.grid.getDataSource().getAt(rowIndex);
286                                 var id = rd.data.id;
287                                 var url = String.format('{0}/Images/{1}/{2}', baseURL, rd.data.id, rd.data.filename);
288                                 _this.form.findField('contents').execCmd('insertimage', url);
289                             
290                             }
291                         },
292                         dataSource : {
293                             xtype: 'Store',
294                             xns: Roo.data,
295                             reader : Pman.Readers.Images,
296                             listeners : {
297                                 beforeload : function (_self, o)
298                                 {
299                                     if (!_this.data.id) {
300                                        return false;
301                                     } 
302                                     o.params = o.params || {};              
303                                     o.params.onid = _this.data.id;
304                                     o.params.ontable = 'Page';
305                                 }
306                             },
307                             proxy : {
308                                 xtype: 'HttpProxy',
309                                 xns: Roo.data,
310                                 method : 'GET',
311                                 url : baseURL + '/Roo/Images.php'
312                             }
313                         },
314                         toolbar : {
315                             xtype: 'Toolbar',
316                             xns: Roo,
317                             items : [
318                                 {
319                                     xtype: 'Button',
320                                     xns: Roo,
321                                     text : "Add",
322                                     cls : 'x-btn-text-icon',
323                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
324                                     listeners : {
325                                         click : function()
326                                                 {
327                                                     Pman.Dialog.Image.show( { id : 0, onid: _this.data.id, ontable: 'Page' }, function() {
328                                                         _this.grid.getDataSource().load();
329                                                     }); 
330                                         
331                                                 }
332                                     }
333                                 },
334                                 {
335                                     xtype: 'Button',
336                                     xns: Roo,
337                                     text : "Delete",
338                                     cls : 'x-btn-text-icon',
339                                     icon : rootURL + '/Pman/templates/images/trash.gif',
340                                     listeners : {
341                                         click : function()
342                                                 {
343                                                 Pman.genericDelete(_this, _this.panel.tableName); 
344                                                 }
345                                     }
346                                 }
347                             ]
348                         },
349                         colModel : [
350                             {
351                                 xtype: 'ColumnModel',
352                                 xns: Roo.grid,
353                                 header : '',
354                                 width : 50,
355                                 dataIndex : 'id',
356                                 renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}">', baseURL, v, r.data.filename); },
357                                 sortable : false
358                             },
359                             {
360                                 xtype: 'ColumnModel',
361                                 xns: Roo.grid,
362                                 header : 'Filename',
363                                 width : 100,
364                                 dataIndex : 'filename',
365                                 renderer : function(v) { return String.format('{0}', v); }
366                             }
367                         ]
368                     }
369                 }
370             ],
371             center : {
372                 xtype: 'LayoutRegion',
373                 xns: Roo,
374                 titlebar : false
375             },
376             east : {
377                 xtype: 'LayoutRegion',
378                 xns: Roo,
379                 titlebar : false,
380                 fitToFrame : 'true',
381                 width : 200
382             },
383             buttons : [
384                 {
385                     xtype: 'Button',
386                     xns: Roo,
387                     text : "Cancel",
388                     listeners : {
389                         click : function() {
390                         
391                                                             _this.form.reset();
392                         
393                                                             _this.dialog.hide();
394                         
395                                                         }
396                     }
397                 },
398                 {
399                     xtype: 'Button',
400                     xns: Roo,
401                     text : "OK",
402                     listeners : {
403                         click : function() {
404                         
405                                                             _this.dialog.el.mask("Saving");
406                          _this.form.findField('contents').syncValue();
407                                                             _this.form.doAction("submit");
408                         
409                                                         }
410                     }
411                 }
412             ]
413         });
414     }
415 };