Project

General

Profile

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

git_sitools_idoc / szcluster-db / workspace / client-user / js / modules / feedsReader / feedReaderProject.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, projectGlobal, i18n*/
20

    
21
Ext.namespace('sitools.user.modules');
22

    
23
/**
24
 * Feeds Reader Module.
25
 * @class sitools.user.modules.feedsReaderProject
26
 * @extends Ext.Panel
27
 */
28
sitools.user.modules.feedsReaderProject = Ext.extend(Ext.Panel, {
29
    layout : "fit",
30
    initComponent : function () {
31
        
32
        this.storeFeeds = new Ext.data.JsonStore({
33
            fields : [ 'id', 'feedType', 'title', 'feedSource', 'name', 'url' ],
34
            url : projectGlobal.sitoolsAttachementForUsers + "/feeds",
35
            root : "data",
36
            autoLoad : true
37
        });
38

    
39
        this.cb = new Ext.form.ComboBox({
40
            // all of your config options
41
            store : this.storeFeeds,
42
            displayField : 'name',
43
            valueField : 'name',
44
            typeAhead : true,
45
            mode : 'local',
46
            forceSelection : true,
47
            triggerAction : 'all',
48
            emptyText : i18n.get('label.selectAFeed'),
49
            selectOnFocus : true,
50
            scope : this,
51
            listeners : {
52
                scope : this,
53
                select : this.selectProject,
54
                render : function (cb) {
55
                    this.storeFeeds.on('load', function (store) {
56
                        if (this.storeFeeds.getTotalCount() > 0) {
57
                            var firstRec = store.getAt(0);
58
                            cb.setValue(firstRec.data.name);
59
                            this.selectProject(cb, firstRec, 0);
60
                        }
61
                    }, this);
62
                }
63
            }
64
        });
65

    
66
        this.buttonDate = this.createSorterButton({
67
            text: i18n.get("label.feedDate"),
68
            sortData: {
69
                //direction: 'ASC'
70
                direction: 'DESC'
71
            }
72
        });
73
       
74
        this.tbar = {
75
            xtype : 'toolbar',
76
            cls : 'services-toolbar-feeds',
77
            defaults : {
78
                scope : this,
79
                cls : 'services-toolbar-btn'
80
            },
81
            items : [ this.cb, '-' , this.buttonDate]
82
        };
83

    
84
        /**/
85

    
86
        sitools.user.modules.feedsReaderProject.superclass.initComponent.call(this);
87

    
88
    },
89

    
90
    selectProject : function (combo, rec, index) {
91
        this.remove(this.feedsReader);
92
        var url = projectGlobal.sitoolsAttachementForUsers + "/clientFeeds/" + rec.data.name;
93

    
94
        this.feedsReader = new sitools.widget.FeedGridFlux({
95
            urlFeed : url,
96
            feedType : rec.data.feedType,
97
            feedSource : rec.data.feedSource,
98
            autoLoad : true
99
        });
100

    
101
        this.add(this.feedsReader);
102
        this.doSort();
103
        this.doLayout();
104
    },
105
    
106
    /** SPECIFIC METHOD FOR SORT BUTTON **/ 
107
    
108
    /**
109
     * Tells the store to sort itself according to our sort data
110
     */
111
    doSort : function () {
112
        this.feedsReader.items.items[0].sortByDate(this.buttonDate.sortData.direction);
113
    },
114
    
115
    /**
116
     * Convenience function for creating Toolbar Buttons that are tied to sorters
117
     * @param {Object} config Optional config object
118
     * @return {Ext.Button} The new Button object
119
     */
120
    createSorterButton : function (config) {
121
        config = config || {};
122
              
123
        Ext.applyIf(config, {
124
            listeners: {
125
                scope : this,
126
                click: function (button, e) {
127
                    this.changeSortDirection(button, true);                    
128
                }
129
            },
130
            iconCls: 'sort-asc',// + config.sortData.direction.toLowerCase(),
131
            reorderable: true
132
        });
133
        
134
        return new Ext.Button(config);
135
    },
136
    
137
    /**
138
     * Callback handler used when a sorter button is clicked or reordered
139
     * @param {Ext.Button} button The button that was clicked
140
     * @param {Boolean} changeDirection True to change direction (default). Set to false for reorder
141
     * operations as we wish to preserve ordering there
142
     */
143
    changeSortDirection : function (button, changeDirection) {
144
        var sortData = button.sortData,
145
            iconCls  = button.iconCls;
146
        
147
        if (sortData != undefined) {
148
            if (changeDirection !== false) {
149
                button.sortData.direction = button.sortData.direction.toggle("ASC", "DESC");
150
                button.setIconClass(iconCls.toggle("sort-asc", "sort-desc"));
151
            }
152
            this.doSort();
153
        }
154
    },
155
    
156
    /**
157
     * Returns an array of sortData from the sorter buttons
158
     * @return {Array} Ordered sort data from each of the sorter buttons
159
     */
160
    getSorters : function () {
161
        var sorters = [];
162
        
163
        Ext.each(this.getTopToolbar().findByType('button'), function (button) {
164
            if (!Ext.isEmpty(button.sortData)) {
165
                sorters.push(button.sortData);
166
            }
167
        }, this);
168
        
169
        return sorters;
170
    }, 
171
    
172
    /**
173
     * method called when trying to save preference
174
     * @returns
175
     */
176
    _getSettings : function () {
177
                return {
178
            preferencesPath : "/modules", 
179
            preferencesFileName : this.id
180
        };
181

    
182
    }
183

    
184
});
185

    
186
Ext.reg('sitools.user.modules.feedsReaderProject', sitools.user.modules.feedsReaderProject);