initial commit
[namibia] / public / js / vendor / ape-source / Request / Request.CycledStack.js
1 APE.Request.CycledStack = new Class({
2         initialize: function(ape) {
3                 this.ape = ape;
4
5                 this.stack = [];
6                 this.reajustTime = false;
7
8                 this.timer = this.send.periodical(this.ape.options.cycledStackTime, this);
9         },
10
11         add: function(cmd, params, sessid) {
12                 this.stack.push({'cmd':cmd, 'params':params, 'sessid':sessid});
13         },
14
15         setTime: function(time, now) {
16                 if (now) {
17                         this.send();
18                         $clear(this.timer);
19                         this.timer = this.send.periodical(time, this);
20                         this.reajustTime = false;
21                 }
22                 else this.reajustTime = time;
23         },
24
25         send: function() {
26                 if (this.stack.length > 0) {
27                         this.ape.request.send(this.stack);
28                         this.stack = [];
29                         if (this.reajustTime) {
30                                 this.setTime(this.reajustTime, true);
31                         }
32                 }
33         }
34 });