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