Alien-GvaScript
view release on metacpan or search on metacpan
src/paginator.js view on Meta::CPAN
this.index += this.options.step;
this.loadContent();
return true;
}
else
return false;
},
/* Get the prev set of records from the current url */
getPrevPage: function() {
if(this._executing == false && this.hasPrevious()) {
this.index -= this.options.step;
this.loadContent();
return true;
}
else
return false;
},
getLastPage: function() {
if(this._executing == false && this.hasNext()) {
this.index = Math.floor(this.total/this.options.step)*this.options.step+1;
this.loadContent();
return true;
}
else
return false;
},
getFirstPage: function() {
if(this._executing == false && this.hasPrevious()) {
this.index = 1;
this.loadContent();
return true;
}
else
return false;
},
// Core function of the pagination object.
// Get records from url that are in the specified range
loadContent: function() {
if(this._executing == true) return; // still handling a previous request
else this._executing = true;
// Add STEP and INDEX as url parameters
var url = this.url;
this.options.parameters.update({
STEP: this.options.step,
INDEX: this.index,
RESET: this.options.reset
});
this.links_container.hide(); // hide 'em. (one click at a time)
this.list_container.update(new Element('div', {'class': bcss+'-loading'}));
new Ajax.Request(url, {
evalJSON: 'force', // force evaluation of response into responseJSON
method: this.options.method,
parameters: this.options.parameters,
requestTimeout: this.options.timeoutAjax * 1000,
onTimeout: function(req) {
this._executing = false;
this.list_container.update(this.options.errorMsg);
}.bind(this),
// on s'attend à avoir du JSON en retour
onFailure: function(req) {
this._executing = false;
var answer = req.responseJSON;
var msg = answer.error.message || this.options.errorMsg;
this.list_container.update(msg);
}.bind(this),
onSuccess: function(req) {
this._executing = false;
var answer = req.responseJSON;
if(answer) {
var nb_displayed_records = this.options.onSuccess(answer);
this.total = answer.total; // total number of records
this.end_index = Math.min(this.total, this.index+nb_displayed_records-1); // end index of records on current page
this.textElem.innerHTML = (this.total > 0)?
this.index + " à " + this.end_index + " de " + this.total: '0';
_toggleNavigatorsVisibility.apply(this);
}
}.bind(this)
});
}
}
}());
( run in 2.001 seconds using v1.01-cache-2.11-cpan-119454b85a5 )