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 this.extractNextFrom( $fieldset
);
83 this.checkForUnseenWatchedChanges( changesListContent
);
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 var data
= $fieldset
.find( '.rclistfrom > a' ).data( 'params' );
114 this.nextFrom
= data
? data
.from : null;
118 * @return {string} The 'from' parameter that can be used to query new changes
120 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNextFrom = function () {
121 return this.nextFrom
;
125 * Toggle the 'live update' feature on/off
127 * @param {boolean} enable
129 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.toggleLiveUpdate = function ( enable
) {
130 enable
= enable
=== undefined ? !this.liveUpdate
: enable
;
131 if ( enable
!== this.liveUpdate
) {
132 this.liveUpdate
= enable
;
133 this.emit( 'liveUpdateChange', this.liveUpdate
);
138 * @return {boolean} The 'live update' feature is enabled
140 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getLiveUpdate = function () {
141 return this.liveUpdate
;
145 * Check if some of the given changes watched and unseen
147 * @param {jQuery|string} changeslistContent
149 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.checkForUnseenWatchedChanges = function ( changeslistContent
) {
150 this.unseenWatchedChanges
= changeslistContent
!== 'NO_RESULTS' &&
151 changeslistContent
.find( '.mw-changeslist-line-watched' ).length
> 0;
155 * @return {boolean} Whether some of the current changes are watched and unseen
157 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.hasUnseenWatchedChanges = function () {
158 return this.unseenWatchedChanges
;