summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Components/RecordDetail/FieldValueComponent.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/RecordDetail/FieldValueComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Components/RecordDetail/FieldValueComponent.js275
1 files changed, 275 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/RecordDetail/FieldValueComponent.js b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/FieldValueComponent.js
new file mode 100644
index 0000000..a30992a
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/FieldValueComponent.js
@@ -0,0 +1,275 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer 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
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
31if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; }
32if (typeof(Clipperz.PM.Components.RecordDetail) == 'undefined') { Clipperz.PM.Components.RecordDetail = {}; }
33
34//#############################################################################
35
36Clipperz.PM.Components.RecordDetail.FieldValueComponent = function(anElement, args) {
37 args = args || {};
38
39 Clipperz.PM.Components.RecordDetail.FieldValueComponent.superclass.constructor.call(this, anElement, args);
40
41 this._inputElement = null;
42 this._scrambledStatus = 'SCRAMBLED'; //'UNSCRAMBLED'
43
44 this.render();
45
46 return this;
47}
48
49//=============================================================================
50
51YAHOO.extendX(Clipperz.PM.Components.RecordDetail.FieldValueComponent, Clipperz.PM.Components.RecordDetail.AbstractFieldSubComponent, {
52
53 'toString': function() {
54 return "Clipperz.PM.Components.RecordDetail.FieldValueComponent component";
55 },
56
57 //-------------------------------------------------------------------------
58
59 'value': function() {
60 return this.recordField().value();
61 },
62
63 'setValue': function(aValue) {
64 this.recordField().setValue(aValue);
65 },
66
67 //-------------------------------------------------------------------------
68
69 'inputElement': function() {
70 return this._inputElement;
71 },
72
73 'setInputElement': function(aValue) {
74 this._inputElement = aValue;
75 },
76
77 //-------------------------------------------------------------------------
78
79 'scrambledStatus': function() {
80 return this._scrambledStatus;
81 },
82
83 'setScrambledStatus': function(aValue) {
84 this._scrambledStatus = aValue;
85 },
86
87 //-------------------------------------------------------------------------
88
89 'handleTypeChange': function() {
90//MochiKit.Logging.logDebug(">>> handling type change - " + this.recordField().type());
91 this.synchronizeComponentValues();
92 this.update();
93 },
94
95 //-------------------------------------------------------------------------
96
97 'addrUrl': function() {
98 var result;
99
100 result = "http://maps.google.com/maps?q=" + this.value().split(' ').join('+');
101
102 return result;
103 },
104
105 //-------------------------------------------------------------------------
106
107 'updateViewMode': function() {
108 var scarmbledStatus;
109
110 scrambledStatus = this.scrambledStatus() || 'SCRAMBLED';
111
112 this.element().update("");
113 if (this.recordField().hidden() == false) {
114 switch(this.recordField().type()) {
115 case 'TXT':
116 case 'PWD':
117 Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'span', html:this.value()});
118 break;
119 case 'URL':
120 varurlLocation;
121
122 urlLocation = Clipperz.Base.sanitizeString(this.value());
123 if (! (/^(https?|ftp|svn):\/\//.test(urlLocation))) {
124 urlLocation = 'http://' + urlLocation;
125 }
126 Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'a', href:urlLocation, html:this.value(), target:'_blank'});
127 break;
128 case 'DATE':
129 Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'span', html:this.value()});
130 break;
131 case 'ADDR':
132 Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'a', href:this.addrUrl(), html:this.value(), target:'_blank'});
133 break;
134 }
135 } else {
136 var tableElement;
137 var tdElement;
138 var inputElement;
139 var passwordElementConfiguration;
140
141 if (scrambledStatus == 'SCRAMBLED') {
142 varscrambledInputElement;
143
144 if ((Clipperz_IEisBroken === true) && (Clipperz.PM.Proxy.defaultProxy.isReadOnly())) {
145 scrambledInputElement = {tag:'input', type:'password', value:"this.value()"};
146 } else {
147 scrambledInputElement = {tag:'input', type:'text', cls:'scrambledField', title:Clipperz.PM.Strings['recordDetailPasswordFieldTooltipLabel'], value:"this.value()"};
148 }
149
150 passwordElementConfiguration =
151 {tag:'table', border:'0', cellspacing:'2', cellpadding:'0', children:[
152 {tag:'tbody', children:[
153 {tag:'tr', children:[
154 {tag:'td', valign:'top', children:[
155 scrambledInputElement,
156 {tag:'a', cls:'scrambleLink', id:this.getId('scrambleLink'), href:'#', htmlString:Clipperz.PM.Strings['recordDetailPasswordFieldUnscrambleLabel']}
157 ]},
158 {tag:'td', valign:'top', children:[
159 {tag:'span', cls:'scrambledFieldLabel', htmlString:Clipperz.PM.Strings['recordDetailPasswordFieldHelpLabel']}
160 ]}
161 ]}
162 ]}
163 ]};
164 } else {
165 passwordElementConfiguration =
166 {tag:'div', children:[
167 {tag:'input', type:'text', cls:'unscrambledField', value:"this.value()"},
168 {tag:'a', cls:'scrambleLink', id:this.getId('scrambleLink'), href:'#', htmlString:Clipperz.PM.Strings['recordDetailPasswordFieldScrambleLabel']}
169 ]};
170 }
171
172 tableElement = Clipperz.YUI.DomHelper.append(this.element().dom, passwordElementConfiguration, true);
173
174 inputElement = tableElement.getChildrenByTagName('input')[0];
175 inputElement.dom.value = this.value();
176 inputElement.wrap({tag:'div', cls:'passwordBackground'}).setStyle('background-position', "0px -" + Math.min(128, Clipperz.PM.Crypto.passwordEntropy(this.value())) + "px");
177
178 MochiKit.Signal.connect(inputElement.dom, 'onfocus', this, 'selectHiddenFieldOnFocus');
179 MochiKit.Signal.connect(this.getDom('scrambleLink'), 'onclick', this, 'toggleScramble');
180 }
181 },
182
183 //-------------------------------------------------------------------------
184
185 'updateEditMode': function() {
186 var inputElement;
187 var scarmbledStatus;
188
189 scrambledStatus = this.scrambledStatus() || 'SCRAMBLED';
190
191 this.element().update("");
192 switch(this.recordField().type()) {
193 case 'TXT':
194 case 'URL':
195 case 'ADDR':
196 inputElement = Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'input', type:'text', value:"this.value()"}, true);
197 inputElement.dom.value = this.value();
198 break;
199 case 'PWD':
200 Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'table', width:'100%', cellpadding:'0', cellspacing:'0', children:[
201 {tag:'tbody', children:[
202 {tag:'tr', children:[
203 {tag:'td', valign:'top', children:[
204 {tag:'input', type:((scrambledStatus == 'SCRAMBLED') ? 'password' : 'text'), id:this.getId('passwordInputElement'), value:"this.value()"},
205 {tag:'a', cls:'scrambleLink', id:this.getId('scrambleLink'), href:'#', html:(scrambledStatus == 'SCRAMBLED' ? Clipperz.PM.Strings['recordDetailPasswordFieldUnscrambleLabel'] : Clipperz.PM.Strings['recordDetailPasswordFieldScrambleLabel'])}
206 ]},
207 {tag:'td', valign:'top', children:[
208 {tag:'div', id:this.getId('passwordGenerator'), cls:'Clipperz_PasswordGenerator_button', html:'&nbsp;'}
209 ]}
210 ]}
211 ]}
212 ]})
213 inputElement = this.getElement('passwordInputElement');
214 inputElement.dom.value = this.value();
215 new Clipperz.PM.Components.PasswordEntropyDisplay(this.getElement('passwordInputElement'));
216 new Clipperz.PM.Components.PasswordGenerator(this.getElement('passwordGenerator'), this);
217 MochiKit.Signal.connect(this.getDom('scrambleLink'), 'onclick', this, 'toggleScramble');
218 break;
219 // case 'NOTE':
220 // inputElement = Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'textarea', rows:'5', html:this.value()}, true);
221 // break
222 case 'DATE':
223 inputElement = Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'input', type:'text', value:"this.value()"}, true);
224 inputElement.dom.value = this.value();
225 break;
226 }
227
228 this.setInputElement(inputElement);
229 },
230
231 //-------------------------------------------------------------------------
232
233 'synchronizeComponentValues': function() {
234//MochiKit.Logging.logDebug(">>> FieldValueComponent.synchronizeComponentValues");
235 if (this.inputElement() != null) {
236 var value;
237
238 switch(this.recordField().type()) {
239 case 'TXT':
240 case 'URL':
241 case 'ADDR':
242 case 'PWD':
243 case 'DATE':
244 value = this.inputElement().dom.value;
245 break;
246 }
247 this.setValue(value);
248 }
249//MochiKit.Logging.logDebug("<<< FieldValueComponent.synchronizeComponentValues");
250 },
251
252 //-------------------------------------------------------------------------
253
254 'selectHiddenFieldOnFocus': function(anEvent) {
255 anEvent.src().select();
256 },
257
258 //-------------------------------------------------------------------------
259
260 'toggleScramble': function(anEvent) {
261 this.synchronizeComponentValues();
262
263 if (this.scrambledStatus() == 'SCRAMBLED') {
264 this.setScrambledStatus('UNSCRAMBLED');
265 } else {
266 this.setScrambledStatus('SCRAMBLED');
267 };
268
269 this.update();
270 },
271
272 //-------------------------------------------------------------------------
273 __syntaxFix__: "syntax fix"
274});
275