2018-11-12 13:56:38 +00:00
|
|
|
( function () {
|
2016-05-20 04:22:41 +00:00
|
|
|
/**
|
|
|
|
* Filters model for displaying filtered notification list.
|
|
|
|
*
|
|
|
|
* @class
|
2024-04-30 14:21:54 +00:00
|
|
|
* @mixes OO.EventEmitter
|
2016-05-20 04:22:41 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config Configuration object
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {string} [config.readState='all'] Notifications read state. Allowed
|
2016-05-20 04:22:41 +00:00
|
|
|
* values are 'all', 'read' or 'unread'.
|
2024-05-27 01:43:21 +00:00
|
|
|
* @param {string} [config.selectedSource] Currently selected source
|
2016-05-20 04:22:41 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.FiltersModel = function MwEchoDmFiltersModel( config ) {
|
|
|
|
config = config || {};
|
|
|
|
|
|
|
|
// Mixin constructor
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
2016-05-31 22:32:16 +00:00
|
|
|
this.readState = config.readState || 'all';
|
|
|
|
|
|
|
|
this.sourcePagesModel = new mw.echo.dm.SourcePagesModel();
|
|
|
|
this.selectedSource = config.selectedSource || '';
|
|
|
|
this.selectedSourcePage = null;
|
2016-05-20 04:22:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
OO.initClass( mw.echo.dm.FiltersModel );
|
|
|
|
OO.mixinClass( mw.echo.dm.FiltersModel, OO.EventEmitter );
|
|
|
|
|
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The filters have been updated
|
2024-04-30 14:21:54 +00:00
|
|
|
*
|
|
|
|
* @event mw.echo.dm.FiltersModel#update
|
2016-05-20 04:22:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the read state filter
|
|
|
|
*
|
|
|
|
* @param {string} readState Notifications read state
|
2024-04-30 14:21:54 +00:00
|
|
|
* @fires mw.echo.dm.FiltersModel#update
|
2016-05-20 04:22:41 +00:00
|
|
|
*/
|
|
|
|
mw.echo.dm.FiltersModel.prototype.setReadState = function ( readState ) {
|
|
|
|
var allowed = [ 'all', 'read', 'unread' ];
|
|
|
|
if (
|
|
|
|
this.readState !== readState &&
|
|
|
|
allowed.indexOf( readState ) > -1
|
|
|
|
) {
|
|
|
|
this.readState = readState;
|
|
|
|
this.emit( 'update' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the read state filter
|
|
|
|
*
|
|
|
|
* @return {string} Notifications read state
|
|
|
|
*/
|
|
|
|
mw.echo.dm.FiltersModel.prototype.getReadState = function () {
|
|
|
|
return this.readState;
|
|
|
|
};
|
2016-05-31 22:32:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the currently selected source and page.
|
|
|
|
* If no page is given, or if page is null, the source title
|
|
|
|
* is assumed to be selected.
|
|
|
|
*
|
|
|
|
* @param {string} source Source name
|
|
|
|
* @param {string} [page] Page name
|
|
|
|
*/
|
|
|
|
mw.echo.dm.FiltersModel.prototype.setCurrentSourcePage = function ( source, page ) {
|
|
|
|
this.sourcePagesModel.setCurrentSourcePage( source, page );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the total count of a source. This sums the count of all
|
|
|
|
* sub pages in that source.
|
|
|
|
*
|
|
|
|
* @param {string} source Symbolic name for source
|
|
|
|
* @return {number} Total count
|
|
|
|
*/
|
|
|
|
mw.echo.dm.FiltersModel.prototype.getSourceTotalCount = function ( source ) {
|
|
|
|
return this.sourcePagesModel.getSourceTotalCount( source );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the source page model
|
|
|
|
*
|
|
|
|
* @return {mw.echo.dm.SourcePagesModel} Source pages model
|
|
|
|
*/
|
|
|
|
mw.echo.dm.FiltersModel.prototype.getSourcePagesModel = function () {
|
|
|
|
return this.sourcePagesModel;
|
|
|
|
};
|
|
|
|
|
2018-11-12 13:56:38 +00:00
|
|
|
}() );
|