git_sitools_idoc / flarecast / workspace / client-public-3.0 / js / widget / sitoolsFilter / NumericFilter.js @ master
1 | d2a8c3fd | Marc NICOLAS | /*******************************************************************************
|
---|---|---|---|
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, i18n, loadUrl, getDesktop, sitools, SitoolsDesk */
|
||
20 | Ext.namespace("sitools.public.widget.sitoolsFilter");
|
||
21 | |||
22 | Ext.define('sitools.public.widget.sitoolsFilter.NumericFilter', {
|
||
23 | extend : 'sitools.public.widget.sitoolsFilter.Filter', |
||
24 | |||
25 | emptyText: 'Enter Filter Text...', |
||
26 | selectOnFocus: true, |
||
27 | |||
28 | /**
|
||
29 | * @private
|
||
30 | * Template method that is to initialize the filter and install required menu items.
|
||
31 | */
|
||
32 | init : function (config) { |
||
33 | config = config || {}; |
||
34 | |||
35 | this.inputFrom = Ext.create("Ext.form.NumberField", { |
||
36 | anchor : "100%" |
||
37 | }); |
||
38 | this.inputTo = Ext.create("Ext.form.NumberField", { |
||
39 | anchor : "100%" |
||
40 | }); |
||
41 | |||
42 | |||
43 | var imageFrom = Ext.create('Ext.Img', { |
||
44 | src : '/sitools/client-public/res/images/sitoolsFilter/greater_than_or_equals.png', |
||
45 | width : 16, |
||
46 | height : 16, |
||
47 | margin : '4 5 4 5' |
||
48 | }); |
||
49 | |||
50 | var imageTo = Ext.create('Ext.Img', { |
||
51 | src : '/sitools/client-public/res/images/sitoolsFilter/less_than_or_equals.png', |
||
52 | width : 16, |
||
53 | height : 16, |
||
54 | margin : '4 5 4 5' |
||
55 | }); |
||
56 | |||
57 | |||
58 | var formPanelFrom = Ext.create("Ext.form.FieldContainer", { |
||
59 | layout : {
|
||
60 | type :'hbox', |
||
61 | align :'stretch' |
||
62 | }, |
||
63 | items : [imageFrom, this.inputFrom], |
||
64 | bodyBorder : false, |
||
65 | border : false |
||
66 | }); |
||
67 | |||
68 | var formPanelTo = Ext.create("Ext.form.FieldContainer", { |
||
69 | layout : {
|
||
70 | type :'hbox', |
||
71 | align :'stretch' |
||
72 | }, |
||
73 | items : [imageTo, this.inputTo], |
||
74 | bodyBorder : false, |
||
75 | border : false |
||
76 | }); |
||
77 | |||
78 | |||
79 | var formPanel = Ext.create("Ext.Container", { |
||
80 | layout : {
|
||
81 | type :'vbox', |
||
82 | align :'stretch' |
||
83 | }, |
||
84 | items : [formPanelFrom, formPanelTo],
|
||
85 | bodyBorder : false, |
||
86 | border : false |
||
87 | }); |
||
88 | |||
89 | this.add(formPanel);
|
||
90 | }, |
||
91 | |||
92 | /**
|
||
93 | * @private
|
||
94 | * Template method that is to get and return the value of the filter.
|
||
95 | * @return {String} The value of this filter
|
||
96 | */
|
||
97 | getValue : function () { |
||
98 | var result = [];
|
||
99 | if (!Ext.isEmpty(this.inputFrom.getValue())) { |
||
100 | result.push({ |
||
101 | "columnAlias" : this.columnAlias, |
||
102 | "data" : {
|
||
103 | "comparison" : "gte", |
||
104 | "value" : this.inputFrom.getValue(), |
||
105 | "type" : "numeric" |
||
106 | } |
||
107 | }); |
||
108 | } |
||
109 | if (!Ext.isEmpty(this.inputTo.getValue())) { |
||
110 | result.push({ |
||
111 | "columnAlias" : this.columnAlias, |
||
112 | "data" : {
|
||
113 | "comparison" : "lte", |
||
114 | "value" : this.inputTo.getValue(), |
||
115 | "type" : "numeric" |
||
116 | } |
||
117 | }); |
||
118 | } |
||
119 | return result;
|
||
120 | }, |
||
121 | getConfig : function () { |
||
122 | if (!Ext.isEmpty(this.inputFrom.getValue()) || !Ext.isEmpty(this.inputTo.getValue())) { |
||
123 | return {
|
||
124 | "columnAlias" : this.columnAlias, |
||
125 | "value" : {
|
||
126 | "from" : this.inputFrom.getValue(), |
||
127 | "to" : this.inputTo.getValue() |
||
128 | }, |
||
129 | "type" : "numeric" |
||
130 | }; |
||
131 | } |
||
132 | else {
|
||
133 | return null; |
||
134 | } |
||
135 | }, |
||
136 | |||
137 | /**
|
||
138 | * @private
|
||
139 | * Template method that is to set the value of the filter.
|
||
140 | * @param {Object} value The value to set the filter
|
||
141 | */
|
||
142 | setValue : function (value) { |
||
143 | this.inputFrom.setValue(value.from);
|
||
144 | this.inputTo.setValue(value.to);
|
||
145 | |||
146 | } , |
||
147 | _getHeight : function () { |
||
148 | return this.height; |
||
149 | } |
||
150 | }); |