Revision dbbd9d34
Added by Alessandro_N over 10 years ago
| szcluster-db/workspace/client-public/js/feedsReader/atom1FeedsReader.js | ||
|---|---|---|
| 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*/ |
|
| 20 |
Ext.namespace('sitools.widget');
|
|
| 21 |
|
|
| 22 |
/** |
|
| 23 |
* Displays a grid of atom1 format feeds |
|
| 24 |
* @class sitools.widget.atom1FeedReader |
|
| 25 |
* @extends Ext.grid.GridPanel |
|
| 26 |
* @cfg {string} datasetId The Dataset id,
|
|
| 27 |
* @cfg {string} urlFeed The url to request feed
|
|
| 28 |
* @cfg {string} datasetName The dataset name
|
|
| 29 |
* @cfg {string} feedSource
|
|
| 30 |
* @cfg {boolean} autoLoad store configuration
|
|
| 31 |
*/ |
|
| 32 |
sitools.widget.atom1FeedReader = function (config) {
|
|
| 33 |
Ext.apply(this); |
|
| 34 |
this.layout = "fit"; |
|
| 35 |
this.storeFeedsRecords = new Ext.data.Store({
|
|
| 36 |
autoLoad : true, |
|
| 37 |
sortInfo : {field : 'pubDate', direction : "DESC"},
|
|
| 38 |
proxy : new Ext.data.HttpProxy({
|
|
| 39 |
url : config.urlFeed, |
|
| 40 |
restful : true, |
|
| 41 |
listeners : {
|
|
| 42 |
scope : this, |
|
| 43 |
exception : onRequestFeedException |
|
| 44 |
} |
|
| 45 |
// url : 'http://extjs.com/forum/external.php?type=RSS2' |
|
| 46 |
}), |
|
| 47 |
reader : new Ext.data.XmlReader({
|
|
| 48 |
record : 'entry' |
|
| 49 |
}, [ 'title', |
|
| 50 |
{
|
|
| 51 |
name : 'author', |
|
| 52 |
mapping : "author.name" |
|
| 53 |
}, {
|
|
| 54 |
name : 'pubDate', |
|
| 55 |
mapping : 'updated', |
|
| 56 |
type : 'date' |
|
| 57 |
}, {
|
|
| 58 |
name : 'link', |
|
| 59 |
mapping: "link@href" |
|
| 60 |
}, |
|
| 61 |
{
|
|
| 62 |
name : 'description', |
|
| 63 |
mapping : 'content' |
|
| 64 |
}, |
|
| 65 |
'content', |
|
| 66 |
{
|
|
| 67 |
name : 'imageUrl', |
|
| 68 |
createAccessor : function (data, field) {
|
|
| 69 |
var q = Ext.DomQuery; |
|
| 70 |
// select node link with attribute type like image% |
|
| 71 |
var node = q.selectNode("link[type^=image]", data);
|
|
| 72 |
var result = {};
|
|
| 73 |
if (Ext.isEmpty(node)) {
|
|
| 74 |
return result; |
|
| 75 |
} |
|
| 76 |
Ext.each(node.attributes, function (attribute) {
|
|
| 77 |
result[attribute.name] = attribute.value; |
|
| 78 |
}); |
|
| 79 |
return result; |
|
| 80 |
} |
|
| 81 |
} |
|
| 82 |
]) |
|
| 83 |
|
|
| 84 |
}); |
|
| 85 |
|
|
| 86 |
var columns = [ {
|
|
| 87 |
id : 'image', |
|
| 88 |
header : "Image", |
|
| 89 |
dataIndex : 'imageUrl', |
|
| 90 |
sortable : false, |
|
| 91 |
width : 120 |
|
| 92 |
, |
|
| 93 |
renderer : this.imageRenderer |
|
| 94 |
}, {
|
|
| 95 |
id : 'title', |
|
| 96 |
header : "Title", |
|
| 97 |
dataIndex : 'title', |
|
| 98 |
sortable : true, |
|
| 99 |
width : 460, |
|
| 100 |
scope : this, |
|
| 101 |
renderer : this.formatTitle |
|
| 102 |
}, {
|
|
| 103 |
header : "Author", |
|
| 104 |
dataIndex : 'author', |
|
| 105 |
width : 100, |
|
| 106 |
hidden : true, |
|
| 107 |
sortable : true |
|
| 108 |
}, {
|
|
| 109 |
id : 'last', |
|
| 110 |
header : "Date", |
|
| 111 |
dataIndex : 'pubDate', |
|
| 112 |
width : 150, |
|
| 113 |
renderer : this.formatDate, |
|
| 114 |
sortable : true, |
|
| 115 |
hidden : true |
|
| 116 |
} ]; |
|
| 117 |
|
|
| 118 |
sitools.widget.atom1FeedReader.superclass.constructor.call(this, {
|
|
| 119 |
// height : 300, |
|
| 120 |
columns : columns, |
|
| 121 |
store : this.storeFeedsRecords, |
|
| 122 |
loadMask : {
|
|
| 123 |
msg : i18n.get("label.loadingFeed")
|
|
| 124 |
}, |
|
| 125 |
sm : new Ext.grid.RowSelectionModel({
|
|
| 126 |
singleSelect : true |
|
| 127 |
}), |
|
| 128 |
autoExpandColumn : 'title', |
|
| 129 |
hideHeaders : true, |
|
| 130 |
viewConfig : {
|
|
| 131 |
forceFit : true, |
|
| 132 |
enableRowBody : true, |
|
| 133 |
showPreview : true, |
|
| 134 |
getRowClass : this.applyRowClass |
|
| 135 |
}, |
|
| 136 |
listeners : config.listeners |
|
| 137 |
}); |
|
| 138 |
}; |
|
| 139 |
|
|
| 140 |
Ext.extend(sitools.widget.atom1FeedReader, Ext.grid.GridPanel, {
|
|
| 141 |
/** |
|
| 142 |
* Load the feeds with the given url |
|
| 143 |
* @param {string} url
|
|
| 144 |
*/ |
|
| 145 |
loadFeed : function (url) {
|
|
| 146 |
this.store.baseParams = {
|
|
| 147 |
feed : url |
|
| 148 |
}; |
|
| 149 |
this.store.load(); |
|
| 150 |
}, |
|
| 151 |
|
|
| 152 |
/** |
|
| 153 |
* switch from preview to complete view |
|
| 154 |
* @param {boolean} show
|
|
| 155 |
*/ |
|
| 156 |
togglePreview : function (show) {
|
|
| 157 |
this.view.showPreview = show; |
|
| 158 |
this.view.refresh(); |
|
| 159 |
}, |
|
| 160 |
|
|
| 161 |
/** |
|
| 162 |
* override the method getRowClass |
|
| 163 |
* @param {Record} record The {@link Ext.data.Record} corresponding to the current row.
|
|
| 164 |
* @param {Number} index The row index.
|
|
| 165 |
* @param {Object} rowParams A config object that is passed to the row template during rendering that allows
|
|
| 166 |
* customization of various aspects of a grid row. |
|
| 167 |
* <p>If {@link #enableRowBody} is configured <b><tt></tt>true</b>, then the following properties may be set
|
|
| 168 |
* by this function, and will be used to render a full-width expansion row below each grid row:</p> |
|
| 169 |
* <ul> |
|
| 170 |
* <li><code>body</code> : String <div class="sub-desc">An HTML fragment to be used as the expansion row's body content (defaults to '').</div></li> |
|
| 171 |
* <li><code>bodyStyle</code> : String <div class="sub-desc">A CSS style specification that will be applied to the expansion row's <tr> element. (defaults to '').</div></li> |
|
| 172 |
* </ul> |
|
| 173 |
* The following property will be passed in, and may be appended to: |
|
| 174 |
* <ul> |
|
| 175 |
* <li><code>tstyle</code> : String <div class="sub-desc">A CSS style specification that willl be applied to the <table> element which encapsulates |
|
| 176 |
* both the standard grid row, and any expansion row.</div></li> |
|
| 177 |
* </ul> |
|
| 178 |
* @param {Store} store The {@link Ext.data.Store} this grid is bound to
|
|
| 179 |
*/ |
|
| 180 |
applyRowClass : function (record, rowIndex, p, ds) {
|
|
| 181 |
if (this.showPreview) {
|
|
| 182 |
var xf = Ext.util.Format; |
|
| 183 |
if (record.data.summary != "" && record.data.summary != undefined){
|
|
| 184 |
p.body = '<p class=sous-titre-flux>' + xf.ellipsis(xf.stripTags(record.data.summary), 300) + '</p>'; |
|
| 185 |
return 'x-grid3-row-expanded'; |
|
| 186 |
} |
|
| 187 |
} |
|
| 188 |
return 'x-grid3-row-collapsed'; |
|
| 189 |
}, |
|
| 190 |
|
|
| 191 |
/** |
|
| 192 |
* Custom date format |
|
| 193 |
* @param {Date} date the input date
|
|
| 194 |
* @return {String} the date formated
|
|
| 195 |
*/ |
|
| 196 |
formatDate : function (date) {
|
|
| 197 |
if (!date) {
|
|
| 198 |
return ''; |
|
| 199 |
} |
|
| 200 |
var now = new Date(); |
|
| 201 |
var d = now.clearTime(true); |
|
| 202 |
if (date instanceof Date){
|
|
| 203 |
var notime = date.clearTime(true).getTime(); |
|
| 204 |
if (notime == d.getTime()) {
|
|
| 205 |
return 'Today ' + date.dateFormat('g:i a');
|
|
| 206 |
} |
|
| 207 |
d = d.add('d', -6);
|
|
| 208 |
if (d.getTime() <= notime) {
|
|
| 209 |
//return date.dateFormat('D g:i a');
|
|
| 210 |
return date.dateFormat('d/m/Y');
|
|
| 211 |
} |
|
| 212 |
//return date.dateFormat('n/j g:i a');
|
|
| 213 |
return date.dateFormat('d/m/Y');
|
|
| 214 |
} |
|
| 215 |
else {
|
|
| 216 |
return date; |
|
| 217 |
} |
|
| 218 |
}, |
|
| 219 |
|
|
| 220 |
/** |
|
| 221 |
* Custom renderer for title columns |
|
| 222 |
* @param {} value the value to format
|
|
| 223 |
* @param {} p
|
|
| 224 |
* @param {Ext.data.Record} record
|
|
| 225 |
* @return {String} The title value formatted.
|
|
| 226 |
*/ |
|
| 227 |
formatTitle : function (value, p, record) {
|
|
| 228 |
var author = (record.data.author.name !== undefined) ? record.data.author.name : ""; |
|
| 229 |
var link = record.data.link; |
|
| 230 |
var xf = Ext.util.Format; |
|
| 231 |
var dateFormat = this.formatDate(record.data.updated); |
|
| 232 |
var author = (record.data.author.name !== undefined) ? record.data.author.name : ""; |
|
| 233 |
var authorEmail = (record.data.author.email !== undefined) ? record.data.author.email : ""; |
|
| 234 |
var res = ""; |
|
| 235 |
if (link !== undefined && link !== "") {
|
|
| 236 |
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,
|
|
| 237 |
xf.ellipsis(xf.stripTags(value), 50), author); |
|
| 238 |
} else {
|
|
| 239 |
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);
|
|
| 240 |
} |
|
| 241 |
if (dateFormat != "" && dateFormat != undefined ){
|
|
| 242 |
res += String.format('<p id="feeds-date">{0}</p>', dateFormat);
|
|
| 243 |
} |
|
| 244 |
return res; |
|
| 245 |
|
|
| 246 |
}, |
|
| 247 |
imageRenderer : function (value, p, record) {
|
|
| 248 |
if (Ext.isEmpty(value) || Ext.isEmpty(value.href)) {
|
|
| 249 |
return ""; |
|
| 250 |
} |
|
| 251 |
if (value.type.substr(0, 5) != "image") {
|
|
| 252 |
return ""; |
|
| 253 |
} |
|
| 254 |
return String.format('<img src="{0}" width="50px">', value.href);
|
|
| 255 |
}, |
|
| 256 |
|
|
| 257 |
sortByDate : function (direction){
|
|
| 258 |
this.storeFeedsRecords.sort('pubDate', direction);
|
|
| 259 |
} |
|
| 260 |
|
|
| 261 |
}); |
|
| szcluster-db/workspace/client-public/js/feedsReader/feedItemDetails.js | ||
|---|---|---|
| 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*/ |
|
| 20 |
Ext.namespace('sitools.widget');
|
|
| 21 |
|
|
| 22 |
/** |
|
| 23 |
* @param urlFeed : |
|
| 24 |
* The feed URL |
|
| 25 |
*/ |
|
| 26 |
sitools.widget.feedItemDetails = Ext.extend(Ext.Panel, {
|
|
| 27 |
|
|
| 28 |
initComponent : function () {
|
|
| 29 |
|
|
| 30 |
this.layout = "fit"; |
|
| 31 |
|
|
| 32 |
var record = this.record; |
|
| 33 |
|
|
| 34 |
if (!Ext.isEmpty(record)) {
|
|
| 35 |
|
|
| 36 |
this.store = new Ext.data.JsonStore({
|
|
| 37 |
idProperty: 'title', |
|
| 38 |
fields: [ |
|
| 39 |
{name : 'title'},
|
|
| 40 |
{name : 'pubDate', type: 'date', dateFormat: 'timestamp'},
|
|
| 41 |
{name : 'published', type: 'date', dateFormat: 'timestamp'},
|
|
| 42 |
{name : 'author'},
|
|
| 43 |
{name : 'link'},
|
|
| 44 |
{name : 'description'},
|
|
| 45 |
{name : 'imageUrl'},
|
|
| 46 |
{name : 'image'}
|
|
| 47 |
], |
|
| 48 |
listeners : {
|
|
| 49 |
scope : this, |
|
| 50 |
add : function (store, records, ind){
|
|
| 51 |
if (record.data.imageUrl == undefined && record.data.image != undefined){
|
|
| 52 |
record.data.image = record.data.imageUrl; |
|
| 53 |
} |
|
| 54 |
if (records[0].data.pubDate != ""){
|
|
| 55 |
records[0].data.pubDate = this.formatDate(records[0].data.pubDate); |
|
| 56 |
} |
|
| 57 |
} |
|
| 58 |
} |
|
| 59 |
}); |
|
| 60 |
|
|
| 61 |
this.store.add(record); |
|
| 62 |
|
|
| 63 |
this.tpl = new Ext.XTemplate( |
|
| 64 |
'<tpl for=".">', |
|
| 65 |
'<div class="feed-article">', |
|
| 66 |
'<tpl if="this.isDisplayable(imageUrl)">', |
|
| 67 |
'<div class="feed-img">', |
|
| 68 |
'<img src="{imageUrl}" title="{title}" width="70" height="70"/>',
|
|
| 69 |
'</div>', |
|
| 70 |
'</tpl>', |
|
| 71 |
'<p class="feed-title"> {title} </p>',
|
|
| 72 |
'<tpl if="this.isDisplayable(pubDate)">', |
|
| 73 |
'<div class="feed-date-detail">', |
|
| 74 |
'<b> Date : </b> {pubDate} ',
|
|
| 75 |
'</div>', |
|
| 76 |
'</tpl>', |
|
| 77 |
'<tpl if="this.isDisplayable(author)">', |
|
| 78 |
'<div class="feed-author">', |
|
| 79 |
'<b> Author : </b> {author} ',
|
|
| 80 |
'</div>', |
|
| 81 |
'</tpl>', |
|
| 82 |
'<div class="feed-description">', |
|
| 83 |
'{description}',
|
|
| 84 |
'</div>', |
|
| 85 |
'<div class="feed-complementary">', |
|
| 86 |
'<p style="padding-bottom: 3px;"> <b> Link : </b> <a href="{link}" target="_blank" title="{title}">{link}</a> </p>',
|
|
| 87 |
'<tpl if="this.isDisplayable(imageUrl)">', |
|
| 88 |
'<p> <b> Image Url : </b> <a href="{imageUrl}" target="_blank">{imageUrl}</a> </p>',
|
|
| 89 |
'</tpl>', |
|
| 90 |
'</div>', |
|
| 91 |
'</div>', |
|
| 92 |
'</tpl>', |
|
| 93 |
{
|
|
| 94 |
compiled : true, |
|
| 95 |
isDisplayable : function (item) {
|
|
| 96 |
if (item != "" && item != undefined){
|
|
| 97 |
return true; |
|
| 98 |
} |
|
| 99 |
else {
|
|
| 100 |
return false; |
|
| 101 |
} |
|
| 102 |
} |
|
| 103 |
} |
|
| 104 |
); |
|
| 105 |
|
|
| 106 |
this.feedsDataview = new Ext.DataView({
|
|
| 107 |
id: 'detailFeed-view', |
|
| 108 |
autoScroll : true, |
|
| 109 |
layout: 'fit', |
|
| 110 |
store : this.store, |
|
| 111 |
tpl : this.tpl, |
|
| 112 |
cls : 'detailFeed-view', |
|
| 113 |
emptyText: i18n.get('label.nothingToDisplay')
|
|
| 114 |
}); |
|
| 115 |
|
|
| 116 |
this.componentType = 'feedDetails'; |
|
| 117 |
this.items = [ this.feedsDataview ]; |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
sitools.widget.feedItemDetails.superclass.initComponent.call(this); |
|
| 121 |
}, |
|
| 122 |
|
|
| 123 |
formatDate : function (date) {
|
|
| 124 |
if (!date) {
|
|
| 125 |
return ''; |
|
| 126 |
} |
|
| 127 |
var now = new Date(); |
|
| 128 |
var d = now.clearTime(true); |
|
| 129 |
if (date instanceof Date){
|
|
| 130 |
var notime = date.clearTime(true).getTime(); |
|
| 131 |
if (notime == d.getTime()) {
|
|
| 132 |
return 'Today ' + date.dateFormat('g:i a');
|
|
| 133 |
} |
|
| 134 |
d = d.add('d', -6);
|
|
| 135 |
if (d.getTime() <= notime) {
|
|
| 136 |
//return date.dateFormat('D g:i a');
|
|
| 137 |
return date.dateFormat('d/m/Y g:i a');
|
|
| 138 |
} |
|
| 139 |
//return date.dateFormat('n/j g:i a');
|
|
| 140 |
return date.dateFormat('d/m/Y g:i a');
|
|
| 141 |
} |
|
| 142 |
else {
|
|
| 143 |
return date; |
|
| 144 |
} |
|
| 145 |
}, |
|
| 146 |
/** |
|
| 147 |
* Method called when trying to show this component with fixed navigation |
|
| 148 |
* |
|
| 149 |
* @param {sitools.user.component.viewDataDetail} me the dataDetail view
|
|
| 150 |
* @param {} config config options
|
|
| 151 |
* @returns |
|
| 152 |
*/ |
|
| 153 |
showMeInFixedNav : function (me, config) {
|
|
| 154 |
Ext.apply(config.windowSettings, {
|
|
| 155 |
width : config.windowSettings.winWidth || DEFAULT_WIN_WIDTH, |
|
| 156 |
height : config.windowSettings.winHeight || DEFAULT_WIN_HEIGHT |
|
| 157 |
}); |
|
| 158 |
SitoolsDesk.openModalWindow(me, config); |
|
| 159 |
}, |
|
| 160 |
/** |
|
| 161 |
* Method called when trying to show this component with Desktop navigation |
|
| 162 |
* |
|
| 163 |
* @param {sitools.user.component.viewDataDetail} me the dataDetail view
|
|
| 164 |
* @param {} config config options
|
|
| 165 |
* @returns |
|
| 166 |
*/ |
|
| 167 |
showMeInDesktopNav : function (me, config) {
|
|
| 168 |
Ext.apply(config.windowSettings, {
|
|
| 169 |
width : config.windowSettings.winWidth || DEFAULT_WIN_WIDTH, |
|
| 170 |
height : config.windowSettings.winHeight || DEFAULT_WIN_HEIGHT |
|
| 171 |
}); |
|
| 172 |
SitoolsDesk.openModalWindow(me, config); |
|
| 173 |
} |
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
}); |
|
| szcluster-db/workspace/client-public/js/feedsReader/rss2FeedsReader.js | ||
|---|---|---|
| 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 |
}); |
|
Also available in: Unified diff
Change necessary to show the dates in the News column/window with format 'dd/mm/yyyy'