r98120 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98119‎ | r98120 | r98121 >
Date:09:57, 26 September 2011
Author:catrope
Status:ok
Tags:
Comment:
MoodBar: Fix the bug that I added a FIXME comment for in r98118: when the user changes the filters but does not submit the form, those changed settings should not be used for the More link.
* Save the form state in the formState variable, and use that state everywhere
* Update the form state on load, after loading from cookies, and when the form is submitted
Modified paths:
  • /trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
@@ -3,6 +3,19 @@
44 */
55 jQuery( function( $ ) {
66 /**
 7+ * Saved form state
 8+ */
 9+ var formState = { types: [], username: '' };
 10+
 11+ /**
 12+ * Save the current form state to formState
 13+ */
 14+ function saveFormState() {
 15+ formState.types = getSelectedTypes();
 16+ formState.username = $( '#fbd-filters-username' ).val();
 17+ }
 18+
 19+ /**
720 * Figure out which comment type filters have been selected.
821 * @return array of comment types
922 */
@@ -17,11 +30,12 @@
1831 }
1932
2033 /**
21 - * Set the moodbar-feedback-types and moodbar-feedback-username cookies based on the form state.
 34+ * Set the moodbar-feedback-types and moodbar-feedback-username cookies based on formState.
 35+ * This function uses the form state saved in formState, so you may want to call saveFormState() first.
2236 */
2337 function setCookies() {
24 - $.cookie( 'moodbar-feedback-types', getSelectedTypes().join( '|' ), { 'path': '/', 'expires': 7 } );
25 - $.cookie( 'moodbar-feedback-username', $( '#fbd-filters-username' ).val(), { 'path': '/', 'expires': 7 } );
 38+ $.cookie( 'moodbar-feedback-types', formState.types.join( '|' ), { 'path': '/', 'expires': 7 } );
 39+ $.cookie( 'moodbar-feedback-username', formState.username, { 'path': '/', 'expires': 7 } );
2640 }
2741
2842 /**
@@ -77,12 +91,13 @@
7892 * Load a set of 20 comments into the list. In 'filter' mode, the list is
7993 * blanked before the new comments are loaded. In 'more' mode, the comments are
8094 * loaded at the end of the existing set.
 95+ *
 96+ * This function uses the form state saved in formState, so you may want to call saveFormState() first.
 97+ *
8198 * @param mode string Either 'filter' or 'more'
8299 */
83100 function loadComments( mode ) {
84101 var limit = 20,
85 - username = $( '#fbd-filters-username' ).val(),
86 - types = getSelectedTypes(),
87102 reqData;
88103
89104 if ( mode == 'filter' ) {
@@ -111,11 +126,11 @@
112127 if ( mode == 'more' ) {
113128 reqData['mbccontinue'] = $( '#fbd-list').find( 'li:last' ).data( 'mbccontinue' );
114129 }
115 - if ( types.length ) {
116 - reqData['mbctype'] = types.join( '|' );
 130+ if ( formState.types.length ) {
 131+ reqData['mbctype'] = formState.types.join( '|' );
117132 }
118 - if ( username.length ) {
119 - reqData['mbcuser'] = username;
 133+ if ( formState.username.length ) {
 134+ reqData['mbcuser'] = formState.username;
120135 }
121136
122137 $.ajax( mw.util.wikiScript( 'api' ), {
@@ -175,22 +190,30 @@
176191 } );
177192 }
178193
 194+ // On-load stuff
 195+
179196 $( '#fbd-filters' ).children( 'form' ).submit( function( e ) {
180197 e.preventDefault();
 198+ saveFormState();
181199 setCookies();
182200 loadComments( 'filter' );
183201 } );
184202
185203 $( '#fbd-list-more' ).children( 'a' ).click( function( e ) {
186204 e.preventDefault();
 205+ // We don't call saveFormState() here because we want to use the state of the form
 206+ // at the time it was last filtered. Otherwise, you would see strange behavior if
 207+ // you changed the form state then clicked More.
187208 loadComments( 'more' );
188209 } );
189210
 211+ saveFormState();
190212 var filterType = $( '#fbd-filters' ).children( 'form' ).data( 'filtertype' );
191213 // If filtering already happened on the PHP side, don't load the form state from cookies
192214 if ( filterType != 'filtered' ) {
193215 // Don't do an AJAX filter if we're on an ID view, or if the form is still blank after loadFromCookies()
194216 if ( loadFromCookies() && filterType != 'id' ) {
 217+ saveFormState();
195218 loadComments( 'filter' );
196219 }
197220 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98118MoodBar: Document all the new stuffcatrope08:57, 26 September 2011

Status & tagging log