Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / FeedGrid1.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js">FeedGrid = function(viewer, config) {\r
9     this.viewer = viewer;\r
10     Ext.apply(this, config);\r
11 \r
12     this.store = new Ext.data.Store({\r
13         proxy: new Ext.data.HttpProxy({\r
14             url: 'feed-proxy.php'\r
15         }),\r
16 \r
17         reader: new Ext.data.XmlReader(\r
18             {record: 'item'},\r
19             ['title', 'author', {name:'pubDate', type:'date'}, 'link', 'description', 'content']\r
20         )\r
21     });\r
22     this.store.setDefaultSort('pubDate', "DESC");\r
23 \r
24     this.columns = [{\r
25         id: 'title',\r
26         header: "Title",\r
27         dataIndex: 'title',\r
28         sortable:true,\r
29         width: 420,\r
30         renderer: this.formatTitle\r
31       },{\r
32         header: "Author",\r
33         dataIndex: 'author',\r
34         width: 100,\r
35         hidden: true,\r
36         sortable:true\r
37       },{\r
38         id: 'last',\r
39         header: "Date",\r
40         dataIndex: 'pubDate',\r
41         width: 150,\r
42         renderer:  this.formatDate,\r
43         sortable:true\r
44     }];\r
45 \r
46     FeedGrid.superclass.constructor.call(this, {\r
47         region: 'center',\r
48         id: 'topic-grid',\r
49         loadMask: {msg:'Loading Feed...'},\r
50 \r
51         sm: new Ext.grid.RowSelectionModel({\r
52             singleSelect:true\r
53         }),\r
54 \r
55         viewConfig: {\r
56             forceFit:true,\r
57             enableRowBody:true,\r
58             showPreview:true,\r
59             getRowClass : this.applyRowClass\r
60         }\r
61     });\r
62 \r
63     this.on('rowcontextmenu', this.onContextClick, this);\r
64 };\r
65 \r
66 Ext.extend(FeedGrid, Ext.grid.GridPanel, {\r
67 \r
68     onContextClick : function(grid, index, e){\r
69         if(!this.menu){ // create context menu on first right click\r
70             this.menu = new Ext.menu.Menu({\r
71                 id:'grid-ctx',\r
72                 items: [{\r
73                     text: 'View in new tab',\r
74                     iconCls: 'new-tab',\r
75                     scope:this,\r
76                     handler: function(){\r
77                         this.viewer.openTab(this.ctxRecord);\r
78                     }\r
79                 },{\r
80                     iconCls: 'new-win',\r
81                     text: 'Go to Post',\r
82                     scope:this,\r
83                     handler: function(){\r
84                         window.open(this.ctxRecord.data.link);\r
85                     }\r
86                 },'-',{\r
87                     iconCls: 'refresh-icon',\r
88                     text:'Refresh',\r
89                     scope:this,\r
90                     handler: function(){\r
91                         this.ctxRow = null;\r
92                         this.store.reload();\r
93                     }\r
94                 }]\r
95             });\r
96             this.menu.on('hide', this.onContextHide, this);\r
97         }\r
98         e.stopEvent();\r
99         if(this.ctxRow){\r
100             Ext.fly(this.ctxRow).removeClass('x-node-ctx');\r
101             this.ctxRow = null;\r
102         }\r
103         this.ctxRow = this.view.getRow(index);\r
104         this.ctxRecord = this.store.getAt(index);\r
105         Ext.fly(this.ctxRow).addClass('x-node-ctx');\r
106         this.menu.showAt(e.getXY());\r
107     },\r
108 \r
109     onContextHide : function(){\r
110         if(this.ctxRow){\r
111             Ext.fly(this.ctxRow).removeClass('x-node-ctx');\r
112             this.ctxRow = null;\r
113         }\r
114     },\r
115 \r
116     loadFeed : function(url) {\r
117         this.store.baseParams = {\r
118             feed: url\r
119         };\r
120         this.store.load();\r
121     },\r
122 \r
123     togglePreview : function(show){\r
124         this.view.showPreview = show;\r
125         this.view.refresh();\r
126     },\r
127 \r
128     // within this function "this" is actually the GridView\r
129     applyRowClass: function(record, rowIndex, p, ds) {\r
130         if (this.showPreview) {\r
131             var xf = Ext.util.Format;\r
132             p.body = '<p>' + xf.ellipsis(xf.stripTags(record.data.description), 200) + '</p>';\r
133             return 'x-grid3-row-expanded';\r
134         }\r
135         return 'x-grid3-row-collapsed';\r
136     },\r
137 \r
138     formatDate : function(date) {\r
139         if (!date) {\r
140             return '';\r
141         }\r
142         var now = new Date();\r
143         var d = now.clearTime(true);\r
144         var notime = date.clearTime(true).getTime();\r
145         if (notime == d.getTime()) {\r
146             return 'Today ' + date.dateFormat('g:i a');\r
147         }\r
148         d = d.add('d', -6);\r
149         if (d.getTime() <= notime) {\r
150             return date.dateFormat('D g:i a');\r
151         }\r
152         return date.dateFormat('n/j g:i a');\r
153     },\r
154 \r
155     formatTitle: function(value, p, record) {\r
156         return String.format(\r
157                 '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',\r
158                 value, record.data.author, record.id, record.data.forumid\r
159                 );\r
160     }\r
161 });\r
162 \r
163 Ext.reg('appfeedgrid', FeedGrid);</pre>    \r
164 </body>\r
165 </html>