Harjotsingh has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/358942 )

Change subject: Put Setting table's HTML in mustache template
......................................................................

Put Setting table's HTML in mustache template

Currently raw HTML code is used to generate settings table that is
displayed in quiz.This change removes the code and moves it to mustache
template.It utilizes template parser to process template.

Bug:T161317
Change-Id: I2a1643bc327bda4a56c9e260a6088207515b7195
---
M Quiz.class.php
M modules/ext.quiz.js
M templates/Quiz.mustache
3 files changed, 35 insertions(+), 52 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Quiz 
refs/changes/42/358942/1

diff --git a/Quiz.class.php b/Quiz.class.php
index db48a12..0875a92 100644
--- a/Quiz.class.php
+++ b/Quiz.class.php
@@ -125,53 +125,36 @@
                // Generates the output.
 
                $templateParser = new TemplateParser( __DIR__ . '/templates' );
-
-               // Determine the content of the settings table.
-               $settings = array_fill( 0, 4, '' );
-               if ( !$this->mDisplaySimple ) {
-                       $settings[0] .= '<td>' . wfMessage( 'quiz_addedPoints', 
$this->mAddedPoints )->escaped() . '</td>' . "\n";
-                       $settings[0] .= '<td><input class="numerical" 
type="text" name="addedPoints" value="' . $this->mAddedPoints 
.'"/>&#160;&#160;</td>' . "\n";
-
-                       $settings[1] .= '<td>' . wfMessage( 
'quiz_cutoffPoints', $this->mCutoffPoints )->escaped() . '</td>' . "\n";
-                       $settings[1] .= '<td><input class="numerical" 
type="text" name="cutoffPoints" value="' . $this->mCutoffPoints . '"/></td>' . 
"\n";
-
-                       $checked = ( $this->mIgnoringCoef ) ? ' 
checked="checked"' : '';
-                       $settings[2] .= '<td>' . wfMessage( 'quiz_ignoreCoef' 
)->escaped() . '</td>' . "\n";
-                       $settings[2] .= '<td><input type="checkbox" 
name="ignoringCoef"' . $checked . '/></td>' . "\n";
-
-                       if ( $this->mShuffle && !$this->mBeingCorrected ) {
-                               $settings[3] .= '<td><input class="shuffle" 
name="shuffleButton" type="button" value="' . wfMessage( 'quiz_shuffle' 
)->escaped() . '" style="display: none;"/></td>' . "\n";
-                       } else {
-                               $settings[3] .= '<td></td>' . "\n";
-                       }
-                       $settings[3] .= '<td></td>' . "\n";
-               }
-               if ( $this->mBeingCorrected ) {
-                       $settings[0] .= '<td class="margin" style="background: 
' . self::getColor( 'right' ) . '"></td>' . "\n";
-                       $settings[0] .= '<td style="background: transparent;">' 
. wfMessage( 'quiz_colorRight' )->escaped() . '</td>' . "\n";
-
-                       $settings[1] .= '<td class="margin" style="background: 
' . self::getColor( 'wrong' ) . '"></td>' . "\n";
-                       $settings[1] .= '<td style="background: transparent;">' 
. wfMessage( 'quiz_colorWrong' )->escaped() . '</td>' . "\n";
-
-                       $settings[2] .= '<td class="margin" style="background: 
' . self::getColor( 'NA' ) . '"></td>' . "\n";
-                       $settings[2] .= '<td style="background: transparent;">' 
. wfMessage( 'quiz_colorNA' )->escaped() . '</td>' . "\n";
-               }
-               if ( $this->mState === 'error' ) {
-                       $errorKey = $this->mBeingCorrected ? 3 : 0;
-                       $settings[$errorKey] .= '<td class="margin" 
style="background: ' . self::getColor( 'error' ) . '"></td>' . "\n";
-                       $settings[$errorKey] .= '<td>' . wfMessage( 
'quiz_colorError' )->escaped() . '</td>' . "\n";
-               }
-
+               $checked = '';
                // Build the settings table.
-               $settingsTable = '';
-               foreach ( $settings as $settingsTr ) {
-                       if ( !empty( $settingsTr ) ) {
-                               $settingsTable .= '<tr>' . "\n";
-                               $settingsTable .= $settingsTr . "\n";
-                               $settingsTable .= '</tr>' . "\n";
-                       }
-               }
-
+               $setTable= '';
+               $setTable = $templateParser->processTemplate(
+                               'Setting',
+                               array( 'notSimple' => !$this->mDisplaySimple,
+                                       'corrected' => $this->mBeingCorrected,
+                                       'shuffle' => $this->mShuffle,
+                                       'error' => $this->mState === 'error',
+                                       'wfMessage' => array(
+                                               'quiz_added' => wfMessage( 
'quiz_addedPoints', $this->mAddedPoints )->escaped(),
+                                               'quiz_cutoff' => wfMessage( 
'quiz_cutoffPoints', $this->mCutoffPoints )->escaped(),
+                                               'quiz_ignoreCoef' => wfMessage( 
'quiz_ignoreCoef' ),
+                                               'quiz_colorRight' => wfMessage( 
'quiz_colorRight' )->escaped(),
+                                               'quiz_colorWrong' => wfMessage( 
'quiz_colorWrong' )->escaped(),
+                                               'quiz_colorNA' => wfMessage( 
'quiz_colorNA' )->escaped(),
+                                               'quiz_colorError' => wfMessage( 
'quiz_colorError' )->escaped(),
+                                               'quiz_shuffle' => wfMessage( 
'quiz_shuffle' )->escaped()
+                                       ),
+                                       'color' => array(
+                                               'colorWrong' => self::getColor( 
'wrong' ),
+                                               'colorRight' => self::getColor( 
'right' ),
+                                               'colorNA' => 
self::getColor('NA'),
+                                               'colorError' => 
self::getColor('error')
+                                       ),
+                                       'mAddedPoints' => $this->mAddedPoints,
+                                       'mCutoffPoints' => $this->mCutoffPoints,
+                                       'checked' => $checked,
+                                       )
+                                );
                $quiz_score = wfMessage( 'quiz_score' )->rawParams(
                        '<span class="score">' . $this->mScore . '</span>',
                        '<span class="total">' . $this->mTotal . '</span>' 
)->escaped();
@@ -184,7 +167,7 @@
                                        'beingCorrected' => 
$this->mBeingCorrected,
                                        'questions' => $input
                                ),
-                               'settingsTable' => $settingsTable,
+                               'settingsTable' => $setTable,
                                'wfMessage' => array(
                                        'quiz_correction' => wfMessage( 
'quiz_correction' )->escaped(),
                                        'quiz_reset' => wfMessage( 'quiz_reset' 
)->escaped(),
diff --git a/modules/ext.quiz.js b/modules/ext.quiz.js
index cbb60fd..441f44f 100644
--- a/modules/ext.quiz.js
+++ b/modules/ext.quiz.js
@@ -83,7 +83,7 @@
                                                input[j].style.display = 
'inline';
                                                /* jshint loopfunc:true */
                                                input[j].onclick = function() {
-                                                       shuffle( 
this.form.getElementsByTagName( 'div' )[0] );
+                                                       shuffle( 
this.form.getElementsByTagName( 'div' )[1] );
                                                        var sh_input = 
this.form.getElementsByTagName( 'input' );
                                                        for( var k = 0; k < 
sh_input.length; ++k ) {
                                                                // Add the 
possibility of unchecking radio buttons
diff --git a/templates/Quiz.mustache b/templates/Quiz.mustache
index 3ad1d03..aaa30e8 100644
--- a/templates/Quiz.mustache
+++ b/templates/Quiz.mustache
@@ -1,10 +1,10 @@
 <div class="quiz">
        <form id="quiz{{ quiz.id }}" method="post" action="#quiz{{ quiz.id }}">
-               {{#settingsTable}}
+               <div style="display:inline-flex">
                        <table class="settings">
-                               {{{ . }}}
+                               {{{ settingsTable }}}
                        </table>
-               {{/settingsTable}}
+               </div>
                <input type="hidden" name="quizId" value="{{ quiz.id }}" />
                <div class="quizQuestions">
                        {{{ quiz.questions }}}
@@ -21,4 +21,4 @@
                        </span>
                {{/if}}
        </form>
-</div>
\ No newline at end of file
+</div>

-- 
To view, visit https://gerrit.wikimedia.org/r/358942
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a1643bc327bda4a56c9e260a6088207515b7195
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Quiz
Gerrit-Branch: master
Gerrit-Owner: Harjotsingh <harjo...@ymail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to