source: trunk/web/addons/job_monarch/lib/extjs/examples/feed-viewer/FeedGrid.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 4.6 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9FeedGrid = function(viewer, config) {
10    this.viewer = viewer;
11    Ext.apply(this, config);
12
13    this.store = new Ext.data.Store({
14        proxy: new Ext.data.HttpProxy({
15            url: 'feed-proxy.php'
16        }),
17
18        reader: new Ext.data.XmlReader(
19            {record: 'item'},
20            ['title', 'author', {name:'pubDate', type:'date'}, 'link', 'description', 'content']
21        )
22    });
23    this.store.setDefaultSort('pubDate', "DESC");
24
25    this.columns = [{
26        id: 'title',
27        header: "Title",
28        dataIndex: 'title',
29        sortable:true,
30        width: 420,
31        renderer: this.formatTitle
32      },{
33        header: "Author",
34        dataIndex: 'author',
35        width: 100,
36        hidden: true,
37        sortable:true
38      },{
39        id: 'last',
40        header: "Date",
41        dataIndex: 'pubDate',
42        width: 150,
43        renderer:  this.formatDate,
44        sortable:true
45    }];
46
47    FeedGrid.superclass.constructor.call(this, {
48        region: 'center',
49        id: 'topic-grid',
50        loadMask: {msg:'Loading Feed...'},
51
52        sm: new Ext.grid.RowSelectionModel({
53            singleSelect:true
54        }),
55
56        viewConfig: {
57            forceFit:true,
58            enableRowBody:true,
59            showPreview:true,
60            getRowClass : this.applyRowClass
61        }
62    });
63
64    this.on('rowcontextmenu', this.onContextClick, this);
65};
66
67Ext.extend(FeedGrid, Ext.grid.GridPanel, {
68
69    onContextClick : function(grid, index, e){
70        if(!this.menu){ // create context menu on first right click
71            this.menu = new Ext.menu.Menu({
72                id:'grid-ctx',
73                items: [{
74                    text: 'View in new tab',
75                    iconCls: 'new-tab',
76                    scope:this,
77                    handler: function(){
78                        this.viewer.openTab(this.ctxRecord);
79                    }
80                },{
81                    iconCls: 'new-win',
82                    text: 'Go to Post',
83                    scope:this,
84                    handler: function(){
85                        window.open(this.ctxRecord.data.link);
86                    }
87                },'-',{
88                    iconCls: 'refresh-icon',
89                    text:'Refresh',
90                    scope:this,
91                    handler: function(){
92                        this.ctxRow = null;
93                        this.store.reload();
94                    }
95                }]
96            });
97            this.menu.on('hide', this.onContextHide, this);
98        }
99        e.stopEvent();
100        if(this.ctxRow){
101            Ext.fly(this.ctxRow).removeClass('x-node-ctx');
102            this.ctxRow = null;
103        }
104        this.ctxRow = this.view.getRow(index);
105        this.ctxRecord = this.store.getAt(index);
106        Ext.fly(this.ctxRow).addClass('x-node-ctx');
107        this.menu.showAt(e.getXY());
108    },
109
110    onContextHide : function(){
111        if(this.ctxRow){
112            Ext.fly(this.ctxRow).removeClass('x-node-ctx');
113            this.ctxRow = null;
114        }
115    },
116
117    loadFeed : function(url) {
118        this.store.baseParams = {
119            feed: url
120        };
121        this.store.load();
122    },
123
124    togglePreview : function(show){
125        this.view.showPreview = show;
126        this.view.refresh();
127    },
128
129    // within this function "this" is actually the GridView
130    applyRowClass: function(record, rowIndex, p, ds) {
131        if (this.showPreview) {
132            var xf = Ext.util.Format;
133            p.body = '<p>' + xf.ellipsis(xf.stripTags(record.data.description), 200) + '</p>';
134            return 'x-grid3-row-expanded';
135        }
136        return 'x-grid3-row-collapsed';
137    },
138
139    formatDate : function(date) {
140        if (!date) {
141            return '';
142        }
143        var now = new Date();
144        var d = now.clearTime(true);
145        var notime = date.clearTime(true).getTime();
146        if (notime == d.getTime()) {
147            return 'Today ' + date.dateFormat('g:i a');
148        }
149        d = d.add('d', -6);
150        if (d.getTime() <= notime) {
151            return date.dateFormat('D g:i a');
152        }
153        return date.dateFormat('n/j g:i a');
154    },
155
156    formatTitle: function(value, p, record) {
157        return String.format(
158                '<div class="topic"><b>{0}</b><span class="author">{1}</span></div>',
159                value, record.data.author, record.id, record.data.forumid
160                );
161    }
162});
Note: See TracBrowser for help on using the repository browser.