1 | ################################################################################ |
1 | ################################################################################ |
2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
3 | # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ |
4 | # $CVSHeader: pg/macros/AppletObjects.pl,v 1.17 2009/02/19 03:05:14 gage Exp $ |
4 | # $CVSHeader: pg/macros/AppletObjects.pl,v 1.18 2009/03/10 12:07:47 gage Exp $ |
5 | # |
5 | # |
6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
… | |
… | |
37 | # Add basic functionality to the header of the question |
37 | # Add basic functionality to the header of the question |
38 | # |
38 | # |
39 | # don't reload this file |
39 | # don't reload this file |
40 | ######################################################################### |
40 | ######################################################################### |
41 | |
41 | |
42 | sub _AppletObjects_init { |
42 | sub _AppletObjects_init{ |
43 | |
43 | |
44 | main::HEADER_TEXT(<<'END_HEADER_TEXT'); |
44 | main::HEADER_TEXT(<<'END_HEADER_TEXT'); |
45 | <script language="javascript">AC_FL_RunContent = 0;</script> |
45 | <script language="javascript">AC_FL_RunContent = 0;</script> |
46 | <script src="/webwork2_files/applets/AC_RunActiveContent.js" language="javascript"> |
46 | <script src="/webwork2_files/applets/AC_RunActiveContent.js" language="javascript"> |
47 | </script> |
47 | </script> |
… | |
… | |
106 | =cut |
106 | =cut |
107 | |
107 | |
108 | sub insertAll { ## inserts both header text and object text |
108 | sub insertAll { ## inserts both header text and object text |
109 | my $self = shift; |
109 | my $self = shift; |
110 | my %options = @_; |
110 | my %options = @_; |
|
|
111 | |
|
|
112 | # debugMode can be turned on by setting it to 1 in either the applet definition or at insertAll time |
111 | $self->debug( (defined($options{debug}) and $options{debug}==1) ? 1 : 0 ); |
113 | my $debugMode = (defined($options{debug}) and $options{debug}==1) ? 1 : 0; |
|
|
114 | $debugMode = $debugMode || $self->debugMode; |
|
|
115 | $self->debugMode( $debugMode); |
|
|
116 | |
|
|
117 | |
112 | my $reset_button = $options{reset_button} || 0; |
118 | my $reset_button = $options{reset_button} || 0; |
113 | # prepare html code for storing state |
119 | # prepare html code for storing state |
114 | my $appletName = $self->appletName; |
120 | my $appletName = $self->appletName; |
115 | my $appletStateName = "${appletName}_state"; |
121 | my $appletStateName = "${appletName}_state"; |
116 | my $getState = $self->getStateAlias; |
122 | my $getState = $self->getStateAlias; |
… | |
… | |
167 | onClick="debugText=''; |
173 | onClick="debugText=''; |
168 | ww_applet_list['$appletName'].getConfig()"; " |
174 | ww_applet_list['$appletName'].getConfig()"; " |
169 | > |
175 | > |
170 | <input type="button" value="$setConfig" |
176 | <input type="button" value="$setConfig" |
171 | onClick="debugText=''; |
177 | onClick="debugText=''; |
172 | ww_applet_list['$appletName'].config(); |
178 | ww_applet_list['$appletName'].setConfig(); |
173 | alert(debugText);" |
179 | alert(debugText);" |
174 | > |
180 | > |
175 | !; |
181 | !; |
176 | |
182 | |
177 | my $state_input_element = ($self->debug == 1) ? $debug_input_element : |
183 | my $state_input_element = ($debugMode) ? $debug_input_element : |
178 | qq!\n<input type="hidden" name = "$appletStateName" value ="$base_64_encoded_answer_value">!; |
184 | qq!\n<input type="hidden" name = "$appletStateName" value ="$base_64_encoded_answer_value">!; |
179 | my $reset_button_str = ($reset_button) ? |
185 | my $reset_button_str = ($reset_button) ? |
180 | qq!<br/><input type='button' value='set applet state to restart' onClick="setAppletStateToRestart('$appletName')"> |
186 | qq!<br/><input type='button' value='set applet state to restart' onClick="setAppletStateToRestart('$appletName')"> |
181 | <input type="button" value="reinitialize applet" onClick="getQE('$appletStateName').value='$base64_initialState'"/><br/>! |
187 | <input type="button" value="reinitialize applet" onClick="getQE('$appletStateName').value='$base64_initialState'"/><br/>! |
182 | : '' |
188 | : '' |
183 | ; |
189 | ; |
184 | # always base64 encode the hidden answer value to prevent problems with quotes. |
190 | # always base64 encode the hidden answer value to prevent problems with quotes. |
185 | # |
191 | # |
186 | $state_storage_html_code = |
|
|
187 | $reset_button_str. |
|
|
188 | $state_input_element. |
|
|
189 | qq!<input type="hidden" name="previous_$appletStateName" value = "$base_64_encoded_answer_value">!; |
|
|
190 | $state_storage_html_code = qq!<input type="hidden" name="previous_$appletStateName" value = "$base_64_encoded_answer_value">! |
192 | $state_storage_html_code = qq!<input type="hidden" name="previous_$appletStateName" value = "$base_64_encoded_answer_value">! |
191 | . $reset_button_str |
193 | . $reset_button_str |
192 | . $state_input_element |
194 | . $state_input_element |
193 | ; |
195 | ; |
194 | $answerBox_code = qq!<br/><input type="input" name="answerBox" value="" size =50><br/> |
196 | $answerBox_code = qq!<br/><input type="input" name="answerBox" value="" size =50><br/> |
195 | <input type="button" value="get Answer from applet" onClick="eval(ww_applet_list['$appletName'].submitActionScript )"/> |
197 | <input type="button" value="get Answer from applet" onClick="eval(ww_applet_list['$appletName'].submitActionScript )"/> |
196 | <br/> |
198 | <br/> |
197 | !; |
199 | !; |
198 | $answerBox_code = ($self->debug == 1) ? $answerBox_code : ""; |
200 | $answerBox_code = ($debugMode) ? $answerBox_code : q!<input type="hidden" name="answerBox" value="" size =50>!; |
199 | ####### |
201 | ####### |
200 | # insert header material |
202 | # insert header material |
201 | ####### |
203 | ####### |
202 | main::HEADER_TEXT($self->insertHeader()); |
204 | main::HEADER_TEXT($self->insertHeader()); |
|
|
205 | # update the debug mode for this applet. |
|
|
206 | main::HEADER_TEXT(qq!<script> ww_applet_list["$appletName"].debugMode = $debugMode;\n</script>!); |
203 | return main::MODES(TeX=>' {\bf applet } ', HTML=>$self->insertObject.$main::BR.$state_storage_html_code.$answerBox_code); |
207 | return main::MODES(TeX=>' {\bf applet } ', HTML=>$self->insertObject.$main::BR.$state_storage_html_code.$answerBox_code); |
204 | } |
208 | } |
205 | |
209 | |
206 | =head3 Example problem |
210 | =head3 Example problem |
207 | |
211 | |