git_sitools_idoc / szcluster-db / workspace / client-public / js / feedsReader / rss2FeedsReader.js @ d45a7442
| 1 |
/***************************************
|
|---|---|
| 2 |
* Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
|
| 3 |
*
|
| 4 |
* This file is part of SITools2.
|
| 5 |
*
|
| 6 |
* SITools2 is free software: you can redistribute it and/or modify
|
| 7 |
* it under the terms of the GNU General Public License as published by
|
| 8 |
* the Free Software Foundation, either version 3 of the License, or
|
| 9 |
* (at your option) any later version.
|
| 10 |
*
|
| 11 |
* SITools2 is distributed in the hope that it will be useful,
|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 14 |
* GNU General Public License for more details.
|
| 15 |
*
|
| 16 |
* You should have received a copy of the GNU General Public License
|
| 17 |
* along with SITools2. If not, see <http://www.gnu.org/licenses/>.
|
| 18 |
***************************************/
|
| 19 |
/*global Ext, sitools, i18n,document,window,SitoolsDesk*/
|
| 20 |
Ext.namespace('sitools.widget');
|
| 21 |
|
| 22 |
/**
|
| 23 |
* @param urlFeed :
|
| 24 |
* The feed URL
|
| 25 |
*/
|
| 26 |
sitools.widget.rss2FeedReader = function (config) { |
| 27 |
Ext.apply(this);
|
| 28 |
this.layout = "fit"; |
| 29 |
this.storeFeedsRecords = new Ext.data.Store({ |
| 30 |
autoLoad : true, |
| 31 |
sortInfo : {field : 'pubDate', direction : "DESC"}, |
| 32 |
proxy : new Ext.data.HttpProxy({ |
| 33 |
url : config.urlFeed,
|
| 34 |
restful : true, |
| 35 |
listeners : {
|
| 36 |
scope : this, |
| 37 |
exception : onRequestFeedException
|
| 38 |
} |
| 39 |
}), |
| 40 |
reader : new Ext.data.XmlReader({ |
| 41 |
record : 'item' |
| 42 |
}, [ 'title', 'author', { |
| 43 |
name : 'pubDate', |
| 44 |
type : 'date' |
| 45 |
}, 'link', 'description', 'content', 'guid', { |
| 46 |
name : 'imageUrl', |
| 47 |
mapping : "enclosure@url" |
| 48 |
}, {
|
| 49 |
name : 'imageType', |
| 50 |
mapping : "enclosure@type" |
| 51 |
}]) |
| 52 |
}); |
| 53 |
|
| 54 |
var columns = [ {
|
| 55 |
id : 'image', |
| 56 |
header : "Image", |
| 57 |
dataIndex : 'imageUrl', |
| 58 |
sortable : false, |
| 59 |
width : 120 |
| 60 |
, |
| 61 |
renderer : this.imageRenderer |
| 62 |
}, {
|
| 63 |
id : 'title', |
| 64 |
header : "Title", |
| 65 |
dataIndex : 'title', |
| 66 |
sortable : true, |
| 67 |
width : 460, |
| 68 |
scope : this, |
| 69 |
renderer : this.formatTitle |
| 70 |
}, {
|
| 71 |
header : "Author", |
| 72 |
dataIndex : 'author', |
| 73 |
width : 100, |
| 74 |
hidden : true, |
| 75 |
sortable : true |
| 76 |
}, {
|
| 77 |
id : 'last', |
| 78 |
header : "Date", |
| 79 |
dataIndex : 'pubDate', |
| 80 |
width : 150, |
| 81 |
renderer : this.formatDate, |
| 82 |
sortable : true, |
| 83 |
hidden : true |
| 84 |
} ]; |
| 85 |
|
| 86 |
sitools.widget.rss2FeedReader.superclass.constructor.call(this, {
|
| 87 |
// height : 300,
|
| 88 |
columns : columns,
|
| 89 |
store : this.storeFeedsRecords, |
| 90 |
loadMask : {
|
| 91 |
msg : i18n.get("label.loadingFeed") |
| 92 |
}, |
| 93 |
sm : new Ext.grid.RowSelectionModel({ |
| 94 |
singleSelect : true |
| 95 |
}), |
| 96 |
autoExpandColumn : 'title', |
| 97 |
hideHeaders : true, |
| 98 |
viewConfig : {
|
| 99 |
forceFit : true, |
| 100 |
enableRowBody : true, |
| 101 |
showPreview : true, |
| 102 |
getRowClass : this.applyRowClass |
| 103 |
}, |
| 104 |
listeners : config.listeners
|
| 105 |
|
| 106 |
}); |
| 107 |
|
| 108 |
// this.on('rowcontextmenu', this.onContextClick, this);
|
| 109 |
// this.on('beforeShow',this.loadData);
|
| 110 |
}; |
| 111 |
|
| 112 |
Ext.extend(sitools.widget.rss2FeedReader, Ext.grid.GridPanel, {
|
| 113 |
|
| 114 |
|
| 115 |
loadData : function () { |
| 116 |
this.loadFeed('http://feeds.feedburner.com/extblog'); |
| 117 |
this.doLayout();
|
| 118 |
}, |
| 119 |
|
| 120 |
loadFeed : function (url) { |
| 121 |
this.store.baseParams = {
|
| 122 |
feed : url
|
| 123 |
}; |
| 124 |
this.store.load();
|
| 125 |
}, |
| 126 |
|
| 127 |
togglePreview : function (show) { |
| 128 |
this.view.showPreview = show;
|
| 129 |
this.view.refresh();
|
| 130 |
}, |
| 131 |
|
| 132 |
// within this function "this" is actually the GridView
|
| 133 |
applyRowClass : function (record, rowIndex, p, ds) { |
| 134 |
if (this.showPreview) { |
| 135 |
var xf = Ext.util.Format;
|
| 136 |
//p.body = '<p class=sous-titre-flux>' + record.data.description + '</p>';
|
| 137 |
p.body = '<p class=sous-titre-flux>' + xf.ellipsis(xf.stripTags(record.data.description), 300) + '</p>'; |
| 138 |
return 'x-grid3-row-expanded'; |
| 139 |
} |
| 140 |
return 'x-grid3-row-collapsed'; |
| 141 |
}, |
| 142 |
|
| 143 |
formatDate : function (date) { |
| 144 |
if (!date) {
|
| 145 |
return ''; |
| 146 |
} |
| 147 |
var now = new Date(); |
| 148 |
var d = now.clearTime(true); |
| 149 |
if (date instanceof Date){ |
| 150 |
var notime = date.clearTime(true).getTime(); |
| 151 |
if (notime == d.getTime()) {
|
| 152 |
return 'Today ' + date.dateFormat('g:i a'); |
| 153 |
} |
| 154 |
d = d.add('d', -0);//-6 |
| 155 |
if (d.getTime() <= notime) {
|
| 156 |
//return date.dateFormat('D g:i a');
|
| 157 |
return date.dateFormat('d/m/Y'); |
| 158 |
} |
| 159 |
//return date.dateFormat('n/j g:i a');
|
| 160 |
return date.dateFormat('d/m/Y'); |
| 161 |
} |
| 162 |
else {
|
| 163 |
return date;
|
| 164 |
} |
| 165 |
}, |
| 166 |
|
| 167 |
formatTitle : function (value, p, record) { |
| 168 |
var link = record.data.link;
|
| 169 |
var xf = Ext.util.Format;
|
| 170 |
var author = (Ext.isEmpty(record.data.author)) ? "" : record.data.author; |
| 171 |
var dateFormat = this.formatDate(record.data.pubDate); |
| 172 |
var res = ""; |
| 173 |
if (link !== undefined && link !== "") { |
| 174 |
res = String.format('<div class="topic"><a href="{0}" title="{1}" target="_blank"><span class="rss_feed_title">{2}</span></a><br/><span class="author">{3}</span></div>', link, value,
|
| 175 |
xf.ellipsis(xf.stripTags(value), 50), author);
|
| 176 |
} else {
|
| 177 |
res = String.format('<div class="topic"><span class="rss_feed_title">{0}</span><br/><span class="author">{1}</span></div>', xf.ellipsis(xf.stripTags(value), 50), author); |
| 178 |
} |
| 179 |
if (dateFormat != "" && dateFormat != null ){ |
| 180 |
res += String.format('<p id="feeds-date">{0}</p>', dateFormat);
|
| 181 |
} |
| 182 |
return res;
|
| 183 |
}, |
| 184 |
|
| 185 |
imageRenderer : function (value, p, record) { |
| 186 |
if (Ext.isEmpty(value) || Ext.isEmpty(record.data.imageType)) {
|
| 187 |
return ""; |
| 188 |
} |
| 189 |
if (record.data.imageType.substr(0, 5) != "image") { |
| 190 |
return ""; |
| 191 |
} |
| 192 |
return String.format('<img src="{0}" width="50px">', value); |
| 193 |
}, |
| 194 |
|
| 195 |
sortByDate : function (direction){ |
| 196 |
this.storeFeedsRecords.sort('pubDate', direction); |
| 197 |
} |
| 198 |
}); |