author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-02 23:56:18 (UTC) |
commit | ef68436ac04da078ffdcacd7e1f785473a303d45 (patch) (unidiff) | |
tree | c403752d66a2c4775f00affd4fa8431b29c5b68c /frontend/gamma/js/Clipperz/PM/UI/Web/Components/DirectLoginEditingFormValueComponent.js | |
parent | 597ecfbc0249d83e1b856cbd558340c01237a360 (diff) | |
download | clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.zip clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.gz clipperz-ef68436ac04da078ffdcacd7e1f785473a303d45.tar.bz2 |
First version of the newly restructured repository
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Components/DirectLoginEditingFormValueComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/UI/Web/Components/DirectLoginEditingFormValueComponent.js | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Components/DirectLoginEditingFormValueComponent.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Components/DirectLoginEditingFormValueComponent.js new file mode 100644 index 0000000..b91eb98 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Components/DirectLoginEditingFormValueComponent.js | |||
@@ -0,0 +1,179 @@ | |||
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 | Clipperz.Base.module('Clipperz.PM.UI.Web.Components'); | ||
30 | |||
31 | Clipperz.PM.UI.Web.Components.DirectLoginEditingFormValueComponent = function(args) { | ||
32 | args = args || {}; | ||
33 | |||
34 | Clipperz.PM.UI.Web.Components.DirectLoginEditingFormValueComponent.superclass.constructor.apply(this, arguments); | ||
35 | |||
36 | this._formFieldName = args.formFieldName|| Clipperz.Base.exception.raise('MandatoryParameter'); | ||
37 | this._fieldOptions = args.fieldOptions || Clipperz.Base.exception.raise('MandatoryParameter'); | ||
38 | this._initialValue = args.initialValue || null; | ||
39 | |||
40 | return this; | ||
41 | } | ||
42 | |||
43 | //============================================================================= | ||
44 | |||
45 | Clipperz.Base.extend(Clipperz.PM.UI.Web.Components.DirectLoginEditingFormValueComponent, Clipperz.PM.UI.Common.Components.BaseComponent, { | ||
46 | |||
47 | //------------------------------------------------------------------------- | ||
48 | |||
49 | 'toString': function () { | ||
50 | return "Clipperz.PM.UI.Web.Components.DirectLoginEditingFormValueComponent component"; | ||
51 | }, | ||
52 | |||
53 | //------------------------------------------------------------------------- | ||
54 | |||
55 | 'formFieldName': function () { | ||
56 | return this._formFieldName; | ||
57 | }, | ||
58 | |||
59 | //------------------------------------------------------------------------- | ||
60 | |||
61 | 'fieldOptions': function () { | ||
62 | return this._fieldOptions; | ||
63 | }, | ||
64 | |||
65 | 'fieldType': function () { | ||
66 | return this.fieldOptions()['type']; | ||
67 | }, | ||
68 | |||
69 | 'optionValues': function () { | ||
70 | return MochiKit.Base.map(function (anOptionValue) { | ||
71 | return { | ||
72 | 'label': anOptionValue['label'] || anOptionValue['value'], | ||
73 | 'value': anOptionValue['value'] | ||
74 | } | ||
75 | }, this.fieldOptions()['options']); | ||
76 | }, | ||
77 | |||
78 | //------------------------------------------------------------------------- | ||
79 | |||
80 | 'selectedValue': function () { | ||
81 | var result; | ||
82 | |||
83 | result = this.getElement('select').value; | ||
84 | |||
85 | if (result == '---') { | ||
86 | result = null; | ||
87 | } | ||
88 | |||
89 | return result; | ||
90 | }, | ||
91 | |||
92 | 'initialValue': function () { | ||
93 | return this._initialValue; | ||
94 | }, | ||
95 | |||
96 | //========================================================================= | ||
97 | |||
98 | 'renderSelf': function() { | ||
99 | //console.log(">>> DirectLoginEditingFormValueComponent.renderSelf"); | ||
100 | //console.log("FIELD OPTIONS", this.fieldOptions()); | ||
101 | //console.log("OPTION VALUES", this.optionValues()); | ||
102 | this.append(this.element(), {tag:'div', id:this.getId('div'), cls:'formValue', children:[ | ||
103 | {tag:'span', cls:'formFieldName', html:this.formFieldName()}, | ||
104 | {tag:'div', id:this.getId('values')} | ||
105 | ]}); | ||
106 | |||
107 | if ((this.fieldType() == 'radio') || (this.fieldType() == 'select')) { | ||
108 | this.append(this.getElement('values'), | ||
109 | {tag:'select', name:this.formFieldName(), id:this.getId('select'), cls:'formFieldMatchinCardField', children: | ||
110 | MochiKit.Base.flattenArguments( | ||
111 | // {tag:'option', value:'---', html:"---"}, | ||
112 | MochiKit.Base.map( | ||
113 | MochiKit.Base.bind(function (aValue) { return {tag:'option', value:aValue['value'], html:aValue['label']}; }, this), | ||
114 | this.optionValues() | ||
115 | ) | ||
116 | ) | ||
117 | } | ||
118 | ); | ||
119 | |||
120 | MochiKit.Signal.connect(this.getElement('select'), 'onchange', this, 'handleSelectChange'); | ||
121 | |||
122 | if (! MochiKit.Base.isUndefinedOrNull(this.initialValue())) { | ||
123 | var initiallySelectedOptions; | ||
124 | initiallySelectedOptions = MochiKit.Selector.findChildElements(this.element(), ['option[value=' + this.initialValue() + ']']); | ||
125 | if (initiallySelectedOptions.length == 1) { | ||
126 | MochiKit.DOM.updateNodeAttributes(initiallySelectedOptions[0], {selected:true}); | ||
127 | this.handleSelectChange(); | ||
128 | } else { | ||
129 | Clipperz.DOM.Helper.insertBefore(this.getElement('select').childNodes[0], {tag:'option', value:'---', html:"", selected:true}); | ||
130 | } | ||
131 | } else { | ||
132 | Clipperz.DOM.Helper.insertBefore(this.getElement('select').childNodes[0], {tag:'option', value:'---', html:"", selected:true}); | ||
133 | } | ||
134 | } else if (this.fieldType() == 'checkbox') { | ||
135 | this.append(this.getElement('values'), | ||
136 | {tag:'input', type:'checkbox', name:this.formFieldName(), id:this.getId('checkbox'), cls:'formFieldMatchinCardField'} | ||
137 | ); | ||
138 | |||
139 | MochiKit.Signal.connect(this.getElement('checkbox'), 'onchange', this, 'handleSelectChange'); | ||
140 | |||
141 | if (this.initialValue()) { | ||
142 | MochiKit.DOM.updateNodeAttributes(this.getElement('checkbox'), {checked:true}); | ||
143 | } | ||
144 | } else { | ||
145 | WTF = TODO; | ||
146 | } | ||
147 | //console.log("<<< DirectLoginEditingFormValueComponent.renderSelf"); | ||
148 | }, | ||
149 | |||
150 | //========================================================================= | ||
151 | |||
152 | 'handleSelectChange': function (anEvent) { | ||
153 | //console.log("handleSelectChange", anEvent, anEvent.src(), anEvent.src().value); | ||
154 | var options; | ||
155 | |||
156 | options = {}; | ||
157 | |||
158 | options['fieldName'] = this.formFieldName(); | ||
159 | |||
160 | if (this.fieldType() == 'checkbox') { | ||
161 | options['selectedValue'] = (this.getElement('checkbox').checked ? 1 : null); | ||
162 | } else { | ||
163 | options['selectedValue'] = this.selectedValue(); | ||
164 | } | ||
165 | |||
166 | MochiKit.Signal.signal(this, 'formValueChange', options); | ||
167 | }, | ||
168 | |||
169 | //========================================================================= | ||
170 | __syntaxFix__: "syntax fix" | ||
171 | }); | ||
172 | |||
173 | |||
174 | |||
175 | |||
176 | |||
177 | |||
178 | |||
179 | |||