Diffstat (limited to 'frontend/gamma/js/Clipperz/Base.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Base.js | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/frontend/gamma/js/Clipperz/Base.js b/frontend/gamma/js/Clipperz/Base.js index 9d399d9..84b2172 100644 --- a/frontend/gamma/js/Clipperz/Base.js +++ b/frontend/gamma/js/Clipperz/Base.js | |||
@@ -1,70 +1,68 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.Base) == 'undefined') { Clipperz.Base = {}; } | 25 | if (typeof(Clipperz.Base) == 'undefined') { Clipperz.Base = {}; } |
28 | 26 | ||
29 | Clipperz.Base.VERSION = "0.2"; | 27 | Clipperz.Base.VERSION = "0.2"; |
30 | Clipperz.Base.NAME = "Clipperz.Base"; | 28 | Clipperz.Base.NAME = "Clipperz.Base"; |
31 | 29 | ||
32 | MochiKit.Base.update(Clipperz.Base, { | 30 | MochiKit.Base.update(Clipperz.Base, { |
33 | 31 | ||
34 | //------------------------------------------------------------------------- | 32 | //------------------------------------------------------------------------- |
35 | 33 | ||
36 | '__repr__': function () { | 34 | '__repr__': function () { |
37 | return "[" + this.NAME + " " + this.VERSION + "]"; | 35 | return "[" + this.NAME + " " + this.VERSION + "]"; |
38 | }, | 36 | }, |
39 | 37 | ||
40 | //------------------------------------------------------------------------- | 38 | //------------------------------------------------------------------------- |
41 | 39 | ||
42 | 'toString': function () { | 40 | 'toString': function () { |
43 | return this.__repr__(); | 41 | return this.__repr__(); |
44 | }, | 42 | }, |
45 | 43 | ||
46 | //------------------------------------------------------------------------- | 44 | //------------------------------------------------------------------------- |
47 | 45 | ||
48 | 'itemgetter': function (aKeyPath) { | 46 | 'itemgetter': function (aKeyPath) { |
49 | // return MochiKit.Base.compose.apply(null, [MochiKit.Base.itemgetter('key3')]); | 47 | // return MochiKit.Base.compose.apply(null, [MochiKit.Base.itemgetter('key3')]); |
50 | return MochiKit.Base.compose.apply(null, | 48 | return MochiKit.Base.compose.apply(null, |
51 | MochiKit.Base.map( | 49 | MochiKit.Base.map( |
52 | MochiKit.Base.itemgetter, | 50 | MochiKit.Base.itemgetter, |
53 | MochiKit.Iter.reversed( | 51 | MochiKit.Iter.reversed( |
54 | aKeyPath.split('.') | 52 | aKeyPath.split('.') |
55 | ) | 53 | ) |
56 | ) | 54 | ) |
57 | ); | 55 | ); |
58 | }, | 56 | }, |
59 | 57 | ||
60 | //------------------------------------------------------------------------- | 58 | //------------------------------------------------------------------------- |
61 | 59 | ||
62 | 'isUrl': function (aValue) { | 60 | 'isUrl': function (aValue) { |
63 | return (MochiKit.Base.urlRegExp.test(aValue)); | 61 | return (MochiKit.Base.urlRegExp.test(aValue)); |
64 | }, | 62 | }, |
65 | 63 | ||
66 | 'isEmail': function (aValue) { | 64 | 'isEmail': function (aValue) { |
67 | return (MochiKit.Base.emailRegExp.test(aValue)); | 65 | return (MochiKit.Base.emailRegExp.test(aValue)); |
68 | }, | 66 | }, |
69 | 67 | ||
70 | //------------------------------------------------------------------------- | 68 | //------------------------------------------------------------------------- |
@@ -396,138 +394,121 @@ MochiKit.Base.update(Clipperz.Base, { | |||
396 | 394 | ||
397 | //------------------------------------------------------------------------- | 395 | //------------------------------------------------------------------------- |
398 | 396 | ||
399 | 'map': function (fn, lstObj/*, lst... */) { | 397 | 'map': function (fn, lstObj/*, lst... */) { |
400 | var result; | 398 | var result; |
401 | 399 | ||
402 | if (MochiKit.Base.isArrayLike(lstObj)) { | 400 | if (MochiKit.Base.isArrayLike(lstObj)) { |
403 | result = MochiKit.Base.map.apply(this, arguments); | 401 | result = MochiKit.Base.map.apply(this, arguments); |
404 | } else { | 402 | } else { |
405 | varkeys; | 403 | varkeys; |
406 | var values; | 404 | var values; |
407 | var computedValues; | 405 | var computedValues; |
408 | 406 | ||
409 | keys = MochiKit.Base.keys(lstObj); | 407 | keys = MochiKit.Base.keys(lstObj); |
410 | values = MochiKit.Base.values(lstObj); | 408 | values = MochiKit.Base.values(lstObj); |
411 | computedValues = MochiKit.Base.map(fn, values); | 409 | computedValues = MochiKit.Base.map(fn, values); |
412 | 410 | ||
413 | result = Clipperz.Base.mergeItems(MochiKit.Base.zip(keys, computedValues)); | 411 | result = Clipperz.Base.mergeItems(MochiKit.Base.zip(keys, computedValues)); |
414 | } | 412 | } |
415 | 413 | ||
416 | return result; | 414 | return result; |
417 | }, | 415 | }, |
418 | 416 | ||
419 | //------------------------------------------------------------------------- | 417 | //------------------------------------------------------------------------- |
420 | 418 | ||
421 | 'sanitizeString': function(aValue) { | 419 | 'sanitizeString': function(aValue) { |
422 | var result; | 420 | var result; |
423 | 421 | ||
424 | if (Clipperz.Base.objectType(aValue) == 'string') { | 422 | if (Clipperz.Base.objectType(aValue) == 'string') { |
425 | result = aValue; | 423 | result = aValue; |
426 | result = result.replace(/</img,"<"); | 424 | result = result.replace(/</img,"<"); |
427 | result = result.replace(/>/img,">"); | 425 | result = result.replace(/>/img,">"); |
428 | } else { | 426 | } else { |
429 | result = aValue; | 427 | result = aValue; |
430 | } | 428 | } |
431 | 429 | ||
432 | return result; | 430 | return result; |
433 | }, | 431 | }, |
434 | 432 | ||
435 | //------------------------------------------------------------------------- | 433 | //------------------------------------------------------------------------- |
436 | 434 | ||
437 | 'module': function(aValue) { | 435 | 'module': function(aValue) { |
438 | // aValue = 'Clipperz.PM.Compact' | 436 | // aValue = 'Clipperz.PM.Compact' |
439 | // | 437 | // |
440 | // if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 438 | // if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
441 | // if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 439 | // if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
442 | // if (typeof(Clipperz.PM.UI.Common.Components) == 'undefined') { Clipperz.PM.UI.Common.Components = {}; } | 440 | // if (typeof(Clipperz.PM.UI.Common.Components) == 'undefined') { Clipperz.PM.UI.Common.Components = {}; } |
443 | 441 | ||
444 | //console.log(">>> module: " + aValue); | ||
445 | var currentScope; | 442 | var currentScope; |
446 | var pathElements; | 443 | var pathElements; |
447 | var i,c; | 444 | var i,c; |
448 | 445 | ||
449 | currentScope = window; | 446 | currentScope = window; |
450 | pathElements = aValue.split('.'); | 447 | pathElements = aValue.split('.'); |
451 | c = pathElements.length; | 448 | c = pathElements.length; |
452 | for (i=0; i<c; i++) { | 449 | for (i=0; i<c; i++) { |
453 | //console.log("--- current path element: " + pathElements[i]); | ||
454 | //console.log("--- current scope", currentScope); | ||
455 | if (typeof(currentScope[pathElements[i]]) == 'undefined') { | 450 | if (typeof(currentScope[pathElements[i]]) == 'undefined') { |
456 | currentScope[pathElements[i]] = {}; | 451 | currentScope[pathElements[i]] = {}; |
457 | } | 452 | } |
458 | 453 | ||
459 | currentScope = currentScope[pathElements[i]]; | 454 | currentScope = currentScope[pathElements[i]]; |
460 | } | 455 | } |
461 | }, | 456 | }, |
462 | 457 | ||
463 | //------------------------------------------------------------------------- | 458 | //------------------------------------------------------------------------- |
464 | 459 | ||
465 | 'exception': { | 460 | 'exception': { |
466 | 'AbstractMethod': new MochiKit.Base.NamedError("Clipperz.Base.exception.AbstractMethod"), | 461 | 'AbstractMethod': new MochiKit.Base.NamedError("Clipperz.Base.exception.AbstractMethod"), |
467 | 'UnknownType': new MochiKit.Base.NamedError("Clipperz.Base.exception.UnknownType"), | 462 | 'UnknownType': new MochiKit.Base.NamedError("Clipperz.Base.exception.UnknownType"), |
468 | 'VulnerabilityIssue':new MochiKit.Base.NamedError("Clipperz.Base.exception.VulnerabilityIssue"), | 463 | 'VulnerabilityIssue':new MochiKit.Base.NamedError("Clipperz.Base.exception.VulnerabilityIssue"), |
469 | 'MandatoryParameter':new MochiKit.Base.NamedError("Clipperz.Base.exception.MandatoryParameter"), | 464 | 'MandatoryParameter':new MochiKit.Base.NamedError("Clipperz.Base.exception.MandatoryParameter"), |
470 | 'ObjectNotFound': new MochiKit.Base.NamedError("Clipperz.Base.exception.ObjectNotFound"), | 465 | 'ObjectNotFound': new MochiKit.Base.NamedError("Clipperz.Base.exception.ObjectNotFound"), |
471 | 'raise': function (aName) { | 466 | 'raise': function (aName) { |
472 | throw Clipperz.Base.exception[aName]; | 467 | throw Clipperz.Base.exception[aName]; |
473 | } | 468 | } |
474 | }, | 469 | }, |
475 | 470 | ||
476 | //------------------------------------------------------------------------- | 471 | //------------------------------------------------------------------------- |
477 | 472 | ||
478 | 'extend': YAHOO.extendX, | 473 | 'extend': YAHOO.extendX, |
479 | 474 | ||
480 | //------------------------------------------------------------------------- | 475 | //------------------------------------------------------------------------- |
481 | __syntaxFix__: "syntax fix" | 476 | __syntaxFix__: "syntax fix" |
482 | 477 | ||
483 | }); | 478 | }); |
484 | 479 | ||
485 | //Original regExp courtesy of John Gruber: http://daringfireball.net/2009/11/liberal_regex_for_matching_urls | 480 | //Original regExp courtesy of John Gruber: http://daringfireball.net/2009/11/liberal_regex_for_matching_urls |
486 | //Updated to match Clipperz usage pattern. | 481 | //Updated to match Clipperz usage pattern. |
487 | //MochiKit.Base.urlRegExp = new RegExp(/\b(([\w-]+:\/\/?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/); | 482 | //MochiKit.Base.urlRegExp = new RegExp(/\b(([\w-]+:\/\/?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/)))/); |
488 | MochiKit.Base.urlRegExp = new RegExp(/^((([\w-]+:\/\/?)|(www\.))[^\s()<>]+((?:\([\w\d]+\)|([^[:punct:]\s]|\/)))?)/); | 483 | MochiKit.Base.urlRegExp = new RegExp(/^((([\w-]+:\/\/?)|(www\.))[^\s()<>]+((?:\([\w\d]+\)|([^[:punct:]\s]|\/)))?)/); |
489 | 484 | ||
490 | //RegExp found here: http://www.tipsntracks.com/117/validate-an-email-address-using-regular-expressions.html | 485 | //RegExp found here: http://www.tipsntracks.com/117/validate-an-email-address-using-regular-expressions.html |
491 | MochiKit.Base.emailRegExp = new RegExp(/^([a-zA-Z0-9_\-\.]+)@(([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}))|(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|25[0-5]|2[0-4]\d))$/); | 486 | MochiKit.Base.emailRegExp = new RegExp(/^([a-zA-Z0-9_\-\.]+)@(([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}))|(([01]?\d\d?|2[0-4]\d|25[0-5])\.){3}([01]?\d\d?|25[0-5]|2[0-4]\d))$/); |
492 | 487 | ||
493 | 488 | ||
494 | MochiKit.Base.registerComparator('Object dummy comparator', | 489 | MochiKit.Base.registerComparator('Object dummy comparator', |
495 | function(a, b) { | 490 | function(a, b) { |
496 | return ((a.constructor == Object) && (b.constructor == Object)); | 491 | return ((a.constructor == Object) && (b.constructor == Object)); |
497 | }, | 492 | }, |
498 | function(a, b) { | 493 | function(a, b) { |
499 | var result; | 494 | var result; |
500 | var aKeys; | 495 | var aKeys; |
501 | var bKeys; | 496 | var bKeys; |
502 | 497 | ||
503 | //MochiKit.Logging.logDebug(">>> comparator"); | ||
504 | //MochiKit.Logging.logDebug("- a: " + Clipperz.Base.serializeJSON(a)); | ||
505 | //MochiKit.Logging.logDebug("- b: " + Clipperz.Base.serializeJSON(a)); | ||
506 | aKeys = MochiKit.Base.keys(a).sort(); | 498 | aKeys = MochiKit.Base.keys(a).sort(); |
507 | bKeys = MochiKit.Base.keys(b).sort(); | 499 | bKeys = MochiKit.Base.keys(b).sort(); |
508 | |||
509 | result = MochiKit.Base.compare(aKeys, bKeys); | 500 | result = MochiKit.Base.compare(aKeys, bKeys); |
510 | //if (result != 0) { | 501 | |
511 | //MochiKit.Logging.logDebug("- comparator 'keys':"); | ||
512 | //MochiKit.Logging.logDebug("- comparator aKeys: " + Clipperz.Base.serializeJSON(aKeys)); | ||
513 | //MochiKit.Logging.logDebug("- comparator bKeys: " + Clipperz.Base.serializeJSON(bKeys)); | ||
514 | //} | ||
515 | if (result == 0) { | 502 | if (result == 0) { |
516 | vari, c; | 503 | vari, c; |
517 | 504 | ||
518 | c = aKeys.length; | 505 | c = aKeys.length; |
519 | for (i=0; (i<c) && (result == 0); i++) { | 506 | for (i=0; (i<c) && (result == 0); i++) { |
520 | result = MochiKit.Base.compare(a[aKeys[i]], b[bKeys[i]]); | 507 | result = MochiKit.Base.compare(a[aKeys[i]], b[bKeys[i]]); |
521 | //if (result != 0) { | ||
522 | //MochiKit.Logging.logDebug("- comparator 'values':"); | ||
523 | //MochiKit.Logging.logDebug("- comparator a[aKeys[i]]: " + Clipperz.Base.serializeJSON(a[aKeys[i]])); | ||
524 | //MochiKit.Logging.logDebug("- comparator b[bKeys[i]]: " + Clipperz.Base.serializeJSON(b[bKeys[i]])); | ||
525 | //} | ||
526 | } | 508 | } |
527 | } | 509 | } |
528 | 510 | ||
529 | //MochiKit.Logging.logDebug("<<< comparator - result: " + result); | ||
530 | return result; | 511 | return result; |
531 | }, | 512 | }, |
532 | true | 513 | true |
533 | ); | 514 | ); |