Index: trunk/extensions/ArticleAssessmentPilot/ArticleAssessmentPilot.i18n.php |
— | — | @@ -43,6 +43,8 @@ |
44 | 44 | 'articleassessment-survey-question-expert-iftrue' => 'Can you describe your expertise?', |
45 | 45 | 'articleassessment-survey-question-comments' => 'Do you have any additional comments?', |
46 | 46 | 'articleassessment-survey-submit' => 'Submit', |
| 47 | + 'articleassessment-survey-title' => 'Please answer a few questions', |
| 48 | + 'articleassessment-survey-thanks' => 'Thanks for filling out the survey.', |
47 | 49 | ); |
48 | 50 | |
49 | 51 | /** Message documentation (Message documentation) |
— | — | @@ -90,6 +92,8 @@ |
91 | 93 | '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.', |
92 | 94 | 'articleassessment-survey-question-comments' => 'This is a question in the survey with a text box that the user can enter their answer in.', |
93 | 95 | '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.', |
94 | 98 | ); |
95 | 99 | |
96 | 100 | /** Afrikaans (Afrikaans) |
Index: trunk/extensions/ArticleAssessmentPilot/css/ArticleAssessment.css |
— | — | @@ -221,4 +221,13 @@ |
222 | 222 | .article-assessment-wrapper .article-assessment-submit, |
223 | 223 | .article-assessment-wrapper .rating-fields { |
224 | 224 | 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 @@ |
100 | 100 | 'articleassessment-stalemessage-norevisioncount', |
101 | 101 | 'articleassessment-results-show', |
102 | 102 | 'articleassessment-results-hide', |
| 103 | + 'articleassessment-survey-title', |
| 104 | + 'articleassessment-survey-thanks', |
103 | 105 | ); |
104 | 106 | |
105 | 107 | foreach ( self::$messages as $i => $message ) { |
Index: trunk/extensions/ArticleAssessmentPilot/js/ArticleAssessment.js |
— | — | @@ -376,10 +376,96 @@ |
377 | 377 | } |
378 | 378 | }, |
379 | 379 | '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 | + } ); |
382 | 410 | return false; |
383 | 411 | }, |
| 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 | + }, |
384 | 470 | 'addMessages': function( messages ) { |
385 | 471 | for ( var key in messages ) { |
386 | 472 | $.ArticleAssessment.messages[key] = messages[key]; |
— | — | @@ -402,6 +488,13 @@ |
403 | 489 | msg = msg.replace( /\$1/g, args ); |
404 | 490 | } |
405 | 491 | 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 | + } |
406 | 499 | } |
407 | 500 | } |
408 | 501 | }; |