Index: trunk/extensions/ArticleFeedback/modules/jquery.articleFeedback/jquery.articleFeedback.js |
— | — | @@ -74,7 +74,7 @@ |
75 | 75 | </div>\ |
76 | 76 | </div>\ |
77 | 77 | <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>\ |
79 | 79 | <div class="articleFeedback-success articleFeedback-visibleWith-form"><span><html:msg key="form-panel-success" /></span></div>\ |
80 | 80 | <div style="clear:both;"></div>\ |
81 | 81 | <div class="articleFeedback-notices articleFeedback-visibleWith-form">\ |
— | — | @@ -167,7 +167,7 @@ |
168 | 168 | 'enableHelpimprove': function( $helpimprove ) { |
169 | 169 | $helpimprove |
170 | 170 | .find( 'input:checkbox[value=on]' ) |
171 | | - .attr( 'disabled', false ) |
| 171 | + .removeAttr( 'disabled' ) |
172 | 172 | .end() |
173 | 173 | .find( '.articleFeedback-helpimprove-disabled' ) |
174 | 174 | .removeClass( 'articleFeedback-helpimprove-disabled' ); |
— | — | @@ -176,7 +176,7 @@ |
177 | 177 | var context = this; |
178 | 178 | $.articleFeedback.fn.enableSubmission.call( context, false ); |
179 | 179 | context.$ui.find( '.articleFeedback-lock' ).show(); |
180 | | - // Build data from form values |
| 180 | + // Build data from form values for 'action=articlefeedback' |
181 | 181 | var data = {}; |
182 | 182 | for ( var key in context.options.ratings ) { |
183 | 183 | var id = context.options.ratings[key].id; |
— | — | @@ -203,7 +203,7 @@ |
204 | 204 | 'success': function( data ) { |
205 | 205 | var context = this; |
206 | 206 | if ( 'error' in data ) { |
207 | | - mw.log( 'Form submission error' ); |
| 207 | + mw.log( 'ArticleFeedback: Form submission error' ); |
208 | 208 | mw.log( data.error ); |
209 | 209 | context.$ui.find( '.articleFeedback-error' ).show(); |
210 | 210 | } else { |
— | — | @@ -217,6 +217,59 @@ |
218 | 218 | context.$ui.find( '.articleFeedback-error' ).show(); |
219 | 219 | } |
220 | 220 | } ); |
| 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 | + } |
221 | 274 | }, |
222 | 275 | 'executePitch': function( action ) { |
223 | 276 | var $pitch = $(this).closest( '.articleFeedback-pitch' ); |
— | — | @@ -298,26 +351,19 @@ |
299 | 352 | |
300 | 353 | // Help improve |
301 | 354 | 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; |
321 | 364 | } |
| 365 | + |
| 366 | + // true: show, false: hide |
| 367 | + $helpimprove.toggle( showHelpimprove ); |
322 | 368 | |
323 | 369 | // Index rating data by rating ID |
324 | 370 | var ratings = {}; |
— | — | @@ -514,13 +560,13 @@ |
515 | 561 | .attr( 'placeholder', mw.msg( 'articlefeedback-form-panel-helpimprove-email-placeholder' ) ) |
516 | 562 | .placeholder() // back. compat. for older browsers |
517 | 563 | .one( 'blur', function() { |
518 | | - var $el = $(this), val = $el.val(); |
| 564 | + var $el = $(this); |
519 | 565 | if ( context.$ui.find( '.articleFeedback-helpimprove-email-validity' ).length === 0 ) { |
520 | 566 | $el.after( '<div class="articleFeedback-helpimprove-email-validity"></div>' ); |
521 | 567 | } |
522 | | - updateMailValidityLabel( val, context ); |
| 568 | + updateMailValidityLabel( $el.val(), context ); |
523 | 569 | $el.keyup( function() { |
524 | | - updateMailValidityLabel( val, context ); |
| 570 | + updateMailValidityLabel( $el.val(), context ); |
525 | 571 | } ); |
526 | 572 | } ) |
527 | 573 | .end() |