git_sitools_idoc / szcluster-db / workspace / client-public / js / forms / components / textfield.js @ d45a7442
1 | d45a7442 | Alessandro_N | /***************************************
|
---|---|---|---|
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.TextField
|
||
28 | * @extends Ext.Container
|
||
29 | */
|
||
30 | sitools.common.forms.components.TextField = Ext.extend(Ext.Container, { |
||
31 | //sitools.component.users.SubSelectionParameters.SingleSelection.TextField = Ext.extend(Ext.Container, {
|
||
32 | |||
33 | initComponent : function () { |
||
34 | this.context = new sitools.common.forms.ComponentFactory(this.context); |
||
35 | //alert (this.valueSelection);
|
||
36 | var store;
|
||
37 | var params = {
|
||
38 | colModel : [ this.code[0]], |
||
39 | distinct : true |
||
40 | }; |
||
41 | store = new Ext.data.JsonStore({
|
||
42 | fields : [ {
|
||
43 | name : 'id', |
||
44 | mapping : this.code[0] |
||
45 | }, { |
||
46 | name : 'value', |
||
47 | mapping : this.code[0] |
||
48 | } ], |
||
49 | autoLoad : false, |
||
50 | root : 'data', |
||
51 | restful : true, |
||
52 | url : this.dataUrl + "/records" , |
||
53 | baseParams : params
|
||
54 | }); |
||
55 | |||
56 | this.tf = new Ext.form.ComboBox ({ |
||
57 | store : store,
|
||
58 | stype : "sitoolsFormItem", |
||
59 | valueField : 'id', |
||
60 | displayField : 'value', |
||
61 | typeAhead : false, |
||
62 | hideTrigger : true, |
||
63 | mode : 'remote', |
||
64 | allowBlank : true, |
||
65 | editable : true, |
||
66 | autoSelect : false, |
||
67 | // width : this.width - 110,
|
||
68 | value : this.defaultValues[0], |
||
69 | |||
70 | /**
|
||
71 | * The code of the parameter to notify changed event.
|
||
72 | */
|
||
73 | code : this.code, |
||
74 | flex : 1, |
||
75 | listeners : {
|
||
76 | scope : this, |
||
77 | beforequery : function () { |
||
78 | if (Ext.isEmpty(this.dataUrl)) { |
||
79 | return false; |
||
80 | } |
||
81 | return this.autoComplete; |
||
82 | } |
||
83 | } |
||
84 | }); |
||
85 | Ext.apply(this, {
|
||
86 | layout : "hbox", |
||
87 | stype : "sitoolsFormContainer", |
||
88 | items : [this.tf] |
||
89 | }); |
||
90 | sitools.common.forms.components.TextField.superclass.initComponent.apply(this,
|
||
91 | arguments);
|
||
92 | if (!Ext.isEmpty(this.label)) { |
||
93 | this.items.insert(0, new Ext.Container({ |
||
94 | border : false, |
||
95 | html : this.label, |
||
96 | width : 100 |
||
97 | })); |
||
98 | } |
||
99 | |||
100 | }, |
||
101 | |||
102 | notifyValueSelected : function () { |
||
103 | this.parent.notifyValueChanged(this.code); |
||
104 | }, |
||
105 | |||
106 | isValueDefined : function () { |
||
107 | if (this.tf.getValue() && this.tf.getValue() !== "") { |
||
108 | return true; |
||
109 | } else {
|
||
110 | return false; |
||
111 | } |
||
112 | }, |
||
113 | getSelectedValue : function () { |
||
114 | if (this.tf.getValue() && this.tf.getValue() !== "") { |
||
115 | return this.tf.getValue(); |
||
116 | } else {
|
||
117 | return null; |
||
118 | } |
||
119 | }, |
||
120 | setSelectedValue : function (value) { |
||
121 | this.tf.setValue(value);
|
||
122 | }, |
||
123 | |||
124 | getParameterValue : function () { |
||
125 | var value = this.getSelectedValue(); |
||
126 | if (Ext.isEmpty(value)) {
|
||
127 | return null; |
||
128 | } |
||
129 | return {
|
||
130 | type : this.type, |
||
131 | code : this.code.join(','), |
||
132 | value : '%'+value+'%' |
||
133 | }; |
||
134 | }, |
||
135 | |||
136 | // *** Reset function for RESET button ***//
|
||
137 | resetToDefault : function () { |
||
138 | this.tf.reset();
|
||
139 | } |
||
140 | // ***************************************//
|
||
141 | |||
142 | }); |