Project

General

Profile

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

git_sitools_idoc / flarecast / workspace / client-admin / js / datasets / UnitWin.js @ master

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, ID, i18n, document, showResponse, alertFailure, LOCALE, ImageChooser, 
20
 showHelp*/
21
Ext.namespace('sitools.admin.datasets');
22

    
23
/**
24
 * @cfg Ext.data.Record recordColumn The record to edit
25
 * @cfg Ext.grid.View viewColumn The grid view to refresh
26
 * @cfg string urlDimension The Url of the dimension to get all the units. 
27
 * @class sitools.admin.datasets.UnitWin
28
 * @extends Ext.Window
29
 */
30
Ext.define('sitools.admin.datasets.UnitWin', { 
31
    extend : 'Ext.Window',
32
        alias : 'widget.s-datasetsUnits',
33
    width : 600,
34
    height : 400,
35
    modal : true,
36
    pageSize : ADMIN_PANEL_NB_ELEMENTS,
37

    
38
    initComponent : function () {
39
        this.title = i18n.get('label.units');
40

    
41
        this.storeUnits = Ext.create('Ext.data.JsonStore', {
42
            id : 'storeUnitSelect',
43
            proxy : {
44
                type : 'ajax',
45
                url : this.urlDimension,
46
                reader : {
47
                    type : 'json',
48
                    root : 'dimension.sitoolsUnits',
49
                    idProperty : 'id'
50
                }
51
            },
52
            fields : [{
53
                name : 'label',
54
                type : 'string'
55
            }, {
56
                name : 'unitName',
57
                type : 'string'
58
            }]
59
        });
60

    
61
        this.cmUnits = {
62
            items : [{
63
                header : i18n.get('headers.label'),
64
                dataIndex : 'label',
65
                width : 100
66
            }],
67
            defaults : {
68
                sortable : true,
69
                width : 100
70
            }
71
        };
72

    
73
        this.smUnits = Ext.create('Ext.selection.RowModel', {
74
            mode : 'SINGLE'
75
        });
76

    
77
        this.gridUnits = Ext.create('Ext.grid.Panel', {
78
            id : 'gridUnitId',
79
            title : i18n.get('title.unitList'),
80
            autoScroll : true,
81
            store : this.storeUnits,
82
            columns : this.cmUnits,
83
            selModel : this.smUnits,
84
            forceFit : true,
85
            region : "center"
86
        });
87

    
88
        var storeDimensions = Ext.create('Ext.data.JsonStore', {
89
            autoLoad : true,
90
            proxy : {
91
                type : 'ajax',
92
                url : this.urlDimension,
93
                reader : {
94
                    type : 'json',
95
                    root : 'data'
96
                }
97
            },
98
            fields : [ 'id', 'name', 'description' ]
99
        });
100
        
101
        this.cmDimensions = {
102
            items : [{
103
                header : i18n.get('headers.name'),
104
                dataIndex : 'name',
105
                width : 100
106
            }, {
107
                header : i18n.get('headers.description'),
108
                dataIndex : 'description',
109
                width : 100
110
            }],
111
            defaults : {
112
                sortable : true,
113
                width : 100
114
            }
115
        };
116

    
117
        this.smDimensions = Ext.create('Ext.selection.RowModel', {
118
            mode : 'SINGLE'
119
        });
120

    
121
        this.gridDimensions = Ext.create('Ext.grid.GridPanel', {
122
            id : 'gridViewDimensionsId',
123
            title : i18n.get('title.DimensionsList'),
124
            region : "west",
125
            autoScroll : true,
126
            store : storeDimensions,
127
            columns : this.cmDimensions,
128
            selModel : this.smDimensions,
129
            flex : 1,
130
            forceFit : true,
131
            listeners : {
132
                                scope : this, 
133
                                itemClick : function (grid, record, item, rowIndex) {
134
//                                        var rec = grid.getStore().getAt(rowIndex);
135
                                        var dimensionId = record.get('id');
136
                                        this.loadUnits(dimensionId);
137
                                }
138
            }
139
        });
140
        
141
                this.layout = "border";
142
        this.items = [this.gridUnits, this.gridDimensions ];
143
        
144
        this.buttons = [{
145
            text : i18n.get('label.ok'),
146
            scope : this,
147
            handler : this.onValidate
148
        }, {
149
            text : i18n.get('label.cancel'),
150
            scope : this,
151
            handler : function () {
152
                this.close();
153
            }
154
        }];
155
        sitools.admin.datasets.UnitWin.superclass.initComponent.call(this);
156
    },
157
    
158
    loadUnits : function (dimensionId) {
159
        this.storeUnits.getProxy().url = this.urlDimension + "/" + dimensionId;
160
//        this.httpProxy.url = this.urlDimension + "/" + dimensionId;
161
        
162
        this.storeUnits.load({
163
            callback : function () {
164
                this.gridUnits.getView().refresh();
165
            },
166
            scope : this
167
        });
168

    
169
    },
170
    
171
    onValidate : function () {
172
        var recUnit = this.gridUnits.getSelectionModel().getSelection()[0];
173
        if (Ext.isEmpty(recUnit)) {
174
                        Ext.Msg.alert(i18n.get('label.error'), i18n.get('label.noSelection'));
175
                        return;
176
        }
177
        var recDimension = this.gridDimensions.getSelectionModel().getSelection()[0];
178
        
179
        this.recordColumn.data.unit = recUnit.data;
180
        this.recordColumn.data.dimensionId = recDimension.data.id;
181
        //this.recordColumn.data.notionDescription = rec.data.description;
182
        this.viewColumn.refresh();
183
        this.close();
184
    }
185
});
186