Merge "Use HTML::hidden to create input fields"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.ChangesListViewModel.js
1 ( function ( mw ) {
2 /**
3 * View model for the changes list
4 *
5 * @mixins OO.EventEmitter
6 *
7 * @constructor
8 */
9 mw.rcfilters.dm.ChangesListViewModel = function MwRcfiltersDmChangesListViewModel() {
10 // Mixin constructor
11 OO.EventEmitter.call( this );
12
13 this.valid = true;
14 this.newChangesExist = false;
15 this.nextFrom = null;
16 this.liveUpdate = false;
17 };
18
19 /* Initialization */
20 OO.initClass( mw.rcfilters.dm.ChangesListViewModel );
21 OO.mixinClass( mw.rcfilters.dm.ChangesListViewModel, OO.EventEmitter );
22
23 /* Events */
24
25 /**
26 * @event invalidate
27 *
28 * The list of changes is now invalid (out of date)
29 */
30
31 /**
32 * @event update
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
37 *
38 * The list of changes has been updated
39 */
40
41 /**
42 * @event newChangesExist
43 * @param {boolean} newChangesExist
44 *
45 * The existence of changes newer than those currently displayed has changed.
46 */
47
48 /**
49 * @event liveUpdateChange
50 * @param {boolean} enable
51 *
52 * The state of the 'live update' feature has changed.
53 */
54
55 /* Methods */
56
57 /**
58 * Invalidate the list of changes
59 *
60 * @fires invalidate
61 */
62 mw.rcfilters.dm.ChangesListViewModel.prototype.invalidate = function () {
63 if ( this.valid ) {
64 this.valid = false;
65 this.emit( 'invalidate' );
66 }
67 };
68
69 /**
70 * Update the model with an updated list of changes
71 *
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
76 * @fires update
77 */
78 mw.rcfilters.dm.ChangesListViewModel.prototype.update = function ( changesListContent, $fieldset, isInitialDOM, separateOldAndNew ) {
79 var from = this.nextFrom;
80 this.valid = true;
81 this.extractNextFrom( $fieldset );
82 this.emit( 'update', changesListContent, $fieldset, isInitialDOM, separateOldAndNew ? from : null );
83 };
84
85 /**
86 * Specify whether new changes exist
87 *
88 * @param {boolean} newChangesExist
89 * @fires newChangesExist
90 */
91 mw.rcfilters.dm.ChangesListViewModel.prototype.setNewChangesExist = function ( newChangesExist ) {
92 if ( newChangesExist !== this.newChangesExist ) {
93 this.newChangesExist = newChangesExist;
94 this.emit( 'newChangesExist', newChangesExist );
95 }
96 };
97
98 /**
99 * @return {boolean} Whether new changes exist
100 */
101 mw.rcfilters.dm.ChangesListViewModel.prototype.getNewChangesExist = function () {
102 return this.newChangesExist;
103 };
104
105 /**
106 * Extract the value of the 'from' parameter from a link in the field set
107 *
108 * @param {jQuery} $fieldset
109 */
110 mw.rcfilters.dm.ChangesListViewModel.prototype.extractNextFrom = function ( $fieldset ) {
111 this.nextFrom = $fieldset.find( '.rclistfrom > a' ).data( 'params' ).from;
112 };
113
114 /**
115 * @return {string} The 'from' parameter that can be used to query new changes
116 */
117 mw.rcfilters.dm.ChangesListViewModel.prototype.getNextFrom = function () {
118 return this.nextFrom;
119 };
120
121 /**
122 * Toggle the 'live update' feature on/off
123 *
124 * @param {boolean} enable
125 */
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 );
131 }
132 };
133
134 /**
135 * @return {boolean} The 'live update' feature is enabled
136 */
137 mw.rcfilters.dm.ChangesListViewModel.prototype.getLiveUpdate = function () {
138 return this.liveUpdate;
139 };
140
141 }( mediaWiki ) );