Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / examples / app / feed-viewer / app / view / article / Grid.js
1 Ext.define('FV.view.article.Grid', {
2         extend: 'Ext.grid.Panel',
3         alias: 'widget.articlegrid',
4
5         cls: 'feed-grid',
6         disabled: true,
7
8     requires: ['Ext.ux.PreviewPlugin', 'Ext.toolbar.Toolbar'],
9     
10     border: false,
11     
12         initComponent: function() {
13                 Ext.apply(this, {
14                     store: 'Articles',
15
16                         viewConfig: {
17                                 plugins: [{
18                                         pluginId: 'preview',
19                                         ptype: 'preview',
20                                         bodyField: 'description',
21                                         previewExpanded: true
22                                 }]
23                         },
24
25                         columns: [{
26                                 text: 'Title',
27                                 dataIndex: 'title',
28                                 flex: 1,
29                                 renderer: this.formatTitle
30                         }, {
31                                 text: 'Author',
32                                 dataIndex: 'author',
33                                 hidden: true,
34                                 width: 200
35                         }, {
36                                 text: 'Date',
37                                 dataIndex: 'pubDate',
38                                 renderer: this.formatDate,
39                                 width: 200
40                         }],
41                         dockedItems:[{
42                                 xtype: 'toolbar',
43                                 dock: 'top',
44                                 items: [{
45                                         text: 'Open All',
46                                         action: 'openall'
47                                 }]
48                         }]
49                 });
50
51                 this.callParent(arguments);
52         },
53
54         /**
55          * Title renderer
56          * @private
57          */
58         formatTitle: function(value, p, record) {
59                 return Ext.String.format('<div class="topic"><b>{0}</b><span class="author">{1}</span></div>', value, record.get('author') || "Unknown");
60         },
61
62         /**
63          * Date renderer
64          * @private
65          */
66         formatDate: function(date) {
67                 if (!date) {
68                         return '';
69                 }
70
71                 var now = new Date(),
72                         d = Ext.Date.clearTime(now, true),
73                         notime = Ext.Date.clearTime(date, true).getTime();
74
75                 if (notime === d.getTime()) {
76                         return 'Today ' + Ext.Date.format(date, 'g:i a');
77                 }
78
79                 d = Ext.Date.add(d, 'd', -6);
80                 if (d.getTime() <= notime) {
81                         return Ext.Date.format(date, 'D g:i a');
82                 }
83                 return Ext.Date.format(date, 'Y/m/d g:i a');
84         }
85 });