summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js392
1 files changed, 392 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js b/frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js
new file mode 100644
index 0000000..d35bdc6
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/PM/Components/Import/RoboFormImportComponent.js
@@ -0,0 +1,392 @@
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.Import) == 'undefined') { Clipperz.PM.Components.Import = {}; }
33
34//#############################################################################
35
36Clipperz.PM.Components.Import.RoboFormImportComponent = function(anElement, args) {
37 args = args || {};
38
39 Clipperz.PM.Components.Import.RoboFormImportComponent.superclass.constructor.call(this, anElement, args);
40
41 this.render();
42
43 return this;
44}
45
46//=============================================================================
47
48YAHOO.extendX(Clipperz.PM.Components.Import.RoboFormImportComponent, Clipperz.PM.Components.Import.GenericImportComponent, {
49
50 'toString': function() {
51 return "Clipperz.PM.Components.Import.RoboFormImportComponent component";
52 },
53
54 //-------------------------------------------------------------------------
55
56 'render': function() {
57//MochiKit.Logging.logDebug(">>> Import.RoboFormImportComponent.render");
58 this.domHelper().append(this.element(), {tag:'div', cls:'roboFormImportWizard', children:[
59 {tag:'h3', htmlString:Clipperz.PM.Strings['RoboForm_ImportWizard_Title']},
60 {tag:'div', cls:'importSteps', id:this.getId('importSteps')},
61 {tag:'div', cls:'importStepBlocks', children:[
62 {tag:'div', cls:'step_0', id:this.getId('step_0'), children:[
63 {tag:'div', children:[
64 {tag:'div', cls:'importOptionsDescription', htmlString:Clipperz.PM.Strings['importOptions_roboForm_description']},
65 {tag:'div', cls:'importOptionsParameters', children:[]},
66 this.textAreaConfig()
67 ]}
68 ]},
69 {tag:'div', cls:'step_1', id:this.getId('step_1'), children:[
70 {tag:'div', children:[
71 {tag:'div', id:this.getId('previewDiv'), html:"preview"}
72 ]}
73 ]},
74 {tag:'div', cls:'step_2', id:this.getId('step_2'), children:[
75 {tag:'div', children:[
76 {tag:'h4', html:"done"}
77 ]}
78 ]}
79 ]},
80 {tag:'div', cls:'importOptionsButtons', children:[
81 {tag:'table', children:[
82 {tag:'tbody', children:[
83 {tag:'tr', children:[
84 {tag:'td', html:'&nbsp;'},
85 {tag:'td', children:[
86 {tag:'div', id:this.getId('backActionButton')}
87 ]},
88 {tag:'td', html:'&nbsp;'},
89 {tag:'td', children:[
90 {tag:'div', id:this.getId('nextActionButton')}
91 ]},
92 {tag:'td', html:'&nbsp;'}
93 ]}
94 ]}
95 ]}
96 ]}
97 ]});
98
99 this.updateSteps();
100
101 this.setBackButton(new YAHOO.ext.Button(this.getDom('backActionButton'), {text:"back", handler:this.backAction, scope:this}));
102 this.setNextButton(new YAHOO.ext.Button(this.getDom('nextActionButton'), {text:"next", handler:this.nextAction, scope:this}));
103
104 this.getElement('step_0').setVisibilityMode(YAHOO.ext.Element.DISPLAY).show()
105 this.getElement('step_1').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide();
106 this.getElement('step_2').setVisibilityMode(YAHOO.ext.Element.DISPLAY).hide();
107//MochiKit.Logging.logDebug("<<< Import.RoboFormImportComponent.render");
108 },
109
110 //-------------------------------------------------------------------------
111
112 'nextAction': function() {
113 switch (this.currentStep()) {
114 case 0: //-> 1
115 this.previewValues();
116 break;
117 case 1: //-> 2
118 this.importValues();
119 break;
120 }
121 },
122
123 //-------------------------------------------------------------------------
124
125 'deferredPreviewValues': function() {
126 var deferredResult;
127
128 // this.setFormValues(MochiKit.DOM.formContents(this.getDom('dataForm')));
129
130 deferredResult = new MochiKit.Async.Deferred();
131 deferredResult.addCallback(MochiKit.Base.bind(function(res) {
132 this.startProcessing();
133
134 return res;
135 }, this));
136 deferredResult.addCallback(MochiKit.Base.method(this, 'processRoboFormValues'));
137 deferredResult.addCallback(MochiKit.Base.method(this, 'setProcessedValues'));
138 deferredResult.addCallback(MochiKit.Base.method(this, 'previewRecordValues'));
139 deferredResult.addCallback(MochiKit.Base.bind(function(res) {
140 this.processingDone();
141 this.getElement('step_0').hide();
142 this.getElement('step_1').show();
143 this.backButton().enable();
144
145 return res;
146 }, this));
147 // deferredResult.addErrback(MochiKit.Base.bind(function() {
148 // this.processingAborted();
149 // }, this))
150 deferredResult.callback(this.textAreaContent());
151
152 return deferredResult;
153 },
154
155 //-------------------------------------------------------------------------
156
157 'processRoboFormValues': function(someData) {
158 var result;
159
160 if (someData.match(/^\<HTML\>\<HEAD\>\<TITLE\>RoboForm Passcards List /g)) {
161 result = this.processRoboFormPasscardsValues(someData);
162 } else if (someData.match(/\<HTML\>\<HEAD\>\<TITLE\>RoboForm Safenotes List /g)) {
163 result = this.processRoboFormSafenotesValues(someData);
164 }
165
166 return result;
167 },
168
169 //.........................................................................
170
171 'processRoboFormPasscardsValues': function(someData) {
172 var deferredResult;
173
174 deferredResult = new MochiKit.Async.Deferred();
175//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 1: "/* + res*/); return res;});
176 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData');
177//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 2: "/* + res*/); return res;});
178 deferredResult.addCallback(function(someData) {
179 var result;
180 var data;
181
182 data = someData.replace(/\r?\n/g, "");
183 result = data.match(/\<TABLE width\=\"100\%\"\>.*?\<\/TABLE\>/g);
184
185 return result;
186 });
187//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3: "/* + res*/); return res;});
188//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3.1: " + res.length); return res;});
189 deferredResult.addCallback(function(res) {
190 return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res);
191 })
192//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 4: "/* + res*/); return res;});
193 deferredResult.addCallback(MochiKit.Base.bind(function(someRecordValues) {
194 var innerDeferredResult;
195 var records;
196 var i,c;
197
198 innerDeferredResult = new MochiKit.Async.Deferred();
199 records = [];
200
201 c = someRecordValues.length;
202 for(i=0; i<c; i++) {
203//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 1: " + res); return res;});
204 innerDeferredResult.addCallback(MochiKit.Async.wait, 0.2);
205//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 2: " + res); return res;});
206 innerDeferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {});
207//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 3: " + res); return res;});
208 innerDeferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) {
209 var data;
210 var record;
211 var recordVersion;
212 var fields;
213 var ii, cc;
214 var hasNotes;
215
216 var caption;
217 var subcaption;
218
219//MochiKit.Logging.logDebug("data: " + someData);
220 data = someData.replace(/\<WBR\>/g, "");
221 hasNotes = false;
222
223 /\<TD class\=caption colSpan\=3\>(.*?)\<\/TD\>/.test(data); //<TD class=caption colSpan=3>110mb</TD>
224 caption = RegExp.$1;
225//MochiKit.Logging.logDebug("caption: " + caption);
226
227 /\<TD class\=subcaption colSpan\=3\>(.*?)\<\/TD\>/.test(data); //<TD class=subcaption colSpan=3>110<WBR>mb.com</TD>
228 subcaption = RegExp.$1;
229//MochiKit.Logging.logDebug("subcaption: " + subcaption);
230
231 record = new Clipperz.PM.DataModel.Record({user:this.user()});
232 recordVersion = record.currentVersion()
233
234 record.setLabel(caption);
235 // record.setNotes(subcaption);
236 if (subcaption != null) {
237 var recordField;
238
239 recordField = new Clipperz.PM.DataModel.RecordField({
240 recordVersion:recordVersion,
241 label: "url",
242 value: subcaption,
243 type: 'URL'
244 });
245 recordVersion.addField(recordField);
246 }
247
248 fields = data.match(/\<TR\>.*?\<\/TR\>/g) || [];
249 cc = fields.length;
250//MochiKit.Logging.logDebug("fields.length: " + cc);
251 for (ii=0; ii<cc; ii++) {
252 var recordField;
253 var fieldString;
254 var fieldName;
255 var fieldValue;
256
257//MochiKit.Logging.logDebug("fieldString: " + fields[ii]);
258 fieldString = fields[ii];
259//MochiKit.Logging.logDebug("fieldString (cleaned): " + fieldString);
260 /\<TD class\=field vAlign\=top align\=left width\=\"40\%\"\>(.*?)\<\/TD\>/.test(fieldString);
261 fieldName = RegExp.$1;
262
263 /\<TD class\=wordbreakfield vAlign\=top align\=left width\=\"55\%\"\>(.*?)\<\/TD\>/.test(fieldString);
264 fieldValue = RegExp.$1;
265
266 if (fieldName == "Note$") {
267 record.setNotes(fieldValue);
268 hasNotes = true;
269 } else {
270 var fieldType;
271
272 if (((ii == 1) && (hasNotes == false)) || ((ii == 2) && (hasNotes == true))) {
273 fieldType = 'PWD';
274 } else {
275 fieldType = 'TXT';
276 }
277
278 recordField = new Clipperz.PM.DataModel.RecordField({
279 recordVersion:recordVersion,
280 label: fieldName,
281 value: fieldValue,
282 type: fieldType
283 });
284 recordVersion.addField(recordField);
285 }
286 }
287
288 someRecords.push(record);
289
290 return someRecords;
291 }, this), records, someRecordValues[i]);
292 }
293//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 4: " + res); return res;});
294 innerDeferredResult.addCallback(MochiKit.Async.succeed, records);
295//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 5: " + res); return res;});
296 innerDeferredResult.callback();
297
298 return innerDeferredResult;
299 }, this));
300 deferredResult.callback(someData);
301
302 return deferredResult;
303 },
304
305
306 //.........................................................................
307
308 'processRoboFormSafenotesValues': function(someData) {
309 var deferredResult;
310
311 deferredResult = new MochiKit.Async.Deferred();
312//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 1: "/* + res*/); return res;});
313 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'parseImportData');
314//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 2: "/* + res*/); return res;});
315 deferredResult.addCallback(function(someData) {
316 var result;
317 var data;
318
319 data = someData.replace(/\r?\n/g, "");
320 result = data.match(/\<TABLE width\=\"100\%\"\>.*?\<\/TABLE\>/g);
321
322 return result;
323 });
324//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3: "/* + res*/); return res;});
325//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 3.1: " + res.length); return res;});
326 deferredResult.addCallback(function(res) {
327 return Clipperz.NotificationCenter.deferredNotification(this, 'updatedProgressState', {steps:(res.length)}, res);
328 })
329//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues - 4: "/* + res*/); return res;});
330 deferredResult.addCallback(MochiKit.Base.bind(function(someRecordValues) {
331 var innerDeferredResult;
332 var records;
333 var i,c;
334
335 innerDeferredResult = new MochiKit.Async.Deferred();
336 records = [];
337
338 c = someRecordValues.length;
339 for(i=0; i<c; i++) {
340//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 1: " + res); return res;});
341 innerDeferredResult.addCallback(MochiKit.Async.wait, 0.2);
342//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 2: " + res); return res;});
343 innerDeferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', {});
344//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 3: " + res); return res;});
345 innerDeferredResult.addCallback(MochiKit.Base.bind(function(someRecords, someData) {
346 var data;
347 var record;
348 var recordVersion;
349
350 var caption;
351 var wordbreakfield;
352
353//MochiKit.Logging.logDebug("data: " + someData);
354 data = someData.replace(/\<WBR\>/g, "");
355 hasNotes = false;
356
357 /\<TD class\=caption colSpan\=3\>(.*?)\<\/TD\>/.test(data); //<TD class=caption colSpan=3>110mb</TD>
358 caption = RegExp.$1;
359//MochiKit.Logging.logDebug("caption: " + caption);
360
361 /\<TD class\=wordbreakfield vAlign=top align\=left width\=\"\1\0\0\%\"\>(.*?)\<\/TD\>/.test(data); //<TD class=wordbreakfield vAlign=top align=left width="100%">7759500</TD>
362 wordbreakfield = RegExp.$1;
363//MochiKit.Logging.logDebug("subcaption: " + subcaption);
364
365 record = new Clipperz.PM.DataModel.Record({user:this.user()});
366 recordVersion = record.currentVersion()
367
368 record.setLabel(caption);
369 record.setNotes(wordbreakfield);
370
371 someRecords.push(record);
372
373 return someRecords;
374 }, this), records, someRecordValues[i]);
375 }
376//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 4: " + res); return res;});
377 innerDeferredResult.addCallback(MochiKit.Async.succeed, records);
378//innerDeferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("RoboFormImportComponent.processRoboFormValues __inner loop__ - 5: " + res); return res;});
379 innerDeferredResult.callback();
380
381 return innerDeferredResult;
382 }, this));
383 deferredResult.callback(someData);
384
385 return deferredResult;
386 },
387
388
389 //-------------------------------------------------------------------------
390 __syntaxFix__: "syntax fix"
391});
392