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 renderer: this.formatTitle
74 renderer: this.formatDate,
83 bodyField: 'description',
88 dblclick: this.onRowDblClick,
89 afterrender: this.onViewRender
93 this.callParent(arguments);
94 this.on('selectionchange', this.onSelect, this);
98 onViewRender: function() {
100 me.keyNav = Ext.create('Ext.util.KeyNav', me.items.getAt(0).el, {
101 enter: me.onEnterKey,
106 onDestroy: function() {
108 Ext.destroy(me.keyNav);
110 me.callParent(arguments);
113 onEnterKey: function(e) {
116 idx = view.indexOf(view.getSelectedNodes()[0]);
118 me.onRowDblClick(view, idx);
122 * Reacts to a double click
124 * @param {Object} view The view
125 * @param {Object} index The row index
127 onRowDblClick: function(view, index){
128 this.fireEvent('rowdblclick', this, this.store.getAt(index));
133 * React to a grid item being selected
135 * @param {Ext.model.Selection} model The selection model
136 * @param {Array} selections An array of selections
138 onSelect: function(model, selections){
139 var selected = selections[0];
141 this.fireEvent('select', this, selected);
146 * Listens for the store loading
150 this.getSelectionModel().select(0);
154 * Instructs the grid to load a new feed
155 * @param {String} url The url to load
157 loadFeed: function(url){
158 var store = this.store;
159 store.getProxy().extraParams.feed = url;
167 formatTitle: function(value, p, record){
168 return Ext.String.format('<div class="topic"><b>{0}</b><span class="author">{1}</span></div>', value, record.get('author'));
175 formatDate: function(date){
180 var now = new Date(), d = Ext.Date.clearTime(now, true), notime = Ext.Date.clearTime(date, true).getTime();
182 if (notime === d.getTime()) {
183 return 'Today ' + Ext.Date.format(date, 'g:i a');
186 d = Ext.Date.add(d, 'd', -6);
187 if (d.getTime() <= notime) {
188 return Ext.Date.format(date, 'D g:i a');
190 return Ext.Date.format(date, 'Y/m/d g:i a');