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
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
12 this.store = new Ext.data.Store({
\r
13 proxy: new Ext.data.HttpProxy({
\r
14 url: 'feed-proxy.php'
\r
17 reader: new Ext.data.XmlReader(
\r
19 ['title', 'author', {name:'pubDate', type:'date'}, 'link', 'description', 'content']
\r
22 this.store.setDefaultSort('pubDate', "DESC");
\r
30 renderer: this.formatTitle
\r
33 dataIndex: 'author',
\r
40 dataIndex: 'pubDate',
\r
42 renderer: this.formatDate,
\r
46 FeedGrid.superclass.constructor.call(this, {
\r
49 loadMask: {msg:'Loading Feed...'},
\r
51 sm: new Ext.grid.RowSelectionModel({
\r
59 getRowClass : this.applyRowClass
\r
63 this.on('rowcontextmenu', this.onContextClick, this);
\r
66 Ext.extend(FeedGrid, Ext.grid.GridPanel, {
\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
73 text: 'View in new tab',
\r
76 handler: function(){
\r
77 this.viewer.openTab(this.ctxRecord);
\r
83 handler: function(){
\r
84 window.open(this.ctxRecord.data.link);
\r
87 iconCls: 'refresh-icon',
\r
90 handler: function(){
\r
92 this.store.reload();
\r
96 this.menu.on('hide', this.onContextHide, this);
\r
100 Ext.fly(this.ctxRow).removeClass('x-node-ctx');
\r
101 this.ctxRow = null;
\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
109 onContextHide : function(){
\r
111 Ext.fly(this.ctxRow).removeClass('x-node-ctx');
\r
112 this.ctxRow = null;
\r
116 loadFeed : function(url) {
\r
117 this.store.baseParams = {
\r
123 togglePreview : function(show){
\r
124 this.view.showPreview = show;
\r
125 this.view.refresh();
\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
135 return 'x-grid3-row-collapsed';
\r
138 formatDate : function(date) {
\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
148 d = d.add('d', -6);
\r
149 if (d.getTime() <= notime) {
\r
150 return date.dateFormat('D g:i a');
\r
152 return date.dateFormat('n/j g:i a');
\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
163 Ext.reg('appfeedgrid', FeedGrid);</pre>
\r