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} isDatabaseTimeout Whether this is an error state due to a database query
37 * @param {boolean} isInitialDOM Whether the previous dom variables are from the initial page load
38 * @param {boolean} fromLiveUpdate These are new changes fetched via Live Update
40 * The list of changes has been updated
44 * @event newChangesExist
45 * @param {boolean} newChangesExist
47 * The existence of changes newer than those currently displayed has changed.
51 * @event liveUpdateChange
52 * @param {boolean} enable
54 * The state of the 'live update' feature has changed.
60 * Invalidate the list of changes
64 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.invalidate = function () {
67 this.emit( 'invalidate' );
72 * Update the model with an updated list of changes
74 * @param {jQuery|string} changesListContent
75 * @param {jQuery} $fieldset
76 * @param {boolean} isDatabaseTimeout Whether this is an error state due to a database query
78 * @param {boolean} [isInitialDOM] Using the initial (already attached) DOM elements
79 * @param {boolean} [separateOldAndNew] Whether a logical separation between old and new changes is needed
82 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.update = function ( changesListContent
, $fieldset
, isDatabaseTimeout
, isInitialDOM
, separateOldAndNew
) {
83 var from = this.nextFrom
;
85 this.extractNextFrom( $fieldset
);
86 this.checkForUnseenWatchedChanges( changesListContent
);
87 this.emit( 'update', changesListContent
, $fieldset
, isDatabaseTimeout
, isInitialDOM
, separateOldAndNew
? from : null );
91 * Specify whether new changes exist
93 * @param {boolean} newChangesExist
94 * @fires newChangesExist
96 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.setNewChangesExist = function ( newChangesExist
) {
97 if ( newChangesExist
!== this.newChangesExist
) {
98 this.newChangesExist
= newChangesExist
;
99 this.emit( 'newChangesExist', newChangesExist
);
104 * @return {boolean} Whether new changes exist
106 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNewChangesExist = function () {
107 return this.newChangesExist
;
111 * Extract the value of the 'from' parameter from a link in the field set
113 * @param {jQuery} $fieldset
115 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.extractNextFrom = function ( $fieldset
) {
116 var data
= $fieldset
.find( '.rclistfrom > a, .wlinfo' ).data( 'params' );
117 this.nextFrom
= data
? data
.from : null;
121 * @return {string} The 'from' parameter that can be used to query new changes
123 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getNextFrom = function () {
124 return this.nextFrom
;
128 * Toggle the 'live update' feature on/off
130 * @param {boolean} enable
132 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.toggleLiveUpdate = function ( enable
) {
133 enable
= enable
=== undefined ? !this.liveUpdate
: enable
;
134 if ( enable
!== this.liveUpdate
) {
135 this.liveUpdate
= enable
;
136 this.emit( 'liveUpdateChange', this.liveUpdate
);
141 * @return {boolean} The 'live update' feature is enabled
143 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.getLiveUpdate = function () {
144 return this.liveUpdate
;
148 * Check if some of the given changes watched and unseen
150 * @param {jQuery|string} changeslistContent
152 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.checkForUnseenWatchedChanges = function ( changeslistContent
) {
153 this.unseenWatchedChanges
= changeslistContent
!== 'NO_RESULTS' &&
154 changeslistContent
.find( '.mw-changeslist-line-watched' ).length
> 0;
158 * @return {boolean} Whether some of the current changes are watched and unseen
160 mw
.rcfilters
.dm
.ChangesListViewModel
.prototype.hasUnseenWatchedChanges = function () {
161 return this.unseenWatchedChanges
;