3 * Copyright(c) 2006-2009 Ext JS, LLC
5 * http://www.extjs.com/license
7 FeedGrid = function(viewer, config) {
\r
8 this.viewer = viewer;
\r
9 Ext.apply(this, config);
\r
11 this.store = new Ext.data.Store({
\r
12 proxy: new Ext.data.HttpProxy({
\r
13 url: 'feed-proxy.php'
\r
16 reader: new Ext.data.XmlReader(
\r
18 ['title', 'author', {name:'pubDate', type:'date'}, 'link', 'description', 'content']
\r
21 this.store.setDefaultSort('pubDate', "DESC");
\r
29 renderer: this.formatTitle
\r
32 dataIndex: 'author',
\r
39 dataIndex: 'pubDate',
\r
41 renderer: this.formatDate,
\r
45 FeedGrid.superclass.constructor.call(this, {
\r
48 loadMask: {msg:'Loading Feed...'},
\r
50 sm: new Ext.grid.RowSelectionModel({
\r
58 getRowClass : this.applyRowClass
\r
62 this.on('rowcontextmenu', this.onContextClick, this);
\r
65 Ext.extend(FeedGrid, Ext.grid.GridPanel, {
\r
67 onContextClick : function(grid, index, e){
\r
68 if(!this.menu){ // create context menu on first right click
\r
69 this.menu = new Ext.menu.Menu({
\r
72 text: 'View in new tab',
\r
75 handler: function(){
\r
76 this.viewer.openTab(this.ctxRecord);
\r
82 handler: function(){
\r
83 window.open(this.ctxRecord.data.link);
\r
86 iconCls: 'refresh-icon',
\r
89 handler: function(){
\r
91 this.store.reload();
\r
95 this.menu.on('hide', this.onContextHide, this);
\r
99 Ext.fly(this.ctxRow).removeClass('x-node-ctx');
\r
100 this.ctxRow = null;
\r
102 this.ctxRow = this.view.getRow(index);
\r
103 this.ctxRecord = this.store.getAt(index);
\r
104 Ext.fly(this.ctxRow).addClass('x-node-ctx');
\r
105 this.menu.showAt(e.getXY());
\r
108 onContextHide : function(){
\r
110 Ext.fly(this.ctxRow).removeClass('x-node-ctx');
\r
111 this.ctxRow = null;
\r
115 loadFeed : function(url) {
\r
116 this.store.baseParams = {
\r
122 togglePreview : function(show){
\r
123 this.view.showPreview = show;
\r
124 this.view.refresh();
\r
127 // within this function "this" is actually the GridView
\r
128 applyRowClass: function(record, rowIndex, p, ds) {
\r
129 if (this.showPreview) {
\r
130 var xf = Ext.util.Format;
\r
131 p.body = '<p>' + xf.ellipsis(xf.stripTags(record.data.description), 200) + '</p>';
\r
132 return 'x-grid3-row-expanded';
\r
134 return 'x-grid3-row-collapsed';
\r
137 formatDate : function(date) {
\r
141 var now = new Date();
\r
142 var d = now.clearTime(true);
\r
143 var notime = date.clearTime(true).getTime();
\r
144 if (notime == d.getTime()) {
\r
145 return 'Today ' + date.dateFormat('g:i a');
\r
147 d = d.add('d', -6);
\r
148 if (d.getTime() <= notime) {
\r
149 return date.dateFormat('D g:i a');
\r
151 return date.dateFormat('n/j g:i a');
\r
154 formatTitle: function(value, p, record) {
\r
155 return String.format(
\r
156 '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',
\r
157 value, record.data.author, record.id, record.data.forumid
\r
162 Ext.reg('appfeedgrid', FeedGrid);