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: 'TextField',
114                                     xns: Roo.form,
115                                     fieldLabel : 'Page link',
116                                     name : 'page_link',
117                                     width : 200
118                                 },
119                                 {
120                                     xtype: 'ComboBox',
121                                     xns: Roo.form,
122                                     allowBlank : true,
123                                     displayField : 'link_path',
124                                     editable : false,
125                                     emptyText : "Select Parent",
126                                     fieldLabel : 'Parent page',
127                                     forceSelection : true,
128                                     hiddenName : 'parent_id',
129                                     listWidth : 400,
130                                     loadingText : "Searching...",
131                                     minChars : 2,
132                                     name : 'parent_id_link_path',
133                                     pageSize : 20,
134                                     qtip : "Select Category ",
135                                     selectOnFocus : true,
136                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b> </div>',
137                                     triggerAction : 'all',
138                                     typeAhead : true,
139                                     valueField : 'id',
140                                     width : 400,
141                                     store : {
142                                         xtype: 'Store',
143                                         xns: Roo.data,
144                                         proxy : {
145                                             xtype: 'HttpProxy',
146                                             xns: Roo.data,
147                                             method : 'GET',
148                                             url : baseURL + '/Roo/Page.php'
149                                         },
150                                         reader : {
151                                             xtype: 'JsonReader',
152                                             xns: Roo.data,
153                                             id : 'id',
154                                             root : 'data',
155                                             totalProperty : 'total',
156                                             fields : [
157                                              { name: 'id', type: 'int' },
158                                              'title',
159                                              'link_path' 
160                                             ]
161                                         }
162                                     }
163                                 },
164                                 {
165                                     xtype: 'DateField',
166                                     xns: Roo.form,
167                                     fieldLabel : 'Date to Publish',
168                                     name : 'published',
169                                     width : 200
170                                 },
171                                 {
172                                     xtype: 'Row',
173                                     xns: Roo.form,
174                                     hideLabels : true,
175                                     labelWidth : 0,
176                                     width : 520,
177                                     items : [
178                                         {
179                                             xtype: 'Checkbox',
180                                             xns: Roo.form,
181                                             boxLabel : 'Visible',
182                                             name : 'visible',
183                                             width : 100
184                                         },
185                                         {
186                                             xtype: 'Checkbox',
187                                             xns: Roo.form,
188                                             boxLabel : 'Display in RSS',
189                                             name : 'in_rss',
190                                             width : 150
191                                         },
192                                         {
193                                             xtype: 'Checkbox',
194                                             xns: Roo.form,
195                                             boxLabel : 'Extended Vis.?',
196                                             inputValue : 1,
197                                             name : 'has_extended',
198                                             width : 140
199                                         }
200                                     ]
201                                 },
202                                 {
203                                     xtype: 'TextField',
204                                     xns: Roo.form,
205                                     fieldLabel : 'Title',
206                                     name : 'title',
207                                     width : 390
208                                 },
209                                 {
210                                     xtype: 'Column',
211                                     xns: Roo.form,
212                                     width : '570',
213                                     labelAlign : 'top',
214                                     items : [
215                                         {
216                                             xtype: 'HtmlEditor',
217                                             xns: Roo.form,
218                                             fieldLabel : 'Contents',
219                                             height : 240,
220                                             name : 'contents',
221                                             width : 550
222                                         }
223                                     ]
224                                 },
225                                 {
226                                     xtype: 'Column',
227                                     xns: Roo.form,
228                                     width : '570',
229                                     labelAlign : 'top',
230                                     items : [
231                                         {
232                                             xtype: 'HtmlEditor',
233                                             xns: Roo.form,
234                                             fieldLabel : 'Extended Contents',
235                                             height : 340,
236                                             name : 'extended',
237                                             width : 550
238                                         }
239                                     ]
240                                 },
241                                 {
242                                     xtype: 'Hidden',
243                                     xns: Roo.form,
244                                     name : 'id'
245                                 }
246                             ]
247                         }
248                     ]
249                 },
250                 {
251                     xtype: 'GridPanel',
252                     xns: Roo,
253                     title : "Images",
254                     fitToframe : true,
255                     fitContainer : true,
256                     tableName : 'Images',
257                     background : false,
258                     listeners : {
259                         activate : function() {
260                             _this.panel = this;
261                             if (_this.grid) {
262                                 _this.grid.footer.onClick('first');
263                             }
264                         }
265                     },
266                     region : 'east',
267                     grid : {
268                         xtype: 'Grid',
269                         xns: Roo.grid,
270                         autoExpandColumn : 'filename',
271                         loadMask : true,
272                         listeners : {
273                             render : function() { 
274                                 _this.grid = this; 
275                                 //_this.dialog = Pman.Dialog.FILL_IN
276                                 if (_this.panel.active) {
277                                    //this.footer.onClick('first');
278                                 }
279                             },
280                             rowdblclick : function (_self, rowIndex, e)
281                             {
282                                 var rd = _this.grid.getDataSource().getAt(rowIndex);
283                                 var id = rd.data.id;
284                                 var url = String.format('{0}/Images/{1}/{2}', baseURL, rd.data.id, rd.data.filename);
285                                 _this.form.findField('contents').execCmd('insertimage', url);
286                             
287                             }
288                         },
289                         dataSource : {
290                             xtype: 'Store',
291                             xns: Roo.data,
292                             reader : Pman.Readers.Images,
293                             listeners : {
294                                 beforeload : function (_self, o)
295                                 {
296                                     if (!_this.data.id) {
297                                        return false;
298                                     } 
299                                     o.params = o.params || {};              
300                                     o.params.onid = _this.data.id;
301                                     o.params.ontable = 'Page';
302                                 }
303                             },
304                             proxy : {
305                                 xtype: 'HttpProxy',
306                                 xns: Roo.data,
307                                 method : 'GET',
308                                 url : baseURL + '/Roo/Images.php'
309                             }
310                         },
311                         toolbar : {
312                             xtype: 'Toolbar',
313                             xns: Roo,
314                             items : [
315                                 {
316                                     xtype: 'Button',
317                                     xns: Roo,
318                                     text : "Add",
319                                     cls : 'x-btn-text-icon',
320                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif',
321                                     listeners : {
322                                         click : function()
323                                                 {
324                                                     Pman.Dialog.Image.show( { id : 0, onid: _this.data.id, ontable: 'Page' }, function() {
325                                                         _this.grid.getDataSource().load();
326                                                     }); 
327                                         
328                                                 }
329                                     }
330                                 },
331                                 {
332                                     xtype: 'Button',
333                                     xns: Roo,
334                                     text : "Delete",
335                                     cls : 'x-btn-text-icon',
336                                     icon : rootURL + '/Pman/templates/images/trash.gif',
337                                     listeners : {
338                                         click : function()
339                                                 {
340                                                 Pman.genericDelete(_this, _this.panel.tableName); 
341                                                 }
342                                     }
343                                 }
344                             ]
345                         },
346                         colModel : [
347                             {
348                                 xtype: 'ColumnModel',
349                                 xns: Roo.grid,
350                                 header : '',
351                                 width : 50,
352                                 dataIndex : 'id',
353                                 renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}">', baseURL, v, r.data.filename); },
354                                 sortable : false
355                             },
356                             {
357                                 xtype: 'ColumnModel',
358                                 xns: Roo.grid,
359                                 header : 'Filename',
360                                 width : 100,
361                                 dataIndex : 'filename',
362                                 renderer : function(v) { return String.format('{0}', v); }
363                             }
364                         ]
365                     }
366                 }
367             ],
368             center : {
369                 xtype: 'LayoutRegion',
370                 xns: Roo,
371                 titlebar : false
372             },
373             east : {
374                 xtype: 'LayoutRegion',
375                 xns: Roo,
376                 titlebar : false,
377                 fitToFrame : 'true',
378                 width : 200
379             },
380             buttons : [
381                 {
382                     xtype: 'Button',
383                     xns: Roo,
384                     text : "Cancel",
385                     listeners : {
386                         click : function() {
387                         
388                                                             _this.form.reset();
389                         
390                                                             _this.dialog.hide();
391                         
392                                                         }
393                     }
394                 },
395                 {
396                     xtype: 'Button',
397                     xns: Roo,
398                     text : "OK",
399                     listeners : {
400                         click : function() {
401                         
402                                                             _this.dialog.el.mask("Saving");
403                          _this.form.findField('contents').syncValue();
404                                                             _this.form.doAction("submit");
405                         
406                                                         }
407                     }
408                 }
409             ]
410         });
411     }
412 };