Project

General

Profile

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

git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / ListBoxMultiple.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*/
20
/*
21
 * @include "../ComponentFactory.js"
22
 */
23
Ext.ns('sitools.common.forms.components');
24

    
25
/**
26
 * @requires sitools.common.forms.ComponentFactory
27
 * @class sitools.common.forms.components.ListBoxMultiple
28
 * @extends Ext.Container
29
 */
30
sitools.common.forms.components.ListBoxMultiple = Ext.extend(Ext.Container, {
31
//sitools.component.users.SubSelectionParameters.MultipleSelection.ListBox = Ext.extend(Ext.Container, {
32

    
33
    initComponent : function () {
34
                this.context = new sitools.common.forms.ComponentFactory(this.context);
35
        var items = [];
36
                this.defaultValues = [];
37
                for (i = 0; i < this.values.length; i++) {
38
                        value = this.values[i];
39
                        items.push([ value.value, value.value ]);
40
                        if (value.defaultValue) {
41
                                this.defaultValues.push(value.value);
42
                        }
43
                }
44

    
45
            var store;
46
        if (this.valueSelection == 'S') {
47
            store = new Ext.data.ArrayStore({
48
                fields : ['value','text'],
49
                data : items, 
50
                valueField : 'value', 
51
                displayField : 'text'
52
            });
53
        } else {
54
            var params = {
55
                colModel : [ this.code ],
56
                distinct : true
57
            };
58
            store = new Ext.data.JsonStore({
59
                fields : [ {
60
                    name : 'value',
61
                    mapping : this.code
62
                }, {
63
                    name : 'text',
64
                    mapping : this.code
65
                } ],
66
                autoLoad : !Ext.isEmpty(this.dataUrl) ? true : false,
67
                root : 'data',
68
                restful : true,
69
                url : this.dataUrl + "/records",
70
                baseParams : params, 
71
                valueField : 'value', 
72
                displayField : 'text'
73
            });
74
        }   
75
        this.multiSelect = new Ext.ux.form.MultiSelect ({
76
                store : store,
77
                width : this.width,
78
                height : this.height - 10,
79
                flex : 1, 
80
                delimiter : '|', 
81
                        stype : "sitoolsFormItem", 
82
            listeners : {
83
                scope : this, 
84
                'click' : function () {
85
                    this.form.fireEvent('componentChanged', this.form, this);
86
                },
87
                'afterRender' : function () {
88
                                    this.setSelectedValue(this.defaultValues);
89
                            }
90
            }
91
            });
92
        Ext.apply(this, {
93
                    height : this.height, 
94
                width : this.width, 
95
                layout : "hbox",
96
                overCls : 'fieldset-child',
97
                stype : "sitoolsFormContainer",
98
                items : [this.multiSelect]
99
            });
100
            sitools.common.forms.components.ListBoxMultiple.superclass.initComponent.apply(this,
101
                    arguments);
102
               if (!Ext.isEmpty(this.label)) {
103
                    this.items.insert(0, new Ext.Container({
104
                    border : false,
105
                    html : this.label,
106
                    width : 100
107
                }));
108
            }
109

    
110
    },
111

    
112
    /**
113
         * The code of the parameter to notify changed event.
114
         */
115
    code : null,
116

    
117
    isValueDefined : function () {
118
            if (this.multiSelect.getValue() && this.multiSelect.getValue() !== "") {
119
                    return true;
120
            } else {
121
                    return false;
122
            }
123
    },
124

    
125
    getSelectedValue : function () {
126
            if (this.multiSelect.getValue()) {
127
                    return this.multiSelect.getValue();
128
            } else {
129
                    return null;
130
            }
131
    },
132
    
133

    
134
    setSelectedValue : function (values) {
135
            this.multiSelect.setValue(values);
136
    },
137
    
138
    getParameterValue : function () {
139
            var value = this.getSelectedValue();
140
            if (Ext.isEmpty(value)) {
141
                    return null;
142
            }
143
//            return this.type + "|" + this.code + "|" + value;
144
                   return {
145
                    type : this.type, 
146
                    code : this.code, 
147
                    value : value
148
            };
149
            
150
    },
151

    
152
//  *** Reset function for RESET button ***//
153
    resetToDefault : function () {
154
        this.multiSelect.reset();
155
    }
156
//  ***************************************//
157
});