r73120 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r73119‎ | r73120 | r73121 >
Date:16:10, 16 September 2010
Author:catrope
Status:deferred
Tags:
Comment:
ArticleAssessment: Add survey dialog. The way it retrieves and submits the survey is a big ugly hack, just like everything else related to the survey. Still needs a little bit of CSS work
Modified paths:
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css (modified) (history)
  • /trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php
@@ -43,6 +43,8 @@
4444 'articleassessment-survey-question-expert-iftrue' => 'Can you describe your expertise?',
4545 'articleassessment-survey-question-comments' => 'Do you have any additional comments?',
4646 'articleassessment-survey-submit' => 'Submit',
 47+ 'articleassessment-survey-title' => 'Please answer a few questions',
 48+ 'articleassessment-survey-thanks' => 'Thanks for filling out the survey.',
4749 );
4850
4951 /** Message documentation (Message documentation)
@@ -90,6 +92,8 @@
9193 'articleassessment-survey-question-expert-iftrue' => 'This question appears when the user checks "no" for the "Do you consider yourself an expert?" question. The user can enter their answer in a text box.',
9294 'articleassessment-survey-question-comments' => 'This is a question in the survey with a text box that the user can enter their answer in.',
9395 'articleassessment-survey-submit' => 'This is the caption for the button that submits the survey.',
 96+ 'articleassessment-survey-title' => 'This text appears in the title bar of the survey dialog.',
 97+ 'articleassessment-survey-thanks' => 'This text appears when the user has successfully submitted the survey.',
9498 );
9599
96100 /** Afrikaans (Afrikaans)
Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css
@@ -221,4 +221,13 @@
222222 .article-assessment-wrapper .article-assessment-submit,
223223 .article-assessment-wrapper .rating-fields {
224224 display: block;
225 -}
\ No newline at end of file
 225+}
 226+
 227+#article-assessment-dialog.loading {
 228+ display: block;
 229+ height: 24px;
 230+ width: 24px;
 231+ background: url( ../images/loading.gif ) center no-repeat;
 232+ text-indent: -9999px;
 233+ margin: 0 auto;
 234+}
Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.hooks.php
@@ -99,6 +99,8 @@
100100 'articleassessment-stalemessage-norevisioncount',
101101 'articleassessment-results-show',
102102 'articleassessment-results-hide',
 103+ 'articleassessment-survey-title',
 104+ 'articleassessment-survey-thanks',
103105 );
104106
105107 foreach ( self::$messages as $i => $message ) {
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js
@@ -376,10 +376,96 @@
377377 }
378378 },
379379 'showFeedback': function() {
380 - // TODO: Implement
381 - $.ArticleAssessment.fn.flashNotice( 'Not implemented yet', { 'class': 'article-assessment-error-msg' } );
 380+ $.ArticleAssessment.fn.withJUI( function() {
 381+ var $dialogDiv = $( '#article-assessment-dialog' );
 382+ if ( $dialogDiv.size() == 0 ) {
 383+ $dialogDiv = $( '<div id="article-assessment-dialog" class="loading" />' )
 384+ .dialog( {
 385+ width: 600,
 386+ height: 400,
 387+ bgiframe: true,
 388+ autoOpen: true,
 389+ modal: true,
 390+ title: $.ArticleAssessment.fn.getMsg( 'articleassessment-survey-title' ),
 391+ close: function() {
 392+ $( this )
 393+ .find( '.article-assessment-success-msg, .article-assessment-error-msg' )
 394+ .remove()
 395+ .end()
 396+ .find( 'form' )
 397+ .show();
 398+ }
 399+ } );
 400+ $dialogDiv.load(
 401+ wgScript + '?title=Special:SimpleSurvey&survey=articlerating&raw=1',
 402+ function() {
 403+ $( this ).find( 'form' ).bind( 'submit', $.ArticleAssessment.fn.submitFeedback );
 404+ $( this ).removeClass( 'loading' );
 405+ }
 406+ );
 407+ }
 408+ $dialogDiv.dialog( 'open' );
 409+ } );
382410 return false;
383411 },
 412+ 'submitFeedback': function() {
 413+ var $dialogDiv = $( '#article-assessment-dialog' );
 414+ $dialogDiv
 415+ .find( 'form' )
 416+ .hide()
 417+ .end()
 418+ .addClass( 'loading' );
 419+
 420+ // Submit straight to the special page. Yes, this is a dirty dirty hack
 421+ // Build request from form data
 422+ var formData = {};
 423+ $dialogDiv.find( 'input' ).each( function() {
 424+ var name = $( this ).attr( 'name' );
 425+ if ( name !== '' ) {
 426+ if ( name.substr( -2 ) == '[]' ) {
 427+ var trimmedName = name.substr( 0, name.length - 2 );
 428+ if ( typeof formData[trimmedName] == 'undefined' ) {
 429+ formData[trimmedName] = [];
 430+ }
 431+ formData[trimmedName].push( $( this ).val() );
 432+ } else {
 433+ formData[name] = $( this ).val();
 434+ }
 435+ }
 436+ } );
 437+ formData.title = 'Special:SimpleSurvey';
 438+
 439+ $.ajax( {
 440+ url: wgScript,
 441+ type: 'POST',
 442+ data: formData,
 443+ dataType: 'html',
 444+ success: function( data ) {
 445+ // This is an evil screenscraping method to determine whether
 446+ // the submission was successful
 447+ var success = $( data ).find( '.simplesurvey-success' ).size() > 0;
 448+ // TODO: Style success-msg, error-msg
 449+ $( '<div />' )
 450+ .addClass( success ? 'article-assessment-success-msg' : 'article-assessment-error-msg' )
 451+ .text( $.ArticleAssessment.fn.getMsg( success? 'articleassessment-survey-thanks' : 'articleassessment-error' ) )
 452+ .appendTo( $dialogDiv );
 453+ $dialogDiv.removeClass( 'loading' );
 454+ if ( success ) {
 455+ // Hide the dialog link
 456+ $( '#article-assessment .article-assessment-rate-feedback' ).hide();
 457+ }
 458+ },
 459+ error: function( XMLHttpRequest, textStatus, errorThrown ) {
 460+ // TODO: Duplicates code, factor out, maybe
 461+ $( '<div />' )
 462+ .addClass( 'article-assessment-error-msg' )
 463+ .text( $.ArticleAssessment.fn.getMsg( 'articleassessment-error' ) )
 464+ .appendTo( $dialogDiv );
 465+ $dialogDiv.removeClass( 'loading' );
 466+ }
 467+ } );
 468+ return false;
 469+ },
384470 'addMessages': function( messages ) {
385471 for ( var key in messages ) {
386472 $.ArticleAssessment.messages[key] = messages[key];
@@ -402,6 +488,13 @@
403489 msg = msg.replace( /\$1/g, args );
404490 }
405491 return msg;
 492+ },
 493+ 'withJUI': function( callback ) {
 494+ if ( typeof $.ui == 'undefined' ) {
 495+ $.getScript( wgScriptPath + '/extensions/UsabilityInitiative/js/js2stopgap/jui.combined.min.js', callback );
 496+ } else {
 497+ callback();
 498+ }
406499 }
407500 }
408501 };

Status & tagging log