2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-03-16 22:47:20 +00:00
|
|
|
/**
|
|
|
|
* Pagination model for echo notifications pages.
|
|
|
|
*
|
|
|
|
* @class
|
2024-04-30 14:21:54 +00:00
|
|
|
* @mixes OO.EventEmitter
|
2016-03-16 22:47:20 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {string} [config.pageNext] The continue value of the next page
|
|
|
|
* @param {number} [config.itemsPerPage] The number of items per page
|
|
|
|
* @param {number} [config.currentPageItemCount] The number of items that are in the
|
2016-07-14 00:03:57 +00:00
|
|
|
* current page. If not given, the initial count defaults to the total number
|
|
|
|
* of items per page.
|
2016-03-16 22:47:20 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel = function MwEchoDmPaginationModel( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
2016-05-27 20:39:15 +00:00
|
|
|
// Mixin constructor
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
2016-03-16 22:47:20 +00:00
|
|
|
this.pagesContinue = [];
|
2016-09-16 00:05:04 +00:00
|
|
|
this.itemsPerPage = config.itemsPerPage || 25;
|
2016-07-14 00:03:57 +00:00
|
|
|
this.currentPageItemCount = config.currentPageItemCount || this.itemsPerPage;
|
2016-03-16 22:47:20 +00:00
|
|
|
|
|
|
|
// Set initial page
|
|
|
|
this.currPageIndex = 0;
|
|
|
|
this.pagesContinue[ 0 ] = '';
|
|
|
|
|
|
|
|
// If a next page is given, fill it
|
|
|
|
if ( config.pageNext ) {
|
|
|
|
this.setPageContinue( 1, config.pageNext );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.initClass( mw.echo.dm.PaginationModel );
|
2016-05-27 20:39:15 +00:00
|
|
|
OO.mixinClass( mw.echo.dm.PaginationModel, OO.EventEmitter );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pagination information was updated
|
2024-04-30 14:21:54 +00:00
|
|
|
*
|
|
|
|
* @event mw.echo.dm.PaginationModel#update
|
2016-05-27 20:39:15 +00:00
|
|
|
*/
|
2016-03-16 22:47:20 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
/**
|
|
|
|
* Reset pagination data
|
|
|
|
*
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.dm.PaginationModel#update
|
2016-05-31 22:32:16 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.reset = function () {
|
|
|
|
this.pagesContinue = [];
|
|
|
|
this.currPageIndex = 0;
|
2016-07-14 00:03:57 +00:00
|
|
|
this.currentPageItemCount = this.itemsPerPage;
|
2016-05-31 22:32:16 +00:00
|
|
|
|
|
|
|
this.emit( 'update' );
|
|
|
|
};
|
2016-03-16 22:47:20 +00:00
|
|
|
/**
|
|
|
|
* Set a page index with its 'continue' value, used for API fetching
|
|
|
|
*
|
|
|
|
* @param {number} page Page index
|
|
|
|
* @param {string} continueVal Continue string value
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.dm.PaginationModel#update
|
2016-03-16 22:47:20 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.setPageContinue = function ( page, continueVal ) {
|
2016-05-27 20:39:15 +00:00
|
|
|
if ( this.pagesContinue[ page ] !== continueVal ) {
|
2016-03-16 22:47:20 +00:00
|
|
|
this.pagesContinue[ page ] = continueVal;
|
2016-05-27 20:39:15 +00:00
|
|
|
this.emit( 'update' );
|
2016-03-16 22:47:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the 'continue' value of a certain page
|
|
|
|
*
|
|
|
|
* @param {number} page Page index
|
|
|
|
* @return {string} Continue string value
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.getPageContinue = function ( page ) {
|
|
|
|
return this.pagesContinue[ page ];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current page index
|
|
|
|
*
|
|
|
|
* @return {number} Current page index
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.getCurrPageIndex = function () {
|
|
|
|
return this.currPageIndex;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current page index
|
|
|
|
*
|
2024-08-11 15:51:26 +00:00
|
|
|
* @internal
|
2016-03-16 22:47:20 +00:00
|
|
|
* @param {number} index Current page index
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.setCurrPageIndex = function ( index ) {
|
|
|
|
this.currPageIndex = index;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move forward to the next page
|
2016-05-27 20:39:15 +00:00
|
|
|
*
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.dm.PaginationModel#update
|
2016-03-16 22:47:20 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.forwards = function () {
|
|
|
|
if ( this.hasNextPage() ) {
|
|
|
|
this.setCurrPageIndex( this.currPageIndex + 1 );
|
2016-05-27 20:39:15 +00:00
|
|
|
this.emit( 'update' );
|
2016-03-16 22:47:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Move backwards to the previous page
|
2016-05-27 20:39:15 +00:00
|
|
|
*
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.dm.PaginationModel#update
|
2016-03-16 22:47:20 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.backwards = function () {
|
|
|
|
if ( this.hasPrevPage() ) {
|
|
|
|
this.setCurrPageIndex( this.currPageIndex - 1 );
|
2016-05-27 20:39:15 +00:00
|
|
|
this.emit( 'update' );
|
2016-03-16 22:47:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the previous page continue value
|
|
|
|
*
|
|
|
|
* @return {string} Previous page continue value
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.getPrevPageContinue = function () {
|
2016-09-16 00:05:04 +00:00
|
|
|
return this.pagesContinue[ this.currPageIndex - 1 ] || '';
|
2016-03-16 22:47:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current page continue value
|
|
|
|
*
|
|
|
|
* @return {string} Current page continue value
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.getCurrPageContinue = function () {
|
2016-09-16 00:05:04 +00:00
|
|
|
return this.pagesContinue[ this.currPageIndex ] || '';
|
2016-03-16 22:47:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next page continue value
|
|
|
|
*
|
|
|
|
* @return {string} Next page continue value
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.getNextPageContinue = function () {
|
2016-09-16 00:05:04 +00:00
|
|
|
return this.pagesContinue[ this.currPageIndex + 1 ] || '';
|
2016-03-16 22:47:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the next page continue value
|
|
|
|
*
|
|
|
|
* @param {string} cont Next page continue value
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.setNextPageContinue = function ( cont ) {
|
2016-05-27 20:39:15 +00:00
|
|
|
this.setPageContinue( this.currPageIndex + 1, cont );
|
2016-03-16 22:47:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a previous page exists
|
|
|
|
*
|
|
|
|
* @return {boolean} Previous page exists
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.hasPrevPage = function () {
|
|
|
|
return this.currPageIndex > 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a next page exists
|
|
|
|
*
|
|
|
|
* @return {boolean} Next page exists
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.hasNextPage = function () {
|
|
|
|
return !!this.pagesContinue[ this.currPageIndex + 1 ];
|
|
|
|
};
|
2016-05-31 00:12:31 +00:00
|
|
|
|
|
|
|
/**
|
2016-07-14 00:03:57 +00:00
|
|
|
* Set the number of items in the current page
|
2016-05-31 00:12:31 +00:00
|
|
|
*
|
|
|
|
* @param {number} count Number of items
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.dm.PaginationModel#update
|
2016-05-31 00:12:31 +00:00
|
|
|
*/
|
2016-07-14 00:03:57 +00:00
|
|
|
mw.echo.dm.PaginationModel.prototype.setCurrentPageItemCount = function ( count ) {
|
|
|
|
if ( this.currentPageItemCount !== count ) {
|
|
|
|
this.currentPageItemCount = count;
|
|
|
|
this.emit( 'update' );
|
|
|
|
}
|
2016-05-31 00:12:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-07-14 00:03:57 +00:00
|
|
|
* Get the number of items in the current page
|
2016-05-31 00:12:31 +00:00
|
|
|
*
|
|
|
|
* @return {number} Number of items
|
|
|
|
*/
|
2016-07-14 00:03:57 +00:00
|
|
|
mw.echo.dm.PaginationModel.prototype.getCurrentPageItemCount = function () {
|
|
|
|
return this.currentPageItemCount;
|
2016-05-31 00:12:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the number of items per page
|
|
|
|
*
|
|
|
|
* @param {number} count Number of items per page
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.setItemsPerPage = function ( count ) {
|
|
|
|
this.itemsPerPage = count;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of items per page
|
|
|
|
*
|
|
|
|
* @return {number} Number of items per page
|
|
|
|
*/
|
|
|
|
mw.echo.dm.PaginationModel.prototype.getItemsPerPage = function () {
|
|
|
|
return this.itemsPerPage;
|
|
|
|
};
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|