d7042ff3c6a4f59fbb46f11ba9c2146409f4cf50
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;
17 this.unseenWatchedChanges
= false;
21 OO
.initClass( mw
.rcfilters
.dm
.ChangesListViewModel
);
22 OO
.mixinClass( mw
.rcfilters
.dm
.ChangesListViewModel
, OO
.EventEmitter
);
29 * The list of changes is now invalid (out of date)
34 * @param {jQuery|string} $changesListContent List of changes
35 * @param {jQuery} $fieldset Server-generated form
36 * @param {boolean} isInitialDOM Whether the previous dom variables are from the initial page load
37 * @param {boolean} fromLiveUpdate These are new changes fetched via Live Update
39 * The list of changes has been updated
43 * @event newChangesExist
44 * @param {boolean} newChangesExist
46 * The existence of changes newer than those currently displayed has changed.
50 * @event liveUpdateChange
51 * @param {boolean} enable
53 * The state of the 'live update' feature has changed.
59 * Invalidate the list of changes
63 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.invalidate = function () {
66 this.emit( 'invalidate' );
71 * Update the model with an updated list of changes
73 * @param {jQuery|string} changesListContent
74 * @param {jQuery} $fieldset
75 * @param {boolean} [isInitialDOM] Using the initial (already attached) DOM elements
76 * @param {boolean} [separateOldAndNew] Whether a logical separation between old and new changes is needed
79 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.update = function ( changesListContent
, $fieldset
, isInitialDOM
, separateOldAndNew
) {
80 var from = this.nextFrom
;
82 if ( mw
.rcfilters
.featureFlags
.liveUpdate
) {
83 this.extractNextFrom( $fieldset
);
85 this.checkForUnseenWatchedChanges( changesListContent
);
86 this.emit( 'update', changesListContent
, $fieldset
, isInitialDOM
, separateOldAndNew
? from : null );
90 * Specify whether new changes exist
92 * @param {boolean} newChangesExist
93 * @fires newChangesExist
95 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.setNewChangesExist = function ( newChangesExist
) {
96 if ( newChangesExist
!== this.newChangesExist
) {
97 this.newChangesExist
= newChangesExist
;
98 this.emit( 'newChangesExist', newChangesExist
);
103 * @return {boolean} Whether new changes exist
105 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNewChangesExist = function () {
106 return this.newChangesExist
;
110 * Extract the value of the 'from' parameter from a link in the field set
112 * @param {jQuery} $fieldset
114 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.extractNextFrom = function ( $fieldset
) {
115 this.nextFrom
= $fieldset
.find( '.rclistfrom > a' ).data( 'params' ).from;
119 * @return {string} The 'from' parameter that can be used to query new changes
121 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNextFrom = function () {
122 return this.nextFrom
;
126 * Toggle the 'live update' feature on/off
128 * @param {boolean} enable
130 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.toggleLiveUpdate = function ( enable
) {
131 enable
= enable
=== undefined ? !this.liveUpdate
: enable
;
132 if ( enable
!== this.liveUpdate
) {
133 this.liveUpdate
= enable
;
134 this.emit( 'liveUpdateChange', this.liveUpdate
);
139 * @return {boolean} The 'live update' feature is enabled
141 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getLiveUpdate = function () {
142 return this.liveUpdate
;
146 * Check if some of the given changes watched and unseen
148 * @param {jQuery|string} changeslistContent
150 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.checkForUnseenWatchedChanges = function ( changeslistContent
) {
151 this.unseenWatchedChanges
= changeslistContent
!== 'NO_RESULTS' &&
152 changeslistContent
.find( '.mw-changeslist-line-watched' ).length
> 0;
156 * @return {boolean} Whether some of the current changes are watched and unseen
158 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.hasUnseenWatchedChanges = function () {
159 return this.unseenWatchedChanges
;