OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
openproject/assets/javascripts/board_updater.js

94 lines
2.5 KiB

/***************************************
BOARD UPDATER
Base object that is extended by
board-type-specific updaters
***************************************/
RB.BoardUpdater = RB.Object.create({
initialize: function(){
var self = this;
$('#refresh').bind('click', function(e,u){ self.handleRefreshClick(e,u) });
$('#disable_autorefresh').bind('click', function(e,u){ self.handleDisableAutorefreshClick(e,u) });
this.pollWait = 1000;
this.poll()
},
adjustPollWait: function(itemsReceived){
itemsReceived = (itemsReceived==null) ? 0 : itemsReceived;
if(itemsReceived==0 && this.pollWait < 60000 && !$('body').hasClass('no_autorefresh')){
this.pollWait += 250;
} else {
this.pollWait = 1000;
}
},
getData: function(){
var self = this;
RB.ajax({
type : "GET",
url : RB.urlFor[self.urlFor] + '?' + self.params,
data : {
after : $('#last_updated').text(),
project_id: RB.constants.project_id
},
beforeSend: function(){ $('body').addClass('loading') },
success : function(d,t,x){ self.processData(d,t,x) },
error : function(){ self.processError() }
});
},
handleDisableAutorefreshClick: function(event, ui){
$('body').toggleClass('no_autorefresh');
if($('body').hasClass('no_autorefresh')){
$('#disable_autorefresh').text('Enable Auto-refresh');
} else {
this.pollWait = 1000;
this.poll();
$('#disable_autorefresh').text('Disable Auto-refresh');
}
},
handleRefreshClick: function(event, ui){
this.getData();
},
poll: function() {
if(!$('body').hasClass('no_autorefresh')){
var self = this;
setTimeout(function(){ self.getData() }, self.pollWait);
} else {
return false;
}
},
processData: function(data, textStatus, xhr){
var self = this;
$('body').removeClass('loading');
var latest_update = $(data).children('#last_updated').text();
if(latest_update.length > 0) $('#last_updated').text(latest_update);
var items = $(data).children('.' + self.itemType);
items.each(function(i, v){
self.processItem(v);
});
self.adjustPollWait(items.length);
self.poll();
},
processError: function(){
this.adjustPollWait(0);
this.poll();
},
processItem: function(update){
throw "RB.BoardUpdater.processItem() was not overriden by child object";
}
});