summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/Record.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/Record.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/Record.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/Record.js b/frontend/beta/js/Clipperz/PM/DataModel/Record.js
index ffb45de..9e496de 100644
--- a/frontend/beta/js/Clipperz/PM/DataModel/Record.js
+++ b/frontend/beta/js/Clipperz/PM/DataModel/Record.js
@@ -199,194 +199,200 @@ Clipperz.PM.DataModel.Record.prototype = MochiKit.Base.update(null, {
199 //------------------------------------------------------------------------- 199 //-------------------------------------------------------------------------
200 200
201 'shouldDecryptData': function() { 201 'shouldDecryptData': function() {
202 return this._shouldDecryptData; 202 return this._shouldDecryptData;
203 }, 203 },
204 204
205 'setShouldDecryptData': function(aValue) { 205 'setShouldDecryptData': function(aValue) {
206 this._shouldDecryptData = aValue; 206 this._shouldDecryptData = aValue;
207 }, 207 },
208 208
209 //------------------------------------------------------------------------- 209 //-------------------------------------------------------------------------
210 210
211 'shouldProcessData': function() { 211 'shouldProcessData': function() {
212 return this._shouldProcessData; 212 return this._shouldProcessData;
213 }, 213 },
214 214
215 'setShouldProcessData': function(aValue) { 215 'setShouldProcessData': function(aValue) {
216 this._shouldProcessData = aValue; 216 this._shouldProcessData = aValue;
217 }, 217 },
218 218
219 //------------------------------------------------------------------------- 219 //-------------------------------------------------------------------------
220 220
221 'loadData': function() { 221 'loadData': function() {
222 var result; 222 var result;
223 223
224//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.loadData - this: " + this); 224//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.loadData - this: " + this);
225 if (this.shouldLoadData()) { 225 if (this.shouldLoadData()) {
226 var deferredResult; 226 var deferredResult;
227 227
228 deferredResult = new MochiKit.Async.Deferred(); 228 deferredResult = new MochiKit.Async.Deferred();
229 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'loadingRecordData'); 229 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'loadingRecordData');
230 deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'getRecordDetail', {reference: this.reference()}); 230 deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'getRecordDetail', {reference: this.reference()});
231 deferredResult.addCallback(MochiKit.Base.method(this,'setServerData')); 231 deferredResult.addCallback(MochiKit.Base.method(this,'setServerData'));
232 deferredResult.callback(); 232 deferredResult.callback();
233 result = deferredResult; 233 result = deferredResult;
234 } else { 234 } else {
235 result = MochiKit.Async.succeed(this.serverData()); 235 result = MochiKit.Async.succeed(this.serverData());
236 } 236 }
237//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.loadData"); 237//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.loadData");
238 238
239 return result; 239 return result;
240 }, 240 },
241 241
242 //------------------------------------------------------------------------- 242 //-------------------------------------------------------------------------
243 243
244 'decryptData': function(anEncryptedData) { 244 'decryptData': function(anEncryptedData) {
245 var result; 245 var result;
246 246
247//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.decryptData - this: " + this + " (" + anEncryptedData + ")"); 247//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.decryptData - this: " + this + " (" + anEncryptedData + ")");
248 if (this.shouldDecryptData()) { 248 if (this.shouldDecryptData()) {
249 var deferredResult; 249 var deferredResult;
250 250
251 deferredResult = new MochiKit.Async.Deferred(); 251 deferredResult = new MochiKit.Async.Deferred();
252 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'decryptingRecordData'); 252 deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'decryptingRecordData');
253 deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.key(), anEncryptedData['data'], anEncryptedData['version']); 253 deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, this.key(), anEncryptedData['data'], anEncryptedData['version']);
254 deferredResult.addCallback(function(anEncryptedData, someDecryptedValues) { 254 deferredResult.addCallback(function(anEncryptedData, someDecryptedValues) {
255 varresult; 255 varresult;
256 256
257 result = anEncryptedData; 257 result = anEncryptedData;
258 result['data'] = someDecryptedValues; 258 result['data'] = someDecryptedValues;
259 259
260 return result; 260 return result;
261 }, anEncryptedData); 261 }, anEncryptedData);
262 deferredResult.addCallback(MochiKit.Base.method(this, 'setDecryptedData')); 262 deferredResult.addCallback(MochiKit.Base.method(this, 'setDecryptedData'));
263 deferredResult.callback(); 263 deferredResult.callback();
264 264
265 result = deferredResult; 265 result = deferredResult;
266 } else { 266 } else {
267 result = MochiKit.Async.succeed(this.decryptedData()); 267 result = MochiKit.Async.succeed(this.decryptedData());
268 } 268 }
269//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.decryptData"); 269//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.decryptData");
270 270
271 return result; 271 return result;
272 }, 272 },
273 273
274 //------------------------------------------------------------------------- 274 //-------------------------------------------------------------------------
275 275
276 'processData': function(someValues) { 276 'processData': function(someValues) {
277//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.processData"); 277//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Record.processData");
278//MochiKit.Logging.logDebug("--- Record.processData: " + Clipperz.Base.serializeJSON(someValues)); 278//MochiKit.Logging.logDebug("--- Record.processData: " + Clipperz.Base.serializeJSON(someValues));
279 if (this.shouldProcessData()) { 279 if (this.shouldProcessData()) {
280 var currentVersionParameters; 280 var currentVersionParameters;
281 281
282console.log("Record.processData", someValues); 282console.log("Record.processData", someValues);
283 this.processDataToExtractLegacyValues(someValues['data']); 283 this.processDataToExtractLegacyValues(someValues['data']);
284 284
285 if (typeof(someValues['data']['notes']) != 'undefined') { 285 if (typeof(someValues['data']['notes']) != 'undefined') {
286 this.setNotes(someValues['data']['notes']); 286 this.setNotes(someValues['data']['notes']);
287 } 287 }
288 288
289 if (someValues['data']['currentVersionKey'] != null) { 289 if (someValues['data']['currentVersionKey'] != null) {
290 this.setCurrentVersionKey(someValues['data']['currentVersionKey']); 290 this.setCurrentVersionKey(someValues['data']['currentVersionKey']);
291 } else { 291 } else {
292 this.setCurrentVersionKey(this.key()); 292 this.setCurrentVersionKey(this.key());
293 } 293 }
294 294
295 // currentVersionParameters = someValues['currentVersion']; 295 // community edition doesn't currently pass version
296 currentVersionParameters = someValues['versions'][someValues['currentVersion']]; 296 // information
297 if (someValues['versions'] == null) {
298 currentVersionParameters = someValues['currentVersion'];
299 } else {
300 currentVersionParameters = someValues['versions'][someValues['currentVersion']];
301 }
302
297console.log("Record.processData - this.currentVersionKey()", this.currentVersionKey()); 303console.log("Record.processData - this.currentVersionKey()", this.currentVersionKey());
298console.log("Record.processData - currentVersionParameters", currentVersionParameters); 304console.log("Record.processData - currentVersionParameters", currentVersionParameters);
299 currentVersionParameters['key'] = this.currentVersionKey(); 305 currentVersionParameters['key'] = this.currentVersionKey();
300 this.setCurrentVersion(new Clipperz.PM.DataModel.RecordVersion(this, currentVersionParameters)); 306 this.setCurrentVersion(new Clipperz.PM.DataModel.RecordVersion(this, currentVersionParameters));
301 307
302 if (someValues['data']['directLogins'] != null) { 308 if (someValues['data']['directLogins'] != null) {
303 vardirectLoginReference; 309 vardirectLoginReference;
304 310
305 for (directLoginReference in someValues['data']['directLogins']) { 311 for (directLoginReference in someValues['data']['directLogins']) {
306 var directLogin; 312 var directLogin;
307 var directLoginParameters; 313 var directLoginParameters;
308 314
309 directLoginParameters = someValues['data']['directLogins'][directLoginReference]; 315 directLoginParameters = someValues['data']['directLogins'][directLoginReference];
310 directLoginParameters.record = this; 316 directLoginParameters.record = this;
311 directLoginParameters.reference = directLoginReference; 317 directLoginParameters.reference = directLoginReference;
312 318
313 directLogin = new Clipperz.PM.DataModel.DirectLogin(directLoginParameters); 319 directLogin = new Clipperz.PM.DataModel.DirectLogin(directLoginParameters);
314 this.addDirectLogin(directLogin, true); 320 this.addDirectLogin(directLogin, true);
315 } 321 }
316 } 322 }
317 this.setShouldProcessData(false); 323 this.setShouldProcessData(false);
318 } 324 }
319 325
320 Clipperz.NotificationCenter.notify(this, 'recordDataReady'); 326 Clipperz.NotificationCenter.notify(this, 'recordDataReady');
321//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.processData"); 327//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Record.processData");
322//MochiKit.Logging.logDebug("<<< Record.processData"); 328//MochiKit.Logging.logDebug("<<< Record.processData");
323 329
324 return this; 330 return this;
325 }, 331 },
326 332
327 //------------------------------------------------------------------------- 333 //-------------------------------------------------------------------------
328 334
329 'processDataToExtractLegacyValues': function(someValues) { 335 'processDataToExtractLegacyValues': function(someValues) {
330//MochiKit.Logging.logDebug(">>> Record.processDataToExtractLegacyValues"); 336//MochiKit.Logging.logDebug(">>> Record.processDataToExtractLegacyValues");
331 if (someValues['data'] != null) { 337 if (someValues['data'] != null) {
332 this.setNotes(someValues['data']); 338 this.setNotes(someValues['data']);
333 } 339 }
334 340
335 if ( 341 if (
336 (typeof(someValues['loginFormData']) != "undefined") 342 (typeof(someValues['loginFormData']) != "undefined")
337 &&(typeof(someValues['loginBindings'] != "undefined")) 343 &&(typeof(someValues['loginBindings'] != "undefined"))
338 &&(someValues['loginFormData'] != "") 344 &&(someValues['loginFormData'] != "")
339 &&(someValues['loginBindings'] != "") 345 &&(someValues['loginBindings'] != "")
340 ) { 346 ) {
341 vardirectLogin; 347 vardirectLogin;
342 348
343 directLogin = new Clipperz.PM.DataModel.DirectLogin({ 349 directLogin = new Clipperz.PM.DataModel.DirectLogin({
344 record:this, 350 record:this,
345 label:this.label() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'], 351 label:this.label() + Clipperz.PM.Strings['newDirectLoginLabelSuffix'],
346 reference:Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(this.label() + 352 reference:Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(this.label() +
347 someValues['loginFormData'] + 353 someValues['loginFormData'] +
348 someValues['loginBindings'])).toHexString().substring(2), 354 someValues['loginBindings'])).toHexString().substring(2),
349 formData:Clipperz.Base.evalJSON(someValues['loginFormData']), 355 formData:Clipperz.Base.evalJSON(someValues['loginFormData']),
350 legacyBindingData:Clipperz.Base.evalJSON(someValues['loginBindings']), 356 legacyBindingData:Clipperz.Base.evalJSON(someValues['loginBindings']),
351 bookmarkletVersion:'0.1' 357 bookmarkletVersion:'0.1'
352 }); 358 });
353 this.addDirectLogin(directLogin, true); 359 this.addDirectLogin(directLogin, true);
354 } 360 }
355//MochiKit.Logging.logDebug("<<< Record.processDataToExtractLegacyValues"); 361//MochiKit.Logging.logDebug("<<< Record.processDataToExtractLegacyValues");
356 }, 362 },
357 363
358 //------------------------------------------------------------------------- 364 //-------------------------------------------------------------------------
359 365
360 'getReadyBeforeUpdatingVersionValues': function() { 366 'getReadyBeforeUpdatingVersionValues': function() {
361 }, 367 },
362 368
363 //------------------------------------------------------------------------- 369 //-------------------------------------------------------------------------
364 370
365 'addNewField': function() { 371 'addNewField': function() {
366 varnewField; 372 varnewField;
367 373
368//MochiKit.Logging.logDebug(">>> Record.addNewField - " + this); 374//MochiKit.Logging.logDebug(">>> Record.addNewField - " + this);
369 this.getReadyBeforeUpdatingVersionValues(); 375 this.getReadyBeforeUpdatingVersionValues();
370 newField = this.currentVersion().addNewField(); 376 newField = this.currentVersion().addNewField();
371 Clipperz.NotificationCenter.notify(this, 'recordUpdated'); 377 Clipperz.NotificationCenter.notify(this, 'recordUpdated');
372//MochiKit.Logging.logDebug("<<< Record.addNewField"); 378//MochiKit.Logging.logDebug("<<< Record.addNewField");
373 379
374 return newField; 380 return newField;
375 }, 381 },
376 382
377 //------------------------------------------------------------------------- 383 //-------------------------------------------------------------------------
378 384
379 'removeField': function(aField) { 385 'removeField': function(aField) {
380 this.getReadyBeforeUpdatingVersionValues(); 386 this.getReadyBeforeUpdatingVersionValues();
381 this.currentVersion().removeField(aField); 387 this.currentVersion().removeField(aField);
382 Clipperz.NotificationCenter.notify(this, 'recordUpdated'); 388 Clipperz.NotificationCenter.notify(this, 'recordUpdated');
383 }, 389 },
384 390
385 'removeEmptyFields': function() { 391 'removeEmptyFields': function() {
386 MochiKit.Iter.forEach(MochiKit.Base.values(this.currentVersion().fields()), MochiKit.Base.bind(function(aField) { 392 MochiKit.Iter.forEach(MochiKit.Base.values(this.currentVersion().fields()), MochiKit.Base.bind(function(aField) {
387 if (aField.isEmpty()) { 393 if (aField.isEmpty()) {
388 this.removeField(aField); 394 this.removeField(aField);
389 // this.currentVersion().removeField(aField); 395 // this.currentVersion().removeField(aField);
390 } 396 }
391 }, this)); 397 }, this));
392 }, 398 },