var tickets_indicator interval 600000 intervalID null indicator null i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var tickets_indicator = {
'interval':600000,
'intervalID':null,
'indicator':null,
'init':function (interval){
if(interval) this.interval = interval;
this.indicator = $('#tickets_indicator');
this.intervalID = setInterval(function(){tickets_indicator.get.call(tickets_indicator)},this.interval);
this.get();
},
'set':function (count_new){
if(count_new > 0) {
this.indicator.text(count_new).show(300);
}else {
this.indicator.text('0').hide(300);
}
},
'set_count':function (count_new){
if(count_new !== false) this.set(count_new);
else this.get();
clearInterval(this.intervalID);
this.intervalID = setInterval(function(){tickets_indicator.get.call(tickets_indicator)},this.interval);
},
'get':function (){
var object = this;
var Cq = new Cquery(true);
Cq.url = PANEL + 'tickets/get_count_new/';
Cq.indicator = false;
Cq.request(function (request){
if(request.count_new >= 0){
object.set(request.count_new);
}else {
object.set(0);
}
});
Cq.init();
}
}