You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(53) |
Feb
(56) |
Mar
|
Apr
|
May
(30) |
Jun
(78) |
Jul
(121) |
Aug
(155) |
Sep
(77) |
Oct
(61) |
Nov
(45) |
Dec
(94) |
2006 |
Jan
(116) |
Feb
(33) |
Mar
(11) |
Apr
(23) |
May
(60) |
Jun
(89) |
Jul
(130) |
Aug
(109) |
Sep
(124) |
Oct
(63) |
Nov
(82) |
Dec
(45) |
2007 |
Jan
(31) |
Feb
(35) |
Mar
(123) |
Apr
(36) |
May
(18) |
Jun
(134) |
Jul
(133) |
Aug
(241) |
Sep
(126) |
Oct
(31) |
Nov
(15) |
Dec
(5) |
2008 |
Jan
(11) |
Feb
(6) |
Mar
(16) |
Apr
(29) |
May
(43) |
Jun
(149) |
Jul
(27) |
Aug
(29) |
Sep
(37) |
Oct
(20) |
Nov
(4) |
Dec
(6) |
2009 |
Jan
(34) |
Feb
(30) |
Mar
(16) |
Apr
(6) |
May
(1) |
Jun
(32) |
Jul
(22) |
Aug
(7) |
Sep
(18) |
Oct
(50) |
Nov
(22) |
Dec
(8) |
2010 |
Jan
(17) |
Feb
(15) |
Mar
(10) |
Apr
(9) |
May
(67) |
Jun
(30) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
|
From: Mike G. v. a. <we...@ma...> - 2009-03-10 12:18:13
|
Log Message: ----------- refactored code using methodDefined() converted configAlias to setConfigAlias replaced debug by jsDebugMode (for now -- eventually we'll have a debug mode for each applet) Modified Files: -------------- pg/macros: AppletObjects.pl Revision Data ------------- Index: AppletObjects.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/AppletObjects.pl,v retrieving revision 1.17 retrieving revision 1.18 diff -Lmacros/AppletObjects.pl -Lmacros/AppletObjects.pl -u -r1.17 -r1.18 --- macros/AppletObjects.pl +++ macros/AppletObjects.pl @@ -115,6 +115,9 @@ my $appletStateName = "${appletName}_state"; my $getState = $self->getStateAlias; my $setState = $self->setStateAlias; + my $getConfig = $self->getConfigAlias; + my $setConfig = $self->setConfigAlias; + my $base64_initialState = $self->base64_state; main::RECORD_FORM_LABEL($appletStateName); #this insures that they'll be saved from one invocation to the next #main::RECORD_FORM_LABEL("previous_$appletStateName"); @@ -160,7 +163,17 @@ ww_applet_list['$appletName'].setState(); alert(debugText);" > + <input type="button" value="$getConfig" + onClick="debugText=''; + ww_applet_list['$appletName'].getConfig()"; " + > + <input type="button" value="$setConfig" + onClick="debugText=''; + ww_applet_list['$appletName'].config(); + alert(debugText);" + > !; + my $state_input_element = ($self->debug == 1) ? $debug_input_element : qq!\n<input type="hidden" name = "$appletStateName" value ="$base_64_encoded_answer_value">!; my $reset_button_str = ($reset_button) ? |
From: Mike G. v. a. <we...@ma...> - 2009-03-10 12:17:52
|
Log Message: ----------- refactored code using methodDefined() converted configAlias to setConfigAlias replaced debug by jsDebugMode (for now -- eventually we'll have a debug mode for each applet) Modified Files: -------------- webwork2/htdocs/js: ww_applet_support.js Revision Data ------------- Index: ww_applet_support.js =================================================================== RCS file: /webwork/cvs/system/webwork2/htdocs/js/ww_applet_support.js,v retrieving revision 1.6 retrieving revision 1.7 diff -Lhtdocs/js/ww_applet_support.js -Lhtdocs/js/ww_applet_support.js -u -r1.6 -r1.7 --- htdocs/js/ww_applet_support.js +++ htdocs/js/ww_applet_support.js @@ -35,15 +35,15 @@ ////////////////////////////////////////////////////////// // DEBUGGING tools ////////////////////////////////////////////////////////// - var debug; + var jsDebugMode; var debugText = ""; function set_debug(num) { // setting debug for any applet sets it for all of them if (num) { - debug =1; + jsDebugMode =1; } } function debug_add(str) { - if (debug) { + if (jsDebugMode) { debugText = debugText + "\n" +str; } } @@ -54,7 +54,7 @@ function submitAction() { // called from the submit button defined in Problem.pm - if (debug) { + if (jsDebugMode) { debugText = "Call submitAction() function on each applet\n"; } @@ -62,7 +62,7 @@ ww_applet_list[appletName].submitAction(); } debug_add("\n Done calling submitAction() on each applet.\n"); - if (debug) { + if (jsDebugMode) { alert(debugText); debugText=""; }; } @@ -82,34 +82,46 @@ } // applet can set isReady flag by calling applet_loaded(appletName, loaded); -// function applet_loaded(appletName,loaded) { -// debug_add("applet reporting that it has been loaded = " + loaded ); -// ww_applet_list[appletName].reportsLoaded = loaded; // 0 means not loaded -// } +function applet_loaded(appletName,loaded) { + debug_add("applet reporting that it has been loaded = " + loaded ); + ww_applet_list[appletName].reportsLoaded = loaded; // 0 means not loaded +} // insures that applet is loaded before initializing it + + function safe_applet_initialize(appletName, i) { - debug_add(" Try to initialize applet " + appletName + " with " +i + " attempts remaining.\n" ); + i--; + debug_add(" Try to initialize applet " + appletName + ". Count down: " + i + ".\n" ); - i--; + var ww_applet = ww_applet_list[appletName]; var applet_loaded = ww_applet.checkLoaded(); + if (applet_loaded=="still_loading" && !(i> 0) ) { + // it's possible that the isActive() response of the applet is not working properly + alert("The isActive() method of applet " +appletName + " claims it is still loading! We'll ignore this."); + i=1; + applet_loaded=1; + } else if (applet_loaded=="still_loading") { + applet_loaded=0; // keep trying + } + debug_add(" applet is ready = " + applet_loaded ); if ( 0 < i && !applet_loaded ) { // wait until applet is loaded - debug_add(" applet " + appletName + "not ready try again"); + debug_add(" applet " + appletName + " is not yet ready try again"); window.setTimeout( "safe_applet_initialize(\"" + appletName + "\"," + i + ")",1); } else if( 0 < i ){ // now that applet is loaded configure it and initialize it with saved data. - debug_add(appletName + " initialization completed with " + i + " possible attempts remaining. "); + debug_add(appletName + " initialization completed with " + i + " possible attempts remaining. \n"); // in-line handler -- configure and initialize try{ - ww_applet.setDebug(debug); + ww_applet.setDebug(jsDebugMode); } catch(e) { var msg = "Unable set debug in " + appletName + " \n " +e; - if (debug) {debug_add(msg);} else {alert(msg)}; + if (jsDebugMode) {debug_add(msg);} else {alert(msg)}; } try{ @@ -117,7 +129,7 @@ } catch(e) { var msg = "Unable to configure " + appletName + " \n " +e; - if (debug) {debug_add(msg);} else {alert(msg)}; + if (jsDebugMode) {debug_add(msg);} else {alert(msg)}; } try{ @@ -125,13 +137,13 @@ } catch(e) { var msg = "unable to initialize " + appletName + " \n " +e; - if (debug) {debug_add(msg);} else {alert(msg)}; + if (jsDebugMode) {debug_add(msg);} else {alert(msg)}; } } else { - if (debug) {debug_add("Error: timed out waiting for applet " +appletName + " to load");} + if (jsDebugMode) {debug_add("Error: timed out waiting for applet " +appletName + " to load");} } - if (debug) {alert(debugText); debugText="";}; + if (jsDebugMode) {alert(debugText); debugText="";}; } /////////////////////////////////////////////////////// @@ -188,7 +200,7 @@ // needed for IE -- searches id and name space so it can be unreliable if names are not unique if (!obj || obj.name != name1) { var msg = "Can't find element " + name1; - if (debug) { + if (jsDebugMode) { debug_add(msg + "\n ( Place listQuestionElements() at end of document in order to get all form elements! )\n" ); } else { alert(msg); listQuestionElements(); @@ -199,6 +211,8 @@ } } + + function getQuestionElement(name1) { return getQE(name1); } @@ -228,6 +242,7 @@ this.reportsLoaded = 0 ; }; + ////////////////////////////////////////////////////////// //CONFIGURATIONS // @@ -238,15 +253,11 @@ var appletName = this.appletName; var applet = getApplet(appletName); var configAlias = this.configAlias; - debug_add(" Checking " + appletName +"."+ configAlias +"( " + this.base64_config + " ) to see if config function is defined. The data is" - + this.base64_config + " " + Base64.decode(this.base64_config) ); + debug_add(" Calling " + appletName +"."+ configAlias +"( " + Base64.decode(this.base64_config) + " ) " ); try { - if (( typeof(applet[configAlias]) == "function" ) ) { - debug_add(" CONFIGURING " + appletName); + if ( this.methodDefined(configAlias) ) { applet[configAlias](Base64.decode(this.base64_config)); - } else { - debug_add("Applet does not have config method named: " + configAlias + "."); - } + } } catch(e) { var msg = "Error in configuring " + appletName + " using command " + configAlias + " : " + e ; alert(msg); @@ -258,6 +269,24 @@ // state can vary as the applet is manipulated -- it is reset from the questions _state values // ////////////////////////////////////////////////////////// +ww_applet.prototype.methodDefined = function(methodName) { + var appletName = this.appletName; + var applet = getApplet(appletName); + try { + if (typeof(applet[methodName]) == "function" ) { + debug_add("Method " + methodName + " is defined in " + appletName ); + return(true); + } else { + debug_add("Method " + methodName + " is not defined in " + appletName); + return(false); + } + } catch(e) { + var msg = "Error in accessing " + methodName + " in applet " +appletName + "Error: " +e ; + alert(msg); + } + return(false); +} + ww_applet.prototype.setState = function(state) { var appletName = this.appletName; @@ -292,17 +321,14 @@ ); try { - if ( typeof(applet[setStateAlias]) == "function" ) { + if ( this.methodDefined(setStateAlias) ) { applet[setStateAlias]( state ); // change the applets current state - debug_add("Completed setting the state of applet: " + appletName + "."); - } else { - debug_add("Applet does not have setState method named: " + setStateAlias + "."); - } + } } catch(e) { msg = "Error in setting state of " + appletName + " using command " + setStateAlias + " : " + e ; alert(msg); } - } else if (debug) { + } else if (jsDebugMode) { debug_add(" new state was empty string or did not begin with <xml> -- Applet state was not reset"); } return(''); @@ -318,7 +344,7 @@ debug_add(" Begin getState for applet " + appletName ); try { - if ((typeof(applet[getStateAlias]) == "function" )) { // there may be no state function + if (this.methodDefined(getStateAlias)) { // there may be no state function state = applet[getStateAlias](); // get state in xml format debug_add(" state has type " + typeof(state)); state = String(state); // geogebra returned an object type instead of a string type @@ -334,13 +360,13 @@ alert(msg); } - if (!debug) { + if (!jsDebugMode) { state = Base64.encode(state); }; // replace state by encoded version unless in debug mode debug_add(" state is \n "+ state + "\n"); // state should still be in plain text - var ww_preserve_applet_state = getQE(appletName + "_state"); // answer box preserving applet state (debug: textarea, otherwise: hidden) - ww_preserve_applet_state.value = state; //place state in input item (debug: textarea, otherwise: hidden) + var ww_preserve_applet_state = getQE(appletName + "_state"); // answer box preserving applet state (jsDebugMode: textarea, otherwise: hidden) + ww_preserve_applet_state.value = state; //place state in input item (jsDebugMode: textarea, otherwise: hidden) debug_add("State stored in answer box "+ appletName + "_state and getState is finished."); }; @@ -352,7 +378,7 @@ debugMode = debugMode || this.debug; try{ - if (typeof(applet.debug) == "function" ) { + if (this.methodDefined("debug") ) { applet.debug(1); // turn the applet's debug functions on. } else { debug_add( " Unable to set debug state in applet " + appletName + "."); @@ -365,6 +391,25 @@ } +ww_applet.prototype.getConfig = function() { // used for debugging purposes -- gets the configuration from the applet + var config = "foobar"; + var appletName = this.appletName; + var applet = getApplet(appletName); + var getConfigAlias = this.getConfigAlias; + try { + if (this.methodDefined(getConfigAlias) ) { + alert( applet[getConfigAlias]() ); + } else { + alert(debugText); + } + } catch(e) { + var msg = " Error in getting configuration from applet " + appletName + " " + e; + alert(msg); + } +} + + + //////////////////////////////////////////////////////////// // //INITIALIZE @@ -382,7 +427,7 @@ var ww_preserve_applet_state = getQE(appletName + "_state"); // hidden answer box preserving applet state var saved_state = ww_preserve_applet_state.value; - if (debug) {debug_add("Begin submit action for applet " + appletName);} + if (jsDebugMode) {debug_add("Begin submit action for applet " + appletName);} var applet = getApplet(appletName); if (! this.isReady ) { alert(appletName + " is not ready"); @@ -391,44 +436,49 @@ // Check to see if we want to restart the applet if (saved_state.match(/^<xml>restart_applet<\/xml>/) ) { - if (debug) { debug_add("Restarting the applet "+appletName);} + if (jsDebugMode) { debug_add("Restarting the applet "+appletName);} setAppletStateToRestart(appletName); // erases all of the saved state return(''); } // if we are not restarting the applet save the state and submit this.getState(); // have ww_applet retrieve state from applet and store in answerbox - if (debug) {debug_add("Submit Action Script " + this.submitActionScript + "\n");} + if (jsDebugMode) {debug_add("Submit Action Script " + this.submitActionScript + "\n");} eval(this.submitActionScript); //getQE(this.answerBox).value = applet.[getAnswer](); //FIXME -- not needed in general? - if (debug) {debug_add("Completed submitAction() for applet " + appletName+ "\n");} + if (jsDebugMode) {debug_add("Completed submitAction() for applet " + appletName+ "\n");} }; + ww_applet.prototype.checkLoaded = function() { // this function returns 0 unless: // applet has already been flagged as ready in applet_isReady_list // applet.config is defined (or alias for .config) // applet.setState is defined - // applet.isActive is defined + // applet.isActive is defined and returns 1; // applet reported that it is loaded by calling applet_loaded() var ready = 0; var appletName = this.appletName; var applet = getApplet(appletName); - if (!debug && this.isReady) {return(1)}; // memorize readiness in non-debug mode - debug_add(" Test 4 methods to see if the applet " + appletName + " has been loaded. "); - if ( typeof(applet[this.configAlias]) == "function") { - debug_add( " applet.config method is defined as " + typeof(applet[this.configAlias]) ); + if (!jsDebugMode && this.isReady) {return(1)}; // memorize readiness in non-debug mode + debug_add("Test 4 methods to see if the applet " + appletName + " has been loaded: \n"); + if ( this.methodDefined(this.setConfigAlias) ) { ready = 1; } - if( typeof(applet[this.getStateAlias]) == "function") { - debug_add( " applet.getState method is defined as " + typeof(applet[this.getStateAlias]) ); + if ( this.methodDefined(this.setStateAlias) ) { ready =1; } - if (typeof(applet.isActive) == "function" && applet.isActive ) { - debug_add( " applet.isActive method is defined as " + typeof(applet.isActive) ); - ready =1; + + if ( this.methodDefined("isActive") ) { + if (applet.isActive()) { //this could be zero if applet is loaded, but it is loading auxiliary data. + debug_add( "Applet " +appletName + " signals it is active."); + ready =1; + } else { + debug_add( "Applet " + appletName + " signals it is not active. -- \n it may still be loading data."); + ready = "still_loading"; + } } if (typeof(this.reportsLoaded) !="undefined" && this.reportsLoaded != 0 ) { - debug_add( " " + appletName + " applet self reports that it is loaded " ); + debug_add( " " + appletName + " applet self reports that it has completed loading. " ); ready =1; } this.isReady = ready; @@ -437,5 +487,5 @@ function iamhere() { - return "functions still work"; + alert( "javaScript loaded. functions still work"); } \ No newline at end of file |
From: dpvc v. a. <we...@ma...> - 2009-03-05 01:24:25
|
Log Message: ----------- make sure $permissionLevel is defined (since it was added recently) Modified Files: -------------- pg/macros: problemPanic.pl Revision Data ------------- Index: problemPanic.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/problemPanic.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -Lmacros/problemPanic.pl -Lmacros/problemPanic.pl -u -r1.3 -r1.4 --- macros/problemPanic.pl +++ macros/problemPanic.pl @@ -131,6 +131,7 @@ # Save the panic level for the next time through. # sub Init { + $main::permissionLevel = 0 unless defined $main::permissionLevel; $allowReset = $main::permissionLevel > $main::PRINT_FILE_NAMES_PERMISSION_LEVEL; $isTeX = ($main::displayMode eq 'TeX'); unless ($isTeX) { |
From: dpvc v. a. <we...@ma...> - 2009-03-03 15:45:15
|
Log Message: ----------- Corrected documentation (panic => panicked) Modified Files: -------------- pg/macros: problemPanic.pl Revision Data ------------- Index: problemPanic.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/problemPanic.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -Lmacros/problemPanic.pl -Lmacros/problemPanic.pl -u -r1.2 -r1.3 --- macros/problemPanic.pl +++ macros/problemPanic.pl @@ -35,10 +35,10 @@ When the student presses the hint button, the button will not longer be available, and the "panic level" will be increased. This sets the -variable $panic, which you can use to determine whether to include the +variable $panicked, which you can use to determine whether to include the hints or not. For example - if ($panic) { + if ($panicked) { BEGIN_TEXT Hint: You should factor the numerator and cancel one of the factors with the denominator. @@ -50,7 +50,7 @@ set $panic to 2 (panic level 2) and you can use that to include the second hint. - if ($panic) { + if ($panicked) { BEGIN_TEXT Hint: You should factor the numerator and cancel one of the factors with the denominator. @@ -59,7 +59,7 @@ (costing an additional 25%) END_TEXT - if ($panic > 1) { + if ($panicked > 1) { BEGIN_TEXT Additional Hint: one of the factors is \(x+$a)\). END_TEXT |
From: dpvc v. a. <we...@ma...> - 2009-03-01 23:06:32
|
Log Message: ----------- Added grader information Modified Files: -------------- pg/macros: problemPanic.pl Revision Data ------------- Index: problemPanic.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/problemPanic.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -Lmacros/problemPanic.pl -Lmacros/problemPanic.pl -u -r1.1 -r1.2 --- macros/problemPanic.pl +++ macros/problemPanic.pl @@ -100,6 +100,15 @@ development, but can be used to allow a student to get full credit for a problem even after he or she has asked for a hint. +To allow the grading penalties to work, you must include the command + + Panic::GradeWithPenalty; + +in order to install the panic-button grader. You should do this afer +setting the grader that you want to use for the problem itself, as the +panic grader will use the one that is installed at the time the +Panic::GradWithPenalty command is issued. + =cut sub _problemPanic_init {Panic::Init()} |
From: dpvc v. a. <we...@ma...> - 2009-03-01 15:25:46
|
Log Message: ----------- New macros for adding 'panic buttons' to get more hints Added Files: ----------- pg/macros: problemPanic.pl Revision Data ------------- --- /dev/null +++ macros/problemPanic.pl @@ -0,0 +1,216 @@ +################################################################################ +# WeBWorK Online Homework Delivery System +# Copyright © 2009 The WeBWorK Project, http://openwebwork.sf.net/ +# $CVSHeader: pg/macros/problemPanic.pl,v 1.1 2009/03/01 15:15:35 dpvc Exp $ +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of either: (a) the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any later +# version, or (b) the "Artistic License" which comes with this package. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the +# Artistic License for more details. +################################################################################ + +=head1 NAME + +problemPanic.pl - Allow for a PANIC button that gives additional + hints, possibly costing some points. + +=head1 DESCRIPTION + +This file implements a mechanism for you to provide one or more "panic +button" that your students can use to get additional hints, at the +cost of a portion of their score. + +To include the button, use the command Panic::Button command within a +BEGIN_TEXT/END_TEXT block. E.g., + + BEGIN_TEXT + \{Panic::Button(label => "Request a Hint", penalty => .25)\} + (you will lose 25% of your points if you do) + END_TEXT + +When the student presses the hint button, the button will not longer +be available, and the "panic level" will be increased. This sets the +variable $panic, which you can use to determine whether to include the +hints or not. For example + + if ($panic) { + BEGIN_TEXT + Hint: You should factor the numerator and cancel + one of the factors with the denominator. + END_TEXT + } + +Note that you can create a "cascade" of hints by including a second +panic button in the hint received from the first button. This will +set $panic to 2 (panic level 2) and you can use that to include the +second hint. + + if ($panic) { + BEGIN_TEXT + Hint: You should factor the numerator and cancel + one of the factors with the denominator. + $PAR + \{Panic::Button(label => "Another Hint", penalty => .25)\} + (costing an additional 25%) + END_TEXT + + if ($panic > 1) { + BEGIN_TEXT + Additional Hint: one of the factors is \(x+$a)\). + END_TEXT + } + } + +You can add more buttons in a similar way. You can not have separate +buttons for separate hints that are NOT cascaded, however. (That may +be possible in future versions.) + +The Panic::Button command takes two optional parameters: + +=over + +=item S<C<< label => "text" >>> + +Sets the text to use for the button. The default is "Request a Hint". + +=item S<C<< penalty => percent >>> + +Specifies the number points to lose (as a number from 0 to 1) if this +hint is displayed. When more than one panic button is used, the +penalties are cumulative. That is, two penalties of .25 would produce +a total penalty of .5, so the student would lose half his points if +both hints were given. + +=back + +Once a hint is displayed, the panic button for that hint will no +longer be shown, and the hint will continue to be displayed as the +student submits new answers. + +A professor will be given a "Reset problem hints" checkbox at the +bottom of the problem, and can use that to request that the panic +level be reset back to 0. This also sets the score and the number of +attempts back to 0 as well, so this effectively resets the problem to +its original state. This is intended for use primarily during problem +development, but can be used to allow a student to get full credit for +a problem even after he or she has asked for a hint. + +=cut + +sub _problemPanic_init {Panic::Init()} + + +# +# The packge to contain the routines and data for the Panic buttons +# +package Panic; + +my $isTeX = 0; # true in hardcopy mode +my $allowReset = 0; # true if a professor is viewing the problem +my $buttonCount = 0; # number of panic buttons displayed so far +my @penalty = (0); # accummulated penalty values +my $grader; # problem's original grader + +# +# Allow resets if permission level is high enough. +# Look up the panic level and reset it if needed. +# Save the panic level for the next time through. +# +sub Init { + $allowReset = $main::permissionLevel > $main::PRINT_FILE_NAMES_PERMISSION_LEVEL; + $isTeX = ($main::displayMode eq 'TeX'); + unless ($isTeX) { + $main::panicked = $main::inputs_ref->{_panicked} || 0; + $main::panicked = 0 if $main::inputs_ref->{_panic_reset} && $allowReset; + main::TEXT(qq!<input type="hidden" name="_panicked" id="_panicked" value="$main::panicked" />!); + main::RECORD_FORM_LABEL("_panicked"); + } +} + +# +# Place a panic button on the page, if it's not hardcopy mode and its not at the wrong level. +# You can set the label, the penalty for taking this hint, and the panic level for this button. +# Use submitAnswers if it is before the due date, and checkAnswers otherwise. +# +sub Button { + $buttonCount++; + my %options = ( + label => "Request a Hint", + level => $buttonCount, + penalty => 0, + @_ + ); + my $label = $options{label}; + my $level = $options{level}; + $penalty[$buttonCount] = $penalty[$buttonCount] + $options{penalty}; + $penalty[$buttonCount] = 1 if $penalty[$buttonCount] > 1; + return if $isTeX || $main::panicked >= $level; + my $time = time(); + my $name = ($main::openDate <= $time && $time <= $main::dueDate ? "submitAnswers" : "checkAnswers"); + $value = quoteHTML($value); + return qq!<input type="submit" name="$name" value="$label" onclick="document.getElementById('_panicked').value++">!; +} + +# +# The reset button +# +sub ResetButton { + main::RECORD_FORM_LABEL("_panic_reset"); + return qq!<input type="checkbox" name="_panic_reset"> Reset problem hints!; +} + +# +# Handle HTML in the value +# +sub quoteHTML { + my $string = shift; + $string =~ s/&/\&/g; $string =~ s/"/\"/g; + $string =~ s/>/\>/g; $string =~ s/</\</g; + return $string; +} + +# +# Install the panic grader, saving the original one +# +sub GradeWithPenalty { + $grader = $main::PG_FLAGS{PROBLEM_GRADER_TO_USE} || \&main::avg_problem_grader; + main::install_problem_grader(\&Panic::grader); +} + +# +# The grader for the panic levels. +# +sub grader { + # + # Save the old score and call the original grader. + # Compute the penalized score, and save it, if it is better than the old score. + # Reset the values if we are resetting scores. + # + my $oldScore = $_[1]->{recorded_score} || 0; + my ($result,$state) = &{$grader}(@_); + $result->{score} *= 1-$penalty[$main::panicked]; + $state->{recorded_score} = ($result->{score} > $oldScore ? $result->{score} : $oldScore); + $state->{recorded_score} = $state->{num_of_incorrect_ans} = $state->{num_of_correct_ans} = 0 + if $main::inputs_ref->{_panic_reset} && $allowReset; + + # + # Add the problemPanic message and data + # + $result->{type} = "problemPanic ($result->{type})"; + if ($main::panicked) { + $result->{msg} .= '</i><p><b>Note:</b> <i>' if $result->{msg}; + $result->{msg} .= 'Your score was reduced by '.(int($penalty[$main::panicked]*100)).'%' + . ' because you accepted '.($main::panicked == 1 ? 'a hint.' : $main::panicked.' hints.'); + # + # Add the reset checkbox, if needed + # + $result->{msg} .= '<p>'.ResetButton() if $allowReset; + } + + return ($result,$state); +} |
From: dpvc v. a. <we...@ma...> - 2009-02-25 00:08:16
|
Log Message: ----------- Apply message conversion before adding position information Modified Files: -------------- pg/lib/Value: Context.pm Revision Data ------------- Index: Context.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Value/Context.pm,v retrieving revision 1.21 retrieving revision 1.22 diff -Llib/Value/Context.pm -Llib/Value/Context.pm -u -r1.21 -r1.22 --- lib/Value/Context.pm +++ lib/Value/Context.pm @@ -142,8 +142,8 @@ while ($message && $error->{msg}{$message}) {$message = $error->{msg}{$message}} while ($more && $error->{msg}{$more}) {$more = $error->{msg}{$more}} $message = sprintf($message,@args) if scalar(@args) > 0; - $message .= sprintf($more,$pos->[0]+1) if $more; while ($message && $error->{msg}{$message}) {$message = $error->{msg}{$message}} + $message .= sprintf($more,$pos->[0]+1) if $more; $message = &{$error->{convert}}($message) if defined $error->{convert}; $error->{message} = $message; $error->{string} = $string; |
From: Mike G. v. a. <we...@ma...> - 2009-02-19 16:45:20
|
Log Message: ----------- Cleaning up duplicated lines Modified Files: -------------- pg/lib: Applet.pm Revision Data ------------- Index: Applet.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Applet.pm,v retrieving revision 1.16 retrieving revision 1.17 diff -Llib/Applet.pm -Llib/Applet.pm -u -r1.16 -r1.17 --- lib/Applet.pm +++ lib/Applet.pm @@ -367,6 +367,7 @@ sub insertHeader { my $self = shift; + my $codebase = $self->codebase; my $appletId = $self->appletId; my $appletName = $self->appletName; |
From: Mike G. v. a. <we...@ma...> - 2009-02-19 03:40:40
|
Log Message: ----------- reset state preserving answer box to blank after restoring applet to virgin state. Modified Files: -------------- webwork2/htdocs/js: ww_applet_support.js Revision Data ------------- Index: ww_applet_support.js =================================================================== RCS file: /webwork/cvs/system/webwork2/htdocs/js/ww_applet_support.js,v retrieving revision 1.5 retrieving revision 1.6 diff -Lhtdocs/js/ww_applet_support.js -Lhtdocs/js/ww_applet_support.js -u -r1.5 -r1.6 --- htdocs/js/ww_applet_support.js +++ htdocs/js/ww_applet_support.js @@ -182,7 +182,6 @@ } function getQE(name1) { // get Question Element in problemMainForm by name - //alert("getting " + name1); var isIE = navigator.appName.indexOf("Microsoft") != -1; var obj = (isIE) ? document.getElementById(name1) :document.problemMainForm[name1]; @@ -196,7 +195,6 @@ }; } else { - //alert("found " +obj); return( obj ); } |
From: Mike G. v. a. <we...@ma...> - 2009-02-19 03:27:26
|
Log Message: ----------- Corrected premature commit which contained a code hack for the macbook. Modified Files: -------------- pg/macros: dangerousMacros.pl Revision Data ------------- Index: dangerousMacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/dangerousMacros.pl,v retrieving revision 1.54 retrieving revision 1.55 diff -Lmacros/dangerousMacros.pl -Lmacros/dangerousMacros.pl -u -r1.54 -r1.55 --- macros/dangerousMacros.pl +++ macros/dangerousMacros.pl @@ -387,12 +387,10 @@ $appletLocation = "$server_root_url$appletLocation"; } my $url = "$appletLocation/$fileName"; - return $appletLocation; # --hack workaround -- just pick the first location and use that -- no checks -#hack to workaround conflict between lwp-request and apache2 -# if (check_url($url)) { -# $appletCodebaseLocations{$fileName} = $appletLocation; #update cache -# return $appletLocation # return codebase part of url -# } + if (check_url($url)) { + $appletCodebaseLocations{$fileName} = $appletLocation; #update cache + return $appletLocation # return codebase part of url + } } return "Error: $fileName not found at ". join(", ", @{$appletPath} ); # no file found } |
From: Mike G. v. a. <we...@ma...> - 2009-02-19 03:15:05
|
Log Message: ----------- Minor cosmetic change Modified Files: -------------- pg/macros: AppletObjects.pl PGbasicmacros.pl dangerousMacros.pl Revision Data ------------- Index: AppletObjects.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/AppletObjects.pl,v retrieving revision 1.16 retrieving revision 1.17 diff -Lmacros/AppletObjects.pl -Lmacros/AppletObjects.pl -u -r1.16 -r1.17 --- macros/AppletObjects.pl +++ macros/AppletObjects.pl @@ -39,8 +39,7 @@ # don't reload this file ######################################################################### -sub _AppletObjects_init { - +sub _AppletObjects_init { main::HEADER_TEXT(<<'END_HEADER_TEXT'); <script language="javascript">AC_FL_RunContent = 0;</script> @@ -165,8 +164,8 @@ my $state_input_element = ($self->debug == 1) ? $debug_input_element : qq!\n<input type="hidden" name = "$appletStateName" value ="$base_64_encoded_answer_value">!; my $reset_button_str = ($reset_button) ? - qq!<br/><input type='button' value='set applet state empty' onClick="setEmptyState('$appletName')"> - <input type="button" value="reinitialize applet" onClick="getQE('$appletStateName').value='$base64_initialState'"/>! + qq!<br/><input type='button' value='set applet state to restart' onClick="setAppletStateToRestart('$appletName')"> + <input type="button" value="reinitialize applet" onClick="getQE('$appletStateName').value='$base64_initialState'"/><br/>! : '' ; # always base64 encode the hidden answer value to prevent problems with quotes. @@ -179,11 +178,16 @@ . $reset_button_str . $state_input_element ; + $answerBox_code = qq!<br/><input type="input" name="answerBox" value="" size =50><br/> + <input type="button" value="get Answer from applet" onClick="eval(ww_applet_list['$appletName'].submitActionScript )"/> + <br/> + !; + $answerBox_code = ($self->debug == 1) ? $answerBox_code : ""; ####### # insert header material ####### main::HEADER_TEXT($self->insertHeader()); - return main::MODES(TeX=>' {\bf applet } ', HTML=>$self->insertObject.$main::BR.$state_storage_html_code); + return main::MODES(TeX=>' {\bf applet } ', HTML=>$self->insertObject.$main::BR.$state_storage_html_code.$answerBox_code); } =head3 Example problem Index: PGbasicmacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/PGbasicmacros.pl,v retrieving revision 1.57 retrieving revision 1.58 diff -Lmacros/PGbasicmacros.pl -Lmacros/PGbasicmacros.pl -u -r1.57 -r1.58 --- macros/PGbasicmacros.pl +++ macros/PGbasicmacros.pl @@ -1014,7 +1014,7 @@ $out = ''; # do nothing since hints are not available for download for students } } elsif ($printHintForInstructor) { # always print hints for instructor types - $out = join(' ', "$BR(Show the student hint after $showHint attempts: )$BR ", @in); + $out = join(' ', "$BR( Show the student hint after $showHint attempts: )$BR $BBOLD HINT: $EBOLD ", @in); } elsif ( $displayHint and ( $attempts > $showHint )) { ## the second test above prevents a hint being shown if a doctored form is submitted Index: dangerousMacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/dangerousMacros.pl,v retrieving revision 1.53 retrieving revision 1.54 diff -Lmacros/dangerousMacros.pl -Lmacros/dangerousMacros.pl -u -r1.53 -r1.54 --- macros/dangerousMacros.pl +++ macros/dangerousMacros.pl @@ -387,10 +387,12 @@ $appletLocation = "$server_root_url$appletLocation"; } my $url = "$appletLocation/$fileName"; - if (check_url($url)) { - $appletCodebaseLocations{$fileName} = $appletLocation; #update cache - return $appletLocation # return codebase part of url - } + return $appletLocation; # --hack workaround -- just pick the first location and use that -- no checks +#hack to workaround conflict between lwp-request and apache2 +# if (check_url($url)) { +# $appletCodebaseLocations{$fileName} = $appletLocation; #update cache +# return $appletLocation # return codebase part of url +# } } return "Error: $fileName not found at ". join(", ", @{$appletPath} ); # no file found } |
From: Mike G. v. a. <we...@ma...> - 2009-02-19 03:14:11
|
Log Message: ----------- Additional support for debugging Modified Files: -------------- pg/lib: Applet.pm Revision Data ------------- Index: Applet.pm =================================================================== RCS file: /webwork/cvs/system/pg/lib/Applet.pm,v retrieving revision 1.15 retrieving revision 1.16 diff -Llib/Applet.pm -Llib/Applet.pm -u -r1.15 -r1.16 --- lib/Applet.pm +++ lib/Applet.pm @@ -199,6 +199,7 @@ params =>undef, width => 550, height => 400, + bgcolor => "#869ca7", base64_state => undef, # this is an state to use for initializing the first occurence of the question. base64_config => undef, # this is the initial (and final?) configuration getStateAlias => 'getXML', @@ -311,6 +312,11 @@ $self->{width} = shift ||$self->{width}; # replace the current width if non-empty $self->{width}; } +sub bgcolor { + my $self = shift; + $self->{bgcolor} = shift ||$self->{bgcolor}; # replace the current background color if non-empty + $self->{bgcolor}; +} sub archive { my $self = shift; $self->{archive} = shift ||$self->{archive}; # replace the current archive if non-empty @@ -361,21 +367,28 @@ sub insertHeader { my $self = shift; - my $codebase = $self->codebase; - my $appletId = $self->appletId; - my $appletName = $self->appletName; - my $base64_initialState = $self->base64_state; - my $initializeAction = $self->initializeActionAlias; - my $submitAction = $self->submitActionAlias; - my $submitActionScript = $self->submitActionScript; - my $setState = $self->setStateAlias; - my $getState = $self->getStateAlias; - my $config = $self->configAlias; - my $base64_config = $self->base64_config; - my $debugMode = ($self->debug) ? "1": "0"; - my $returnFieldName = $self->{returnFieldName}; - my $answerBox = $self->{answerBox}; - my $headerText = $self->header(); + my $codebase = $self->codebase; + my $appletId = $self->appletId; + my $appletName = $self->appletName; + my $base64_initialState = $self->base64_state; + my $initializeAction = $self->initializeActionAlias; + my $submitActionAlias = $self->submitActionAlias; + my $submitActionScript = $self->submitActionScript; + my $setStateAlias = $self->setStateAlias; + my $getStateAlias = $self->getStateAlias; + my $configAlias = $self->configAlias; + my $base64_config = $self->base64_config; + my $debugMode = ($self->debug) ? "1": "0"; + my $returnFieldName = $self->{returnFieldName}; + my $answerBox = $self->{answerBox}; + my $headerText = $self->header(); + + + $submitActionScript =~ s/"/\\"/g; # escape quotes for ActionScript + # other variables should not have quotes. + + $submitActionScript =~ s/\n/ /g; # replace returns with spaces -- returns in the wrong spot can cause trouble with javaScript + $submitActionScript =~ s/\r/ /g; # replace returns with spaces -- returns can cause trouble $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook @@ -393,6 +406,7 @@ my $archive = $self->{archive}; my $width = $self->{width}; my $height = $self->{height}; + my $applet_bgcolor = $self->{bgcolor}; my $javaParameters = ''; my $flashParameters = ''; my %param_hash = %{$self->params()}; @@ -424,7 +438,7 @@ use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; <script src="/webwork2_files/js/Base64.js" language="javascript"> </script> - <script src="/webwork2_files/js/ww_applet_support.js"> + <script src="/webwork2_files/js/ww_applet_support.js" language="javascript"> //upload functions stored in /opt/webwork/webwork2/htdocs/js ... </script> <script language="JavaScript"> @@ -446,135 +460,15 @@ ww_applet_list["$appletName"].appletID = "$appletID"; ww_applet_list["$appletName"].base64_state = "$base64_initializationState"; ww_applet_list["$appletName"].base64_config = "$base64_config"; - ww_applet_list["$appletName"].getStateAlias = "$getState"; - ww_applet_list["$appletName"].setStateAlias = "$setState"; - ww_applet_list["$appletName"].configAlias = "$config"; + ww_applet_list["$appletName"].getStateAlias = "$getStateAlias"; + ww_applet_list["$appletName"].setStateAlias = "$setStateAlias"; + ww_applet_list["$appletName"].configAlias = "$configAlias"; ww_applet_list["$appletName"].initializeActionAlias = "$initializeAction"; - ww_applet_list["$appletName"].submitActionAlias = "$submitAction"; + ww_applet_list["$appletName"].submitActionAlias = "$submitActionAlias"; ww_applet_list["$appletName"].submitActionScript = "$submitActionScript"; ww_applet_list["$appletName"].answerBox = "$answerBox"; ww_applet_list["$appletName"].debug = "$debugMode"; - - ////////////////////////////////////////////////////////// - //CONFIGURATIONS - // - // configurations are "permanent" - ////////////////////////////////////////////////////////// - -// applet_config_list["$appletName"] = function() { -// debug_add("applet_config_list:\n attempt to configure $appletName . $config ( $base64_config ) if config function is defined: " -// ); -// try { -// if (( typeof(getApplet("$appletName").$config) == "function" ) ) { -// debug_add("CONFIGURE $appletName"); -// getApplet("$appletName").$config(Base64.decode("$base64_config")); -// } -// } catch(e) { -// alert("Error executing configuration command $config for $appletName: " + e ); -// } -// } -// //////////////////////////////////////////////////////////// -// // -// //STATE: -// // state can vary as the applet is manipulated -- it is reset from the questions _state values -// // -// ////////////////////////////////////////////////////////// -// -// applet_setState_list["$appletName"] = function(state) { -// debug_add("Begin setState for applet $appletName"); -// debug_add("Obtain state from $appletName"+"_state"); -// state = state || getQE("$appletName"+"_state").value; -// if ( base64Q(state) ) { -// state=Base64.decode(state); -// } -// if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml -// -// debug_add("applet_setState_list: \n set (decoded) state for $appletName to " + -// state +"\nfunction type is " +typeof(getApplet("$appletName").$setState) -// ); -// try { -// if (( typeof(getApplet("$appletName").$setState) =="function" ) ) { -// debug_add("setState for $appletName"); -// getApplet("$appletName").$setState( state ); -// } -// } catch(e) { -// alert("Error in setting state of $appletName using command $setState : " + e ); -// } -// } else if (debug) { -// alert("new state was empty string or did not begin with <xml-- state was not reset"); -// } -// }; -// applet_getState_list["$appletName"] = function () { -// debug_add("get current state for applet $appletName and store it in $appletName"+"_state"); -// var applet = getApplet("$appletName"); -// try { -// if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function -// state = applet.$getState(); // get state in xml format -// debug_add("state has type " + typeof(state)); -// state = String(state); // geogebra returned an object type instead of a string type -// debug_add("state converted to type " + typeof(state)); -// } -// -// if (!debug) { -// state = Base64.encode(state); -// }; // replace state by encoded version unless in debug mode -// -// debug_add("state is "+state); // this should still be in plain text -// getQE("$appletName"+"_state").value = state; //place state in input item (debug: textarea, otherwise: hidden) -// } catch (e) { -// alert("Error in getting state for $appletName " + e ); -// } -// }; -// -// //////////////////////////////////////////////////////////// -// // -// //INITIALIZE -// // -// //////////////////////////////////////////////////////////// -// -// -// applet_checkLoaded_list["$appletName"] = function() { // this function returns 0 unless: -// // applet has already been flagged as ready in applet_isReady_list -// // applet.config is defined (or alias for .config) -// // applet.setState is defined -// // applet.isActive is defined -// // applet reported that it is loaded by calling loadQ() -// var ready = 0; -// var applet = getApplet("$appletName"); -// if (!debug && applet_isReady_list["$appletName"]) {return(1)}; // memorize readiness in non-debug mode -// if ( typeof(applet.$config) == "function") { -// debug_add( "applet.config is " + typeof(applet.$config) ); -// ready = 1; -// } -// if( typeof(applet.$getState) == "function") { -// debug_add( "applet.getState is " + typeof(applet.$getState) ); -// ready =1; -// } -// if (typeof(applet.isActive) == "function" && applet.isActive ) { -// debug_add( "applet.isActive is " + typeof(applet.isActive) ); -// ready =1; -// } -// if (typeof(applet_reportsLoaded_list["$appletName"]) !="undefined" && applet_reportsLoaded_list["$appletName"] != 0 ) { -// debug_add( "applet reports that it is loaded " + applet_reportsLoaded_list["$appletName"] ); -// ready =1; -// } -// applet_isReady_list["$appletName"]= ready; -// return(ready); -// } -// -// applet_initializeAction_list["$appletName"] = function (state) { -// applet_setState_list["$appletName"](state); -// }; -// -// applet_submitAction_list["$appletName"] = function () { -// if (! applet_isReady_list["$appletName"] ) { -// alert("$appletName is not ready"); -// } -// applet_getState_list["$appletName"](); -// $submitActionScript -// //getQE("$answerBox").value = getApplet("$appletName").getAnswer(); //FIXME -- not needed in general? -// }; </script> END_HEADER_SCRIPT @@ -606,9 +500,9 @@ codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> <param name="movie" value="$codebase/$appletName.swf" /> <param name="quality" value="high" /> - <param name="bgcolor" value="#869ca7" /> + <param name="bgcolor" value="$applet_bgcolor" /> <param name="allowScriptAccess" value="sameDomain" /> - <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" + <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor" width="$width" height="$height" name="$appletName" align="middle" id="$appletName" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" @@ -628,10 +522,10 @@ codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> <param name="movie" value="$codebase/$appletName.swf" /> <param name="quality" value="high" /> - <param name="bgcolor" value="#869ca7" /> + <param name="bgcolor" value="$applet_bgcolor" /> <param name="allowScriptAccess" value="sameDomain" /> <param name="FlashVars" value="$flashParameters"/> - <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" + <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor" width="$width" height="$height" name="$appletName" align="middle" id="$appletName" play="true" loop="false" quality="high" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" @@ -698,6 +592,7 @@ id = "$appletName" width = "$width" height = "$height" + bgcolor = "$applet_bgcolor" MAYSCRIPT > $javaParameters |
From: Mike G. v. a. <we...@ma...> - 2009-02-19 03:13:32
|
Log Message: ----------- Additional support for debugging -- including the ability to reset the applet to it's virgin state. Modified Files: -------------- webwork2/htdocs/js: ww_applet_support.js Revision Data ------------- Index: ww_applet_support.js =================================================================== RCS file: /webwork/cvs/system/webwork2/htdocs/js/ww_applet_support.js,v retrieving revision 1.4 retrieving revision 1.5 diff -Lhtdocs/js/ww_applet_support.js -Lhtdocs/js/ww_applet_support.js -u -r1.4 -r1.5 --- htdocs/js/ww_applet_support.js +++ htdocs/js/ww_applet_support.js @@ -174,14 +174,15 @@ function base64Q(str) { /// determine whether an XML string has been base64 encoded. return ( !str.match(/<XML/i) && !str.match(/<?xml/i)); } -function setEmptyState(appletName){ - var newState = "<xml></xml>"; - ww_applet_list[appletName].setState(newState); +function setAppletStateToRestart(appletName){ + var newState = "<xml>restart_applet</xml>"; + //ww_applet_list[appletName].setState(newState); getQE(appletName+"_state").value = newState; getQE("previous_" + appletName + "_state").value = newState } function getQE(name1) { // get Question Element in problemMainForm by name + //alert("getting " + name1); var isIE = navigator.appName.indexOf("Microsoft") != -1; var obj = (isIE) ? document.getElementById(name1) :document.problemMainForm[name1]; @@ -195,6 +196,7 @@ }; } else { + //alert("found " +obj); return( obj ); } @@ -278,6 +280,13 @@ if ( base64Q(state) ) { state=Base64.decode(state); } + // if we are restarting the applet bail -- we don't want to set the state. + + if (state.match(/^<xml>restart_applet<\/xml>/) ) { + alert("The applet " +appletName + "has been reset to its virgin state."); + ww_preserve_applet_state.value =""; //Fixme? should we set the last answer to blank as well? + return(''); + } if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml debug_add(" Set (decoded) state for " + appletName + " to \n\n" + @@ -296,7 +305,7 @@ alert(msg); } } else if (debug) { - debug_add(" new state was empty string or did not begin with <xml-- \n Applet state was not reset"); + debug_add(" new state was empty string or did not begin with <xml> -- Applet state was not reset"); } return(''); }; @@ -372,15 +381,28 @@ ww_applet.prototype.submitAction = function () { var appletName = this.appletName; // var getAnswer = this.getAnswerAlias; + var ww_preserve_applet_state = getQE(appletName + "_state"); // hidden answer box preserving applet state + var saved_state = ww_preserve_applet_state.value; + if (debug) {debug_add("Begin submit action for applet " + appletName);} var applet = getApplet(appletName); if (! this.isReady ) { alert(appletName + " is not ready"); initializeAction(); } - this.getState(); // have ww_applet retrieve state from applet and store in answerbox - eval(this.submitActionScript); - //getQE(this.answerBox).value = applet.[getAnswer](); //FIXME -- not needed in general? + // Check to see if we want to restart the applet + + if (saved_state.match(/^<xml>restart_applet<\/xml>/) ) { + if (debug) { debug_add("Restarting the applet "+appletName);} + setAppletStateToRestart(appletName); // erases all of the saved state + return(''); + } + // if we are not restarting the applet save the state and submit + + this.getState(); // have ww_applet retrieve state from applet and store in answerbox + if (debug) {debug_add("Submit Action Script " + this.submitActionScript + "\n");} + eval(this.submitActionScript); + //getQE(this.answerBox).value = applet.[getAnswer](); //FIXME -- not needed in general? if (debug) {debug_add("Completed submitAction() for applet " + appletName+ "\n");} }; |
From: Mike G. v. a. <we...@ma...> - 2009-02-14 17:02:09
|
Log Message: ----------- Reverse the order in which site_info and login_info appear on the page. Once again login_info appears first. This was inadvertently switched when I updated Login a few days ago. Modified Files: -------------- webwork2/lib/WeBWorK/ContentGenerator: Login.pm Revision Data ------------- Index: Login.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/Login.pm,v retrieving revision 1.46 retrieving revision 1.47 diff -Llib/WeBWorK/ContentGenerator/Login.pm -Llib/WeBWorK/ContentGenerator/Login.pm -u -r1.46 -r1.47 --- lib/WeBWorK/ContentGenerator/Login.pm +++ lib/WeBWorK/ContentGenerator/Login.pm @@ -45,56 +45,60 @@ my $ce = $r->ce; my $result; - # This section should be kept in sync with the Home.pm version - my $site_info = $ce->{webworkFiles}->{site_info}; - if (defined $site_info and $site_info) { + # list the login info first. + + # FIXME this is basically the same code as below... TIME TO REFACTOR! + my $login_info = $ce->{courseFiles}->{login_info}; + + if (defined $login_info and $login_info) { + # login info is relative to the templates directory, apparently + $login_info = $ce->{courseDirs}->{templates} . "/$login_info"; + # deal with previewing a temporary file # FIXME: DANGER: this code allows viewing of any file # FIXME: this code is disabled because PGProblemEditor no longer uses editFileSuffix #if (defined $r->param("editMode") and $r->param("editMode") eq "temporaryFile" # and defined $r->param("editFileSuffix")) { - # $site_info .= $r->param("editFileSuffix"); + # $login_info .= $r->param("editFileSuffix"); #} - if (-f $site_info) { - my $text = eval { readFile($site_info) }; + if (-f $login_info) { + my $text = eval { readFile($login_info) }; if ($@) { - $result .= CGI::h2("Site Information"); + $result .= CGI::h2("Login Info"); $result .= CGI::div({class=>"ResultsWithError"}, $@); } elsif ($text =~ /\S/) { - $result .= CGI::h2("Site Information"); + $result .= CGI::h2("Login Info"); $result .= $text; } } } - - # FIXME this is basically the same code as above... TIME TO REFACTOR! - my $login_info = $ce->{courseFiles}->{login_info}; - if (defined $login_info and $login_info) { - # login info is relative to the templates directory, apparently - $login_info = $ce->{courseDirs}->{templates} . "/$login_info"; - + + my $site_info = $ce->{webworkFiles}->{site_info}; + if (defined $site_info and $site_info) { # deal with previewing a temporary file # FIXME: DANGER: this code allows viewing of any file # FIXME: this code is disabled because PGProblemEditor no longer uses editFileSuffix #if (defined $r->param("editMode") and $r->param("editMode") eq "temporaryFile" # and defined $r->param("editFileSuffix")) { - # $login_info .= $r->param("editFileSuffix"); + # $site_info .= $r->param("editFileSuffix"); #} - if (-f $login_info) { - my $text = eval { readFile($login_info) }; + if (-f $site_info) { + my $text = eval { readFile($site_info) }; if ($@) { - $result .= CGI::h2("Login Info"); + $result .= CGI::h2("Site Information"); $result .= CGI::div({class=>"ResultsWithError"}, $@); } elsif ($text =~ /\S/) { - $result .= CGI::h2("Login Info"); + $result .= CGI::h2("Site Information"); $result .= $text; } } } + + if (defined $result and $result ne "") { return CGI::div({class=>"info-box", id=>"InfoPanel"}, $result); } else { |
From: Mike G. v. a. <we...@ma...> - 2009-02-12 20:14:18
|
Log Message: ----------- changes to interface imported from the 2-4-patches code that didn't make it into head Modified Files: -------------- webwork2/lib/WeBWorK/ContentGenerator/Instructor: PGProblemEditor.pm Revision Data ------------- Index: PGProblemEditor.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm,v retrieving revision 1.94 retrieving revision 1.95 diff -Llib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm -Llib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm -u -r1.94 -r1.95 --- lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm +++ lib/WeBWorK/ContentGenerator/Instructor/PGProblemEditor.pm @@ -118,7 +118,8 @@ # save_to_new_file # -use constant ACTION_FORMS => [qw(view add_problem make_local_copy save save_as revert)]; #[qw(view save save_as revert add_problem add_header make_local_copy)]; +use constant ACTION_FORMS => [qw(view add_problem save save_as revert)]; +#[qw(view save save_as revert add_problem add_header make_local_copy)]; # permissions needed to perform a given action use constant FORM_PERMS => { @@ -372,13 +373,13 @@ } elsif ((not -w $inputFilePath) && $file_type ne 'blank_problem' ) { $self->addbadmessage("The file '".$self->shortPath($inputFilePath)."' is protected! ".CGI::br(). - "To edit this text you must make a copy of this file using the 'make local editable copy at ...' action below."); + "To edit this text you must first make a copy of this file using the 'Save as' action below."); } if ($inputFilePath =~/$BLANKPROBLEM$/ && $file_type ne 'blank_problem') { # $self->addbadmessage("This file '$inputFilePath' is a blank problem! ".CGI::br()."To edit this text you must $self->addbadmessage("The file '".$self->shortPath($inputFilePath)."' is a blank problem! ".CGI::br()."To edit this text you must - use 'Create a copy' below to save it to another file."); + use the 'Save as' action below to save it to another file."); } } @@ -681,7 +682,8 @@ my $setID = $self->{setID}; $setID = int(rand(1000)) unless $setID =~/\S/; # setID can be 0 if ($path =~ /Library/) { - $path =~ s|^.*?Library/||; # truncate the url up to a segment such as ...rochesterLibrary/....... + #$path =~ s|^.*?Library/||; # truncate the url up to a segment such as ...rochesterLibrary/....... + $path =~ s|^.*?Library/|local/|; # truncate the url up to a segment such as ...rochesterLibrary/....... and prepend local } elsif ($path eq $default_screen_header_path) { $path = "set$setID/setHeader.pg"; } elsif ($path eq $default_hardcopy_header_path) { @@ -852,7 +854,7 @@ ($file_type eq 'blank_problem') and do { $editFilePath = $ce->{webworkFiles}->{screenSnippets}->{blankProblem}; $self->addbadmessage("This is a blank problem template file and can not be edited directly. " - ."First use 'Create a copy' below to make a local copy, then add the file to the current problem set, then edit the file." + ."Use the 'Save as' action below to create a local copy of the file and add it to the current problem set." ); last CASE; }; @@ -1582,8 +1584,13 @@ or $self->{file_type} eq 'set_header' # $editFilePath eq $self->r->ce->{webworkFiles}->{hardcopySnippets}->{setHeader} # special case to make copy of screen header or $self->{file_type} eq 'hardcopy_header'; # $editFilePath eq $self->r->ce->{webworkFiles}->{screenSnippets}->{setHeader} ; # special case to make copy of hardcopy header # or $self->{file_type} eq 'source_path_for_problem_file'; # need setID and problemID to make local copy -- can't be done in this case. + # make sure setID is well defined before allowing local copy + my $setID = $self->{setID}; + my $probNum = ($self->{file_type} eq 'problem')? "/problem $self->{problemID}" : ""; + return "" unless defined($setID) && $setID =~ m/\S/ && $setID ne 'Undefined_Set'; + return join ("", - "Make local editable copy at: [TMPL]/".($self->determineLocalFilePath($editFilePath)), + "Save local editable copy as: [TMPL]/".($self->determineLocalFilePath($editFilePath)).CGI::br()." and use in ".CGI::b("set $setID$probNum"), CGI::hidden(-name=>'action.make_local_copy.target_file', -value=>$self->determineLocalFilePath($editFilePath) ), CGI::hidden(-name=>'action.make_local_copy.source_file', -value=>$editFilePath ), CGI::hidden(-name=>'action.make_local_copy.file_type',-value=>$self->{file_type}), @@ -1630,7 +1637,7 @@ my $probNum = ($self->{file_type} eq 'problem')? "/problem $self->{problemID}" : ""; my $andRelink = ''; - $andRelink = ' and '.CGI::checkbox( + $andRelink = CGI::br().' and '.CGI::checkbox( -name => "action.save_as.saveMode", -value => "rename", -label => "", @@ -1640,9 +1647,9 @@ " use in ".CGI::b("set $fullSetID$probNum") if defined($setID) && $setID =~ m/\S/ && $setID ne 'Undefined_Set' && $self->{file_type} ne 'blank_problem'; - return 'Create a copy at [TMPL]/'. + return 'Save as [TMPL]/'. CGI::textfield( - -name=>'action.save_as.target_file', -size=>30, -value=>"$shortFilePath", #FIXME -- you might not be able to save to this default filepath + -name=>'action.save_as.target_file', -size=>60, -value=>"$shortFilePath", #FIXME -- you might not be able to save to this default filepath -onfocus=>$onChange ). CGI::hidden(-name=>'action.save_as.source_file', -value=>$editFilePath ). |
From: dpvc v. a. <we...@ma...> - 2009-02-11 23:16:53
|
Log Message: ----------- Prevent extra dots from appearing in image names for TeX mode Modified Files: -------------- pg/macros: dangerousMacros.pl Revision Data ------------- Index: dangerousMacros.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/dangerousMacros.pl,v retrieving revision 1.52 retrieving revision 1.53 diff -Lmacros/dangerousMacros.pl -Lmacros/dangerousMacros.pl -u -r1.52 -r1.53 --- macros/dangerousMacros.pl +++ macros/dangerousMacros.pl @@ -1076,6 +1076,7 @@ # .gif FILES in TeX mode ################################################################################ + $setNumber =~ s/\./_/g; ## extra dots confuse latex's graphics package if ($envir{texDisposition} eq "pdf") { # We're going to create PDF files with our TeX (using pdflatex), so we # need images in PNG format. @@ -1208,6 +1209,7 @@ # .png FILES in TeX mode ################################################################################ + $setNumber =~ s/\./_/g; ## extra dots confuse latex's graphics package if ($envir{texDisposition} eq "pdf") { # We're going to create PDF files with our TeX (using pdflatex), so we # need images in PNG format. what luck! they're already in PDF format! |
From: Mike G. v. a. <we...@ma...> - 2009-02-11 03:41:44
|
Log Message: ----------- Added ability to automatically create some directories -- so far only html_temp when archiving the course. Modified Files: -------------- webwork2/lib/WeBWorK/ContentGenerator: CourseAdmin.pm Revision Data ------------- Index: CourseAdmin.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v retrieving revision 1.82 retrieving revision 1.83 diff -Llib/WeBWorK/ContentGenerator/CourseAdmin.pm -Llib/WeBWorK/ContentGenerator/CourseAdmin.pm -u -r1.82 -r1.83 --- lib/WeBWorK/ContentGenerator/CourseAdmin.pm +++ lib/WeBWorK/ContentGenerator/CourseAdmin.pm @@ -926,6 +926,7 @@ $msg .= $CIchecker->updateTableFields($rename_oldCourseID, $table_name); } print CGI::p({-style=>'color:green; font-weight:bold'}, $msg); + } ($tables_ok,$dbStatus) = $CIchecker->checkCourseTables($rename_oldCourseID); @@ -1846,6 +1847,13 @@ } print CGI::p({-style=>'color:green; font-weight:bold'}, $msg); } + if ($r->param("upgrade_course_tables") ) { + + $CIchecker -> updateCourseDirectories(); # needs more error messages + + + + } ($tables_ok,$dbStatus) = $CIchecker->checkCourseTables($archive_courseID); @@ -1977,8 +1985,10 @@ ); } else { print CGI::p({style=>"text-align: center"}, - CGI::submit(-name => "decline_archive_course", -value => "Don't archive"),CGI::br(), - "Directory structure needs to be repaired manually before archiving." + CGI::br(), + "Directory structure needs to be repaired manually before archiving.",CGI::br(), + CGI::submit(-name => "decline_archive_course", -value => "Don't archive"), + CGI::submit(-name => "upgrade_course_tables", -value => "Attempt to upgrade directories"), ); } |
From: Mike G. v. a. <we...@ma...> - 2009-02-11 03:41:06
|
Log Message: ----------- Added ability to automatically create html_temp directory -- which is often missing if the course hasn't been used when preparing course for archival. Modified Files: -------------- webwork2/lib/WeBWorK/Utils: CourseIntegrityCheck.pm Revision Data ------------- Index: CourseIntegrityCheck.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/Utils/CourseIntegrityCheck.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -Llib/WeBWorK/Utils/CourseIntegrityCheck.pm -Llib/WeBWorK/Utils/CourseIntegrityCheck.pm -u -r1.3 -r1.4 --- lib/WeBWorK/Utils/CourseIntegrityCheck.pm +++ lib/WeBWorK/Utils/CourseIntegrityCheck.pm @@ -27,6 +27,7 @@ use warnings; use WeBWorK::Debug; use WeBWorK::Utils::CourseManagement qw/listCourses/; +use WeBWorK::PG::IO; use constant { # constants describing the comparison of two hashes. ONLY_IN_A=>0, @@ -306,6 +307,41 @@ return ( $directories_ok, $str); } +=item $CIchecker->updateCourseDirectories($courseName); + +Creates some course directories automatically. + + +=cut + +sub updateCourseDirectories { + my ($self) = @_; + my $ce = $self->{ce}; + my @webworkDirectories = keys %{$ce->{webworkDirs}}; + my @courseDirectories = keys %{$ce->{courseDirs}}; + + my %updateable_directories = (html_temp=>1); #FIXME this is hardwired for the time being. + + foreach my $dir (sort @courseDirectories) { + next unless exists $updateable_directories{$dir}; + my $path = $ce->{courseDirs}->{$dir}; + unless ( -e $path) { # if by some unlucky chance the tmpDirectory hasn't been created, create it. + my $parentDirectory = $path; + $parentDirectory =~s|/$||; # remove a trailing / + $parentDirectory =~s|/\w*$||; # remove last node + my ($perms, $groupID) = (stat $parentDirectory)[2,5]; + WeBWorK::PG::IO::createDirectory($path, $perms, $groupID) + or warn "Failed to create directory at $path"; + + } + } + + return ( ); +} + + + + ############################################################################## # Database utilities -- borrowed from DBUpgrade.pm ??use or modify??? --MEG ############################################################################## |
From: Mike G. v. a. <we...@ma...> - 2009-02-08 15:26:15
|
Log Message: ----------- Added copyright notice Modified Files: -------------- webwork2/htdocs/js: ww_applet_support.js Revision Data ------------- Index: ww_applet_support.js =================================================================== RCS file: /webwork/cvs/system/webwork2/htdocs/js/ww_applet_support.js,v retrieving revision 1.3 retrieving revision 1.4 diff -Lhtdocs/js/ww_applet_support.js -Lhtdocs/js/ww_applet_support.js -u -r1.3 -r1.4 --- htdocs/js/ww_applet_support.js +++ htdocs/js/ww_applet_support.js @@ -1,3 +1,18 @@ +// ################################################################################ +// # WeBWorK Online Homework Delivery System +// # Copyright © 2000-2009 The WeBWorK Project, http://openwebwork.sf.net/ +// # $CVSHeader$ +// # +// # This program is free software; you can redistribute it and/or modify it under +// # the terms of either: (a) the GNU General Public License as published by the +// # Free Software Foundation; either version 2, or (at your option) any later +// # version, or (b) the "Artistic License" which comes with this package. +// # +// # This program is distributed in the hope that it will be useful, but WITHOUT +// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the +// # Artistic License for more details. +// ################################################################################ |
From: Mike G. v. a. <we...@ma...> - 2009-02-08 03:39:20
|
Log Message: ----------- Corrected typo Applet.pm ww_applet_support.js AppletObject.pl and math/system.template should soon be up to date and synchronized Modified Files: -------------- webwork2/htdocs/js: ww_applet_support.js Revision Data ------------- Index: ww_applet_support.js =================================================================== RCS file: /webwork/cvs/system/webwork2/htdocs/js/ww_applet_support.js,v retrieving revision 1.2 retrieving revision 1.3 diff -Lhtdocs/js/ww_applet_support.js -Lhtdocs/js/ww_applet_support.js -u -r1.2 -r1.3 --- htdocs/js/ww_applet_support.js +++ htdocs/js/ww_applet_support.js @@ -98,7 +98,7 @@ } try{ - ww_applet.config; + ww_applet.config(); } catch(e) { var msg = "Unable to configure " + appletName + " \n " +e; @@ -223,8 +223,8 @@ var appletName = this.appletName; var applet = getApplet(appletName); var configAlias = this.configAlias; - debug_add(" check " + appletName +"."+ config +"( " + this.base64_config + " ) to see if config function is defined: " - ); + debug_add(" Checking " + appletName +"."+ configAlias +"( " + this.base64_config + " ) to see if config function is defined. The data is" + + this.base64_config + " " + Base64.decode(this.base64_config) ); try { if (( typeof(applet[configAlias]) == "function" ) ) { debug_add(" CONFIGURING " + appletName); |
From: Mike G. v. a. <we...@ma...> - 2009-02-08 01:17:36
|
Log Message: ----------- Added an alert message to warn that some of the support files might not be up to date. Modified Files: -------------- webwork2/htdocs/js: ww_applet_support.js Revision Data ------------- Index: ww_applet_support.js =================================================================== RCS file: /webwork/cvs/system/webwork2/htdocs/js/ww_applet_support.js,v retrieving revision 1.1 retrieving revision 1.2 diff -Lhtdocs/js/ww_applet_support.js -Lhtdocs/js/ww_applet_support.js -u -r1.1 -r1.2 --- htdocs/js/ww_applet_support.js +++ htdocs/js/ww_applet_support.js @@ -52,8 +52,8 @@ }; } -function intializeAction() { // deprecated call -- removed - alert("You are using an old template (stored at webwork2/conf/templates). The <body> tag in the template calls a function 'initializeAction()' -- this function name should be replaced by 'initializeWWquestion()'"); +function initializeAction() { // deprecated call -- removed + alert("You might be using an old template (stored at webwork2/conf/templates). The <body> tag in the system.template calls a function 'initializeAction()' -- this function name should be replaced by 'initializeWWquestion()'. Please update to a recent version of system.template"); initializeWWquestion(); } @@ -361,6 +361,7 @@ var applet = getApplet(appletName); if (! this.isReady ) { alert(appletName + " is not ready"); + initializeAction(); } this.getState(); // have ww_applet retrieve state from applet and store in answerbox eval(this.submitActionScript); |
From: Mike G. v. a. <we...@ma...> - 2009-02-07 23:51:56
|
Log Message: ----------- Changed the function called when the WW question is submitted. Modified Files: -------------- webwork2/conf/templates/math: system.template Revision Data ------------- Index: system.template =================================================================== RCS file: /webwork/cvs/system/webwork2/conf/templates/math/system.template,v retrieving revision 1.11 retrieving revision 1.12 diff -Lconf/templates/math/system.template -Lconf/templates/math/system.template -u -r1.11 -r1.12 --- conf/templates/math/system.template +++ conf/templates/math/system.template @@ -28,7 +28,7 @@ <title><!--#path style="text" text=" : " textonly="1"--></title> <!--#head--> </head> -<body bgcolor="white" onload="if (typeof(initializeAction) == 'function') {initializeAction()}"> +<body bgcolor="white" onload="if (typeof(initializeWWquestion) == 'function') {initializeWWquestion()}"> <div id="masthead"> <div id="loginstatus"> |
From: Mike G. v. a. <we...@ma...> - 2009-02-07 23:22:53
|
Log Message: ----------- javaScript support file for adding applets to WeBWorK. Added Files: ----------- webwork2/htdocs/js: ww_applet_support.js Revision Data ------------- --- /dev/null +++ htdocs/js/ww_applet_support.js @@ -0,0 +1,405 @@ + + + +////////////////////////////////////////////////////////// +// applet lists +////////////////////////////////////////////////////////// + +// var applet_initializeAction_list = new Object; // functions for initializing question with an applet +// var applet_submitAction_list = new Object; // functions for submitting question with applet +// var applet_setState_list = new Object; // functions for setting state (XML) from applets +// var applet_getState_list = new Object; // functions for getting state (XML) from applets +// var applet_config_list = new Object; // functions for configuring on applets +// var applet_checkLoaded_list = new Object; // functions for probing the applet to see if it is loaded +// var applet_reportsLoaded_list = new Object; // flag set by applet +// var applet_isReady_list = new Object; // flag set by javaScript in checkLoaded + + var ww_applet_list = new Object; // holds intelligent ww_applet objects + + +////////////////////////////////////////////////////////// +// DEBUGGING tools +////////////////////////////////////////////////////////// + var debug; + var debugText = ""; + function set_debug(num) { // setting debug for any applet sets it for all of them + if (num) { + debug =1; + } + } + function debug_add(str) { + if (debug) { + debugText = debugText + "\n" +str; + } + } + +////////////////////////////////////////////////////////// +// INITIALIZE and SUBMIT actions +////////////////////////////////////////////////////////// + +function submitAction() { // called from the submit button defined in Problem.pm + + if (debug) { + debugText = "Call submitAction() function on each applet\n"; + } + + for (var appletName in ww_applet_list ) { + ww_applet_list[appletName].submitAction(); + } + debug_add("\n Done calling submitAction() on each applet.\n"); + if (debug) { + alert(debugText); debugText=""; + }; +} + +function intializeAction() { // deprecated call -- removed + alert("You are using an old template (stored at webwork2/conf/templates). The <body> tag in the template calls a function 'initializeAction()' -- this function name should be replaced by 'initializeWWquestion()'"); + initializeWWquestion(); +} + +function initializeWWquestion() { // called from <body> tag defined in the webwork2/conf/template + var iMax = 5; + debugText="Initialize each applet. \nUse up to " +iMax + " cycles to wait for each applet to load\n"; + for (var appletName in ww_applet_list) { + safe_applet_initialize(appletName, iMax); + } + +} + +// applet can set isReady flag by calling applet_loaded(appletName, loaded); +// function applet_loaded(appletName,loaded) { +// debug_add("applet reporting that it has been loaded = " + loaded ); +// ww_applet_list[appletName].reportsLoaded = loaded; // 0 means not loaded +// } + + +// insures that applet is loaded before initializing it +function safe_applet_initialize(appletName, i) { + debug_add(" Try to initialize applet " + appletName + " with " +i + " attempts remaining.\n" ); + + i--; + var ww_applet = ww_applet_list[appletName]; + var applet_loaded = ww_applet.checkLoaded(); + + debug_add(" applet is ready = " + applet_loaded ); + + if ( 0 < i && !applet_loaded ) { // wait until applet is loaded + debug_add(" applet " + appletName + "not ready try again"); + window.setTimeout( "safe_applet_initialize(\"" + appletName + "\"," + i + ")",1); + } else if( 0 < i ){ // now that applet is loaded configure it and initialize it with saved data. + debug_add(appletName + " initialization completed with " + i + " possible attempts remaining. "); + + // in-line handler -- configure and initialize + try{ + ww_applet.setDebug(debug); + } catch(e) { + var msg = "Unable set debug in " + appletName + " \n " +e; + if (debug) {debug_add(msg);} else {alert(msg)}; + } + try{ + + ww_applet.config; + + } catch(e) { + var msg = "Unable to configure " + appletName + " \n " +e; + if (debug) {debug_add(msg);} else {alert(msg)}; + } + try{ + + ww_applet.initializeAction(); + + } catch(e) { + var msg = "unable to initialize " + appletName + " \n " +e; + if (debug) {debug_add(msg);} else {alert(msg)}; + } + + } else { + if (debug) {debug_add("Error: timed out waiting for applet " +appletName + " to load");} + } + if (debug) {alert(debugText); debugText="";}; +} + +/////////////////////////////////////////////////////// +// Utility functions +/////////////////////////////////////////////////////// + + +function getApplet(appletName) { + var isIE = navigator.appName.indexOf("Microsoft") != -1; + var obj = (isIE) ? window[appletName] : window.document[appletName]; + //return window.document[appletName]; + if (obj && (obj.name = appletName)) { + return( obj ); + } else { + alert ("can't find applet " + appletName); + } + } + +function listQuestionElements() { // list all HTML input and textarea elements in main problem form + var isIE = navigator.appName.indexOf("Microsoft") != -1; + var elementList = (isIE) ? document.getElementsByTagName("input") : document.problemMainForm.getElementsByTagName("input"); + var str=elementList.length +" Question Elements\n type | name = value < id > \n"; + for( var i=0; i< elementList.length; i++) { + str = str + " "+i+" " + elementList[i].type + + " | " + elementList[i].name + + "= " + elementList[i].value + + " <" + elementList[i].id + ">\n"; + } + elementList = (isIE) ? document.getElementsByTagName("textarea") : document.problemMainForm.getElementsByTagName("textarea"); + for( var i=0; i< elementList.length; i++) { + str = str + " "+i+" " + elementList[i].type + + " | " + elementList[i].name + + "= " + elementList[i].value + + " <" + elementList[i].id + ">\n"; + } + var msg = " ( Place listQuestionElements() at end of document in order to get all form elements! )\n"+str; + alert(msg); +} + +function base64Q(str) { /// determine whether an XML string has been base64 encoded. + return ( !str.match(/<XML/i) && !str.match(/<?xml/i)); +} +function setEmptyState(appletName){ + var newState = "<xml></xml>"; + ww_applet_list[appletName].setState(newState); + getQE(appletName+"_state").value = newState; + getQE("previous_" + appletName + "_state").value = newState +} + +function getQE(name1) { // get Question Element in problemMainForm by name + var isIE = navigator.appName.indexOf("Microsoft") != -1; + var obj = (isIE) ? document.getElementById(name1) + :document.problemMainForm[name1]; + // needed for IE -- searches id and name space so it can be unreliable if names are not unique + if (!obj || obj.name != name1) { + var msg = "Can't find element " + name1; + if (debug) { + debug_add(msg + "\n ( Place listQuestionElements() at end of document in order to get all form elements! )\n" ); + } else { + alert(msg); listQuestionElements(); + }; + + } else { + return( obj ); + } + +} +function getQuestionElement(name1) { + return getQE(name1); +} + + +/////////////////////////////////////////////////////// +// WW_Applet class definition +/////////////////////////////////////////////////////// + +function ww_applet(appletName) { + this.appletName = appletName; + this.code = ''; + this.codebase = ''; + this.appletID = ''; + this.base64_state = ''; + this.base64_config = ''; + this.getStateAlias = ''; + this.setStateAlias = ''; + this.configAlias = ''; + this.initializeActionAlias = ''; + this.submitActionAlias = ''; + this.submitActionScript = ''; + this.getAnswerAlias = ''; + this.answerBox = ''; + this.debug = ''; + this.isReady = 0 ; + this.reportsLoaded = 0 ; +}; + +////////////////////////////////////////////////////////// +//CONFIGURATIONS +// +// configurations are "permanent" +////////////////////////////////////////////////////////// +ww_applet.prototype.config = function () { + + var appletName = this.appletName; + var applet = getApplet(appletName); + var configAlias = this.configAlias; + debug_add(" check " + appletName +"."+ config +"( " + this.base64_config + " ) to see if config function is defined: " + ); + try { + if (( typeof(applet[configAlias]) == "function" ) ) { + debug_add(" CONFIGURING " + appletName); + applet[configAlias](Base64.decode(this.base64_config)); + } else { + debug_add("Applet does not have config method named: " + configAlias + "."); + } + } catch(e) { + var msg = "Error in configuring " + appletName + " using command " + configAlias + " : " + e ; + alert(msg); + } + }; +//////////////////////////////////////////////////////////// +// +//STATE: +// state can vary as the applet is manipulated -- it is reset from the questions _state values +// +////////////////////////////////////////////////////////// +ww_applet.prototype.setState = function(state) { + + var appletName = this.appletName; + var applet = getApplet(appletName); + var setStateAlias = this.setStateAlias; + + debug_add("\nBegin process of setting state for applet " + appletName); + + if (state) { + debug_add(" Obtain state from calling parameter:\n " + state + "\n"); + } else { + debug_add(" Obtain state from " + appletName +"_state"); + + var ww_preserve_applet_state = getQE(appletName + "_state"); // hidden answer box preserving applet state + state = ww_preserve_applet_state.value; + } + + if ( base64Q(state) ) { + state=Base64.decode(state); + } + if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml + + debug_add(" Set (decoded) state for " + appletName + " to \n\n" + + state +"\n\n Check that applet's setState method " +setStateAlias + " is a function: " +typeof(applet[setStateAlias]) + ); + + try { + if ( typeof(applet[setStateAlias]) == "function" ) { + applet[setStateAlias]( state ); // change the applets current state + debug_add("Completed setting the state of applet: " + appletName + "."); + } else { + debug_add("Applet does not have setState method named: " + setStateAlias + "."); + } + } catch(e) { + msg = "Error in setting state of " + appletName + " using command " + setStateAlias + " : " + e ; + alert(msg); + } + } else if (debug) { + debug_add(" new state was empty string or did not begin with <xml-- \n Applet state was not reset"); + } + return(''); +}; + +ww_applet.prototype.getState = function () { + + var state ="<xml>foobar</xml>"; + var appletName = this.appletName; + var applet = getApplet(appletName); + var getStateAlias = this.getStateAlias; + + debug_add(" Begin getState for applet " + appletName ); + + try { + if ((typeof(applet[getStateAlias]) == "function" )) { // there may be no state function + state = applet[getStateAlias](); // get state in xml format + debug_add(" state has type " + typeof(state)); + state = String(state); // geogebra returned an object type instead of a string type + // this insures that we can view the state as a string + debug_add(" state converted to type " + typeof(state)); + } else { + debug_add(" Applet does not have a getState method named: "+ getStateAlias + "."); + state ="<xml>undefined_state</xml>"; + } + + } catch (e) { + var msg = " Error in getting state from applet " + appletName + " " + e; + alert(msg); + } + + if (!debug) { + state = Base64.encode(state); + }; // replace state by encoded version unless in debug mode + + debug_add(" state is \n "+ state + "\n"); // state should still be in plain text + var ww_preserve_applet_state = getQE(appletName + "_state"); // answer box preserving applet state (debug: textarea, otherwise: hidden) + ww_preserve_applet_state.value = state; //place state in input item (debug: textarea, otherwise: hidden) + debug_add("State stored in answer box "+ appletName + "_state and getState is finished."); + +}; + +ww_applet.prototype.setDebug = function(debugMode) { + + var appletName = this.appletName; + var applet = getApplet(appletName); + debugMode = debugMode || this.debug; + + try{ + if (typeof(applet.debug) == "function" ) { + applet.debug(1); // turn the applet's debug functions on. + } else { + debug_add( " Unable to set debug state in applet " + appletName + "."); + + } + } catch(e) { + var msg = "Unable to set debug mode for applet " + appletName; + alert(msg); + } + + +} +//////////////////////////////////////////////////////////// +// +//INITIALIZE +// +//////////////////////////////////////////////////////////// + +ww_applet.prototype.initializeAction = function () { + var state = ''; + this.setState(); +}; + +ww_applet.prototype.submitAction = function () { + var appletName = this.appletName; + // var getAnswer = this.getAnswerAlias; + if (debug) {debug_add("Begin submit action for applet " + appletName);} + var applet = getApplet(appletName); + if (! this.isReady ) { + alert(appletName + " is not ready"); + } + this.getState(); // have ww_applet retrieve state from applet and store in answerbox + eval(this.submitActionScript); + //getQE(this.answerBox).value = applet.[getAnswer](); //FIXME -- not needed in general? + if (debug) {debug_add("Completed submitAction() for applet " + appletName+ "\n");} +}; + +ww_applet.prototype.checkLoaded = function() { // this function returns 0 unless: + // applet has already been flagged as ready in applet_isReady_list + // applet.config is defined (or alias for .config) + // applet.setState is defined + // applet.isActive is defined + // applet reported that it is loaded by calling applet_loaded() + var ready = 0; + var appletName = this.appletName; + var applet = getApplet(appletName); + if (!debug && this.isReady) {return(1)}; // memorize readiness in non-debug mode + debug_add(" Test 4 methods to see if the applet " + appletName + " has been loaded. "); + if ( typeof(applet[this.configAlias]) == "function") { + debug_add( " applet.config method is defined as " + typeof(applet[this.configAlias]) ); + ready = 1; + } + if( typeof(applet[this.getStateAlias]) == "function") { + debug_add( " applet.getState method is defined as " + typeof(applet[this.getStateAlias]) ); + ready =1; + } + if (typeof(applet.isActive) == "function" && applet.isActive ) { + debug_add( " applet.isActive method is defined as " + typeof(applet.isActive) ); + ready =1; + } + if (typeof(this.reportsLoaded) !="undefined" && this.reportsLoaded != 0 ) { + debug_add( " " + appletName + " applet self reports that it is loaded " ); + ready =1; + } + this.isReady = ready; + return(ready); +} + + +function iamhere() { + return "functions still work"; +} \ No newline at end of file |
From: Mike G. v. a. <we...@ma...> - 2009-02-07 23:18:38
|
Log Message: ----------- More code to check that the javaScript file is availabe. Modified Files: -------------- pg/macros: AppletObjects.pl Revision Data ------------- Index: AppletObjects.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/AppletObjects.pl,v retrieving revision 1.15 retrieving revision 1.16 diff -Lmacros/AppletObjects.pl -Lmacros/AppletObjects.pl -u -r1.15 -r1.16 --- macros/AppletObjects.pl +++ macros/AppletObjects.pl @@ -50,10 +50,7 @@ </script> <script src="/webwork2_files/js/ww_applet_support.js"> //upload functions stored in /opt/webwork/webwork2/htdocs/js ... - - if (!( typeof(set_debug) == "function") ) { - alert("Can't find the function set_debug. Is the file ww_applet_support.js in /webwork2/htdocs/js"); - } + </script> END_HEADER_TEXT |
From: Mike G. v. a. <we...@ma...> - 2009-02-07 23:05:25
|
Log Message: ----------- Fixed typo Modified Files: -------------- pg/macros: AppletObjects.pl Revision Data ------------- Index: AppletObjects.pl =================================================================== RCS file: /webwork/cvs/system/pg/macros/AppletObjects.pl,v retrieving revision 1.14 retrieving revision 1.15 diff -Lmacros/AppletObjects.pl -Lmacros/AppletObjects.pl -u -r1.14 -r1.15 --- macros/AppletObjects.pl +++ macros/AppletObjects.pl @@ -50,10 +50,11 @@ </script> <script src="/webwork2_files/js/ww_applet_support.js"> //upload functions stored in /opt/webwork/webwork2/htdocs/js ... - </script> - if (!( typeof(set_debug) == "function") ) { - alert("Can't find the function set_debug. Is the file ww_applet_support.js in /webwork2/htdocs/js"); - } + + if (!( typeof(set_debug) == "function") ) { + alert("Can't find the function set_debug. Is the file ww_applet_support.js in /webwork2/htdocs/js"); + } + </script> END_HEADER_TEXT }; |