Pman.Tab.CmsProduct.js
[Pman.Cms] / Pman.Dialog.CmsBlog.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.CmsBlog = {
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                                           if ( _this.data.id) {
76                                                 _this.dialog.el.mask("Loading");
77                                                 this.load({ method: 'GET', params: { '_id' : _this.data.id }});
78                                            } else {
79                                                 _this.loaded = true;
80                                                  this.findField('is_draft').setValue(1);
81                                           }
82                                 
83                                        return;
84                                       
85                                     }
86                                     
87                                     if (action.type == 'load') {
88                                         _this.dialog.el.unmask();
89                                        _this.grid.getDataSource().load();
90                                         return;
91                                     }
92                                 },
93                                 rendered : function (_self)
94                                 {
95                                     _this.form = _self;
96                                 }
97                             },
98                             method : 'POST',
99                             style : 'margin: 5px',
100                             url : baseURL + '/Roo/CmsBlog.php',
101                             items : [
102                                 {
103                                     xtype: 'Row',
104                                     xns: Roo.form,
105                                     labelWidth : 70,
106                                     width : 900,
107                                     items : [
108                                         {
109                                             xtype: 'TextField',
110                                             xns: Roo.form,
111                                             fieldLabel : 'Page link',
112                                             name : 'page_link',
113                                             width : 200
114                                         },
115                                         {
116                                             xtype: 'ComboBox',
117                                             xns: Roo.form,
118                                             allowBlank : 'false',
119                                             displayField : 'title',
120                                             editable : 'false',
121                                             emptyText : "Select Category",
122                                             fieldLabel : 'Category',
123                                             forceSelection : true,
124                                             hiddenName : 'category_id',
125                                             listWidth : 400,
126                                             loadingText : "Searching...",
127                                             minChars : 2,
128                                             name : 'category_id_title',
129                                             pageSize : 20,
130                                             qtip : "Select Category",
131                                             queryParam : '',
132                                             selectOnFocus : true,
133                                             tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b> </div>',
134                                             triggerAction : 'all',
135                                             typeAhead : true,
136                                             valueField : 'id',
137                                             width : 200,
138                                             store : {
139                                                 xtype: 'Store',
140                                                 xns: Roo.data,
141                                                 listeners : {
142                                                     beforeload : function (_self, o){
143                                                         o.params = o.params || {};
144                                                         // set more here
145                                                     }
146                                                 },
147                                                 proxy : {
148                                                     xtype: 'HttpProxy',
149                                                     xns: Roo.data,
150                                                     method : 'GET',
151                                                     url : baseURL + '/Roo/Category.php'
152                                                 },
153                                                 reader : {
154                                                     xtype: 'JsonReader',
155                                                     xns: Roo.data,
156                                                     id : 'id',
157                                                     root : 'data',
158                                                     totalProperty : 'total',
159                                                     fields : [{"name":"id","type":"int"},{"name":"title","type":"string"}]
160                                                 }
161                                             }
162                                         }
163                                     ]
164                                 },
165                                 {
166                                     xtype: 'ComboBox',
167                                     xns: Roo.form,
168                                     allowBlank : true,
169                                     displayField : 'page_link',
170                                     editable : true,
171                                     emptyText : "Select Parent",
172                                     fieldLabel : 'Parent page',
173                                     forceSelection : true,
174                                     hiddenName : 'parent_id',
175                                     listWidth : 400,
176                                     loadingText : "Searching...",
177                                     minChars : 2,
178                                     name : 'parent_id_page_link',
179                                     pageSize : 20,
180                                     qtip : "Select Category ",
181                                     queryParam : '_search',
182                                     selectOnFocus : true,
183                                     tpl : '<div class="x-grid-cell-text x-btn button"><b>{title}</b><br/><i>{page_link}</i> </div>',
184                                     triggerAction : 'all',
185                                     typeAhead : true,
186                                     valueField : 'id',
187                                     width : 400,
188                                     store : {
189                                         xtype: 'Store',
190                                         xns: Roo.data,
191                                         listeners : {
192                                             beforeload : function (_self, options)
193                                             {
194                                                  options.params['query[page_link_no_empty]'] =1;
195                                             }
196                                         },
197                                         remoteSort : true,
198                                         sortInfo : { field: 'page_link', direction: 'ASC' },
199                                         proxy : {
200                                             xtype: 'HttpProxy',
201                                             xns: Roo.data,
202                                             method : 'GET',
203                                             url : baseURL + '/Roo/CmsBlog.php'
204                                         },
205                                         reader : {
206                                             xtype: 'JsonReader',
207                                             xns: Roo.data,
208                                             id : 'id',
209                                             root : 'data',
210                                             totalProperty : 'total',
211                                             fields : [
212                                              { name: 'id', type: 'int' },
213                                              'title',
214                                              'page_link' 
215                                             ]
216                                         }
217                                     }
218                                 },
219                                 {
220                                     xtype: 'Row',
221                                     xns: Roo.form,
222                                     items : [
223                                         {
224                                             xtype: 'DateField',
225                                             xns: Roo.form,
226                                             altFormats : 'Y-m-d H:i:s',
227                                             fieldLabel : 'Date to Publish',
228                                             format : 'Y-m-d',
229                                             name : 'published',
230                                             width : 200
231                                         },
232                                         {
233                                             xtype: 'TextField',
234                                             xns: Roo.form,
235                                             fieldLabel : 'Replaces',
236                                             name : 'to_replace_id',
237                                             width : 75
238                                         }
239                                     ]
240                                 },
241                                 {
242                                     xtype: 'Row',
243                                     xns: Roo.form,
244                                     hideLabels : true,
245                                     labelWidth : 0,
246                                     width : 520,
247                                     items : [
248                                         {
249                                             xtype: 'Checkbox',
250                                             xns: Roo.form,
251                                             boxLabel : 'Draft',
252                                             name : 'is_draft',
253                                             width : 150
254                                         },
255                                         {
256                                             xtype: 'Checkbox',
257                                             xns: Roo.form,
258                                             boxLabel : 'Extended Vis.?',
259                                             inputValue : 1,
260                                             name : 'has_extended',
261                                             width : 140
262                                         },
263                                         {
264                                             xtype: 'Checkbox',
265                                             xns: Roo.form,
266                                             boxLabel : 'Display in RSS',
267                                             name : 'in_rss',
268                                             width : 150
269                                         }
270                                     ]
271                                 },
272                                 {
273                                     xtype: 'TextField',
274                                     xns: Roo.form,
275                                     fieldLabel : 'Title',
276                                     name : 'title',
277                                     width : 430
278                                 },
279                                 {
280                                     xtype: 'Column',
281                                     xns: Roo.form,
282                                     width : '570',
283                                     labelAlign : 'top',
284                                     items : [
285                                         {
286                                             xtype: 'HtmlEditor',
287                                             xns: Roo.form,
288                                             fieldLabel : 'Contents',
289                                             height : 240,
290                                             name : 'body',
291                                             width : 550
292                                         }
293                                     ]
294                                 },
295                                 {
296                                     xtype: 'Column',
297                                     xns: Roo.form,
298                                     width : '570',
299                                     labelAlign : 'top',
300                                     items : [
301                                         {
302                                             xtype: 'HtmlEditor',
303                                             xns: Roo.form,
304                                             fieldLabel : 'Extended Contents',
305                                             height : 340,
306                                             name : 'extended',
307                                             width : 550
308                                         }
309                                     ]
310                                 },
311                                 {
312                                     xtype: 'Hidden',
313                                     xns: Roo.form,
314                                     name : 'id'
315                                 }
316                             ]
317                         }
318                     ]
319                 },
320                 {
321                     xtype: 'GridPanel',
322                     xns: Roo,
323                     title : "Images",
324                     fitToframe : true,
325                     fitContainer : true,
326                     tableName : 'Images',
327                     background : false,
328                     listeners : {
329                         activate : function() {
330                             _this.panel = this;
331                             if (_this.grid) {
332                                 _this.grid.footer.onClick('first');
333                             }
334                         }
335                     },
336                     region : 'east',
337                     grid : {
338                         xtype: 'Grid',
339                         xns: Roo.grid,
340                         autoExpandColumn : 'filename',
341                         loadMask : true,
342                         listeners : {
343                             render : function() { 
344                                 _this.grid = this; 
345                                 //_this.dialog = Pman.Dialog.FILL_IN
346                                 if (_this.panel.active) {
347                                    //this.footer.onClick('first');
348                                 }
349                             },
350                             rowdblclick : function (_self, rowIndex, e)
351                             {
352                                 var rd = _this.grid.getDataSource().getAt(rowIndex);
353                                 var id = rd.data.id;
354                                 var url = String.format('{0}/Images/{1}/{2}', baseURL, rd.data.id, rd.data.filename);
355                                 _this.form.findField('contents').execCmd('insertimage', url);
356                             
357                             }
358                         },
359                         dataSource : {
360                             xtype: 'Store',
361                             xns: Roo.data,
362                             listeners : {
363                                 beforeload : function (_self, o)
364                                 {
365                                     if (!_this.data.id) {
366                                        return false;
367                                     } 
368                                     o.params = o.params || {};              
369                                     o.params.onid = _this.data.id;
370                                     o.params.ontable = 'CmsBlog';
371                                 }
372                             },
373                             reader : Pman.Readers.Images,
374                             proxy : {
375                                 xtype: 'HttpProxy',
376                                 xns: Roo.data,
377                                 method : 'GET',
378                                 url : baseURL + '/Roo/Images.php'
379                             }
380                         },
381                         toolbar : {
382                             xtype: 'Toolbar',
383                             xns: Roo,
384                             items : [
385                                 {
386                                     xtype: 'Button',
387                                     xns: Roo,
388                                     listeners : {
389                                         click : function()
390                                                 {
391                                                     Pman.Dialog.Image.show( { id : 0, onid: _this.data.id, ontable: 'CmsBlog' }, function() {
392                                                         _this.grid.getDataSource().load();
393                                                     }); 
394                                         
395                                                 }
396                                     },
397                                     cls : 'x-btn-text-icon',
398                                     text : "Add",
399                                     icon : Roo.rootURL + 'images/default/dd/drop-add.gif'
400                                 },
401                                 {
402                                     xtype: 'Button',
403                                     xns: Roo,
404                                     text : "Delete",
405                                     cls : 'x-btn-text-icon',
406                                     icon : rootURL + '/Pman/templates/images/trash.gif',
407                                     listeners : {
408                                         click : function()
409                                                 {
410                                                 Pman.genericDelete(_this, _this.panel.tableName); 
411                                                 }
412                                     }
413                                 }
414                             ]
415                         },
416                         colModel : [
417                             {
418                                 xtype: 'ColumnModel',
419                                 xns: Roo.grid,
420                                 header : '',
421                                 width : 50,
422                                 dataIndex : 'id',
423                                 renderer : function(v,x,r) { return String.format('<img src="{0}/Images/Thumb/100/{1}/{2}">', baseURL, v, r.data.filename); },
424                                 sortable : false
425                             },
426                             {
427                                 xtype: 'ColumnModel',
428                                 xns: Roo.grid,
429                                 header : 'Filename',
430                                 width : 100,
431                                 dataIndex : 'filename',
432                                 renderer : function(v) { return String.format('{0}', v); }
433                             }
434                         ]
435                     }
436                 }
437             ],
438             center : {
439                 xtype: 'LayoutRegion',
440                 xns: Roo,
441                 titlebar : false
442             },
443             east : {
444                 xtype: 'LayoutRegion',
445                 xns: Roo,
446                 titlebar : false,
447                 fitToFrame : 'true',
448                 width : 200
449             },
450             buttons : [
451                 {
452                     xtype: 'Button',
453                     xns: Roo,
454                     text : "Cancel",
455                     listeners : {
456                         click : function() {
457                         
458                                                             _this.form.reset();
459                         
460                                                             _this.dialog.hide();
461                         
462                                                         }
463                     }
464                 },
465                 {
466                     xtype: 'Button',
467                     xns: Roo,
468                     listeners : {
469                         click : function() {
470                         
471                                                             _this.dialog.el.mask("Saving");
472                                      _this.form.findField('body').syncValue();
473                                                             _this.form.doAction("submit");
474                         
475                                                         }
476                     },
477                     text : "OK"
478                 }
479             ]
480         });
481     }
482 };