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} [separateOldAndNew] Whether a logical separation between old and new changes is needed
78 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.update = function ( changesListContent
, $fieldset
, isInitialDOM
, separateOldAndNew
) {
79 var from = this.nextFrom
;
81 if ( mw
.rcfilters
.featureFlags
.liveUpdate
) {
82 this.extractNextFrom( $fieldset
);
84 this.emit( 'update', changesListContent
, $fieldset
, isInitialDOM
, separateOldAndNew
? from : null );
88 * Specify whether new changes exist
90 * @param {boolean} newChangesExist
91 * @fires newChangesExist
93 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.setNewChangesExist = function ( newChangesExist
) {
94 if ( newChangesExist
!== this.newChangesExist
) {
95 this.newChangesExist
= newChangesExist
;
96 this.emit( 'newChangesExist', newChangesExist
);
101 * @return {boolean} Whether new changes exist
103 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNewChangesExist = function () {
104 return this.newChangesExist
;
108 * Extract the value of the 'from' parameter from a link in the field set
110 * @param {jQuery} $fieldset
112 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.extractNextFrom = function ( $fieldset
) {
113 this.nextFrom
= $fieldset
.find( '.rclistfrom > a' ).data( 'params' ).from;
117 * @return {string} The 'from' parameter that can be used to query new changes
119 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNextFrom = function () {
120 return this.nextFrom
;
124 * Toggle the 'live update' feature on/off
126 * @param {boolean} enable
128 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.toggleLiveUpdate = function ( enable
) {
129 enable
= enable
=== undefined ? !this.liveUpdate
: enable
;
130 if ( enable
!== this.liveUpdate
) {
131 this.liveUpdate
= enable
;
132 this.emit( 'liveUpdateChange', this.liveUpdate
);
137 * @return {boolean} The 'live update' feature is enabled
139 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getLiveUpdate = function () {
140 return this.liveUpdate
;