Debian Codegraph @

extensions/Echo/modules/model/mw.echo.dm.FiltersModel.js

raw symbols SCIP
1 ( function () {
2 /**
3 * Filters model for displaying filtered notification list.
4 *
5 * @class
6 * @mixes OO.EventEmitter
7 *
8 * @constructor
9 * @param {Object} config Configuration object
10 * @param {string} [config.readState='all'] Notifications read state. Allowed
11 * values are 'all', 'read' or 'unread'.
12 * @param {string} [config.selectedSource] Currently selected source
13 */
14 mw.echo.dm.FiltersModel = function MwEchoDmFiltersModel( config ) {
15 config = config || {};
16
17 // Mixin constructor
18 OO.EventEmitter.call( this );
19
20 this.readState = config.readState || 'all';
21
22 this.sourcePagesModel = new mw.echo.dm.SourcePagesModel();
23 this.selectedSource = config.selectedSource || '';
24 this.selectedSourcePage = null;
25 };
26
27 /* Initialization */
28
29 OO.initClass( mw.echo.dm.FiltersModel );
30 OO.mixinClass( mw.echo.dm.FiltersModel, OO.EventEmitter );
31
32 /* Events */
33
34 /**
35 * The filters have been updated
36 *
37 * @event mw.echo.dm.FiltersModel#update
38 */
39
40 /* Methods */
41
42 /**
43 * Set the read state filter
44 *
45 * @param {string} readState Notifications read state
46 * @fires mw.echo.dm.FiltersModel#update
47 */
48 mw.echo.dm.FiltersModel.prototype.setReadState = function ( readState ) {
49 const allowed = [ 'all', 'read', 'unread' ];
50 if (
51 this.readState !== readState &&
52 allowed.indexOf( readState ) > -1
53 ) {
54 this.readState = readState;
55 this.emit( 'update' );
56 }
57 };
58
59 /**
60 * Get the read state filter
61 *
62 * @return {string} Notifications read state
63 */
64 mw.echo.dm.FiltersModel.prototype.getReadState = function () {
65 return this.readState;
66 };
67
68 /**
69 * Set the currently selected source and page.
70 * If no page is given, or if page is null, the source title
71 * is assumed to be selected.
72 *
73 * @param {string} source Source name
74 * @param {string} [page] Page name
75 */
76 mw.echo.dm.FiltersModel.prototype.setCurrentSourcePage = function ( source, page ) {
77 this.sourcePagesModel.setCurrentSourcePage( source, page );
78 };
79
80 /**
81 * Get the total count of a source. This sums the count of all
82 * sub pages in that source.
83 *
84 * @param {string} source Symbolic name for source
85 * @return {number} Total count
86 */
87 mw.echo.dm.FiltersModel.prototype.getSourceTotalCount = function ( source ) {
88 return this.sourcePagesModel.getSourceTotalCount( source );
89 };
90
91 /**
92 * Get the source page model
93 *
94 * @return {mw.echo.dm.SourcePagesModel} Source pages model
95 */
96 mw.echo.dm.FiltersModel.prototype.getSourcePagesModel = function () {
97 return this.sourcePagesModel;
98 };
99
100 }() );