diff --git a/htdocs/js/apps/LocalStorage/localstorage.js b/htdocs/js/apps/LocalStorage/localstorage.js index 7b11953eda..d000daf713 100644 --- a/htdocs/js/apps/LocalStorage/localstorage.js +++ b/htdocs/js/apps/LocalStorage/localstorage.js @@ -19,26 +19,25 @@ var WWLocalStorage = function(givenContainer) { storedData = {}; } - var storeData = function () { - //event.preventDefault(); - - if (!storedData['inputs']) { - storedData['inputs'] = {}; - } - - var inputs = $(container).find(":input") - .each(function(index,input) { - if ($(input).attr('type').toUpperCase() == 'RADIO') { - var name = $(input).attr('name'); - storedData['inputs'][name] = $('input[name="'+name+'"]:checked').val(); - } else if (/AnSwEr/.test($(input).attr('name'))) { - - storedData['inputs'][$(input).attr('name')] = $(input).val(); + var storeData = function () { + if (!storedData['inputs']) { + storedData['inputs'] = {}; } - }); - $.jStorage.set(identifier,storedData); - } + var inputs = $(container).find(":input") + .each(function(index) { + var input = $(this); + var type = input.attr('type'); + if (type && type.toUpperCase() == 'RADIO') { + var name = input.attr('name'); + storedData['inputs'][name] = $('input[name="'+name+'"]:checked').val(); + } else if (/AnSwEr/.test(input.attr('name'))) { + storedData['inputs'][input.attr('name')] = $(input).val(); + } + }); + + $.jStorage.set(identifier,storedData); + } $(container).find(":submit").click(storeData); diff --git a/htdocs/js/apps/ProblemSetDetail2/problemsetdetail2.js b/htdocs/js/apps/ProblemSetDetail2/problemsetdetail2.js index a20c556f7d..d9584761a8 100644 --- a/htdocs/js/apps/ProblemSetDetail2/problemsetdetail2.js +++ b/htdocs/js/apps/ProblemSetDetail2/problemsetdetail2.js @@ -241,7 +241,7 @@ ro.permissionLevel = 10; ro.noprepostambles = 1; ro.processAnswers = 0; - ro.showFooter = "no"; + ro.showFooter = 0; ro.displayMode = $('#problem_displaymode').val(); ro.extra_header_text = ""; if (window.location.port) ro.forcePortNumber = window.location.port; diff --git a/htdocs/js/apps/SetMaker/setmaker.js b/htdocs/js/apps/SetMaker/setmaker.js index cdd48b6916..f2783be218 100644 --- a/htdocs/js/apps/SetMaker/setmaker.js +++ b/htdocs/js/apps/SetMaker/setmaker.js @@ -367,7 +367,7 @@ ro.showSolutions = $('input[name=showSolutions]').is(':checked') ? 1 : 0; ro.noprepostambles = 1; ro.processAnswers = 0; - ro.showFooter = "no"; + ro.showFooter = 0; ro.displayMode = $('select[name=mydisplayMode]').val(); ro.send_pg_flags = 1; ro.extra_header_text = ""; diff --git a/lib/FormatRenderedProblem.pm b/lib/FormatRenderedProblem.pm index 8b133818d8..72f75d4953 100644 --- a/lib/FormatRenderedProblem.pm +++ b/lib/FormatRenderedProblem.pm @@ -125,6 +125,10 @@ sub formatRenderedProblem { my $fileName = $self->{input}{envir}{fileName} // ""; my $encoded_source = $self->encoded_source // ""; + # Select the theme and theme directory + my $theme = $self->{inputs_ref}{theme} || $ce->{defaultTheme}; + my $themeDir = "$ce->{webworkURLs}{htdocs}/themes/$theme"; + # Set up the header text my $problemHeadText = ''; @@ -212,7 +216,7 @@ sub formatRenderedProblem { summary => $problemResult->{summary} // '', # can be set by problem grader ); my $answerTemplate = $tbl->answerTemplate; - my $color_input_blanks_script = $tbl->color_answer_blanks; + my $color_input_blanks_script = (!$previewMode && ($checkMode || $submitMode)) ? $tbl->color_answer_blanks : ""; $tbl->imgGen->render(refresh => 1) if $tbl->displayMode eq 'images'; # Score summary @@ -236,16 +240,29 @@ sub formatRenderedProblem { $localStorageMessages .= CGI::p('Your overall score for this problem is ' . CGI::span({ id => 'problem-overall-score' }, '')); $localStorageMessages .= CGI::end_div(); - # Submit buttons - my $STRING_Preview = $mt->maketext("Preview My Answers"); - my $STRING_ShowCorrect = $mt->maketext("Show correct answers"); - my $STRING_Submit = $mt->maketext("Check Answers"); + # Submit buttons (all are shown by default) + my $showPreviewButton = $self->{inputs_ref}{showPreviewButton} // ""; + my $previewButton = $showPreviewButton eq "0" ? '' : + ''; + my $showCheckAnswersButton = $self->{inputs_ref}{showCheckAnswersButton} // ""; + my $checkAnswersButton = $showCheckAnswersButton eq "0" ? '' : + ''; + my $showCorrectAnswersButton = $self->{inputs_ref}{showCorrectAnswersButton} // ""; + my $correctAnswersButton = $showCorrectAnswersButton eq "0" ? '' : + ''; + + my $showSolutions = $self->{inputs_ref}{showSolutions} // ""; + my $showHints = $self->{inputs_ref}{showHints} // ""; # Regular Perl warning messages generated with warn. my $warnings = ''; - if (defined($rh_result->{WARNINGS}) and $rh_result->{WARNINGS}) { - $warnings = qq{

WARNINGS

} . - decode_utf8_base64($rh_result->{WARNINGS}) . "

"; + if ($rh_result->{pg_warnings}) { + $warnings .= qq{
PG WARNINGS
} . + decode_utf8_base64($rh_result->{pg_warnings}) . "
"; + } + if ($rh_result->{translator_warnings}) { + $warnings .= qq{

TRANSLATOR WARNINGS

} . + decode_utf8_base64($rh_result->{translator_warnings}) . "

"; } # PG debug messages generated with DEBUG_message(); @@ -264,13 +281,14 @@ sub formatRenderedProblem { my $debug_messages = $rh_result->{debug_messages}; + # For debugging purposes (only used in the debug format) + my $clientDebug = $self->{inputs_ref}{clientDebug} // ""; + my $client_debug_data = $clientDebug ? "

Webwork client data

" . WebworkClient::pretty_print($self) : ''; + # Show the footer unless it is explicity disabled. my $showFooter = $self->{inputs_ref}{showFooter} // ""; - my $footer = $showFooter && $showFooter eq "no" ? '' - : ""; - - # For debugging purposes add $pretty_print_self to the output format in use and uncomment below. - #my $pretty_print_self = WebworkClient::pretty_print($self); + my $footer = $showFooter eq "0" ? '' + : ""; # Execute and return the interpolated problem template my $format_name = $self->{inputs_ref}{outputformat} // 'simple'; @@ -278,16 +296,24 @@ sub formatRenderedProblem { # The json format if ($format_name eq "json") { my $json_output = do("WebworkClient/json_format.pl"); + for my $key (keys %{$json_output->{hidden_input_field}}) { + $json_output->{hidden_input_field}{$key} =~ s/(\$\w+)/$1/gee; + } + for my $key (keys %$json_output) { - if (($key =~ /^hidden_input_field/) || + if ( ($key =~ /^real_webwork/) || ($key =~ /^internal/) || - ($key =~ /_VI$/) + ($key =~ /_A?VI$/) ) { # Interpolate values - $json_output->{$key} =~ s/(\$\w+)/$1/gee; - if ($key =~ /_VI$/) { - my $new_key = $key =~ s/_VI$//gr; + if ($key =~ /_AVI$/) { + map { s/(\$\w+)/$1/gee } @{$json_output->{$key}}; + } else { + $json_output->{$key} =~ s/(\$\w+)/$1/gee; + } + if (($key =~ /_A?VI$/)) { + my $new_key = $key =~ s/_A?VI$//r; $json_output->{$new_key} = $json_output->{$key}; delete $json_output->{$key}; } diff --git a/lib/WebworkClient/debug_format.pl b/lib/WebworkClient/debug_format.pl index 45ac8a5816..6a8cc5b08d 100644 --- a/lib/WebworkClient/debug_format.pl +++ b/lib/WebworkClient/debug_format.pl @@ -1,18 +1,107 @@ -$debug_format = -q{ +$debug_format = <<'ENDPROBLEMTEMPLATE'; + + + + + + - - - - - $SITE_URL WeBWorK using host: $SITE_URL, course: $courseID format: debug - - - -

WeBWorK using host: $SITE_URL, course: $courseID format: debug

-$pretty_print_self + + + + + + + + + + + + + + + + + + + + + + + + + + + +$problemHeadText + +WeBWorK using host: $SITE_URL, format: debug, seed: $problemSeed, course: $courseID + + +
+

WeBWorK using host: $SITE_URL, course: $courseID, format: debug

+
+
+
+$answerTemplate +$color_input_blanks_script +
+
+$problemText +
+$scoreSummary +$LTIGradeMessage + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+$previewButton +$checkAnswersButton +$correctAnswersButton +

+
+
+
+ +

Perl warning section

+$warnings +

PG Warning section

+$PG_warning_messages +

Debug message section

+$debug_messages +

internal errors

+$internal_debug_messages +$client_debug_data +
+$footer -}; +ENDPROBLEMTEMPLATE $debug_format; diff --git a/lib/WebworkClient/json_format.pl b/lib/WebworkClient/json_format.pl index 9e1916e371..f68a49f9ab 100644 --- a/lib/WebworkClient/json_format.pl +++ b/lib/WebworkClient/json_format.pl @@ -3,10 +3,13 @@ # variable interpolation. # Most parts which need variable interpolation end in "_VI". +# Parts ending in "_AVI" are references to anonymous arrays whose entries need variable interpolation. # Other parts which need variable interpolation are: -# hidden_input_field_* +# hidden_input_field}{* # real_webwork_* +# NOTE: When a variable needs to be interpolated later, the string should be in single quotes not in double quotes. + $json_output = { head_part001_VI => '' }; $json_output->{head_part010} = <<'ENDPROBLEMTEMPLATE'; @@ -16,34 +19,41 @@ ENDPROBLEMTEMPLATE -$json_output->{head_part100} = <<'ENDPROBLEMTEMPLATE'; - - - - - - - - -ENDPROBLEMTEMPLATE - -$json_ouput{head_part200} = <<'ENDPROBLEMTEMPLATE'; - - - - - - - - - - - - - - - -ENDPROBLEMTEMPLATE +# CSS loads - as an array of href values +$json_output->{head_part100_AVI} = [ + "/webwork2_files/js/vendor/bootstrap/css/bootstrap.css", + "/webwork2_files/js/vendor/bootstrap/css/bootstrap-responsive.css", + "/webwork2_files/node_modules/jquery-ui-dist/jquery-ui.min.css", + "/webwork2_files/node_modules/@fortawesome/fontawesome-free/css/all.min.css", + "/webwork2_files/css/knowlstyle.css", + "/webwork2_files/js/apps/ImageView/imageview.css", + '$themeDir/math4.css', + '$themeDir/math4-coloring.css', + '$themeDir/math4-overrides.css', +]; + +# JS loads - as an array of href values - the ones which need defer are in head_part201_AVI +$json_output->{head_part200_AVI} = [ + "/webwork2_files/node_modules/jquery/dist/jquery.min.js", + "/webwork2_files/node_modules/jquery-ui-dist/jquery-ui.min.js", + "/webwork2_files/js/vendor/bootstrap/js/bootstrap.js", + "/webwork2_files/js/apps/InputColor/color.js", + "/webwork2_files/js/apps/Base64/Base64.js", + "/webwork2_files/js/vendor/underscore/underscore.js", + "/webwork2_files/js/legacy/vendor/knowl.js", + "/webwork2_files/js/apps/Problem/problem.js", + "/webwork2_files/js/apps/ImageView/imageview.js", + "/webwork2_files/node_modules/iframe-resizer/js/iframeResizer.contentWindow.min.js", +]; + +# JS loads - as an array of href values - the ones which need defer are in head_part201_AVI +# mathjax/es5/tex-chtml.js also needs id="MathJax-script" in the - - - - - - - - - - - - - -$problemHeadText - -WeBWorK using host: $SITE_URL, format: simple seed: $problemSeed - - -
-
-
- $answerTemplate -
-
- $problemText -
-$scoreSummary -$LTIGradeMessage - - - - - - - - - - - - - - - - - - -

- - - -

-
-
-
- - - - - - -ENDPROBLEMTEMPLATE - -$simple_format; diff --git a/lib/WebworkClient/simple_format.pl b/lib/WebworkClient/simple_format.pl index bfdac15f89..f1e25155eb 100644 --- a/lib/WebworkClient/simple_format.pl +++ b/lib/WebworkClient/simple_format.pl @@ -11,9 +11,11 @@ - + + + @@ -28,8 +30,9 @@ - + + $problemHeadText WeBWorK using host: $SITE_URL, format: simple seed: $problemSeed @@ -37,41 +40,48 @@
-
- $answerTemplate -
+
+$answerTemplate +$color_input_blanks_script +
- $problemText +$problemText
$scoreSummary $LTIGradeMessage - - - - - - - - - - - - - - - - - - - - -

- - - -

- + + + + + + + + + + + + + + + + + + + + + + + + + + +

+$previewButton +$checkAnswersButton +$correctAnswersButton +

+
$footer diff --git a/lib/WebworkClient/standard_format.pl b/lib/WebworkClient/standard_format.pl deleted file mode 100644 index aeacd48f2b..0000000000 --- a/lib/WebworkClient/standard_format.pl +++ /dev/null @@ -1,91 +0,0 @@ -$standard_format = <<'ENDPROBLEMTEMPLATE'; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -$problemHeadText - - -WeBWorK using host: $SITE_URL, format: standard seed: $problemSeed course: $courseID - - - -

WeBWorK using host: $SITE_URL, course: $courseID format: standard

- $answerTemplate - $color_input_blanks_script -
-
- $problemText -
-$scoreSummary -$LTIGradeMessage - - - - - - - - - - - - - - - - - - - -

- - - -

-
-
- -

Perl warning section

-$warnings -

PG Warning section

-$PG_warning_messages; -

Debug message section

-$debug_messages -

internal errors

-$internal_debug_messages - - - - - -ENDPROBLEMTEMPLATE - -$standard_format; diff --git a/lib/WebworkClient/sticky_format.pl b/lib/WebworkClient/sticky_format.pl index 72d5ec71a6..f936b7ff17 100644 --- a/lib/WebworkClient/sticky_format.pl +++ b/lib/WebworkClient/sticky_format.pl @@ -12,9 +12,11 @@ - + + + @@ -32,8 +34,9 @@ - + + $problemHeadText WeBWorK using host: $SITE_URL, format: sticky seed: $problemSeed @@ -41,9 +44,10 @@
-
-
+
+
$answerTemplate +$color_input_blanks_script
@@ -59,10 +63,10 @@ $LTIGradeMessage - + - - + + @@ -73,22 +77,28 @@ + + + + + + + +

- - - +$previewButton +$checkAnswersButton +$correctAnswersButton

- +$footer diff --git a/lib/WebworkWebservice/RenderProblem.pm b/lib/WebworkWebservice/RenderProblem.pm index 820911e8d6..8c2cd96a08 100644 --- a/lib/WebworkWebservice/RenderProblem.pm +++ b/lib/WebworkWebservice/RenderProblem.pm @@ -404,9 +404,8 @@ sub renderProblem { post_header_text => encode_utf8_base64( $pg->{post_header_text} ), answers => $pg->{answers}, errors => $pg->{errors}, - WARNINGS => encode_utf8_base64( - "WARNINGS\n".$warning_messages."\n
More
\n".$pg->{warnings} - ), + translator_warnings => encode_utf8_base64($pg->{warnings}), + pg_warnings => encode_utf8_base64($warning_messages), PG_ANSWERS_HASH => $pg->{pgcore}->{PG_ANSWERS_HASH}, problem_result => $pg->{result}, problem_state => $pg->{state},