Merge "Use HTML::hidden to create input fields"
[lhc/web/wiklou.git] / resources / src / mediawiki.rcfilters / dm / mw.rcfilters.dm.ChangesListViewModel.js
index 49c0b82..f221b2b 100644 (file)
@@ -11,6 +11,9 @@
                OO.EventEmitter.call( this );
 
                this.valid = true;
+               this.newChangesExist = false;
+               this.nextFrom = null;
+               this.liveUpdate = false;
        };
 
        /* Initialization */
 
        /**
         * @event update
-        * @param {jQuery|string} changesListContent
-        * @param {jQuery} $fieldset
+        * @param {jQuery|string} $changesListContent List of changes
+        * @param {jQuery} $fieldset Server-generated form
+        * @param {boolean} isInitialDOM Whether the previous dom variables are from the initial page load
+        * @param {boolean} fromLiveUpdate These are new changes fetched via Live Update
+        *
+        * The list of changes has been updated
+        */
+
+       /**
+        * @event newChangesExist
+        * @param {boolean} newChangesExist
+        *
+        * The existence of changes newer than those currently displayed has changed.
+        */
+
+       /**
+        * @event liveUpdateChange
+        * @param {boolean} enable
         *
-        * The list of change is now up to date
+        * The state of the 'live update' feature has changed.
         */
 
        /* Methods */
         * @param {jQuery|string} changesListContent
         * @param {jQuery} $fieldset
         * @param {boolean} [isInitialDOM] Using the initial (already attached) DOM elements
+        * @param {boolean} [separateOldAndNew] Whether a logical separation between old and new changes is needed
+        * @fires update
         */
-       mw.rcfilters.dm.ChangesListViewModel.prototype.update = function ( changesListContent, $fieldset, isInitialDOM ) {
+       mw.rcfilters.dm.ChangesListViewModel.prototype.update = function ( changesListContent, $fieldset, isInitialDOM, separateOldAndNew ) {
+               var from = this.nextFrom;
                this.valid = true;
-               this.emit( 'update', changesListContent, $fieldset, isInitialDOM );
+               this.extractNextFrom( $fieldset );
+               this.emit( 'update', changesListContent, $fieldset, isInitialDOM, separateOldAndNew ? from : null );
+       };
+
+       /**
+        * Specify whether new changes exist
+        *
+        * @param {boolean} newChangesExist
+        * @fires newChangesExist
+        */
+       mw.rcfilters.dm.ChangesListViewModel.prototype.setNewChangesExist = function ( newChangesExist ) {
+               if ( newChangesExist !== this.newChangesExist ) {
+                       this.newChangesExist = newChangesExist;
+                       this.emit( 'newChangesExist', newChangesExist );
+               }
+       };
+
+       /**
+        * @return {boolean} Whether new changes exist
+        */
+       mw.rcfilters.dm.ChangesListViewModel.prototype.getNewChangesExist = function () {
+               return this.newChangesExist;
+       };
+
+       /**
+        * Extract the value of the 'from' parameter from a link in the field set
+        *
+        * @param {jQuery} $fieldset
+        */
+       mw.rcfilters.dm.ChangesListViewModel.prototype.extractNextFrom = function ( $fieldset ) {
+               this.nextFrom = $fieldset.find( '.rclistfrom > a' ).data( 'params' ).from;
+       };
+
+       /**
+        * @return {string} The 'from' parameter that can be used to query new changes
+        */
+       mw.rcfilters.dm.ChangesListViewModel.prototype.getNextFrom = function () {
+               return this.nextFrom;
+       };
+
+       /**
+        * Toggle the 'live update' feature on/off
+        *
+        * @param {boolean} enable
+        */
+       mw.rcfilters.dm.ChangesListViewModel.prototype.toggleLiveUpdate = function ( enable ) {
+               enable = enable === undefined ? !this.liveUpdate : enable;
+               if ( enable !== this.liveUpdate ) {
+                       this.liveUpdate = enable;
+                       this.emit( 'liveUpdateChange', this.liveUpdate );
+               }
+       };
+
+       /**
+        * @return {boolean} The 'live update' feature is enabled
+        */
+       mw.rcfilters.dm.ChangesListViewModel.prototype.getLiveUpdate = function () {
+               return this.liveUpdate;
        };
 
 }( mediaWiki ) );