r86532 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86531‎ | r86532 | r86533 >
Date:19:36, 20 April 2011
Author:krinkle
Status:deferred (Comments)
Tags:
Comment:
Continue emailcapture + fix minor regression bug
* Don't cache $el.val(), just $el (value changes ofcourse!)
* Removed code that would populate helpimprove-email. There is no query module for emailcapture, and today's meeting has learned we don't need this. Instead we set a cookie if the helpimprove-email was successfully used and if that cookie is set, we won't show the helpimprove-email option again (just like pitch-**)
* When appropiate, submitting the form will also make a POST request to action=emailcapture.
* If emailcapture is done, cookie is set so it won't be shown again
* new showHelpimprove variable. Currently checks cookie and is-anonymoous. Bucket stuff would override this variable if needed. Defaults to true, bucket should only override to false.
Modified paths:
  • /trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js
@@ -74,7 +74,7 @@
7575 </div>\
7676 </div>\
7777 <div style="clear:both;"></div>\
78 - <button class="articleFeedback-submit articleFeedback-visibleWith-form" type="submit" disabled><html:msg key="form-panel-submit" /></button>\
 78+ <button class="articleFeedback-submit articleFeedback-visibleWith-form" type="submit" disabled="disabled"><html:msg key="form-panel-submit" /></button>\
7979 <div class="articleFeedback-success articleFeedback-visibleWith-form"><span><html:msg key="form-panel-success" /></span></div>\
8080 <div style="clear:both;"></div>\
8181 <div class="articleFeedback-notices articleFeedback-visibleWith-form">\
@@ -167,7 +167,7 @@
168168 'enableHelpimprove': function( $helpimprove ) {
169169 $helpimprove
170170 .find( 'input:checkbox[value=on]' )
171 - .attr( 'disabled', false )
 171+ .removeAttr( 'disabled' )
172172 .end()
173173 .find( '.articleFeedback-helpimprove-disabled' )
174174 .removeClass( 'articleFeedback-helpimprove-disabled' );
@@ -176,7 +176,7 @@
177177 var context = this;
178178 $.articleFeedback.fn.enableSubmission.call( context, false );
179179 context.$ui.find( '.articleFeedback-lock' ).show();
180 - // Build data from form values
 180+ // Build data from form values for 'action=articlefeedback'
181181 var data = {};
182182 for ( var key in context.options.ratings ) {
183183 var id = context.options.ratings[key].id;
@@ -203,7 +203,7 @@
204204 'success': function( data ) {
205205 var context = this;
206206 if ( 'error' in data ) {
207 - mw.log( 'Form submission error' );
 207+ mw.log( 'ArticleFeedback: Form submission error' );
208208 mw.log( data.error );
209209 context.$ui.find( '.articleFeedback-error' ).show();
210210 } else {
@@ -217,6 +217,59 @@
218218 context.$ui.find( '.articleFeedback-error' ).show();
219219 }
220220 } );
 221+ // Build data from form values for 'action=emailcapture'
 222+ // Ignore if email was invalid
 223+ if ( context.$ui.find( '.articleFeedback-helpimprove-email-validity.valid' ).length
 224+ // Ignore if email field was empty (it's optional)
 225+ && !$.isEmpty( context.$ui.find( '.articleFeedback-helpimprove-email' ).val() )
 226+ // Ignore if checkbox was unchecked (ie. user can enter and then decide to uncheck,
 227+ // field fades out, then we shouldn't submit)
 228+ && $( '#articleFeedback-expertise-on:checked' ).length
 229+ ) {
 230+
 231+ var ecData = {
 232+ email: context.$ui.find( '.articleFeedback-helpimprove-email' ).val()
 233+ };
 234+
 235+ $.ajax( {
 236+ 'url': mw.config.get( 'wgScriptPath' ) + '/api.php',
 237+ 'type': 'POST',
 238+ 'dataType': 'json',
 239+ 'context': context,
 240+ 'data': $.extend( ecData, {
 241+ 'action': 'emailcapture',
 242+ 'format': 'json'
 243+ } ),
 244+ 'success': function( data ) {
 245+ var context = this;
 246+
 247+ if ( 'error' in data ) {
 248+ mw.log( 'EmailCapture: Form submission error' );
 249+ mw.log( data.error );
 250+ updateMailValidityLabel( 'triggererror' );
 251+
 252+ } else {
 253+ // Hide helpimprove-email for when user returns to Rate-view
 254+ // without reloading page
 255+ context.$ui.find( '.articleFeedback-helpimprove' ).hide();
 256+
 257+ // Set cookie if it was successful, so it won't be asked again
 258+ $.cookie(
 259+ prefix( 'helpimprove-email' ),
 260+ // Path must be set so it will be remembered
 261+ // for all article (not just current level)
 262+ // @XXX: '/' may be too wide (multi-wiki domains)
 263+ 'hide', { 'expires': 30, 'path': '/' }
 264+ );
 265+ }
 266+ }
 267+ } );
 268+
 269+ // If something was invalid, reset the helpimprove-email part of the form.
 270+ // When user returns from submit, it will be clean
 271+ } else {
 272+
 273+ }
221274 },
222275 'executePitch': function( action ) {
223276 var $pitch = $(this).closest( '.articleFeedback-pitch' );
@@ -298,26 +351,19 @@
299352
300353 // Help improve
301354 var $helpimprove = context.$ui.find( '.articleFeedback-helpimprove' );
302 - // @FIXME: Needs serverside handling to actually pass this
303 - feedback.helpimprove = 'on test@example.org';
304 - if ( typeof feedback.helpimprove === 'string' ) {
305 - var tags = feedback.helpimprove.split( ' ', 2 );
306 - if ( tags.length == 2 && tags[0] == 'on' ) {
307 - $helpimprove.find( 'input:checkbox[value=on]' ).attr( 'checked', 'checked' );
308 - $helpimprove.find( '.articleFeedback-helpimprove-email' ).val( tags[1] );
309 - // IE7 seriously has issues, and we have to hide, then show
310 - $helpimprove.find( '.articleFeedback-helpimprove-options' )
311 - .hide().show();
312 - $.articleFeedback.fn.enableHelpimprove( $helpimprove );
313 - }
314 - } else {
315 - $helpimprove
316 - .find( 'input:checkbox' )
317 - .removeAttr( 'checked' )
318 - .end()
319 - .find( '.articleFeedback-helpimprove-options' )
320 - .hide();
 355+
 356+ var showHelpimprove = true;
 357+
 358+ // @XXX: Insert bucket thing override here
 359+ // bucket thing will set it to false when needed, default is true
 360+
 361+ if ( $.cookie( prefix( 'helpimprove-email' ) ) == 'hide'
 362+ || !mw.user.anonymous() ) {
 363+ showHelpimprove = false;
321364 }
 365+
 366+ // true: show, false: hide
 367+ $helpimprove.toggle( showHelpimprove );
322368
323369 // Index rating data by rating ID
324370 var ratings = {};
@@ -514,13 +560,13 @@
515561 .attr( 'placeholder', mw.msg( 'articlefeedback-form-panel-helpimprove-email-placeholder' ) )
516562 .placeholder() // back. compat. for older browsers
517563 .one( 'blur', function() {
518 - var $el = $(this), val = $el.val();
 564+ var $el = $(this);
519565 if ( context.$ui.find( '.articleFeedback-helpimprove-email-validity' ).length === 0 ) {
520566 $el.after( '<div class="articleFeedback-helpimprove-email-validity"></div>' );
521567 }
522 - updateMailValidityLabel( val, context );
 568+ updateMailValidityLabel( $el.val(), context );
523569 $el.keyup( function() {
524 - updateMailValidityLabel( val, context );
 570+ updateMailValidityLabel( $el.val(), context );
525571 } );
526572 } )
527573 .end()

Follow-up revisions

RevisionCommit summaryAuthorDate
r86533Follow-up r86532: Adding code to reset the form in the else casekrinkle19:43, 20 April 2011

Comments

#Comment by Krinkle (talk | contribs)   19:37, 20 April 2011
+			// If something was invalid, reset the helpimprove-email part of the form.
+			// When user returns from submit, it will be clean
+			} else {
+			
+			}

coming soon.

#Comment by Krinkle (talk | contribs)   19:43, 20 April 2011

Status & tagging log