1 Ext.define('FeedViewer.FeedGrid', {
2 extend: 'Ext.grid.Panel',
4 alias: 'widget.feedgrid',
6 initComponent: function(){
10 * Fires when a row is double clicked
11 * @param {FeedViewer.FeedGrid} this
12 * @param {Ext.data.Model} model
17 * Fires when a grid row is selected
18 * @param {FeedViewer.FeedGrid} this
19 * @param {Ext.data.Model} model
26 store: Ext.create('Ext.data.Store', {
34 url: 'feed-proxy.php',
50 bodyField: 'description',
55 itemdblclick: this.onRowDblClick
62 renderer: this.formatTitle
72 renderer: this.formatDate,
76 this.callParent(arguments);
77 this.on('selectionchange', this.onSelect, this);
81 * Reacts to a double click
83 * @param {Object} view The view
84 * @param {Object} index The row index
86 onRowDblClick: function(view, record, item, index, e) {
87 this.fireEvent('rowdblclick', this, this.store.getAt(index));
92 * React to a grid item being selected
94 * @param {Ext.model.Selection} model The selection model
95 * @param {Array} selections An array of selections
97 onSelect: function(model, selections){
98 var selected = selections[0];
100 this.fireEvent('select', this, selected);
105 * Listens for the store loading
109 this.getSelectionModel().select(0);
113 * Instructs the grid to load a new feed
114 * @param {String} url The url to load
116 loadFeed: function(url){
117 var store = this.store;
118 store.getProxy().extraParams.feed = url;
126 formatTitle: function(value, p, record){
127 return Ext.String.format('<div class="topic"><b>{0}</b><span class="author">{1}</span></div>', value, record.get('author') || "Unknown");
134 formatDate: function(date){
139 var now = new Date(), d = Ext.Date.clearTime(now, true), notime = Ext.Date.clearTime(date, true).getTime();
141 if (notime === d.getTime()) {
142 return 'Today ' + Ext.Date.format(date, 'g:i a');
145 d = Ext.Date.add(d, 'd', -6);
146 if (d.getTime() <= notime) {
147 return Ext.Date.format(date, 'D g:i a');
149 return Ext.Date.format(date, 'Y/m/d g:i a');