3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
15 Ext.define('FeedViewer.FeedGrid', {
16 extend: 'Ext.grid.Panel',
18 alias: 'widget.feedgrid',
20 initComponent: function(){
24 * Fires when a row is double clicked
25 * @param {FeedViewer.FeedGrid} this
26 * @param {Ext.data.Model} model
31 * Fires when a grid row is selected
32 * @param {FeedViewer.FeedGrid} this
33 * @param {Ext.data.Model} model
40 store: Ext.create('Ext.data.Store', {
48 url: 'feed-proxy.php',
64 bodyField: 'description',
69 itemdblclick: this.onRowDblClick
76 renderer: this.formatTitle
86 renderer: this.formatDate,
90 this.callParent(arguments);
91 this.on('selectionchange', this.onSelect, this);
95 * Reacts to a double click
97 * @param {Object} view The view
98 * @param {Object} index The row index
100 onRowDblClick: function(view, record, item, index, e) {
101 this.fireEvent('rowdblclick', this, this.store.getAt(index));
106 * React to a grid item being selected
108 * @param {Ext.model.Selection} model The selection model
109 * @param {Array} selections An array of selections
111 onSelect: function(model, selections){
112 var selected = selections[0];
114 this.fireEvent('select', this, selected);
119 * Listens for the store loading
123 this.getSelectionModel().select(0);
127 * Instructs the grid to load a new feed
128 * @param {String} url The url to load
130 loadFeed: function(url){
131 var store = this.store;
132 store.getProxy().extraParams.feed = url;
140 formatTitle: function(value, p, record){
141 return Ext.String.format('<div class="topic"><b>{0}</b><span class="author">{1}</span></div>', value, record.get('author') || "Unknown");
148 formatDate: function(date){
153 var now = new Date(), d = Ext.Date.clearTime(now, true), notime = Ext.Date.clearTime(date, true).getTime();
155 if (notime === d.getTime()) {
156 return 'Today ' + Ext.Date.format(date, 'g:i a');
159 d = Ext.Date.add(d, 'd', -6);
160 if (d.getTime() <= notime) {
161 return Ext.Date.format(date, 'D g:i a');
163 return Ext.Date.format(date, 'Y/m/d g:i a');