summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/Async.js
authorGiulio 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)
commit67455b069c4c9ec493f9cef76017e172a430a7d4 (patch) (unidiff)
tree0b287debfeeb0819b3df9dd02860cd84103e25b3 /frontend/gamma/js/Clipperz/Async.js
parentb312e037ebba7c94abea9661bcf62c52b7d73fbf (diff)
downloadclipperz-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.
Diffstat (limited to 'frontend/gamma/js/Clipperz/Async.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/Async.js19
1 files changed, 13 insertions, 6 deletions
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
@@ -17,152 +17,158 @@ refer to http://www.clipperz.com.
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
29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 29if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
30if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; } 30if (typeof(Clipperz.Async) == 'undefined') { Clipperz.Async = {}; }
31 31
32Clipperz.Async.VERSION = "0.1"; 32Clipperz.Async.VERSION = "0.1";
33Clipperz.Async.NAME = "Clipperz.Async"; 33Clipperz.Async.NAME = "Clipperz.Async";
34 34
35Clipperz.Async.Deferred = function(aName, args) { 35Clipperz.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
51Clipperz.Base.extend(Clipperz.Async.Deferred, MochiKit.Async.Deferred, { 51Clipperz.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
@@ -361,96 +367,97 @@ MochiKit.Base.update(Clipperz.Async.DeferredSynchronizer.prototype, {
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
421MochiKit.Base.update(Clipperz.Async, { 428MochiKit.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;