Project

General

Profile

Download (6.69 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / szcluster-db / workspace / client-public / js / feedsReader / feedItemDetails.js @ 2830ca05

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
});