Diffstat (limited to 'frontend/gamma/js/Clipperz/Async.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/Async.js | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/frontend/gamma/js/Clipperz/Async.js b/frontend/gamma/js/Clipperz/Async.js index f7a9517..d525453 100644 --- a/frontend/gamma/js/Clipperz/Async.js +++ b/frontend/gamma/js/Clipperz/Async.js | |||
@@ -1,38 +1,36 @@ | |||
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 | //Clipperz.Async = MochiKit.Async; | 24 | //Clipperz.Async = MochiKit.Async; |
27 | 25 | ||
28 | 26 | ||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 27 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } | 28 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } |
31 | 29 | ||
32 | Clipperz.Async.VERSION = "0.1"; | 30 | Clipperz.Async.VERSION = "0.1"; |
33 | Clipperz.Async.NAME = "Clipperz.Async"; | 31 | Clipperz.Async.NAME = "Clipperz.Async"; |
34 | 32 | ||
35 | Clipperz.Async.Deferred = function(aName, args) { | 33 | Clipperz.Async.Deferred = function(aName, args) { |
36 | args = args || {}; | 34 | args = args || {}; |
37 | 35 | ||
38 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); | 36 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); |
@@ -49,94 +47,87 @@ Clipperz.Async.Deferred = function(aName, args) { | |||
49 | //============================================================================= | 47 | //============================================================================= |
50 | 48 | ||
51 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { | 49 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { |
52 | 50 | ||
53 | 'name': function () { | 51 | 'name': function () { |
54 | return this._name; | 52 | return this._name; |
55 | }, | 53 | }, |
56 | 54 | ||
57 | 'args': function () { | 55 | 'args': function () { |
58 | return this._args; | 56 | return this._args; |
59 | }, | 57 | }, |
60 | 58 | ||
61 | //----------------------------------------------------------------------------- | 59 | //----------------------------------------------------------------------------- |
62 | 60 | ||
63 | 'callback': function (aValue) { | 61 | 'callback': function (aValue) { |
64 | if (this._shouldTrace) { | 62 | if (this._shouldTrace) { |
65 | //Clipperz.log("CALLBACK " + this._name, aValue); | 63 | Clipperz.log("CALLBACK " + this._name, aValue); |
66 | console.log("CALLBACK " + this._name, aValue); | ||
67 | } | 64 | } |
68 | 65 | ||
69 | if (this.chained == false) { | 66 | if (this.chained == false) { |
70 | var message; | 67 | var message; |
71 | 68 | ||
72 | message = "ERROR [" + this._name + "]"; | 69 | message = "ERROR [" + this._name + "]"; |
73 | this.addErrback(function(aResult) { | 70 | this.addErrback(function(aResult) { |
74 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { | 71 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { |
75 | Clipperz.log(message, aResult); | 72 | Clipperz.log(message, aResult); |
76 | } | 73 | } |
77 | return aResult; | 74 | return aResult; |
78 | }); | 75 | }); |
79 | 76 | ||
80 | if (this._shouldTrace) { | 77 | if (this._shouldTrace) { |
81 | var resultMessage; | 78 | var resultMessage; |
82 | 79 | ||
83 | resultMessage = "RESULT " + this._name + " <=="; | 80 | resultMessage = "RESULT " + this._name + " <=="; |
84 | // this.addCallback(function(aResult) { | 81 | // this.addCallback(function(aResult) { |
85 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { | 82 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { |
86 | //Clipperz.log(resultMessage, aResult); | 83 | Clipperz.log(resultMessage, aResult); |
87 | console.log(resultMessage, aResult); | ||
88 | |||
89 | return aResult; | 84 | return aResult; |
90 | }); | 85 | }); |
91 | } | 86 | } |
92 | } | 87 | } |
93 | 88 | ||
94 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { | 89 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { |
95 | Clipperz.log("callback " + this._name, this); | 90 | Clipperz.log("callback " + this._name, this); |
96 | } | 91 | } |
97 | 92 | ||
98 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); | 93 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); |
99 | }, | 94 | }, |
100 | 95 | ||
101 | //----------------------------------------------------------------------------- | 96 | //----------------------------------------------------------------------------- |
102 | 97 | ||
103 | 'addCallback': function () { | 98 | 'addCallback': function () { |
104 | var message; | 99 | var message; |
105 | 100 | ||
106 | if (this._shouldTrace) { | 101 | if (this._shouldTrace) { |
107 | this._count ++; | 102 | this._count ++; |
108 | message = "[" + this._count + "] " + this._name + " "; | 103 | message = "[" + this._count + "] " + this._name + " "; |
109 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); | 104 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); |
110 | this.addCallbacks( | 105 | this.addCallbacks( |
111 | //function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, | 106 | function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, |
112 | function(aResult) {console.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, | 107 | function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} |
113 | //function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
114 | function(aResult) {console.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
115 | ); | 108 | ); |
116 | } | 109 | } |
117 | 110 | ||
118 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); | 111 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); |
119 | 112 | ||
120 | if (this._shouldTrace) { | 113 | if (this._shouldTrace) { |
121 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); | 114 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); |
122 | this.addCallbacks( | 115 | this.addCallbacks( |
123 | //function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, | 116 | function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, |
124 | function(aResult) {console.log("-OK- " + message + "<--", aResult); return aResult;}, | 117 | function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} |
125 | //function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} | ||
126 | function(aResult) {console.log("FAIL " + message + "<--", aResult); return aResult;} | ||
127 | ); | 118 | ); |
128 | } | 119 | } |
129 | }, | 120 | }, |
130 | 121 | ||
131 | //============================================================================= | 122 | //============================================================================= |
132 | 123 | ||
133 | 'addCallbackPass': function() { | 124 | 'addCallbackPass': function() { |
134 | var passFunction; | 125 | var passFunction; |
135 | 126 | ||
136 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 127 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
137 | 128 | ||
138 | this.addCallback(function() { | 129 | this.addCallback(function() { |
139 | var result; | 130 | var result; |
140 | 131 | ||
141 | result = arguments[arguments.length -1]; | 132 | result = arguments[arguments.length -1]; |
142 | passFunction(); | 133 | passFunction(); |
@@ -199,58 +190,57 @@ Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { | |||
199 | 190 | ||
200 | 'addMethod': function () { | 191 | 'addMethod': function () { |
201 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); | 192 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); |
202 | }, | 193 | }, |
203 | 194 | ||
204 | //----------------------------------------------------------------------------- | 195 | //----------------------------------------------------------------------------- |
205 | 196 | ||
206 | 'addMethodcaller': function () { | 197 | 'addMethodcaller': function () { |
207 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); | 198 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); |
208 | }, | 199 | }, |
209 | 200 | ||
210 | //============================================================================= | 201 | //============================================================================= |
211 | 202 | ||
212 | 'addLog': function (aLog) { | 203 | 'addLog': function (aLog) { |
213 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { | 204 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { |
214 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); | 205 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); |
215 | // this.addBothPass(function(res) {console.log(aLog + " ", res);}); | ||
216 | } | 206 | } |
217 | }, | 207 | }, |
218 | 208 | ||
219 | //============================================================================= | 209 | //============================================================================= |
220 | 210 | ||
221 | 'acquireLock': function (aLock) { | 211 | 'acquireLock': function (aLock) { |
222 | // this.addCallback(function (aResult) { | 212 | // this.addCallback(function (aResult) { |
223 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ | 213 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ |
224 | // MochiKit.Base.method(aLock, 'acquire'), | 214 | // MochiKit.Base.method(aLock, 'acquire'), |
225 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 215 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
226 | // ], {trace:false}); | 216 | // ], {trace:false}); |
227 | // }); | 217 | // }); |
228 | 218 | ||
229 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); | 219 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); |
230 | }, | 220 | }, |
231 | 221 | ||
232 | 'releaseLock': function (aLock) { | 222 | 'releaseLock': function (aLock) { |
233 | // this.addCallback(function (aResult) { | 223 | // this.addCallback(function (aResult) { |
234 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ | 224 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ |
235 | // MochiKit.Base.method(aLock, 'release'), | 225 | // MochiKit.Base.method(aLock, 'release'), |
236 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 226 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
237 | // ], {trace:false}); | 227 | // ], {trace:false}); |
238 | // }); | 228 | // }); |
239 | // this.addErrback(function (aResult) { | 229 | // this.addErrback(function (aResult) { |
240 | ///console.log("releaseLock.addErrback:", aResult); | 230 | ///Clipperz.log("releaseLock.addErrback:", aResult); |
241 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ | 231 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ |
242 | // MochiKit.Base.method(aLock, 'release'), | 232 | // MochiKit.Base.method(aLock, 'release'), |
243 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) | 233 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) |
244 | // ], {trace:false}); | 234 | // ], {trace:false}); |
245 | // }); | 235 | // }); |
246 | 236 | ||
247 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); | 237 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); |
248 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); | 238 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); |
249 | this.addErrback(function (anError) { | 239 | this.addErrback(function (anError) { |
250 | aLock.release(); | 240 | aLock.release(); |
251 | 241 | ||
252 | return anError; | 242 | return anError; |
253 | }); | 243 | }); |
254 | }, | 244 | }, |
255 | 245 | ||
256 | //============================================================================= | 246 | //============================================================================= |
@@ -364,33 +354,33 @@ MochiKit.Base.update(Clipperz.Async.DeferredSynchronizer.prototype, { | |||
364 | 354 | ||
365 | //----------------------------------------------------------------------------- | 355 | //----------------------------------------------------------------------------- |
366 | 356 | ||
367 | 'run': function(args, aValue) { | 357 | 'run': function(args, aValue) { |
368 | var deferredResults; | 358 | var deferredResults; |
369 | var i, c; | 359 | var i, c; |
370 | 360 | ||
371 | deferredResults = []; | 361 | deferredResults = []; |
372 | args = args || {}; | 362 | args = args || {}; |
373 | 363 | ||
374 | c = this.methods().length; | 364 | c = this.methods().length; |
375 | for (i=0; i<c; i++) { | 365 | for (i=0; i<c; i++) { |
376 | var deferredResult; | 366 | var deferredResult; |
377 | varmethodCalls; | 367 | varmethodCalls; |
378 | var ii, cc; | 368 | var ii, cc; |
379 | 369 | ||
380 | //console.log("TYPEOF", typeof(this.methods()[i])); | 370 | //Clipperz.log("TYPEOF", typeof(this.methods()[i])); |
381 | if (typeof(this.methods()[i]) == 'function') { | 371 | if (typeof(this.methods()[i]) == 'function') { |
382 | methodCalls = [ this.methods()[i] ]; | 372 | methodCalls = [ this.methods()[i] ]; |
383 | } else { | 373 | } else { |
384 | methodCalls = this.methods()[i]; | 374 | methodCalls = this.methods()[i]; |
385 | } | 375 | } |
386 | 376 | ||
387 | cc = methodCalls.length; | 377 | cc = methodCalls.length; |
388 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); | 378 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); |
389 | for (ii=0; ii<cc; ii++) { | 379 | for (ii=0; ii<cc; ii++) { |
390 | deferredResult.addCallback(methodCalls[ii]); | 380 | deferredResult.addCallback(methodCalls[ii]); |
391 | } | 381 | } |
392 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); | 382 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); |
393 | 383 | ||
394 | deferredResults.push(deferredResult); | 384 | deferredResults.push(deferredResult); |
395 | } | 385 | } |
396 | 386 | ||
@@ -624,33 +614,33 @@ MochiKit.Base.update(Clipperz.Async, { | |||
624 | } | 614 | } |
625 | 615 | ||
626 | return deferredResult; | 616 | return deferredResult; |
627 | }, | 617 | }, |
628 | 618 | ||
629 | //------------------------------------------------------------------------- | 619 | //------------------------------------------------------------------------- |
630 | 620 | ||
631 | 'deferredSort': function (aDeferredComparator, someObjects) { | 621 | 'deferredSort': function (aDeferredComparator, someObjects) { |
632 | var deferredResult; | 622 | var deferredResult; |
633 | var i, c; | 623 | var i, c; |
634 | 624 | ||
635 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); | 625 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); |
636 | c = someObjects.length; | 626 | c = someObjects.length; |
637 | for (i=0; i<c; i++) { | 627 | for (i=0; i<c; i++) { |
638 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); | 628 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); |
639 | if ((i % 50) == 0) { | 629 | if ((i % 50) == 0) { |
640 | //console.log("######### sort wait ##########"); | 630 | //Clipperz.log("######### sort wait ##########"); |
641 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); | 631 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); |
642 | } | 632 | } |
643 | } | 633 | } |
644 | deferredResult.callback([]); | 634 | deferredResult.callback([]); |
645 | 635 | ||
646 | return deferredResult; | 636 | return deferredResult; |
647 | }, | 637 | }, |
648 | 638 | ||
649 | //========================================================================= | 639 | //========================================================================= |
650 | 640 | ||
651 | 'deferredFilter': function (aFunction, someObjects) { | 641 | 'deferredFilter': function (aFunction, someObjects) { |
652 | vardeferredResult; | 642 | vardeferredResult; |
653 | vari, c; | 643 | vari, c; |
654 | 644 | ||
655 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); | 645 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); |
656 | c = someObjects.length; | 646 | c = someObjects.length; |
@@ -675,33 +665,33 @@ MochiKit.Base.update(Clipperz.Async, { | |||
675 | 665 | ||
676 | return deferredResult; | 666 | return deferredResult; |
677 | }, | 667 | }, |
678 | 668 | ||
679 | 'forEach': function (aFunction) { | 669 | 'forEach': function (aFunction) { |
680 | return MochiKit.Base.partial(function (aFunction, anIterable) { | 670 | return MochiKit.Base.partial(function (aFunction, anIterable) { |
681 | MochiKit.Iter.forEach(anIterable, aFunction); | 671 | MochiKit.Iter.forEach(anIterable, aFunction); |
682 | }, aFunction); | 672 | }, aFunction); |
683 | }, | 673 | }, |
684 | 674 | ||
685 | //========================================================================= | 675 | //========================================================================= |
686 | 676 | ||
687 | 'or': function (someValues) { | 677 | 'or': function (someValues) { |
688 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ | 678 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ |
689 | MochiKit.Base.values, | 679 | MochiKit.Base.values, |
690 | MochiKit.Base.flattenArguments, | 680 | MochiKit.Base.flattenArguments, |
691 | //function (aValue) { console.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, | 681 | //function (aValue) { Clipperz.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, |
692 | function(someInnerValues) { | 682 | function(someInnerValues) { |
693 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); | 683 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); |
694 | } | 684 | } |
695 | ], {trace:false}, someValues); | 685 | ], {trace:false}, someValues); |
696 | }, | 686 | }, |
697 | 687 | ||
698 | //========================================================================= | 688 | //========================================================================= |
699 | 689 | ||
700 | 'clearResult': function () {}, | 690 | 'clearResult': function () {}, |
701 | 691 | ||
702 | //========================================================================= | 692 | //========================================================================= |
703 | __syntaxFix__: "syntax fix" | 693 | __syntaxFix__: "syntax fix" |
704 | }); | 694 | }); |
705 | 695 | ||
706 | 696 | ||
707 | //############################################################################# | 697 | //############################################################################# |