Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/RecordDetail/DirectLoginValueComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/RecordDetail/DirectLoginValueComponent.js | 257 |
1 files changed, 257 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/RecordDetail/DirectLoginValueComponent.js b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/DirectLoginValueComponent.js new file mode 100644 index 0000000..e70229b --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/DirectLoginValueComponent.js | |||
@@ -0,0 +1,257 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } | ||
32 | if (typeof(Clipperz.PM.Components.RecordDetail) == 'undefined') { Clipperz.PM.Components.RecordDetail = {}; } | ||
33 | |||
34 | //############################################################################# | ||
35 | |||
36 | Clipperz.PM.Components.RecordDetail.DirectLoginValueComponent = function(anElement, args) { | ||
37 | //MochiKit.Logging.logDebug(">>> new DirectLoginValueComponent"); | ||
38 | args = args || {}; | ||
39 | |||
40 | Clipperz.PM.Components.RecordDetail.DirectLoginValueComponent.superclass.constructor.call(this, anElement, args); | ||
41 | |||
42 | this._directLoginInputValue = args.directLoginInputValue || null; | ||
43 | this._value = this.directLoginInputValue().directLogin().formValues()[this.directLoginInputValue().name()]; | ||
44 | |||
45 | this.render(); | ||
46 | //MochiKit.Logging.logDebug("<<< new DirectLoginValueComponent - record: " + this.record()); | ||
47 | |||
48 | return this; | ||
49 | } | ||
50 | |||
51 | //============================================================================= | ||
52 | |||
53 | YAHOO.extendX(Clipperz.PM.Components.RecordDetail.DirectLoginValueComponent, Clipperz.PM.Components.RecordDetail.AbstractComponent, { | ||
54 | |||
55 | 'toString': function() { | ||
56 | return "Clipperz.PM.Components.RecordDetail.DirectLoginValueComponent component - " + this.directLoginInputValue().name(); | ||
57 | }, | ||
58 | |||
59 | //------------------------------------------------------------------------- | ||
60 | |||
61 | 'directLoginInputValue': function() { | ||
62 | return this._directLoginInputValue; | ||
63 | }, | ||
64 | |||
65 | //------------------------------------------------------------------------- | ||
66 | |||
67 | 'render': function() { | ||
68 | //MochiKit.Logging.logDebug(">>> DirectLoginValueComponent.render"); | ||
69 | Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'td', cls:'directLoginDataLabelTD', children:[ | ||
70 | {tag:'span', html:this.directLoginInputValue().name()} | ||
71 | ]}); | ||
72 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.render - 1"); | ||
73 | Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'td', cls:'directLoginDataValueTD', children:[ | ||
74 | {tag:'span', id:this.getId('inputElement')} | ||
75 | ]}); | ||
76 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.render - 2"); | ||
77 | this.update(); | ||
78 | //MochiKit.Logging.logDebug("<<< DirectLoginValueComponent.render"); | ||
79 | }, | ||
80 | |||
81 | //------------------------------------------------------------------------- | ||
82 | |||
83 | 'inputElementConfiguration': function() { | ||
84 | var result; | ||
85 | var currentValue; | ||
86 | |||
87 | //MochiKit.Logging.logDebug(">>> DirectLoginValueComponent.inputElementConfiguration - " + this.directLoginInputValue().name()); | ||
88 | result = []; | ||
89 | currentValue = this.value(); | ||
90 | |||
91 | switch (this.directLoginInputValue().type()) { | ||
92 | case 'checkbox': | ||
93 | var checkbox; | ||
94 | //{"type":"checkbox", "name":"rememberUsernameChk", "value":"checkbox"} | ||
95 | checkbox = {tag:'input', id:this.getId('checkbox'), type:'checkbox'} | ||
96 | if (currentValue == true) { | ||
97 | checkbox.checked = true; | ||
98 | } | ||
99 | result.push(checkbox); | ||
100 | break; | ||
101 | |||
102 | case 'select': | ||
103 | var input; | ||
104 | //{"type":"select", "name":"DOMAIN", "options":[{"selected":true, "label":"@tin.it", "value":"tin.it"}, {"selected":false, "label":"@virgilio.it", "value":"virgilio.it"}]} | ||
105 | input = {tag:'select', id:this.getId('select'), name:this.directLoginInputValue().name(), children:[]}; | ||
106 | input.children.push({tag:'option', value:null, html:"---"}); | ||
107 | MochiKit.Iter.forEach(this.directLoginInputValue().args()['options'], function(anOption) { | ||
108 | var option; | ||
109 | |||
110 | //TODO: remove the value: field and replace it with element.dom.value = <some value> | ||
111 | option = {tag:'option', value:anOption['value'], html:anOption['label']} | ||
112 | if (currentValue == anOption['value']) { | ||
113 | option.selected = true; | ||
114 | } | ||
115 | input.children.push(option); | ||
116 | }) | ||
117 | result.push(input); | ||
118 | break; | ||
119 | |||
120 | case 'radio': | ||
121 | var name; | ||
122 | var radioBox; | ||
123 | |||
124 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3"); | ||
125 | name = this.getId(this.directLoginInputValue().name()); | ||
126 | radioBox = {tag:'div', id:this.getId('radioBox'), children:[]}; | ||
127 | result.push(radioBox); | ||
128 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.1 - options.length: " + this.directLoginInputValue().args()['options'].length); | ||
129 | //{"name":"dominio", "type":"radio", "options":[{"value":"@alice.it", "checked":true}, {"value":"@tin.it", "checked":false}, {"value":"@virgilio.it", "checked":false}, {"value":"@tim.it", "checked":false}]} | ||
130 | |||
131 | MochiKit.Iter.forEach(this.directLoginInputValue().args()['options'], function(anOption) { | ||
132 | varradio; | ||
133 | |||
134 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.1.1"); | ||
135 | //TODO: remove the value: field and replace it with element.dom.value = <some value> | ||
136 | radio = {tag:'input', type:'radio', name:name, value:anOption['value']}; | ||
137 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.1.2"); | ||
138 | if (currentValue == anOption['value']) { | ||
139 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.1.3"); | ||
140 | radio.checked = true; | ||
141 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.1.4"); | ||
142 | } | ||
143 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.1.5"); | ||
144 | radioBox.children.push({tag:'div', children:[ radio, {tag:'span', html:anOption['value']} ]}) | ||
145 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.1.6"); | ||
146 | }) | ||
147 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.inputElementConfiguration - 3.2"); | ||
148 | break; | ||
149 | } | ||
150 | //MochiKit.Logging.logDebug("<<< DirectLoginValueComponent.inputElementConfiguration"); | ||
151 | |||
152 | return result; | ||
153 | }, | ||
154 | |||
155 | //------------------------------------------------------------------------- | ||
156 | |||
157 | 'inputValue': function() { | ||
158 | var result; | ||
159 | |||
160 | switch (this.directLoginInputValue().type()) { | ||
161 | case 'checkbox': | ||
162 | result = this.getDom('checkbox').checked; | ||
163 | break; | ||
164 | case 'select': | ||
165 | result = this.getDom('select').value; | ||
166 | break; | ||
167 | case 'radio': | ||
168 | var checkedRadioButtons; | ||
169 | |||
170 | checkedRadioButtons = MochiKit.Base.filter(function(aRadioButton) { return aRadioButton.dom.checked }, | ||
171 | this.getElement('radioBox').getChildrenByTagName('input')); | ||
172 | |||
173 | if (checkedRadioButtons.length == 0) { | ||
174 | result = null; | ||
175 | } else { | ||
176 | result = checkedRadioButtons[0].dom.value; | ||
177 | } | ||
178 | break; | ||
179 | } | ||
180 | |||
181 | return result; | ||
182 | }, | ||
183 | |||
184 | //------------------------------------------------------------------------- | ||
185 | |||
186 | 'value': function() { | ||
187 | return this._value; | ||
188 | }, | ||
189 | |||
190 | 'setValue': function(aValue) { | ||
191 | this._value = aValue; | ||
192 | }, | ||
193 | |||
194 | //------------------------------------------------------------------------- | ||
195 | |||
196 | 'updateEditMode': function() { | ||
197 | //MochiKit.Logging.logDebug(">>> DirectLoginValueComponent.updateEditMode - " + this); | ||
198 | this.getElement('inputElement').update(""); | ||
199 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.updateEditMode - 1"); | ||
200 | Clipperz.YUI.DomHelper.append(this.getDom('inputElement'), {tag:'div', children:this.inputElementConfiguration()}); | ||
201 | //MochiKit.Logging.logDebug("<<< DirectLoginValueComponent.updateEditMode"); | ||
202 | }, | ||
203 | |||
204 | //------------------------------------------------------------------------- | ||
205 | |||
206 | 'updateViewMode': function() { | ||
207 | //MochiKit.Logging.logDebug(">>> DirectLoginValueComponent.updateViewMode"); | ||
208 | // this.getElement('inputElement').update(this.directLoginInputValue().value()); | ||
209 | |||
210 | this.getElement('inputElement').update(""); | ||
211 | |||
212 | switch (this.directLoginInputValue().type()) { | ||
213 | case 'checkbox': | ||
214 | if (this.value() == true) { | ||
215 | this.getElement('inputElement').update(Clipperz.PM.Strings['directLoginConfigurationCheckBoxFieldSelectedValue']); | ||
216 | } else { | ||
217 | this.getElement('inputElement').update(Clipperz.PM.Strings['directLoginConfigurationCheckBoxFieldNotSelectedValue']) | ||
218 | } | ||
219 | break; | ||
220 | case 'select': | ||
221 | var displayedValue; | ||
222 | var selectedOptions; | ||
223 | var currentValue; | ||
224 | |||
225 | currentValue = this.value(); | ||
226 | selectedOptions = MochiKit.Base.filter(function(anOption) { return (anOption['value'] == currentValue); }, | ||
227 | this.directLoginInputValue().args()['options']); | ||
228 | if (selectedOptions.length == 0) { | ||
229 | displayedValue = "---"; | ||
230 | } else { | ||
231 | //MochiKit.Logging.logDebug("+++ " + Clipperz.Base.serializeJSON(selectedOptions)); | ||
232 | //MochiKit.Logging.logDebug("*** " + Clipperz.Base.serializeJSON(selectedOptions[0])); | ||
233 | displayedValue = selectedOptions[0]['label']; | ||
234 | } | ||
235 | this.getElement('inputElement').update(displayedValue); | ||
236 | break; | ||
237 | case 'radio': | ||
238 | this.getElement('inputElement').update(this.value()); | ||
239 | break; | ||
240 | } | ||
241 | //MochiKit.Logging.logDebug("<<< DirectLoginValueComponent.updateViewMode"); | ||
242 | }, | ||
243 | |||
244 | //------------------------------------------------------------------------- | ||
245 | |||
246 | 'synchronizeComponentValues': function() { | ||
247 | //MochiKit.Logging.logDebug(">>> DirectLoginValueComponent.synchronizeComponentValues"); | ||
248 | //MochiKit.Logging.logDebug("--- DirectLoginValueComponent.synchronizeComponentValues - 1; value: " + this.inputValue()); | ||
249 | this.setValue(this.inputValue()); | ||
250 | this.directLoginInputValue().directLogin().formValues()[this.directLoginInputValue().name()] = this.value(); | ||
251 | //MochiKit.Logging.logDebug("<<< DirectLoginValueComponent.synchronizeComponentValues"); | ||
252 | }, | ||
253 | |||
254 | //------------------------------------------------------------------------- | ||
255 | __syntaxFix__: "syntax fix" | ||
256 | }); | ||
257 | |||