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/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.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/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js | 450 |
1 files changed, 450 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js new file mode 100644 index 0000000..0657520 --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/Import/KeePassImportComponent.js | |||
@@ -0,0 +1,450 @@ | |||
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.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; } | ||
33 | |||
34 | //############################################################################# | ||
35 | |||
36 | Clipperz.PM.Components.Import.KeePassImportComponent = function(anElement, args) { | ||
37 | args = args || {}; | ||
38 | |||
39 | Clipperz.PM.Components.Import.KeePassImportComponent.superclass.constructor.call(this, anElement, args); | ||
40 | |||
41 | this._steps = ['EDIT', 'KEEPASS_SETTINGS', 'PREVIEW', 'IMPORT']; | ||
42 | this._definedFields = ['Group', 'Group Tree', 'UserName', 'URL', 'Password', 'Notes', 'UUID', 'Icon', 'Creation Time', 'Last Access', 'Last Modification', 'Expires', 'Attachment Description', 'Attachment']; | ||
43 | |||
44 | this.render(); | ||
45 | |||
46 | return this; | ||
47 | } | ||
48 | |||
49 | //============================================================================= | ||
50 | |||
51 | YAHOO.extendX(Clipperz.PM.Components.Import.KeePassImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, { | ||
52 | |||
53 | 'toString': function() { | ||
54 | return "Clipperz.PM.Components.Import.KeePassImportComponent component"; | ||
55 | }, | ||
56 | |||
57 | //------------------------------------------------------------------------- | ||
58 | |||
59 | 'render': function() { | ||
60 | //MochiKit.Logging.logDebug(">>> Import.KeePassImportComponent.render"); | ||
61 | this.domHelper().append(this.element(), {tag:'div', cls:'keePassImportWizard', children:[ | ||
62 | {tag:'h3', htmlString:Clipperz.PM.Strings['KeePass_ImportWizard_Title']}, | ||
63 | {tag:'div', cls:'importSteps', id:this.getId('importSteps')}, | ||
64 | {tag:'div', cls:'importStepBlocks', children:[ | ||
65 | {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[ | ||
66 | {tag:'div', children:[ | ||
67 | {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_keePass_description']}, | ||
68 | {tag:'div', cls:'importOptionsParameters', children:[]}, | ||
69 | this.textAreaConfig() | ||
70 | ]} | ||
71 | ]}, | ||
72 | {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[ | ||
73 | {tag:'div', children:[ | ||
74 | {tag:'div', id:this.getId('settingsDiv'), children:[ | ||
75 | {tag:'table', id:'KeePassSettings', children:[ | ||
76 | {tag:'tbody', children:[ | ||
77 | {tag:'tr', children:[ | ||
78 | {tag:'td', width:'50%', valign:'top', children:[ | ||
79 | {tag:'table', children:[ | ||
80 | {tag:'tbody', children:[ | ||
81 | {tag:'tr', children:[ | ||
82 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Group_checkbox'), name:'Group'/*, checked:true*/}]}, | ||
83 | {tag:'td', width:'150', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Group_label'), html:"Group"}]} | ||
84 | ]}, | ||
85 | {tag:'tr', children:[ | ||
86 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Group Tree_checkbox'), name:'Group Tree'/*, checked:true*/}]}, | ||
87 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Group Tree_label'), html:"Group Tree"}]} | ||
88 | ]}, | ||
89 | {tag:'tr', children:[ | ||
90 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('UserName_checkbox'), name:'UserName', checked:true}]}, | ||
91 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('UserName_label'), html:"UserName"}]} | ||
92 | ]}, | ||
93 | {tag:'tr', children:[ | ||
94 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('URL_checkbox'), name:'URL', checked:true}]}, | ||
95 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('URL_label'), html:"URL"}]} | ||
96 | ]}, | ||
97 | {tag:'tr', children:[ | ||
98 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Password_checkbox'), name:'Password', checked:true}]}, | ||
99 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Password_label'), html:"Password"}]} | ||
100 | ]}, | ||
101 | {tag:'tr', children:[ | ||
102 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Notes_checkbox'), name:'Notes', checked:true}]}, | ||
103 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Notes_label'), html:"Notes"}]} | ||
104 | ]}, | ||
105 | {tag:'tr', children:[ | ||
106 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('UUID_checkbox'), name:'UUID'/*, checked:true*/}]}, | ||
107 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('UUID_label'), html:"UUID"}]} | ||
108 | ]} | ||
109 | ]} | ||
110 | ]} | ||
111 | ]}, | ||
112 | {tag:'td', width:'50%', valign:'top', children:[ | ||
113 | {tag:'table', children:[ | ||
114 | {tag:'tbody', children:[ | ||
115 | {tag:'tr', children:[ | ||
116 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Icon_checkbox'), name:'Icon'/*, checked:true*/}]}, | ||
117 | {tag:'td', width:'150', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Icon_label'), html:"Icon"}]} | ||
118 | ]}, | ||
119 | {tag:'tr', children:[ | ||
120 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Creation Time_checkbox'), name:'Creation Time'/*, checked:true*/}]}, | ||
121 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Creation Time_label'), html:"Creation Time"}]} | ||
122 | ]}, | ||
123 | {tag:'tr', children:[ | ||
124 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Last Access_checkbox'), name:'Last Access'/*, checked:true*/}]}, | ||
125 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Last Access_label'), html:"Last Access"}]} | ||
126 | ]}, | ||
127 | {tag:'tr', children:[ | ||
128 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Last Modification_checkbox'), name:'Last Modification'/*, checked:true*/}]}, | ||
129 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Last Modification_label'), html:"Last Modification"}]} | ||
130 | ]}, | ||
131 | {tag:'tr', children:[ | ||
132 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Expires_checkbox'), name:'Expires'/*, checked:true*/}]}, | ||
133 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Expires_label'), html:"Expires"}]} | ||
134 | ]}, | ||
135 | {tag:'tr', children:[ | ||
136 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Attachment Description_checkbox'), name:'Attachment Description', checked:true}]}, | ||
137 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Attachment Description_label'), html:"Attachment Description"}]} | ||
138 | ]}, | ||
139 | {tag:'tr', children:[ | ||
140 | {tag:'td', valign:'top', children:[{tag:'input', type:'checkbox', id:this.getId('Attachment_checkbox'), name:'Attachment', checked:true}]}, | ||
141 | {tag:'td', valign:'top', children:[{tag:'span', cls:'keePassFieldLabel', id:this.getId('Attachment_label'), html:"Attachment"}]} | ||
142 | ]} | ||
143 | ]} | ||
144 | ]} | ||
145 | ]} | ||
146 | ]} | ||
147 | ]} | ||
148 | ]} | ||
149 | ]} | ||
150 | ]} | ||
151 | ]}, | ||
152 | {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[ | ||
153 | {tag:'div', children:[ | ||
154 | {tag:'div', id:this.getId('previewDiv'), html:"preview"} | ||
155 | ]} | ||
156 | ]}, | ||
157 | {tag:'div', cls:'step_3', id:this.getId('step_3'), children:[ | ||
158 | {tag:'div', children:[ | ||
159 | {tag:'h4', html:"done"} | ||
160 | ]} | ||
161 | ]} | ||
162 | ]}, | ||
163 | {tag:'div', cls:'importOptionsButtons', children:[ | ||
164 | {tag:'table', children:[ | ||
165 | {tag:'tbody', children:[ | ||
166 | {tag:'tr', children:[ | ||
167 | {tag:'td', html:' '}, | ||
168 | {tag:'td', children:[ | ||
169 | {tag:'div', id:this.getId('backActionButton')} | ||
170 | ]}, | ||
171 | {tag:'td', html:' '}, | ||
172 | {tag:'td', children:[ | ||
173 | {tag:'div', id:this.getId('nextActionButton')} | ||
174 | ]}, | ||
175 | {tag:'td', html:' '} | ||
176 | ]} | ||
177 | ]} | ||
178 | ]} | ||
179 | ]} | ||
180 | ]}); | ||
181 | |||
182 | this.updateSteps(); | ||
183 | |||
184 | this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this})); | ||
185 | this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this})); | ||
186 | |||
187 | this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show() | ||
188 | this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); | ||
189 | this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); | ||
190 | this.getElement('step_3').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide(); | ||
191 | //MochiKit.Logging.logDebug("<<< Import.KeePassImportComponent.render"); | ||
192 | }, | ||
193 | |||
194 | //------------------------------------------------------------------------- | ||
195 | |||
196 | 'nextAction': function() { | ||
197 | switch (this.currentStep()) { | ||
198 | case 0: //-> 1 | ||
199 | Clipperz.PM.Components.MessageBox.showProgressPanel( | ||
200 | MochiKit.Base.method(this, 'deferredParseValues'), | ||
201 | MochiKit.Base.method(this, 'handleParseError'), | ||
202 | this.getDom('nextActionButton') | ||
203 | ); | ||
204 | break; | ||
205 | case 1: //-> 2 | ||
206 | this.previewValues(); | ||
207 | break; | ||
208 | case 2: //-> 3 | ||
209 | this.importValues(); | ||
210 | break; | ||
211 | } | ||
212 | }, | ||
213 | |||
214 | //------------------------------------------------------------------------- | ||
215 | |||
216 | 'deferredParseValues': function() { | ||
217 | var deferredResult; | ||
218 | |||
219 | deferredResult = new MochiKit.Async.Deferred(); | ||
220 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 1 " + res.substring(0,50)); return res;}); | ||
221 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData'); | ||
222 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 2 " + res.substring(0,50)); return res;}); | ||
223 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | ||
224 | this.startProcessing(); | ||
225 | |||
226 | return res; | ||
227 | }, this)); | ||
228 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 3 " + res.substring(0,50)); return res;}); | ||
229 | deferredResult.addCallback(MochiKit.Base.method(this, 'parseKeePassValues')); //processPasswordPlusValues | ||
230 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 4 " + res); return res;}); | ||
231 | deferredResult.addCallback(MochiKit.Base.method(this, 'setParsedValues')); //setProcessedValues | ||
232 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 5 " + res); return res;}); | ||
233 | deferredResult.addCallback(MochiKit.Base.method(this, 'showSettings')); //previewRecordValues | ||
234 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 6 " + res); return res;}); | ||
235 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | ||
236 | this.processingDone(); | ||
237 | this.getElement('step_0').hide(); | ||
238 | this.getElement('step_1').show(); | ||
239 | this.backButton().enable(); | ||
240 | |||
241 | return res; | ||
242 | }, this)); | ||
243 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredParseValues - 7 " + res); return res;}); | ||
244 | deferredResult.callback(this.textAreaContent()); | ||
245 | |||
246 | return deferredResult; | ||
247 | }, | ||
248 | |||
249 | //------------------------------------------------------------------------- | ||
250 | |||
251 | 'deferredPreviewValues': function() { | ||
252 | var deferredResult; | ||
253 | |||
254 | //MochiKit.Logging.logDebug(">>> KeePassImportComonent.deferredPreviewValues"); | ||
255 | deferredResult = new MochiKit.Async.Deferred(); | ||
256 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 1 " + res); return res;}); | ||
257 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'previewImportData'); | ||
258 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 2 " + res); return res;}); | ||
259 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | ||
260 | this.startProcessing(); | ||
261 | |||
262 | return res; | ||
263 | }, this)); | ||
264 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 3 " + res); return res;}); | ||
265 | deferredResult.addCallback(MochiKit.Base.method(this, 'processKeePassParsedValues')); | ||
266 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 4 " + res); return res;}); | ||
267 | deferredResult.addCallback(MochiKit.Base.method(this, 'setProcessedValues')); | ||
268 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 5 " + res); return res;}); | ||
269 | deferredResult.addCallback(MochiKit.Base.method(this, 'previewRecordValues')); | ||
270 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 6 " + res); return res;}); | ||
271 | deferredResult.addCallback(MochiKit.Base.bind(function(res) { | ||
272 | this.processingDone(); | ||
273 | this.getElement('step_1').hide(); | ||
274 | this.getElement('step_2').show(); | ||
275 | this.backButton().enable(); | ||
276 | |||
277 | return res; | ||
278 | }, this)); | ||
279 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 7 " + res); return res;}); | ||
280 | // deferredResult.addErrback(MochiKit.Base.bind(function() { | ||
281 | // this.processingAborted(); | ||
282 | // }, this)) | ||
283 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.deferredPreviewValues - 8 " + res); return res;}); | ||
284 | deferredResult.callback(this.parsedValues()); | ||
285 | //MochiKit.Logging.logDebug("<<< KeePassImportComonent.deferredPreviewValues"); | ||
286 | |||
287 | return deferredResult; | ||
288 | }, | ||
289 | |||
290 | //------------------------------------------------------------------------- | ||
291 | |||
292 | 'definedFields': function() { | ||
293 | return this._definedFields; | ||
294 | }, | ||
295 | |||
296 | //------------------------------------------------------------------------- | ||
297 | |||
298 | 'parseKeePassValues': function(someData) { | ||
299 | var deferredResult; | ||
300 | var keePassProcessor; | ||
301 | |||
302 | keePassProcessor = new Clipperz.KeePassExportProcessor(); | ||
303 | |||
304 | deferredResult = new MochiKit.Async.Deferred(); | ||
305 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 1 " + res.substring(0,50)); return res;}); | ||
306 | deferredResult.addCallback(function(res) { | ||
307 | return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res); | ||
308 | }) | ||
309 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 2 " + res.substring(0,50)); return res;}); | ||
310 | deferredResult.addCallback(MochiKit.Base.method(keePassProcessor, 'deferredParse')); | ||
311 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("KeePassImportComponent.parseKeePassValues - 3 " + res); return res;}); | ||
312 | deferredResult.callback(someData); | ||
313 | |||
314 | return deferredResult; | ||
315 | }, | ||
316 | |||
317 | //------------------------------------------------------------------------- | ||
318 | |||
319 | 'showSettings': function(someValues) { | ||
320 | var availableFields; | ||
321 | var i,c; | ||
322 | |||
323 | //MochiKit.Logging.logDebug(">>> KeePassImportCOmponent.showSettings"); | ||
324 | availableFields = new Clipperz.Set(); | ||
325 | c = this.parsedValues().length; | ||
326 | for (i=0; i<c; i++) { | ||
327 | var fieldLabel; | ||
328 | |||
329 | for (fieldLabel in this.parsedValues()[i]) { | ||
330 | availableFields.add(fieldLabel); | ||
331 | } | ||
332 | } | ||
333 | |||
334 | c = this.definedFields().length; | ||
335 | for (i=0; i<c; i++) { | ||
336 | var definedField; | ||
337 | |||
338 | definedField = this.definedFields()[i]; | ||
339 | if (availableFields.contains(definedField)) { | ||
340 | //MochiKit.Logging.logDebug("enabling field " + definedField); | ||
341 | this.getDom(definedField + '_checkbox').disabled = false; | ||
342 | this.getElement(definedField + '_label').removeClass('disabled'); | ||
343 | } else { | ||
344 | //MochiKit.Logging.logDebug("disabling field " + definedField); | ||
345 | this.getDom(definedField + '_checkbox').disabled = true; | ||
346 | this.getDom(definedField + '_checkbox').checked = false; //???? | ||
347 | this.getElement(definedField + '_label').addClass('disabled'); | ||
348 | } | ||
349 | } | ||
350 | //MochiKit.Logging.logDebug("<<< KeePassImportCOmponent.showSettings"); | ||
351 | |||
352 | return MochiKit.Async.succeed(someValues); | ||
353 | }, | ||
354 | |||
355 | //------------------------------------------------------------------------- | ||
356 | |||
357 | 'shouldImportField': function(aFieldName) { | ||
358 | var fieldCheckbox; | ||
359 | var result; | ||
360 | |||
361 | //MochiKit.Logging.logDebug(">>> shouldImportField: " + aFieldName); | ||
362 | // fieldCheckbox = this.getDom(aFieldName + '_checkbox'); | ||
363 | fieldCheckbox = MochiKit.DOM.getElement(this.getId(aFieldName + '_checkbox')); | ||
364 | if (fieldCheckbox != null) { | ||
365 | result = fieldCheckbox.checked; | ||
366 | } else { | ||
367 | result = false; | ||
368 | } | ||
369 | //MochiKit.Logging.logDebug("<<< shouldImportField: " + result); | ||
370 | |||
371 | return result; | ||
372 | }, | ||
373 | |||
374 | //------------------------------------------------------------------------- | ||
375 | |||
376 | 'processKeePassParsedValues': function(someValues) { | ||
377 | var deferredResult; | ||
378 | var records; | ||
379 | var i,c; | ||
380 | |||
381 | //MochiKit.Logging.logDebug(">>> processKeePassParsedValues"); | ||
382 | deferredResult = new MochiKit.Async.Deferred(); | ||
383 | records = []; | ||
384 | |||
385 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("processKeePassParsedValues - 1: " + res); return res;}); | ||
386 | c = someValues.length; | ||
387 | deferredResult.addCallback(function(res) { | ||
388 | return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:c}, res); | ||
389 | }) | ||
390 | for(i=0; i<c; i++) { | ||
391 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.1: " + res); return res;}); | ||
392 | deferredResult.addCallback(MochiKit.Async.wait, 0.2); | ||
393 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.2: " + res); return res;}); | ||
394 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {}); | ||
395 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.3: " + res); return res;}); | ||
396 | deferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) { | ||
397 | var record; | ||
398 | var recordVersion; | ||
399 | var ii; | ||
400 | |||
401 | record = new Clipperz.PM.DataModel.Record({user:this.user()}); | ||
402 | record.setLabel(someData['Title']); | ||
403 | if (this.shouldImportField('Notes')) { | ||
404 | record.setNotes(someData['Notes']); | ||
405 | } | ||
406 | recordVersion = record.currentVersion() | ||
407 | |||
408 | for (ii in someData) { | ||
409 | if ((ii != 'Title') && (ii != 'Notes') && (typeof(someData[ii]) != "undefined") && (this.shouldImportField(ii))) { | ||
410 | var recordField; | ||
411 | var recordFieldType; | ||
412 | |||
413 | recordFieldType = 'TXT'; | ||
414 | if (ii == 'Password') { | ||
415 | recordFieldType = 'PWD'; | ||
416 | } else if (ii == 'URL') { | ||
417 | recordFieldType = 'URL'; | ||
418 | } else if ((ii == 'Creation Time') || (ii == 'Last Access') || (ii == 'Last Modification') || (ii == 'Expires')) { | ||
419 | recordFieldType = 'Date'; | ||
420 | } | ||
421 | |||
422 | recordField = new Clipperz.PM.DataModel.RecordField({ | ||
423 | recordVersion:recordVersion, | ||
424 | label: ii, | ||
425 | value: someData[ii], | ||
426 | type: recordFieldType | ||
427 | }); | ||
428 | recordVersion.addField(recordField); | ||
429 | } | ||
430 | } | ||
431 | |||
432 | someRecords.push(record); | ||
433 | |||
434 | return someRecords; | ||
435 | }, this), records, someValues[i]); | ||
436 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + i + "] processKeePassParsedValues - 1.4: " + res); return res;}); | ||
437 | } | ||
438 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("processKeePassParsedValues - 2: " + res); return res;}); | ||
439 | deferredResult.addCallback(MochiKit.Async.succeed, records); | ||
440 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("processKeePassParsedValues - 3: " + res); return res;}); | ||
441 | deferredResult.callback(); | ||
442 | //MochiKit.Logging.logDebug("<<< processKeePassParsedValues"); | ||
443 | |||
444 | return deferredResult; | ||
445 | }, | ||
446 | |||
447 | //------------------------------------------------------------------------- | ||
448 | __syntaxFix__: "syntax fix" | ||
449 | }); | ||
450 | |||