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                     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                                     if (action.type == 'setdata') {    
73                                           _this.loaded = false;
74                                           
75                                   //      _this.dialog.getLayout().showPanel(0);
76                                     //   _this.form.addForm(_this.form1);
77                                           if ( _this.data.id) {
78                                                 _this.dialog.el.mask("Loading");
79                                                 this.load({ method: 'GET', params: { '_id' : _this.data.id }});
80                                            } else {
81                                                 _this.loaded = true;
82                                                 //disable image upload!
83                                               _this.form.findField('publish_status').setValue(-1);
84                                           }
85                                 
86                                        return;
87                                       
88                                     }
89                                     
90                                     if (action.type == 'load') {
91                                         _this.dialog.el.unmask();
92                                        _this.grid.getDataSource().load();
93                                         return;
94                                     }
95                                 },
96                                 rendered : function (_self)
97                                 {
98                                     _this.form = _self;
99                                 }
100                             },
101                             method : 'POST',
102                             style : 'margin: 5px',
103                             url : baseURL + '/Roo/Page.php',
104                             items : [
105                                 {
106                                     xtype: 'TextField',
107                                     xns: Roo.form,
108                                     fieldLabel : 'Replaces',
109                                     name : 'replaces_id',
110                                     width : 75
111                                 },
112                                 {
113                                     xtype: 'ComboBox',
114                                     xns: Roo.form,
115                                     allowBlank : true,
116                                     displayField : 'link_path',
117                                     editable : false,
118                                     emptyText : "Select Parent",
119                                     fieldLabel : 'Parent page',
120                                     forceSelection : true,
121                                     hiddenName : 'parent_id',
122                                     listWidth : 400,
123                                     loadingText : "Searching...",
124                                     minChars : 2,
125                                     name : 'parent_id_link_path',
126                                     pageSize : 20,
127                                     qtip : "Select Category ",
128                                     selectOnFocus : true,
129                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b> </div>',
130                                     triggerAction : 'all',
131                                     typeAhead : true,
132                                     valueField : 'id',
133                                     width : 400,
134                                     store : {
135                                         xtype: 'Store',
136                                         xns: Roo.data,
137                                         proxy : {
138                                             xtype: 'HttpProxy',
139                                             xns: Roo.data,
140                                             method : 'GET',
141                                             url : baseURL + '/Roo/Page.php'
142                                         },
143                                         reader : {
144                                             xtype: 'JsonReader',
145                                             xns: Roo.data,
146                                             totalProperty : 'total',
147                                             root : 'data',
148                                             id : 'id',
149                                             fields : []
150                                         }
151                                     }
152                                 },
153                                 {
154                                     xtype: 'TextField',
155                                     xns: Roo.form,
156                                     fieldLabel : 'Parent',
157                                     name : 'parent_id',
158                                     width : 75
159                                 },
160                                 {
161                                     xtype: 'TextField',
162                                     xns: Roo.form,
163                                     fieldLabel : 'Page link',
164                                     name : 'page_link',
165                                     width : 200
166                                 },
167                                 {
168                                     xtype: 'DateField',
169                                     xns: Roo.form,
170                                     fieldLabel : 'Date to Publish',
171                                     name : 'published',
172                                     width : 200
173                                 },
174                                 {
175                                     xtype: 'Row',
176                                     xns: Roo.form,
177                                     hideLabels : true,
178                                     labelWidth : 0,
179                                     width : 520,
180                                     items : [
181                                         {
182                                             xtype: 'Checkbox',
183                                             xns: Roo.form,
184                                             boxLabel : 'Visible',
185                                             name : 'visible',
186                                             width : 100
187                                         },
188                                         {
189                                             xtype: 'Checkbox',
190                                             xns: Roo.form,
191                                             boxLabel : 'Display in RSS',
192                                             name : 'in_rss',
193                                             width : 150
194                                         },
195                                         {
196                                             xtype: 'Checkbox',
197                                             xns: Roo.form,
198                                             boxLabel : 'Extended Vis.?',
199                                             inputValue : 1,
200                                             name : 'has_extended',
201                                             width : 140
202                                         }
203                                     ]
204                                 },
205                                 {
206                                     xtype: 'TextField',
207                                     xns: Roo.form,
208                                     fieldLabel : 'Title',
209                                     name : 'title',
210                                     width : 390
211                                 },
212                                 {
213                                     xtype: 'Column',
214                                     xns: Roo.form,
215                                     width : '570',
216                                     labelAlign : 'top',
217                                     items : [
218                                         {
219                                             xtype: 'HtmlEditor',
220                                             xns: Roo.form,
221                                             fieldLabel : 'Contents',
222                                             height : 240,
223                                             name : 'contents',
224                                             width : 550
225                                         }
226                                     ]
227                                 },
228                                 {
229                                     xtype: 'Column',
230                                     xns: Roo.form,
231                                     width : '570',
232                                     labelAlign : 'top',
233                                     items : [
234                                         {
235                                             xtype: 'HtmlEditor',
236                                             xns: Roo.form,
237                                             fieldLabel : 'Extended Contents',
238                                             height : 340,
239                                             name : 'extended',
240                                             width : 550
241                                         }
242                                     ]
243                                 },
244                                 {
245                                     xtype: 'Hidden',
246                                     xns: Roo.form,
247                                     name : 'id'
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 };