author | Eugene Ostroukhov <eugeneo@symbian.org> |
Wed, 10 Mar 2010 09:22:00 -0800 | |
changeset 238 | 977c9f9adc30 |
parent 211 | 7b148352159e |
child 273 | b1f63c2c240c |
permissions | -rw-r--r-- |
210
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
1 |
/** |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
2 |
* Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies). |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
3 |
* All rights reserved. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
5 |
* under the terms of the License "Eclipse Public License v1.0" |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
8 |
* |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
9 |
* Initial Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
10 |
* Symbian Foundation - initial contribution. |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
11 |
* Contributors: |
0f7abfd6ae62
Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents:
102
diff
changeset
|
12 |
*/ |
73 | 13 |
/* |
211 | 14 |
© Copyright 2008 Nokia Corporation. All rights reserved. |
73 | 15 |
|
16 |
IMPORTANT: The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia |
|
211 | 17 |
Corporation ("Nokia") in consideration of your agreement to the following terms. Your use, installation |
73 | 18 |
and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If |
19 |
you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example |
|
20 |
Widget files. |
|
21 |
||
22 |
In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia |
|
211 | 23 |
grants you a personal, non-exclusive license, under Nokia's copyrights in the WRTKit and Example |
73 | 24 |
Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML, |
25 |
CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60 |
|
26 |
Widgets. |
|
27 |
||
28 |
If you redistribute the WRTKit and Example files, you must retain this entire notice in all such |
|
29 |
redistributions of the WRTKit and Example files. |
|
30 |
||
31 |
You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products |
|
32 |
that include the WRTKit and Example files without the prior written explicit agreement with Nokia. |
|
33 |
Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by |
|
34 |
Nokia herein, including but not limited to any patent rights that may be infringed by your products that |
|
35 |
incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files |
|
36 |
may be incorporated. |
|
37 |
||
38 |
The WRTKit and Example files are provided on an "AS IS" basis. NOKIA MAKES NO |
|
39 |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
|
40 |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A |
|
41 |
PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION |
|
42 |
ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
|
43 |
||
44 |
IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
|
45 |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
46 |
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
47 |
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR |
|
48 |
DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY |
|
49 |
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, |
|
50 |
EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
51 |
||
52 |
*/ |
|
53 |
||
54 |
/////////////////////////////////////////////////////////////////////////////// |
|
55 |
// The SelectionControl class is an abstract base class for controls that lets |
|
56 |
// the user select one or more options from a list of options. Don't use |
|
57 |
// SelectionControl directly. |
|
58 |
||
59 |
// Constructor. |
|
60 |
function SelectionControl(id, caption, options, multipleSelection, selected) { |
|
61 |
if (id != UI_NO_INIT_ID) { |
|
62 |
this.init(id, caption, options, multipleSelection, selected); |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
// SelectionControl inherits from Control. |
|
67 |
SelectionControl.prototype = new Control(UI_NO_INIT_ID); |
|
68 |
||
69 |
// List of options. |
|
70 |
SelectionControl.prototype.options = null; |
|
71 |
||
72 |
// The single selected option in single selection controls |
|
73 |
// or list of options in multi selection controls. |
|
74 |
SelectionControl.prototype.selected = null; |
|
75 |
||
76 |
// Single or multiple selection. |
|
77 |
SelectionControl.prototype.multipleSelection = false; |
|
78 |
||
79 |
// Initializer - called from constructor. |
|
80 |
SelectionControl.prototype.init = function(id, caption, options, multipleSelection, selected) { |
|
81 |
uiLogger.debug("SelectionControl.init(" + id + ", " + caption + ", " + options + ", " + multipleSelection + ", " + selected + ")"); |
|
82 |
||
83 |
// call superclass initializer |
|
84 |
Control.prototype.init.call(this, id, caption); |
|
85 |
||
86 |
// set the multiple selection property |
|
87 |
this.multipleSelection = multipleSelection; |
|
88 |
||
89 |
// init options and selected (makes copies of the original arrays) |
|
90 |
this.options = (options != null) ? options.slice(0) : []; |
|
91 |
if (multipleSelection) { |
|
92 |
this.selected = (selected == null) ? [] : selected.slice(0); |
|
93 |
} else { |
|
94 |
this.selected = selected; |
|
95 |
} |
|
96 |
this.validateSelected(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
97 |
}; |
73 | 98 |
|
99 |
// Returns true if the control is a multiple selection control; false if single. |
|
100 |
SelectionControl.prototype.isMultipleSelection = function() { |
|
101 |
return this.multipleSelection; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
102 |
}; |
73 | 103 |
|
104 |
// Returns true if the specified option is selected; false if not. |
|
105 |
SelectionControl.prototype.isSelected = function(option) { |
|
106 |
if (this.multipleSelection) { |
|
107 |
// multiple selection |
|
108 |
// iterate through all selected options and look for the specified option |
|
109 |
for (var i = 0; i < this.selected.length; i++) { |
|
110 |
if (this.selected[i] == option) { |
|
111 |
return true; |
|
112 |
} |
|
113 |
} |
|
114 |
return false; |
|
115 |
} else { |
|
116 |
// single selection |
|
117 |
return (this.selected == option); |
|
118 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
119 |
}; |
73 | 120 |
|
121 |
// Returns the currently selected option in a single selection control or |
|
122 |
// an array of selected options in a multiple selection control. If there are |
|
123 |
// no selected options a single selection control returns null and a multiple |
|
124 |
// selection control returns an empty array. |
|
125 |
SelectionControl.prototype.getSelected = function() { |
|
126 |
return this.multipleSelection ? this.selected.slice(0) : this.selected; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
127 |
}; |
73 | 128 |
|
129 |
// Sets the currently selected options. Pass a single option in a single selection |
|
130 |
// control or an array of selected controls in a multiple selection control. To |
|
131 |
// deselect all options pass null in a single selection control and an empty array |
|
132 |
// in a multiple selection control. |
|
133 |
// Override in sublcasses to provide full implementation. |
|
134 |
SelectionControl.prototype.setSelected = function(selected) { |
|
135 |
this.selected = this.multipleSelection ? selected.slice(0) : selected; |
|
136 |
// make sure the selected option or options are legal |
|
137 |
this.validateSelected(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
138 |
}; |
73 | 139 |
|
140 |
// Ensures that the selected option or options exist among the options in this control. |
|
141 |
SelectionControl.prototype.validateSelected = function() { |
|
142 |
if (this.multipleSelection) { |
|
143 |
// multiple selection |
|
144 |
// iterate through all selected options and ensure they exist among the options |
|
145 |
for (var i = 0; i < this.selected.length; i++) { |
|
146 |
// check that the selected option exists among the options |
|
147 |
var found = false; |
|
148 |
for (var j = 0; j < this.options.length; j++) { |
|
149 |
if (this.options[j] == this.selected[i]) { |
|
150 |
// found - stop looking for this option |
|
151 |
found = true; |
|
152 |
break; |
|
153 |
} |
|
154 |
} |
|
155 |
// not found - remove this selected element |
|
156 |
if (!found) { |
|
157 |
this.selected.splice(i, 1); |
|
158 |
// since we removed an entry we must re-check this position |
|
159 |
i--; |
|
160 |
} |
|
161 |
} |
|
162 |
} else { |
|
163 |
// single selection |
|
164 |
if (this.selected != null) { |
|
165 |
// check that the selected option exists among the options |
|
166 |
for (var i = 0; i < this.options.length; i++) { |
|
167 |
if (this.options[i] == this.selected) { |
|
168 |
// found - we're done |
|
169 |
return; |
|
170 |
} |
|
171 |
} |
|
172 |
// not found - remove the selection |
|
173 |
this.selected = null; |
|
174 |
} |
|
175 |
} |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
176 |
}; |
73 | 177 |
|
178 |
// Returns the options in the control as an array of option objects with |
|
179 |
// a value and text property. |
|
180 |
SelectionControl.prototype.getOptions = function() { |
|
181 |
return this.options; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
182 |
}; |
73 | 183 |
|
184 |
// Sets the options in the control. |
|
185 |
// Override in sublcasses to provide full implementation. |
|
186 |
SelectionControl.prototype.setOptions = function(options) { |
|
187 |
this.options = options.slice(0); |
|
188 |
// make sure the selected option or options are legal |
|
189 |
this.validateSelected(); |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
190 |
}; |
73 | 191 |
|
192 |
// Returns the option that has the specified value; null if none. |
|
193 |
SelectionControl.prototype.getOptionForValue = function(value) { |
|
194 |
// iterate through all options and look for a match |
|
195 |
for (var i = 0; i < this.options.length; i++) { |
|
196 |
if (this.options[i].value == value) { |
|
197 |
return this.options[i]; |
|
198 |
} |
|
199 |
} |
|
200 |
return null; |
|
102
30e0796f3ebb
Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
73
diff
changeset
|
201 |
}; |