author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-23 17:36:57 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2011-10-23 17:36:57 (UTC) |
commit | 67455b069c4c9ec493f9cef76017e172a430a7d4 (patch) (unidiff) | |
tree | 0b287debfeeb0819b3df9dd02860cd84103e25b3 /frontend/gamma | |
parent | b312e037ebba7c94abea9661bcf62c52b7d73fbf (diff) | |
download | clipperz-67455b069c4c9ec493f9cef76017e172a430a7d4.zip clipperz-67455b069c4c9ec493f9cef76017e172a430a7d4.tar.gz clipperz-67455b069c4c9ec493f9cef76017e172a430a7d4.tar.bz2 |
Integration of PHP backend with /beta and /gamma front ends
Fixed PHP backend and /beta code to handle request and data format compatible with /gamma.
At the moment adding/deleting/editing records seem to work fine.
-rw-r--r-- | frontend/gamma/html/index_template.html | 5 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/Async.js | 19 | ||||
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Proxy.js | 2 |
3 files changed, 19 insertions, 7 deletions
diff --git a/frontend/gamma/html/index_template.html b/frontend/gamma/html/index_template.html index 8cf838c..bedb243 100644 --- a/frontend/gamma/html/index_template.html +++ b/frontend/gamma/html/index_template.html | |||
@@ -1,62 +1,67 @@ | |||
1 | <html> | 1 | <html> |
2 | <head> | 2 | <head> |
3 | <title>@page.title@</title> | 3 | <title>@page.title@</title> |
4 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> | 4 | <meta http-equiv="content-type" content="text/html; charset=utf-8" /> |
5 | <!-- | 5 | <!-- |
6 | @copyright@ | 6 | @copyright@ |
7 | --> | 7 | --> |
8 | 8 | ||
9 | @css@ | 9 | @css@ |
10 | 10 | ||
11 | <link rel="shortcut icon" href="./clipperz.ico" /> | 11 | <link rel="shortcut icon" href="./clipperz.ico" /> |
12 | 12 | ||
13 | <meta name="description" content="Login to your web accounts with just one click. Never type a password again! Use multiple complex passwords and forget them. A password manager that enhances your online security." /> | 13 | <meta name="description" content="Login to your web accounts with just one click. Never type a password again! Use multiple complex passwords and forget them. A password manager that enhances your online security." /> |
14 | <meta name="keywords" content="password manager,gestor de contraseñas,gerenciador de senhas,Kennwortmanager,passwords,security,privacy,cryptography" /> | 14 | <meta name="keywords" content="password manager,gestor de contraseñas,gerenciador de senhas,Kennwortmanager,passwords,security,privacy,cryptography" /> |
15 | <script> | 15 | <script> |
16 | Clipperz_IEisBroken = false; | 16 | Clipperz_IEisBroken = false; |
17 | Clipperz_normalizedNewLine = '\n'; | 17 | Clipperz_normalizedNewLine = '\n'; |
18 | Clipperz_dumpUrl = "/dump/"; | 18 | Clipperz_dumpUrl = "/dump/"; |
19 | </script> | 19 | </script> |
20 | 20 | ||
21 | <!--[if IE]><script> | 21 | <!--[if IE]><script> |
22 | Clipperz_IEisBroken = true; | 22 | Clipperz_IEisBroken = true; |
23 | Clipperz_normalizedNewLine = '\x0d\x0a'; | 23 | Clipperz_normalizedNewLine = '\x0d\x0a'; |
24 | </script><![endif]--> | 24 | </script><![endif]--> |
25 | 25 | ||
26 | @js_DEBUG@ | 26 | @js_DEBUG@ |
27 | 27 | ||
28 | </head> | 28 | </head> |
29 | <body> | 29 | <body> |
30 | <div id="mainDiv"> | 30 | <div id="mainDiv"> |
31 | <div id="loading"> | 31 | <div id="loading"> |
32 | <a href="http://www.clipperz.com" target="_blank"><div id="logo"></div></a> | 32 | <a href="http://www.clipperz.com" target="_blank"><div id="logo"></div></a> |
33 | <h5 class="clipperzPayoff">keep it to yourself!</h5> | 33 | <h5 class="clipperzPayoff">keep it to yourself!</h5> |
34 | <h2>loading ...</h2> | 34 | <h2>loading ...</h2> |
35 | </div> | 35 | </div> |
36 | 36 | ||
37 | @js_INSTALL@ | 37 | @js_INSTALL@ |
38 | 38 | ||
39 | </div> | 39 | </div> |
40 | <div id="applicationVersionType" class="@application.version.type@"></div> | 40 | <div id="applicationVersionType" class="@application.version.type@"></div> |
41 | 41 | ||
42 | <script> | ||
43 | Clipperz.PM.Proxy.defaultProxy = new Clipperz.PM.Proxy.JSON({'url':'@request.path@', 'shouldPayTolls':@should.pay.toll@}); | ||
44 | /*offline_data_placeholder*/ | ||
45 | </script> | ||
46 | |||
42 | <!-- --> | 47 | <!-- --> |
43 | <div id="javaScriptAlert"> | 48 | <div id="javaScriptAlert"> |
44 | <div class="mask"></div> | 49 | <div class="mask"></div> |
45 | <div class="message"> | 50 | <div class="message"> |
46 | <div class="header"></div> | 51 | <div class="header"></div> |
47 | <div class="body"> | 52 | <div class="body"> |
48 | <div class="alertLogo"></div> | 53 | <div class="alertLogo"></div> |
49 | <div class="alert"> | 54 | <div class="alert"> |
50 | <h1>Attention!</h1> | 55 | <h1>Attention!</h1> |
51 | <p>If you can read this message, the chances are that your browser does not properly support JavaScript? or you have disabled this functionality yourself.</p> | 56 | <p>If you can read this message, the chances are that your browser does not properly support JavaScript? or you have disabled this functionality yourself.</p> |
52 | <h3>Javascript is required to access Clipperz.</h3> | 57 | <h3>Javascript is required to access Clipperz.</h3> |
53 | <h5>Please enable scripting or upgrade your browser.</h5> | 58 | <h5>Please enable scripting or upgrade your browser.</h5> |
54 | </div> | 59 | </div> |
55 | </div> | 60 | </div> |
56 | <div class="footer"></div> | 61 | <div class="footer"></div> |
57 | </div> | 62 | </div> |
58 | </div> | 63 | </div> |
59 | <!-- --> | 64 | <!-- --> |
60 | 65 | ||
61 | </body> | 66 | </body> |
62 | </html> | 67 | </html> |
diff --git a/frontend/gamma/js/Clipperz/Async.js b/frontend/gamma/js/Clipperz/Async.js index 7c9d783..97d8ecf 100644 --- a/frontend/gamma/js/Clipperz/Async.js +++ b/frontend/gamma/js/Clipperz/Async.js | |||
@@ -1,704 +1,711 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | //Clipperz.Async = MochiKit.Async; | 26 | //Clipperz.Async = MochiKit.Async; |
27 | 27 | ||
28 | 28 | ||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
30 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } | 30 | if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } |
31 | 31 | ||
32 | Clipperz.Async.VERSION = "0.1"; | 32 | Clipperz.Async.VERSION = "0.1"; |
33 | Clipperz.Async.NAME = "Clipperz.Async"; | 33 | Clipperz.Async.NAME = "Clipperz.Async"; |
34 | 34 | ||
35 | Clipperz.Async.Deferred = function(aName, args) { | 35 | Clipperz.Async.Deferred = function(aName, args) { |
36 | args = args || {}; | 36 | args = args || {}; |
37 | 37 | ||
38 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); | 38 | Clipperz.Async.Deferred.superclass.constructor.call(this, args.canceller); |
39 | 39 | ||
40 | this._args = args; | 40 | this._args = args; |
41 | this._name = aName || "Anonymous deferred"; | 41 | this._name = aName || "Anonymous deferred"; |
42 | this._count = 0; | 42 | this._count = 0; |
43 | this._shouldTrace = ((CLIPPERZ_DEFERRED_TRACING_ENABLED === true) || (args.trace === true)); | 43 | this._shouldTrace = ((CLIPPERZ_DEFERRED_TRACING_ENABLED === true) || (args.trace === true)); |
44 | this._vars = null; | 44 | this._vars = null; |
45 | 45 | ||
46 | return this; | 46 | return this; |
47 | } | 47 | } |
48 | 48 | ||
49 | //============================================================================= | 49 | //============================================================================= |
50 | 50 | ||
51 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { | 51 | Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { |
52 | 52 | ||
53 | 'name': function () { | 53 | 'name': function () { |
54 | return this._name; | 54 | return this._name; |
55 | }, | 55 | }, |
56 | 56 | ||
57 | 'args': function () { | 57 | 'args': function () { |
58 | return this._args; | 58 | return this._args; |
59 | }, | 59 | }, |
60 | 60 | ||
61 | //----------------------------------------------------------------------------- | 61 | //----------------------------------------------------------------------------- |
62 | 62 | ||
63 | 'callback': function (aValue) { | 63 | 'callback': function (aValue) { |
64 | if (this._shouldTrace) { | 64 | if (this._shouldTrace) { |
65 | Clipperz.log("CALLBACK " + this._name, aValue); | 65 | //Clipperz.log("CALLBACK " + this._name, aValue); |
66 | console.log("CALLBACK " + this._name, aValue); | ||
66 | } | 67 | } |
67 | 68 | ||
68 | if (this.chained == false) { | 69 | if (this.chained == false) { |
69 | var message; | 70 | var message; |
70 | 71 | ||
71 | message = "ERROR [" + this._name + "]"; | 72 | message = "ERROR [" + this._name + "]"; |
72 | this.addErrback(function(aResult) { | 73 | this.addErrback(function(aResult) { |
73 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { | 74 | if (! (aResult instanceof MochiKit.Async.CancelledError)) { |
74 | Clipperz.log(message, aResult); | 75 | Clipperz.log(message, aResult); |
75 | } | 76 | } |
76 | return aResult; | 77 | return aResult; |
77 | }); | 78 | }); |
78 | 79 | ||
79 | if (this._shouldTrace) { | 80 | if (this._shouldTrace) { |
80 | var resultMessage; | 81 | var resultMessage; |
81 | 82 | ||
82 | resultMessage = "RESULT " + this._name + " <=="; | 83 | resultMessage = "RESULT " + this._name + " <=="; |
83 | // this.addCallback(function(aResult) { | 84 | // this.addCallback(function(aResult) { |
84 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { | 85 | Clipperz.Async.Deferred.superclass.addCallback.call(this, function(aResult) { |
85 | Clipperz.log(resultMessage, aResult); | 86 | //Clipperz.log(resultMessage, aResult); |
87 | console.log(resultMessage, aResult); | ||
86 | 88 | ||
87 | return aResult; | 89 | return aResult; |
88 | }); | 90 | }); |
89 | } | 91 | } |
90 | } | 92 | } |
91 | 93 | ||
92 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { | 94 | if (CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED === true) { |
93 | Clipperz.log("callback " + this._name, this); | 95 | Clipperz.log("callback " + this._name, this); |
94 | } | 96 | } |
95 | 97 | ||
96 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); | 98 | return Clipperz.Async.Deferred.superclass.callback.apply(this, arguments); |
97 | }, | 99 | }, |
98 | 100 | ||
99 | //----------------------------------------------------------------------------- | 101 | //----------------------------------------------------------------------------- |
100 | 102 | ||
101 | 'addCallback': function () { | 103 | 'addCallback': function () { |
102 | var message; | 104 | var message; |
103 | 105 | ||
104 | if (this._shouldTrace) { | 106 | if (this._shouldTrace) { |
105 | this._count ++; | 107 | this._count ++; |
106 | message = "[" + this._count + "] " + this._name + " "; | 108 | message = "[" + this._count + "] " + this._name + " "; |
107 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); | 109 | // this.addBoth(function(aResult) {Clipperz.log(message + "-->", aResult); return aResult;}); |
108 | this.addCallbacks( | 110 | this.addCallbacks( |
109 | function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, | 111 | //function(aResult) {Clipperz.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, |
110 | function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | 112 | function(aResult) {console.log("-OK- " + message + "-->"/*, aResult*/); return aResult;}, |
113 | //function(aResult) {Clipperz.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
114 | function(aResult) {console.log("FAIL " + message + "-->"/*, aResult*/); return aResult;} | ||
111 | ); | 115 | ); |
112 | } | 116 | } |
113 | 117 | ||
114 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); | 118 | Clipperz.Async.Deferred.superclass.addCallback.apply(this, arguments); |
115 | 119 | ||
116 | if (this._shouldTrace) { | 120 | if (this._shouldTrace) { |
117 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); | 121 | // this.addBoth(function(aResult) {Clipperz.log(message + "<--", aResult); return aResult;}); |
118 | this.addCallbacks( | 122 | this.addCallbacks( |
119 | function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, | 123 | //function(aResult) {Clipperz.log("-OK- " + message + "<--", aResult); return aResult;}, |
120 | function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} | 124 | function(aResult) {console.log("-OK- " + message + "<--", aResult); return aResult;}, |
125 | //function(aResult) {Clipperz.log("FAIL " + message + "<--", aResult); return aResult;} | ||
126 | function(aResult) {console.log("FAIL " + message + "<--", aResult); return aResult;} | ||
121 | ); | 127 | ); |
122 | } | 128 | } |
123 | }, | 129 | }, |
124 | 130 | ||
125 | //============================================================================= | 131 | //============================================================================= |
126 | 132 | ||
127 | 'addCallbackPass': function() { | 133 | 'addCallbackPass': function() { |
128 | var passFunction; | 134 | var passFunction; |
129 | 135 | ||
130 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 136 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
131 | 137 | ||
132 | this.addCallback(function() { | 138 | this.addCallback(function() { |
133 | var result; | 139 | var result; |
134 | 140 | ||
135 | result = arguments[arguments.length -1]; | 141 | result = arguments[arguments.length -1]; |
136 | passFunction(); | 142 | passFunction(); |
137 | 143 | ||
138 | return result; | 144 | return result; |
139 | }); | 145 | }); |
140 | }, | 146 | }, |
141 | 147 | ||
142 | //----------------------------------------------------------------------------- | 148 | //----------------------------------------------------------------------------- |
143 | 149 | ||
144 | 'addErrbackPass': function() { | 150 | 'addErrbackPass': function() { |
145 | var passFunction; | 151 | var passFunction; |
146 | 152 | ||
147 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 153 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
148 | 154 | ||
149 | this.addErrback(function() { | 155 | this.addErrback(function() { |
150 | var result; | 156 | var result; |
151 | 157 | ||
152 | result = arguments[arguments.length -1]; | 158 | result = arguments[arguments.length -1]; |
153 | passFunction(); | 159 | passFunction(); |
154 | 160 | ||
155 | return result; | 161 | return result; |
156 | }); | 162 | }); |
157 | }, | 163 | }, |
158 | 164 | ||
159 | //----------------------------------------------------------------------------- | 165 | //----------------------------------------------------------------------------- |
160 | 166 | ||
161 | 'addBothPass': function() { | 167 | 'addBothPass': function() { |
162 | var passFunction; | 168 | var passFunction; |
163 | 169 | ||
164 | passFunction = MochiKit.Base.partial.apply(null, arguments); | 170 | passFunction = MochiKit.Base.partial.apply(null, arguments); |
165 | 171 | ||
166 | this.addBoth(function() { | 172 | this.addBoth(function() { |
167 | var result; | 173 | var result; |
168 | 174 | ||
169 | result = arguments[arguments.length -1]; | 175 | result = arguments[arguments.length -1]; |
170 | passFunction(); | 176 | passFunction(); |
171 | 177 | ||
172 | return result; | 178 | return result; |
173 | }); | 179 | }); |
174 | }, | 180 | }, |
175 | 181 | ||
176 | //----------------------------------------------------------------------------- | 182 | //----------------------------------------------------------------------------- |
177 | 183 | ||
178 | 'addIf': function (aThenBlock, anElseBlock) { | 184 | 'addIf': function (aThenBlock, anElseBlock) { |
179 | this.addCallback(MochiKit.Base.bind(function (aValue) { | 185 | this.addCallback(MochiKit.Base.bind(function (aValue) { |
180 | var deferredResult; | 186 | var deferredResult; |
181 | 187 | ||
182 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { | 188 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { |
183 | deferredResult = Clipperz.Async.callbacks(this._name + " <then>", aThenBlock, null, aValue); | 189 | deferredResult = Clipperz.Async.callbacks(this._name + " <then>", aThenBlock, null, aValue); |
184 | } else { | 190 | } else { |
185 | deferredResult = Clipperz.Async.callbacks(this._name + " <else>", anElseBlock, null, aValue); | 191 | deferredResult = Clipperz.Async.callbacks(this._name + " <else>", anElseBlock, null, aValue); |
186 | } | 192 | } |
187 | 193 | ||
188 | return deferredResult; | 194 | return deferredResult; |
189 | })) | 195 | })) |
190 | }, | 196 | }, |
191 | 197 | ||
192 | //----------------------------------------------------------------------------- | 198 | //----------------------------------------------------------------------------- |
193 | 199 | ||
194 | 'addMethod': function () { | 200 | 'addMethod': function () { |
195 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); | 201 | this.addCallback(MochiKit.Base.method.apply(this, arguments)); |
196 | }, | 202 | }, |
197 | 203 | ||
198 | //----------------------------------------------------------------------------- | 204 | //----------------------------------------------------------------------------- |
199 | 205 | ||
200 | 'addMethodcaller': function () { | 206 | 'addMethodcaller': function () { |
201 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); | 207 | this.addCallback(MochiKit.Base.methodcaller.apply(this, arguments)); |
202 | }, | 208 | }, |
203 | 209 | ||
204 | //============================================================================= | 210 | //============================================================================= |
205 | 211 | ||
206 | 'addLog': function (aLog) { | 212 | 'addLog': function (aLog) { |
207 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { | 213 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { |
208 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); | 214 | this.addBothPass(function(res) {Clipperz.log(aLog + " ", res);}); |
209 | // this.addBothPass(function(res) {console.log(aLog + " ", res);}); | 215 | // this.addBothPass(function(res) {console.log(aLog + " ", res);}); |
210 | } | 216 | } |
211 | }, | 217 | }, |
212 | 218 | ||
213 | //============================================================================= | 219 | //============================================================================= |
214 | 220 | ||
215 | 'acquireLock': function (aLock) { | 221 | 'acquireLock': function (aLock) { |
216 | // this.addCallback(function (aResult) { | 222 | // this.addCallback(function (aResult) { |
217 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ | 223 | // return Clipperz.Async.callbacks("Clipperz.Async.acquireLock", [ |
218 | // MochiKit.Base.method(aLock, 'acquire'), | 224 | // MochiKit.Base.method(aLock, 'acquire'), |
219 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 225 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
220 | // ], {trace:false}); | 226 | // ], {trace:false}); |
221 | // }); | 227 | // }); |
222 | 228 | ||
223 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); | 229 | this.addCallback(MochiKit.Base.method(aLock, 'acquire')); |
224 | }, | 230 | }, |
225 | 231 | ||
226 | 'releaseLock': function (aLock) { | 232 | 'releaseLock': function (aLock) { |
227 | // this.addCallback(function (aResult) { | 233 | // this.addCallback(function (aResult) { |
228 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ | 234 | // return Clipperz.Async.callbacks("Clipperz.Async.release <ok>", [ |
229 | // MochiKit.Base.method(aLock, 'release'), | 235 | // MochiKit.Base.method(aLock, 'release'), |
230 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) | 236 | // MochiKit.Base.partial(MochiKit.Async.succeed, aResult) |
231 | // ], {trace:false}); | 237 | // ], {trace:false}); |
232 | // }); | 238 | // }); |
233 | // this.addErrback(function (aResult) { | 239 | // this.addErrback(function (aResult) { |
234 | ///console.log("releaseLock.addErrback:", aResult); | 240 | ///console.log("releaseLock.addErrback:", aResult); |
235 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ | 241 | // return Clipperz.Async.callbacks("Clipperz.Async.release <fail>", [ |
236 | // MochiKit.Base.method(aLock, 'release'), | 242 | // MochiKit.Base.method(aLock, 'release'), |
237 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) | 243 | // MochiKit.Base.partial(MochiKit.Async.fail, aResult) |
238 | // ], {trace:false}); | 244 | // ], {trace:false}); |
239 | // }); | 245 | // }); |
240 | 246 | ||
241 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); | 247 | // this.addBothPass(MochiKit.Base.method(aLock, 'release')); |
242 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); | 248 | this.addCallbackPass(MochiKit.Base.method(aLock, 'release')); |
243 | this.addErrback(function (anError) { | 249 | this.addErrback(function (anError) { |
244 | aLock.release(); | 250 | aLock.release(); |
245 | 251 | ||
246 | return anError; | 252 | return anError; |
247 | }); | 253 | }); |
248 | }, | 254 | }, |
249 | 255 | ||
250 | //============================================================================= | 256 | //============================================================================= |
251 | 257 | ||
252 | 'collectResults': function (someRequests) { | 258 | 'collectResults': function (someRequests) { |
253 | this.addCallback(Clipperz.Async.collectResults(this._name + " <collect results>", someRequests, this._args)); | 259 | this.addCallback(Clipperz.Async.collectResults(this._name + " <collect results>", someRequests, this._args)); |
254 | }, | 260 | }, |
255 | 261 | ||
256 | 'addCallbackList': function (aRequestList) { | 262 | 'addCallbackList': function (aRequestList) { |
257 | this.addCallback(Clipperz.Async.callbacks, this._name + " <callback list>", aRequestList, this._args); | 263 | this.addCallback(Clipperz.Async.callbacks, this._name + " <callback list>", aRequestList, this._args); |
258 | }, | 264 | }, |
259 | 265 | ||
260 | //============================================================================= | 266 | //============================================================================= |
261 | 267 | ||
262 | 'vars': function () { | 268 | 'vars': function () { |
263 | if (this._vars == null) { | 269 | if (this._vars == null) { |
264 | this._vars = {} | 270 | this._vars = {} |
265 | } | 271 | } |
266 | 272 | ||
267 | return this._vars; | 273 | return this._vars; |
268 | }, | 274 | }, |
269 | 275 | ||
270 | 'setValue': function (aKey) { | 276 | 'setValue': function (aKey) { |
271 | this.addCallback(MochiKit.Base.bind(function (aValue) { | 277 | this.addCallback(MochiKit.Base.bind(function (aValue) { |
272 | this.vars()[aKey] = aValue; | 278 | this.vars()[aKey] = aValue; |
273 | return aValue; | 279 | return aValue; |
274 | }, this)); | 280 | }, this)); |
275 | }, | 281 | }, |
276 | 282 | ||
277 | 'getValue': function (aKey) { | 283 | 'getValue': function (aKey) { |
278 | this.addCallback(MochiKit.Base.bind(function () { | 284 | this.addCallback(MochiKit.Base.bind(function () { |
279 | return this.vars()[aKey]; | 285 | return this.vars()[aKey]; |
280 | }, this)); | 286 | }, this)); |
281 | }, | 287 | }, |
282 | 288 | ||
283 | //============================================================================= | 289 | //============================================================================= |
284 | 290 | ||
285 | __syntaxFix__: "syntax fix" | 291 | __syntaxFix__: "syntax fix" |
286 | }); | 292 | }); |
287 | 293 | ||
288 | //############################################################################# | 294 | //############################################################################# |
289 | 295 | ||
290 | Clipperz.Async.DeferredSynchronizer = function(aName, someMethods) { | 296 | Clipperz.Async.DeferredSynchronizer = function(aName, someMethods) { |
291 | this._name = aName || "Anonymous deferred Synchronizer"; | 297 | this._name = aName || "Anonymous deferred Synchronizer"; |
292 | this._methods = someMethods; | 298 | this._methods = someMethods; |
293 | 299 | ||
294 | this._numberOfMethodsDone= 0; | 300 | this._numberOfMethodsDone= 0; |
295 | this._methodResults = []; | 301 | this._methodResults = []; |
296 | 302 | ||
297 | this._result = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer # " + this.name(), {trace:false}); | 303 | this._result = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer # " + this.name(), {trace:false}); |
298 | this._result.addMethod(this, 'methodResults'); | 304 | this._result.addMethod(this, 'methodResults'); |
299 | this._result.addCallback(function(someResults) { | 305 | this._result.addCallback(function(someResults) { |
300 | varcancels; | 306 | varcancels; |
301 | var errors; | 307 | var errors; |
302 | var result; | 308 | var result; |
303 | 309 | ||
304 | cancels = MochiKit.Base.filter(function(aResult) { return (aResult instanceof MochiKit.Async.CancelledError)}, someResults); | 310 | cancels = MochiKit.Base.filter(function(aResult) { return (aResult instanceof MochiKit.Async.CancelledError)}, someResults); |
305 | 311 | ||
306 | if (cancels.length == 0) { | 312 | if (cancels.length == 0) { |
307 | errors = MochiKit.Base.filter(function(aResult) { return (aResult instanceof Error)}, someResults); | 313 | errors = MochiKit.Base.filter(function(aResult) { return (aResult instanceof Error)}, someResults); |
308 | 314 | ||
309 | if (errors.length == 0) { | 315 | if (errors.length == 0) { |
310 | // result = MochiKit.Async.succeed(someResults); | 316 | // result = MochiKit.Async.succeed(someResults); |
311 | result = someResults; | 317 | result = someResults; |
312 | } else { | 318 | } else { |
313 | result = MochiKit.Async.fail(someResults); | 319 | result = MochiKit.Async.fail(someResults); |
314 | } | 320 | } |
315 | } else { | 321 | } else { |
316 | result = MochiKit.Async.fail(cancels[0]); | 322 | result = MochiKit.Async.fail(cancels[0]); |
317 | } | 323 | } |
318 | 324 | ||
319 | return result; | 325 | return result; |
320 | }/*, this._methodResults */); | 326 | }/*, this._methodResults */); |
321 | 327 | ||
322 | return this; | 328 | return this; |
323 | } | 329 | } |
324 | 330 | ||
325 | MochiKit.Base.update(Clipperz.Async.DeferredSynchronizer.prototype, { | 331 | MochiKit.Base.update(Clipperz.Async.DeferredSynchronizer.prototype, { |
326 | 332 | ||
327 | //----------------------------------------------------------------------------- | 333 | //----------------------------------------------------------------------------- |
328 | 334 | ||
329 | 'name': function() { | 335 | 'name': function() { |
330 | return this._name; | 336 | return this._name; |
331 | }, | 337 | }, |
332 | 338 | ||
333 | //----------------------------------------------------------------------------- | 339 | //----------------------------------------------------------------------------- |
334 | 340 | ||
335 | 'methods': function() { | 341 | 'methods': function() { |
336 | return this._methods; | 342 | return this._methods; |
337 | }, | 343 | }, |
338 | 344 | ||
339 | 'methodResults': function() { | 345 | 'methodResults': function() { |
340 | return this._methodResults; | 346 | return this._methodResults; |
341 | }, | 347 | }, |
342 | 348 | ||
343 | //----------------------------------------------------------------------------- | 349 | //----------------------------------------------------------------------------- |
344 | 350 | ||
345 | 'result': function() { | 351 | 'result': function() { |
346 | return this._result; | 352 | return this._result; |
347 | }, | 353 | }, |
348 | 354 | ||
349 | //----------------------------------------------------------------------------- | 355 | //----------------------------------------------------------------------------- |
350 | 356 | ||
351 | 'numberOfMethodsDone':function() { | 357 | 'numberOfMethodsDone':function() { |
352 | return this._numberOfMethodsDone; | 358 | return this._numberOfMethodsDone; |
353 | }, | 359 | }, |
354 | 360 | ||
355 | 'incrementNumberOfMethodsDone': function() { | 361 | 'incrementNumberOfMethodsDone': function() { |
356 | this._numberOfMethodsDone ++; | 362 | this._numberOfMethodsDone ++; |
357 | }, | 363 | }, |
358 | 364 | ||
359 | //----------------------------------------------------------------------------- | 365 | //----------------------------------------------------------------------------- |
360 | 366 | ||
361 | 'run': function(args, aValue) { | 367 | 'run': function(args, aValue) { |
362 | var deferredResults; | 368 | var deferredResults; |
363 | var i, c; | 369 | var i, c; |
364 | 370 | ||
365 | deferredResults = []; | 371 | deferredResults = []; |
366 | args = args || {}; | 372 | args = args || {}; |
367 | 373 | ||
368 | c = this.methods().length; | 374 | c = this.methods().length; |
369 | for (i=0; i<c; i++) { | 375 | for (i=0; i<c; i++) { |
370 | var deferredResult; | 376 | var deferredResult; |
371 | varmethodCalls; | 377 | varmethodCalls; |
372 | var ii, cc; | 378 | var ii, cc; |
373 | 379 | ||
374 | //console.log("TYPEOF", typeof(this.methods()[i])); | 380 | //console.log("TYPEOF", typeof(this.methods()[i])); |
375 | if (typeof(this.methods()[i]) == 'function') { | 381 | if (typeof(this.methods()[i]) == 'function') { |
376 | methodCalls = [ this.methods()[i] ]; | 382 | methodCalls = [ this.methods()[i] ]; |
377 | } else { | 383 | } else { |
378 | methodCalls = this.methods()[i]; | 384 | methodCalls = this.methods()[i]; |
379 | } | 385 | } |
380 | 386 | ||
381 | cc = methodCalls.length; | 387 | cc = methodCalls.length; |
382 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); | 388 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.DeferredSynchronizer.run => " + this.name() + "[" + i + "]", args); |
383 | for (ii=0; ii<cc; ii++) { | 389 | for (ii=0; ii<cc; ii++) { |
384 | deferredResult.addCallback(methodCalls[ii]); | 390 | deferredResult.addCallback(methodCalls[ii]); |
385 | } | 391 | } |
386 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); | 392 | deferredResult.addBoth(MochiKit.Base.method(this, 'handleMethodCallDone', i)); |
387 | 393 | ||
388 | deferredResults.push(deferredResult); | 394 | deferredResults.push(deferredResult); |
389 | } | 395 | } |
390 | 396 | ||
391 | for (i=0; i<c; i++) { | 397 | for (i=0; i<c; i++) { |
392 | deferredResults[i].callback(aValue); | 398 | deferredResults[i].callback(aValue); |
393 | } | 399 | } |
394 | 400 | ||
395 | return this.result(); | 401 | return this.result(); |
396 | }, | 402 | }, |
397 | 403 | ||
398 | //----------------------------------------------------------------------------- | 404 | //----------------------------------------------------------------------------- |
399 | 405 | ||
400 | 'handleMethodCallDone': function(anIndexValue, aResult) { | 406 | 'handleMethodCallDone': function(anIndexValue, aResult) { |
401 | this.incrementNumberOfMethodsDone(); | 407 | this.incrementNumberOfMethodsDone(); |
402 | this.methodResults()[anIndexValue] = aResult; | 408 | this.methodResults()[anIndexValue] = aResult; |
403 | 409 | ||
404 | if (this.numberOfMethodsDone() < this.methods().length) { | 410 | if (this.numberOfMethodsDone() < this.methods().length) { |
405 | //nothing to do here other than possibly log something | 411 | //nothing to do here other than possibly log something |
406 | } else if (this.numberOfMethodsDone() == this.methods().length) { | 412 | } else if (this.numberOfMethodsDone() == this.methods().length) { |
407 | this.result().callback(); | 413 | this.result().callback(); |
408 | } else if (this.numberOfMethodsDone() > this.methods().length) { | 414 | } else if (this.numberOfMethodsDone() > this.methods().length) { |
415 | alert("Clipperz.Async.Deferred.handleMethodCallDone -> WTF!"); | ||
409 | //WTF!!! :( | 416 | //WTF!!! :( |
410 | } | 417 | } |
411 | 418 | ||
412 | }, | 419 | }, |
413 | 420 | ||
414 | //----------------------------------------------------------------------------- | 421 | //----------------------------------------------------------------------------- |
415 | 422 | ||
416 | __syntaxFix__: "syntax fix" | 423 | __syntaxFix__: "syntax fix" |
417 | }); | 424 | }); |
418 | 425 | ||
419 | //############################################################################# | 426 | //############################################################################# |
420 | 427 | ||
421 | MochiKit.Base.update(Clipperz.Async, { | 428 | MochiKit.Base.update(Clipperz.Async, { |
422 | 429 | ||
423 | 'callbacks': function (aName, someFunctions, someArguments, aCallbackValue) { | 430 | 'callbacks': function (aName, someFunctions, someArguments, aCallbackValue) { |
424 | var deferredResult; | 431 | var deferredResult; |
425 | var i, c; | 432 | var i, c; |
426 | 433 | ||
427 | deferredResult = new Clipperz.Async.Deferred(aName, someArguments); | 434 | deferredResult = new Clipperz.Async.Deferred(aName, someArguments); |
428 | c = someFunctions.length; | 435 | c = someFunctions.length; |
429 | for (i=0; i<c; i++) { | 436 | for (i=0; i<c; i++) { |
430 | deferredResult.addCallback(someFunctions[i]); | 437 | deferredResult.addCallback(someFunctions[i]); |
431 | } | 438 | } |
432 | deferredResult.callback(aCallbackValue); | 439 | deferredResult.callback(aCallbackValue); |
433 | 440 | ||
434 | return deferredResult; | 441 | return deferredResult; |
435 | }, | 442 | }, |
436 | 443 | ||
437 | //------------------------------------------------------------------------- | 444 | //------------------------------------------------------------------------- |
438 | 445 | ||
439 | 'forkAndJoin': function (aName, someMethods, args) { | 446 | 'forkAndJoin': function (aName, someMethods, args) { |
440 | return MochiKit.Base.partial(function (aName, someMethods, args, aValue) { | 447 | return MochiKit.Base.partial(function (aName, someMethods, args, aValue) { |
441 | var synchronizer; | 448 | var synchronizer; |
442 | varresult; | 449 | varresult; |
443 | 450 | ||
444 | args = args || {}; | 451 | args = args || {}; |
445 | synchronizer = new Clipperz.Async.DeferredSynchronizer(aName, someMethods); | 452 | synchronizer = new Clipperz.Async.DeferredSynchronizer(aName, someMethods); |
446 | result = synchronizer.run(args, aValue); | 453 | result = synchronizer.run(args, aValue); |
447 | 454 | ||
448 | return result; | 455 | return result; |
449 | }, aName, someMethods, args); | 456 | }, aName, someMethods, args); |
450 | }, | 457 | }, |
451 | 458 | ||
452 | //------------------------------------------------------------------------- | 459 | //------------------------------------------------------------------------- |
453 | 460 | ||
454 | 'collectResults': function(aName, someRequests, args) { | 461 | 'collectResults': function(aName, someRequests, args) { |
455 | return MochiKit.Base.partial(function(aName, someRequests, args, aValue) { | 462 | return MochiKit.Base.partial(function(aName, someRequests, args, aValue) { |
456 | var deferredResult; | 463 | var deferredResult; |
457 | var requestKeys; | 464 | var requestKeys; |
458 | var methods; | 465 | var methods; |
459 | 466 | ||
460 | requestKeys = MochiKit.Base.keys(someRequests); | 467 | requestKeys = MochiKit.Base.keys(someRequests); |
461 | methods = MochiKit.Base.values(someRequests); | 468 | methods = MochiKit.Base.values(someRequests); |
462 | 469 | ||
463 | deferredResult = new Clipperz.Async.Deferred(aName, args); | 470 | deferredResult = new Clipperz.Async.Deferred(aName, args); |
464 | deferredResult.addCallback(Clipperz.Async.forkAndJoin(aName + " [inner forkAndJoin]", methods, args)); | 471 | deferredResult.addCallback(Clipperz.Async.forkAndJoin(aName + " [inner forkAndJoin]", methods, args)); |
465 | deferredResult.addBoth(function(someResults) { | 472 | deferredResult.addBoth(function(someResults) { |
466 | var returnFunction; | 473 | var returnFunction; |
467 | var results; | 474 | var results; |
468 | var i,c; | 475 | var i,c; |
469 | var result; | 476 | var result; |
470 | 477 | ||
471 | if (someResults instanceof MochiKit.Async.CancelledError) { | 478 | if (someResults instanceof MochiKit.Async.CancelledError) { |
472 | returnFunction = MochiKit.Async.fail; | 479 | returnFunction = MochiKit.Async.fail; |
473 | result = someResults; | 480 | result = someResults; |
474 | } else { | 481 | } else { |
475 | if (someResults instanceof Error) { | 482 | if (someResults instanceof Error) { |
476 | returnFunction = MochiKit.Async.fail; | 483 | returnFunction = MochiKit.Async.fail; |
477 | results = someResults['message']; | 484 | results = someResults['message']; |
478 | } else { | 485 | } else { |
479 | returnFunction = MochiKit.Async.succeed; | 486 | returnFunction = MochiKit.Async.succeed; |
480 | results = someResults; | 487 | results = someResults; |
481 | } | 488 | } |
482 | 489 | ||
483 | result = {}; | 490 | result = {}; |
484 | 491 | ||
485 | c = requestKeys.length; | 492 | c = requestKeys.length; |
486 | for (i=0; i<c; i++) { | 493 | for (i=0; i<c; i++) { |
487 | result[requestKeys[i]] = results[i]; | 494 | result[requestKeys[i]] = results[i]; |
488 | } | 495 | } |
489 | } | 496 | } |
490 | 497 | ||
491 | return returnFunction.call(null, result); | 498 | return returnFunction.call(null, result); |
492 | }); | 499 | }); |
493 | deferredResult.callback(aValue); | 500 | deferredResult.callback(aValue); |
494 | 501 | ||
495 | return deferredResult; | 502 | return deferredResult; |
496 | }, aName, someRequests, args); | 503 | }, aName, someRequests, args); |
497 | }, | 504 | }, |
498 | 505 | ||
499 | //------------------------------------------------------------------------- | 506 | //------------------------------------------------------------------------- |
500 | 507 | ||
501 | 'collectAll': function (someDeferredObjects) { | 508 | 'collectAll': function (someDeferredObjects) { |
502 | var deferredResult; | 509 | var deferredResult; |
503 | 510 | ||
504 | deferredResult = new MochiKit.Async.DeferredList(someDeferredObjects, false, false, false); | 511 | deferredResult = new MochiKit.Async.DeferredList(someDeferredObjects, false, false, false); |
505 | deferredResult.addCallback(function (aResultList) { | 512 | deferredResult.addCallback(function (aResultList) { |
506 | return MochiKit.Base.map(function (aResult) { | 513 | return MochiKit.Base.map(function (aResult) { |
507 | if (aResult[0]) { | 514 | if (aResult[0]) { |
508 | return aResult[1]; | 515 | return aResult[1]; |
509 | } else { | 516 | } else { |
510 | throw aResult[1]; | 517 | throw aResult[1]; |
511 | } | 518 | } |
512 | }, aResultList); | 519 | }, aResultList); |
513 | }); | 520 | }); |
514 | 521 | ||
515 | return deferredResult; | 522 | return deferredResult; |
516 | }, | 523 | }, |
517 | 524 | ||
518 | //------------------------------------------------------------------------- | 525 | //------------------------------------------------------------------------- |
519 | 526 | ||
520 | 'setItem': function (anObject, aKey, aValue) { | 527 | 'setItem': function (anObject, aKey, aValue) { |
521 | anObject[aKey] = aValue; | 528 | anObject[aKey] = aValue; |
522 | 529 | ||
523 | return anObject; | 530 | return anObject; |
524 | }, | 531 | }, |
525 | 532 | ||
526 | 'setItemOnObject': function (aKey, aValue, anObject) { | 533 | 'setItemOnObject': function (aKey, aValue, anObject) { |
527 | anObject[aKey] = aValue; | 534 | anObject[aKey] = aValue; |
528 | 535 | ||
529 | return anObject; | 536 | return anObject; |
530 | }, | 537 | }, |
531 | 538 | ||
532 | 'setDeferredItemOnObject': function (aKey, aDeferredFunction, anObject) { | 539 | 'setDeferredItemOnObject': function (aKey, aDeferredFunction, anObject) { |
533 | return Clipperz.Async.callbacks("Clipperz.Async.setDeferredItemOnObject", [ | 540 | return Clipperz.Async.callbacks("Clipperz.Async.setDeferredItemOnObject", [ |
534 | aDeferredFunction, | 541 | aDeferredFunction, |
535 | MochiKit.Base.partial(Clipperz.Async.setItem, anObject, aKey) | 542 | MochiKit.Base.partial(Clipperz.Async.setItem, anObject, aKey) |
536 | ], {trace:false}, anObject); | 543 | ], {trace:false}, anObject); |
537 | }, | 544 | }, |
538 | 545 | ||
539 | //------------------------------------------------------------------------- | 546 | //------------------------------------------------------------------------- |
540 | 547 | ||
541 | 'deferredIf': function (aName, aThenBlock, anElseBlock) { | 548 | 'deferredIf': function (aName, aThenBlock, anElseBlock) { |
542 | return function (aValue) { | 549 | return function (aValue) { |
543 | var deferredResult; | 550 | var deferredResult; |
544 | 551 | ||
545 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { | 552 | if (!MochiKit.Base.isUndefinedOrNull(aValue) && aValue) { |
546 | deferredResult = Clipperz.Async.callbacks(aName + " <then>", aThenBlock, null, aValue); | 553 | deferredResult = Clipperz.Async.callbacks(aName + " <then>", aThenBlock, null, aValue); |
547 | } else { | 554 | } else { |
548 | deferredResult = Clipperz.Async.callbacks(aName + " <else>", anElseBlock, null, aValue); | 555 | deferredResult = Clipperz.Async.callbacks(aName + " <else>", anElseBlock, null, aValue); |
549 | } | 556 | } |
550 | 557 | ||
551 | return deferredResult; | 558 | return deferredResult; |
552 | } | 559 | } |
553 | }, | 560 | }, |
554 | 561 | ||
555 | //------------------------------------------------------------------------- | 562 | //------------------------------------------------------------------------- |
556 | 563 | ||
557 | 'log': function(aMessage, aResult) { | 564 | 'log': function(aMessage, aResult) { |
558 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { | 565 | if (CLIPPERZ_DEFERRED_LOGGING_ENABLED) { |
559 | Clipperz.log(aMessage + " ", aResult); | 566 | Clipperz.log(aMessage + " ", aResult); |
560 | } | 567 | } |
561 | 568 | ||
562 | return aResult; | 569 | return aResult; |
563 | }, | 570 | }, |
564 | 571 | ||
565 | //========================================================================= | 572 | //========================================================================= |
566 | 573 | ||
567 | 'deferredCompare': function (aComparator, aDeferred, bDeferred) { | 574 | 'deferredCompare': function (aComparator, aDeferred, bDeferred) { |
568 | var deferredResult; | 575 | var deferredResult; |
569 | 576 | ||
570 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredCompare", {trace:false}); | 577 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredCompare", {trace:false}); |
571 | deferredResult.addCallback(Clipperz.Async.collectAll, [aDeferred, bDeferred]); | 578 | deferredResult.addCallback(Clipperz.Async.collectAll, [aDeferred, bDeferred]); |
572 | deferredResult.addCallback(function (someResults) { | 579 | deferredResult.addCallback(function (someResults) { |
573 | var result; | 580 | var result; |
574 | 581 | ||
575 | if (aComparator(someResults[0], someResults[1]) > 0) { | 582 | if (aComparator(someResults[0], someResults[1]) > 0) { |
576 | result = MochiKit.Async.succeed(); | 583 | result = MochiKit.Async.succeed(); |
577 | } else { | 584 | } else { |
578 | result = MochiKit.Async.fail(); | 585 | result = MochiKit.Async.fail(); |
579 | }; | 586 | }; |
580 | 587 | ||
581 | return result; | 588 | return result; |
582 | }); | 589 | }); |
583 | deferredResult.callback(); | 590 | deferredResult.callback(); |
584 | 591 | ||
585 | return deferredResult; | 592 | return deferredResult; |
586 | }, | 593 | }, |
587 | 594 | ||
588 | //------------------------------------------------------------------------- | 595 | //------------------------------------------------------------------------- |
589 | 596 | ||
590 | 'insertIntoSortedArray': function (anObject, aDeferredComparator, aSortedResult) { | 597 | 'insertIntoSortedArray': function (anObject, aDeferredComparator, aSortedResult) { |
591 | var deferredResult; | 598 | var deferredResult; |
592 | var i, c; | 599 | var i, c; |
593 | 600 | ||
594 | if (aSortedResult.length == 0) { | 601 | if (aSortedResult.length == 0) { |
595 | deferredResult = MochiKit.Async.succeed([anObject]); | 602 | deferredResult = MochiKit.Async.succeed([anObject]); |
596 | } else { | 603 | } else { |
597 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray", {trace:false}); | 604 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray", {trace:false}); |
598 | c = aSortedResult.length + 1; | 605 | c = aSortedResult.length + 1; |
599 | for (i=0; i<c; i++) { | 606 | for (i=0; i<c; i++) { |
600 | deferredResult.addCallback(function (aDeferredComparator, aObject, bObject, aContext) { | 607 | deferredResult.addCallback(function (aDeferredComparator, aObject, bObject, aContext) { |
601 | var innerDeferredResult; | 608 | var innerDeferredResult; |
602 | 609 | ||
603 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray <inner compare>", {trace:false}); | 610 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.insertIntoSortedArray <inner compare>", {trace:false}); |
604 | innerDeferredResult.addCallback(aDeferredComparator, aObject, bObject); | 611 | innerDeferredResult.addCallback(aDeferredComparator, aObject, bObject); |
605 | innerDeferredResult.addErrback(MochiKit.Async.fail, aContext); | 612 | innerDeferredResult.addErrback(MochiKit.Async.fail, aContext); |
606 | innerDeferredResult.callback(); | 613 | innerDeferredResult.callback(); |
607 | 614 | ||
608 | return innerDeferredResult; | 615 | return innerDeferredResult; |
609 | }, aDeferredComparator, anObject, aSortedResult[i], i); | 616 | }, aDeferredComparator, anObject, aSortedResult[i], i); |
610 | } | 617 | } |
611 | deferredResult.addMethod(aSortedResult, 'push', anObject); | 618 | deferredResult.addMethod(aSortedResult, 'push', anObject); |
612 | deferredResult.addErrback(function (anError) { | 619 | deferredResult.addErrback(function (anError) { |
613 | aSortedResult.splice(anError.message, 0, anObject); | 620 | aSortedResult.splice(anError.message, 0, anObject); |
614 | }) | 621 | }) |
615 | deferredResult.addBoth(MochiKit.Async.succeed, aSortedResult); | 622 | deferredResult.addBoth(MochiKit.Async.succeed, aSortedResult); |
616 | deferredResult.callback(); | 623 | deferredResult.callback(); |
617 | } | 624 | } |
618 | 625 | ||
619 | return deferredResult; | 626 | return deferredResult; |
620 | }, | 627 | }, |
621 | 628 | ||
622 | //------------------------------------------------------------------------- | 629 | //------------------------------------------------------------------------- |
623 | 630 | ||
624 | 'deferredSort': function (aDeferredComparator, someObjects) { | 631 | 'deferredSort': function (aDeferredComparator, someObjects) { |
625 | var deferredResult; | 632 | var deferredResult; |
626 | var i, c; | 633 | var i, c; |
627 | 634 | ||
628 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); | 635 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredSort", {trace:false}); |
629 | c = someObjects.length; | 636 | c = someObjects.length; |
630 | for (i=0; i<c; i++) { | 637 | for (i=0; i<c; i++) { |
631 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); | 638 | deferredResult.addCallback(Clipperz.Async.insertIntoSortedArray, someObjects[i], aDeferredComparator); |
632 | if ((i % 50) == 0) { | 639 | if ((i % 50) == 0) { |
633 | //console.log("######### sort wait ##########"); | 640 | //console.log("######### sort wait ##########"); |
634 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); | 641 | deferredResult.addCallback(MochiKit.Async.wait, 0.5); |
635 | } | 642 | } |
636 | } | 643 | } |
637 | deferredResult.callback([]); | 644 | deferredResult.callback([]); |
638 | 645 | ||
639 | return deferredResult; | 646 | return deferredResult; |
640 | }, | 647 | }, |
641 | 648 | ||
642 | //========================================================================= | 649 | //========================================================================= |
643 | 650 | ||
644 | 'deferredFilter': function (aFunction, someObjects) { | 651 | 'deferredFilter': function (aFunction, someObjects) { |
645 | vardeferredResult; | 652 | vardeferredResult; |
646 | vari, c; | 653 | vari, c; |
647 | 654 | ||
648 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); | 655 | deferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter", {trace:false}); |
649 | c = someObjects.length; | 656 | c = someObjects.length; |
650 | for (i=0; i<c; i++) { | 657 | for (i=0; i<c; i++) { |
651 | deferredResult.addCallback(function (aFunction, anObject, anIndex, aResult) { | 658 | deferredResult.addCallback(function (aFunction, anObject, anIndex, aResult) { |
652 | var innerDeferredResult; | 659 | var innerDeferredResult; |
653 | 660 | ||
654 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter <inner - " + anIndex + ">", {trace:false}); | 661 | innerDeferredResult = new Clipperz.Async.Deferred("Clipperz.Async.deferredFilter <inner - " + anIndex + ">", {trace:false}); |
655 | innerDeferredResult.addCallback(aFunction, anObject); | 662 | innerDeferredResult.addCallback(aFunction, anObject); |
656 | innerDeferredResult.addCallback(function (aFilterResult) { | 663 | innerDeferredResult.addCallback(function (aFilterResult) { |
657 | if (aFilterResult) { | 664 | if (aFilterResult) { |
658 | aResult.push(anObject); | 665 | aResult.push(anObject); |
659 | }; | 666 | }; |
660 | }); | 667 | }); |
661 | innerDeferredResult.addBoth(MochiKit.Async.succeed, aResult); | 668 | innerDeferredResult.addBoth(MochiKit.Async.succeed, aResult); |
662 | innerDeferredResult.callback(); | 669 | innerDeferredResult.callback(); |
663 | 670 | ||
664 | return innerDeferredResult; | 671 | return innerDeferredResult; |
665 | }, aFunction, someObjects[i], i); | 672 | }, aFunction, someObjects[i], i); |
666 | } | 673 | } |
667 | deferredResult.callback([]); | 674 | deferredResult.callback([]); |
668 | 675 | ||
669 | return deferredResult; | 676 | return deferredResult; |
670 | }, | 677 | }, |
671 | 678 | ||
672 | 'forEach': function (aFunction) { | 679 | 'forEach': function (aFunction) { |
673 | return MochiKit.Base.partial(function (aFunction, anIterable) { | 680 | return MochiKit.Base.partial(function (aFunction, anIterable) { |
674 | MochiKit.Iter.forEach(anIterable, aFunction); | 681 | MochiKit.Iter.forEach(anIterable, aFunction); |
675 | }, aFunction); | 682 | }, aFunction); |
676 | }, | 683 | }, |
677 | 684 | ||
678 | //========================================================================= | 685 | //========================================================================= |
679 | 686 | ||
680 | 'or': function (someValues) { | 687 | 'or': function (someValues) { |
681 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ | 688 | return Clipperz.Async.callbacks("Clipperz.Async.or", [ |
682 | MochiKit.Base.values, | 689 | MochiKit.Base.values, |
683 | MochiKit.Base.flattenArguments, | 690 | MochiKit.Base.flattenArguments, |
684 | //function (aValue) { console.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, | 691 | //function (aValue) { console.log("Record.hasAnyCleanTextData - flatten", aValue); return aValue; }, |
685 | function(someInnerValues) { | 692 | function(someInnerValues) { |
686 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); | 693 | return MochiKit.Iter.some(someInnerValues, MochiKit.Base.operator.identity); |
687 | } | 694 | } |
688 | ], {trace:false}, someValues); | 695 | ], {trace:false}, someValues); |
689 | }, | 696 | }, |
690 | 697 | ||
691 | //========================================================================= | 698 | //========================================================================= |
692 | 699 | ||
693 | 'clearResult': function () {}, | 700 | 'clearResult': function () {}, |
694 | 701 | ||
695 | //========================================================================= | 702 | //========================================================================= |
696 | __syntaxFix__: "syntax fix" | 703 | __syntaxFix__: "syntax fix" |
697 | }); | 704 | }); |
698 | 705 | ||
699 | 706 | ||
700 | //############################################################################# | 707 | //############################################################################# |
701 | 708 | ||
702 | CLIPPERZ_DEFERRED_LOGGING_ENABLED = true; | 709 | CLIPPERZ_DEFERRED_LOGGING_ENABLED = true; |
703 | CLIPPERZ_DEFERRED_TRACING_ENABLED = false; | 710 | CLIPPERZ_DEFERRED_TRACING_ENABLED = false; |
704 | CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED = false; | 711 | CLIPPERZ_DEFERRED_CALL_LOGGING_ENABLED = false; |
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy.js b/frontend/gamma/js/Clipperz/PM/Proxy.js index 190bffd..9817eac 100644 --- a/frontend/gamma/js/Clipperz/PM/Proxy.js +++ b/frontend/gamma/js/Clipperz/PM/Proxy.js | |||
@@ -1,169 +1,169 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2011 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz Community Edition. |
6 | Clipperz Community Edition is an online password manager. | 6 | Clipperz Community Edition is an online password manager. |
7 | For further information about its features and functionalities please | 7 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 8 | refer to http://www.clipperz.com. |
9 | 9 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 10 | * Clipperz Community Edition is free software: you can redistribute |
11 | it and/or modify it under the terms of the GNU Affero General Public | 11 | it and/or modify it under the terms of the GNU Affero General Public |
12 | License as published by the Free Software Foundation, either version | 12 | License as published by the Free Software Foundation, either version |
13 | 3 of the License, or (at your option) any later version. | 13 | 3 of the License, or (at your option) any later version. |
14 | 14 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 15 | * Clipperz Community Edition is distributed in the hope that it will |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 16 | be useful, but WITHOUT ANY WARRANTY; without even the implied |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 18 | See the GNU Affero General Public License for more details. |
19 | 19 | ||
20 | * You should have received a copy of the GNU Affero General Public | 20 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 21 | License along with Clipperz Community Edition. If not, see |
22 | <http://www.gnu.org/licenses/>. | 22 | <http://www.gnu.org/licenses/>. |
23 | 23 | ||
24 | */ | 24 | */ |
25 | 25 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | 28 | ||
29 | //============================================================================= | 29 | //============================================================================= |
30 | 30 | ||
31 | Clipperz.PM.Proxy = function(args) { | 31 | Clipperz.PM.Proxy = function(args) { |
32 | args = args || {}; | 32 | args = args || {}; |
33 | 33 | ||
34 | this._shouldPayTolls = args.shouldPayTolls || false; | 34 | this._shouldPayTolls = args.shouldPayTolls || false; |
35 | 35 | ||
36 | this._tolls = { | 36 | this._tolls = { |
37 | 'CONNECT':[], | 37 | 'CONNECT':[], |
38 | 'REGISTER':[], | 38 | 'REGISTER':[], |
39 | 'MESSAGE':[] | 39 | 'MESSAGE':[] |
40 | }; | 40 | }; |
41 | 41 | ||
42 | if (args.isDefault === true) { | 42 | if (args.isDefault === true) { |
43 | Clipperz.PM.Proxy.defaultProxy = this; | 43 | Clipperz.PM.Proxy.defaultProxy = this; |
44 | } | 44 | } |
45 | 45 | ||
46 | return this; | 46 | return this; |
47 | } | 47 | } |
48 | 48 | ||
49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { | 49 | Clipperz.PM.Proxy.prototype = MochiKit.Base.update(null, { |
50 | 50 | ||
51 | 'toString': function() { | 51 | 'toString': function() { |
52 | return "Clipperz.PM.Proxy"; | 52 | return "Clipperz.PM.Proxy"; |
53 | }, | 53 | }, |
54 | 54 | ||
55 | //========================================================================= | 55 | //========================================================================= |
56 | 56 | ||
57 | 'shouldPayTolls': function() { | 57 | 'shouldPayTolls': function() { |
58 | return this._shouldPayTolls; | 58 | return this._shouldPayTolls; |
59 | }, | 59 | }, |
60 | 60 | ||
61 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
62 | 62 | ||
63 | 'tolls': function() { | 63 | 'tolls': function() { |
64 | return this._tolls; | 64 | return this._tolls; |
65 | }, | 65 | }, |
66 | 66 | ||
67 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
68 | 68 | ||
69 | 'payToll': function(aRequestType, someParameters) { | 69 | 'payToll': function(aRequestType, someParameters) { |
70 | vardeferredResult; | 70 | vardeferredResult; |
71 | 71 | ||
72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); | 72 | //console.log(">>> Proxy.payToll", aRequestType, someParameters); |
73 | if (this.shouldPayTolls()) { | 73 | if (this.shouldPayTolls()) { |
74 | deferredResult = new Clipperz.Async.Deferred("Proxy.payToll", {trace:false}); | 74 | deferredResult = new Clipperz.Async.Deferred("Proxy.payToll", {trace:false}); |
75 | 75 | ||
76 | if (this.tolls()[aRequestType].length == 0) { | 76 | if (this.tolls()[aRequestType].length == 0) { |
77 | deferredResult.addMethod(this, 'sendMessage', 'knock', {requestType:aRequestType}); | 77 | deferredResult.addMethod(this, 'sendMessage', 'knock', {requestType:aRequestType}); |
78 | deferredResult.addMethod(this, 'setTollCallback'); | 78 | deferredResult.addMethod(this, 'setTollCallback'); |
79 | } | 79 | } |
80 | deferredResult.addMethod(this.tolls()[aRequestType], 'pop'); | 80 | deferredResult.addMethod(this.tolls()[aRequestType], 'pop'); |
81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); | 81 | deferredResult.addCallback(MochiKit.Base.methodcaller('deferredPay')); |
82 | deferredResult.addCallback(function(aToll) { | 82 | deferredResult.addCallback(function(aToll) { |
83 | var result; | 83 | var result; |
84 | 84 | ||
85 | result = { | 85 | result = { |
86 | parameters: someParameters, | 86 | parameters: someParameters, |
87 | toll: aToll | 87 | toll: aToll |
88 | } | 88 | } |
89 | 89 | ||
90 | return result; | 90 | return result; |
91 | }); | 91 | }); |
92 | 92 | ||
93 | deferredResult.callback(); | 93 | deferredResult.callback(); |
94 | } else { | 94 | } else { |
95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); | 95 | deferredResult = MochiKit.Async.succeed({parameters:someParameters}); |
96 | } | 96 | } |
97 | //console.log("<<< Proxy.payToll"); | 97 | //console.log("<<< Proxy.payToll"); |
98 | 98 | ||
99 | return deferredResult; | 99 | return deferredResult; |
100 | }, | 100 | }, |
101 | 101 | ||
102 | //------------------------------------------------------------------------- | 102 | //------------------------------------------------------------------------- |
103 | 103 | ||
104 | 'addToll': function(aToll) { | 104 | 'addToll': function(aToll) { |
105 | //console.log(">>> Proxy.addToll", aToll); | 105 | //console.log(">>> Proxy.addToll", aToll); |
106 | this.tolls()[aToll.requestType()].push(aToll); | 106 | this.tolls()[aToll.requestType()].push(aToll); |
107 | //console.log("<<< Proxy.addToll"); | 107 | //console.log("<<< Proxy.addToll"); |
108 | }, | 108 | }, |
109 | 109 | ||
110 | //========================================================================= | 110 | //========================================================================= |
111 | 111 | ||
112 | 'setTollCallback': function(someParameters) { | 112 | 'setTollCallback': function(someParameters) { |
113 | //console.log(">>> Proxy.setTollCallback", someParameters); | 113 | //console.log(">>> Proxy.setTollCallback", someParameters); |
114 | if (typeof(someParameters['toll']) != 'undefined') { | 114 | if (typeof(someParameters['toll']) != 'undefined') { |
115 | //console.log("added a new toll", someParameters['toll']); | 115 | //console.log("added a new toll", someParameters['toll']); |
116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); | 116 | this.addToll(new Clipperz.PM.Toll(someParameters['toll'])); |
117 | } | 117 | } |
118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); | 118 | //console.log("<<< Proxy.setTallCallback", someParameters['result']); |
119 | return someParameters['result']; | 119 | return someParameters['result']; |
120 | }, | 120 | }, |
121 | 121 | ||
122 | //========================================================================= | 122 | //========================================================================= |
123 | 123 | ||
124 | 'registration': function (someParameters) { | 124 | 'registration': function (someParameters) { |
125 | return this.processMessage('registration', someParameters, 'REGISTER'); | 125 | return this.processMessage('registration', someParameters, 'REGISTER'); |
126 | }, | 126 | }, |
127 | 127 | ||
128 | 'handshake': function (someParameters) { | 128 | 'handshake': function (someParameters) { |
129 | return this.processMessage('handshake', someParameters, 'CONNECT'); | 129 | return this.processMessage('handshake', someParameters, 'CONNECT'); |
130 | }, | 130 | }, |
131 | 131 | ||
132 | 'message': function (someParameters) { | 132 | 'message': function (someParameters) { |
133 | return this.processMessage('message', someParameters, 'MESSAGE'); | 133 | return this.processMessage('message', someParameters, 'MESSAGE'); |
134 | }, | 134 | }, |
135 | 135 | ||
136 | 'logout': function (someParameters) { | 136 | 'logout': function (someParameters) { |
137 | return this.processMessage('logout', someParameters, 'MESSAGE'); | 137 | return this.processMessage('logout', someParameters, 'MESSAGE'); |
138 | }, | 138 | }, |
139 | 139 | ||
140 | //========================================================================= | 140 | //========================================================================= |
141 | 141 | ||
142 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { | 142 | 'processMessage': function (aFunctionName, someParameters, aRequestType) { |
143 | vardeferredResult; | 143 | vardeferredResult; |
144 | 144 | ||
145 | deferredResult = new Clipperz.Async.Deferred("Proxy.processMessage", {trace:false}); | 145 | deferredResult = new Clipperz.Async.Deferred("Proxy.processMessage", {trace:true}); |
146 | deferredResult.addMethod(this, 'payToll', aRequestType); | 146 | deferredResult.addMethod(this, 'payToll', aRequestType); |
147 | deferredResult.addMethod(this, 'sendMessage', aFunctionName); | 147 | deferredResult.addMethod(this, 'sendMessage', aFunctionName); |
148 | deferredResult.addMethod(this, 'setTollCallback'); | 148 | deferredResult.addMethod(this, 'setTollCallback'); |
149 | deferredResult.callback(someParameters); | 149 | deferredResult.callback(someParameters); |
150 | 150 | ||
151 | return deferredResult; | 151 | return deferredResult; |
152 | }, | 152 | }, |
153 | 153 | ||
154 | //========================================================================= | 154 | //========================================================================= |
155 | 155 | ||
156 | 'sendMessage': function () { | 156 | 'sendMessage': function () { |
157 | throw Clipperz.Base.exception.AbstractMethod; | 157 | throw Clipperz.Base.exception.AbstractMethod; |
158 | }, | 158 | }, |
159 | 159 | ||
160 | //========================================================================= | 160 | //========================================================================= |
161 | 161 | ||
162 | 'isReadOnly': function () { | 162 | 'isReadOnly': function () { |
163 | return false; | 163 | return false; |
164 | }, | 164 | }, |
165 | 165 | ||
166 | //========================================================================= | 166 | //========================================================================= |
167 | __syntaxFix__: "syntax fix" | 167 | __syntaxFix__: "syntax fix" |
168 | 168 | ||
169 | }); | 169 | }); |