Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / examples / app / feed-viewer / app / view / article / Grid.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 Ext.define('FV.view.article.Grid', {
16         extend: 'Ext.grid.Panel',
17         alias: 'widget.articlegrid',
18
19         cls: 'feed-grid',
20         disabled: true,
21
22     requires: ['Ext.ux.PreviewPlugin', 'Ext.toolbar.Toolbar'],
23     
24     border: false,
25     
26         initComponent: function() {
27                 Ext.apply(this, {
28                     store: 'Articles',
29
30                         viewConfig: {
31                                 plugins: [{
32                                         pluginId: 'preview',
33                                         ptype: 'preview',
34                                         bodyField: 'description',
35                                         previewExpanded: true
36                                 }]
37                         },
38
39                         columns: [{
40                                 text: 'Title',
41                                 dataIndex: 'title',
42                                 flex: 1,
43                                 renderer: this.formatTitle
44                         }, {
45                                 text: 'Author',
46                                 dataIndex: 'author',
47                                 hidden: true,
48                                 width: 200
49                         }, {
50                                 text: 'Date',
51                                 dataIndex: 'pubDate',
52                                 renderer: this.formatDate,
53                                 width: 200
54                         }],
55                         dockedItems:[{
56                                 xtype: 'toolbar',
57                                 dock: 'top',
58                                 items: [{
59                                         text: 'Open All',
60                                         action: 'openall'
61                                 }]
62                         }]
63                 });
64
65                 this.callParent(arguments);
66         },
67
68         /**
69          * Title renderer
70          * @private
71          */
72         formatTitle: function(value, p, record) {
73                 return Ext.String.format('<div class="topic"><b>{0}</b><span class="author">{1}</span></div>', value, record.get('author') || "Unknown");
74         },
75
76         /**
77          * Date renderer
78          * @private
79          */
80         formatDate: function(date) {
81                 if (!date) {
82                         return '';
83                 }
84
85                 var now = new Date(),
86                         d = Ext.Date.clearTime(now, true),
87                         notime = Ext.Date.clearTime(date, true).getTime();
88
89                 if (notime === d.getTime()) {
90                         return 'Today ' + Ext.Date.format(date, 'g:i a');
91                 }
92
93                 d = Ext.Date.add(d, 'd', -6);
94                 if (d.getTime() <= notime) {
95                         return Ext.Date.format(date, 'D g:i a');
96                 }
97                 return Ext.Date.format(date, 'Y/m/d g:i a');
98         }
99 });
100