3 * View model for the changes list
5 * @mixins OO.EventEmitter
9 mw
.rcfilters
.dm
.ChangesListViewModel
= function MwRcfiltersDmChangesListViewModel() {
11 OO
.EventEmitter
.call( this );
14 this.newChangesExist
= false;
16 this.liveUpdate
= false;
20 OO
.initClass( mw
.rcfilters
.dm
.ChangesListViewModel
);
21 OO
.mixinClass( mw
.rcfilters
.dm
.ChangesListViewModel
, OO
.EventEmitter
);
28 * The list of changes is now invalid (out of date)
33 * @param {jQuery|string} $changesListContent List of changes
34 * @param {jQuery} $fieldset Server-generated form
35 * @param {boolean} isInitialDOM Whether the previous dom variables are from the initial page load
36 * @param {boolean} fromLiveUpdate These are new changes fetched via Live Update
38 * The list of changes has been updated
42 * @event newChangesExist
43 * @param {boolean} newChangesExist
45 * The existence of changes newer than those currently displayed has changed.
49 * @event liveUpdateChange
50 * @param {boolean} enable
52 * The state of the 'live update' feature has changed.
58 * Invalidate the list of changes
62 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.invalidate = function () {
65 this.emit( 'invalidate' );
70 * Update the model with an updated list of changes
72 * @param {jQuery|string} changesListContent
73 * @param {jQuery} $fieldset
74 * @param {boolean} [isInitialDOM] Using the initial (already attached) DOM elements
75 * @param {boolean} [fromLiveUpdate] These are new changes fetched via Live Update
78 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.update = function ( changesListContent
, $fieldset
, isInitialDOM
, fromLiveUpdate
) {
79 var from = this.nextFrom
;
81 this.extractNextFrom( $fieldset
);
82 this.emit( 'update', changesListContent
, $fieldset
, isInitialDOM
, fromLiveUpdate
? from : null );
86 * Specify whether new changes exist
88 * @param {boolean} newChangesExist
89 * @fires newChangesExist
91 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.setNewChangesExist = function ( newChangesExist
) {
92 if ( newChangesExist
!== this.newChangesExist
) {
93 this.newChangesExist
= newChangesExist
;
94 this.emit( 'newChangesExist', newChangesExist
);
99 * @return {boolean} Whether new changes exist
101 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNewChangesExist = function () {
102 return this.newChangesExist
;
106 * Extract the value of the 'from' parameter from a link in the field set
108 * @param {jQuery} $fieldset
110 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.extractNextFrom = function ( $fieldset
) {
111 this.nextFrom
= $fieldset
.find( '.rclistfrom > a' ).data( 'params' ).from;
115 * @return {string} The 'from' parameter that can be used to query new changes
117 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNextFrom = function () {
118 return this.nextFrom
;
122 * Toggle the 'live update' feature on/off
124 * @param {boolean} enable
126 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.toggleLiveUpdate = function ( enable
) {
127 enable
= enable
=== undefined ? !this.liveUpdate
: enable
;
128 if ( enable
!== this.liveUpdate
) {
129 this.liveUpdate
= enable
;
130 this.emit( 'liveUpdateChange', this.liveUpdate
);
135 * @return {boolean} The 'live update' feature is enabled
137 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getLiveUpdate = function () {
138 return this.liveUpdate
;