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/lib/Applet.pm,v 1.7 2008/03/26 01:25:52 gage Exp $ |
4 | # $CVSHeader: pg/lib/Applet.pm,v 1.10 2008/05/05 17:24:31 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. |
… | |
… | |
35 | ################################### |
35 | ################################### |
36 | # Configure applet |
36 | # Configure applet |
37 | ################################### |
37 | ################################### |
38 | |
38 | |
39 | #xml data to set up the problem-rac |
39 | #xml data to set up the problem-rac |
40 | $applet->state(qq{<XML> |
40 | $applet->config(qq{<XML> |
41 | <point xval='$xval_1' yval='$yval_1' /> |
41 | <point xval='$xval_1' yval='$yval_1' /> |
42 | <point xval='$xval_2' yval='$yval_2' /> |
42 | <point xval='$xval_2' yval='$yval_2' /> |
43 | </XML>}); |
43 | </XML>}); |
44 | |
44 | |
45 | |
45 | |
… | |
… | |
190 | codebase=>'', |
190 | codebase=>'', |
191 | # appletId =>'', #always use identical applet Id's and applet Names |
191 | # appletId =>'', #always use identical applet Id's and applet Names |
192 | params =>undef, |
192 | params =>undef, |
193 | width => 550, |
193 | width => 550, |
194 | height => 400, |
194 | height => 400, |
195 | base64_state => '', |
195 | base64_state => undef, # this is an state to use for initializing the first occurence of the question. |
196 | base64_config => '', |
196 | base64_config => undef, # this is the initial (and final?) configuration |
197 | getStateAlias => 'getXML', |
197 | getStateAlias => 'getXML', |
198 | setStateAlias => 'setXML', |
198 | setStateAlias => 'setXML', |
199 | configAlias => 'config', |
199 | configAlias => 'config', |
200 | initializeActionAlias => 'setXML', |
200 | initializeActionAlias => 'setXML', |
201 | submitActionAlias => 'getXML', |
201 | submitActionAlias => 'getXML', |
… | |
… | |
204 | objectText => '', |
204 | objectText => '', |
205 | debug => 0, |
205 | debug => 0, |
206 | @_, |
206 | @_, |
207 | }; |
207 | }; |
208 | bless $self, $class; |
208 | bless $self, $class; |
|
|
209 | $self->state('<xml></xml>'); |
|
|
210 | $self->config('<xml></xml>'); |
209 | return $self; |
211 | return $self; |
210 | } |
212 | } |
211 | |
213 | |
212 | sub header { |
214 | sub header { |
213 | my $self = shift; |
215 | my $self = shift; |
… | |
… | |
395 | // this should really be done in the <body> tag |
397 | // this should really be done in the <body> tag |
396 | </script> |
398 | </script> |
397 | }; |
399 | }; |
398 | |
400 | |
399 | } |
401 | } |
400 | |
402 | ######################################################## |
|
|
403 | # HEADER material for one flash or java applet |
|
|
404 | ######################################################## |
401 | |
405 | |
402 | use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; |
406 | use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; |
403 | |
407 | |
404 | <script language="JavaScript"> |
408 | <script language="JavaScript"> |
405 | var debug = $debugMode; |
409 | |
406 | // |
410 | // set debug mode for this applet |
|
|
411 | set_debug($debugMode); |
|
|
412 | |
|
|
413 | ////////////////////////////////////////////////////////// |
407 | //CONFIGURATIONS |
414 | //CONFIGURATIONS |
408 | // |
415 | // |
409 | // configurations are "permanent" |
416 | // configurations are "permanent" |
|
|
417 | ////////////////////////////////////////////////////////// |
|
|
418 | |
410 | applet_config_list["$appletName"] = function() { |
419 | applet_config_list["$appletName"] = function() { |
411 | if (debug) { alert("configure $appletName . $config ( $base64_config )");} |
420 | debug_add("applet_config_list:\n attempt to configure $appletName . $config ( $base64_config ) if config function is defined: " |
|
|
421 | ); |
412 | try { |
422 | try { |
413 | if (debug || !( typeof(getApplet("$appletName").$config) == "undefined" ) ) { |
423 | if (( typeof(getApplet("$appletName").$config) == "function" ) ) { |
414 | |
424 | debug_add("CONFIGURE $appletName"); |
415 | getApplet("$appletName").$config(Base64.decode("$base64_config")); |
425 | getApplet("$appletName").$config(Base64.decode("$base64_config")); |
416 | } |
426 | } |
417 | } catch(e) { |
427 | } catch(e) { |
418 | alert("error executing configuration command $config for $appletName: " + e ); |
428 | alert("Error executing configuration command $config for $appletName: " + e ); |
419 | } |
429 | } |
420 | } |
430 | } |
|
|
431 | //////////////////////////////////////////////////////////// |
421 | // |
432 | // |
422 | //STATE |
433 | //STATE: |
|
|
434 | // state can vary as the applet is manipulated -- it is reset from the questions _state values |
423 | // |
435 | // |
424 | // state can vary as the applet is manipulated. |
436 | ////////////////////////////////////////////////////////// |
|
|
437 | |
425 | applet_setState_list["$appletName"] = function(state) { |
438 | applet_setState_list["$appletName"] = function(state) { |
426 | if (debug) { alert("set state for $appletName to " + state);} |
439 | debug_add("Begin setState for applet $appletName"); |
|
|
440 | debug_add("Obtain state from $appletName"+"_state"); |
427 | state = state || getQE("$appletName"+"_state").value |
441 | state = state || getQE("$appletName"+"_state").value; |
428 | if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state is not all white space |
|
|
429 | if ( base64Q(state) ) { |
442 | if ( base64Q(state) ) { |
430 | state=Base64.decode(state); |
443 | state=Base64.decode(state); |
431 | } |
444 | } |
432 | alert("set (decoded) state for $appletName to " + state); |
445 | if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml |
|
|
446 | |
|
|
447 | debug_add("applet_setState_list: \n set (decoded) state for $appletName to " + |
|
|
448 | state +"\nfunction type is " +typeof(getApplet("$appletName").$setState) |
|
|
449 | ); |
433 | try { |
450 | try { |
434 | if (debug || !( typeof(getApplet("$appletName").$setState) =="undefined" ) ) { |
451 | if (( typeof(getApplet("$appletName").$setState) =="function" ) ) { |
|
|
452 | debug_add("setState for $appletName"); |
435 | getApplet("$appletName").$setState( state ); |
453 | getApplet("$appletName").$setState( state ); |
436 | } |
454 | } |
437 | } catch(e) { |
455 | } catch(e) { |
438 | alert("Error in setting state of $appletName using command $setState : " + e ); |
456 | alert("Error in setting state of $appletName using command $setState : " + e ); |
439 | } |
457 | } |
440 | } else if (debug) { |
458 | } else if (debug) { |
441 | alert("new state was empty string or did not begin with <xml-- state was not reset"); |
459 | alert("new state was empty string or did not begin with <xml-- state was not reset"); |
442 | } |
460 | } |
443 | }; |
461 | }; |
444 | applet_getState_list["$appletName"] = function () { |
462 | applet_getState_list["$appletName"] = function () { |
445 | if (debug) { alert("getState for applet $appletName");} |
463 | debug_add("get current state for applet $appletName and store it in $appletName"+"_state"); |
446 | try { |
|
|
447 | var applet = getApplet("$appletName"); |
464 | var applet = getApplet("$appletName"); |
448 | var state; |
465 | try { |
449 | if (!( typeof(getApplet("$appletName").$getState) =="undefined" ) ) { |
466 | if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function |
450 | state = applet.$getState(); // get state in xml format |
467 | state = applet.$getState(); // get state in xml format |
451 | } |
468 | } |
|
|
469 | |
452 | if (!debug) {state = Base64.encode(state) }; // replace state by encoded version |
470 | if (!debug) {state = Base64.encode(state) }; // replace state by encoded version unless in debug mode |
|
|
471 | debug_add("state is "+state); // this should still be in plain text |
453 | getQE("$appletName"+"_state").value = state; //place in state htmlItem (debug: textarea, otherwise hidden) |
472 | getQE("$appletName"+"_state").value = state; //place state in input item (debug: textarea, otherwise: hidden) |
454 | } catch (e) { |
473 | } catch (e) { |
455 | alert("Error in getting state for $appletName " + e ); |
474 | alert("Error in getting state for $appletName " + e ); |
456 | } |
475 | } |
457 | }; |
476 | }; |
|
|
477 | |
|
|
478 | //////////////////////////////////////////////////////////// |
458 | // |
479 | // |
459 | //INITIALIZE |
480 | //INITIALIZE |
460 | // |
481 | // |
|
|
482 | //////////////////////////////////////////////////////////// |
|
|
483 | |
|
|
484 | |
|
|
485 | applet_checkLoaded_list["$appletName"] = function() { // this function returns 0 unless: |
|
|
486 | // applet has already been flagged as ready in applet_isReady_list |
|
|
487 | // applet.config is defined (or alias for .config) |
|
|
488 | // applet.setState is defined |
|
|
489 | // applet.isActive is defined |
|
|
490 | // applet reported that it is loaded by calling loadQ() |
|
|
491 | var ready = 0; |
|
|
492 | var applet = getApplet("$appletName"); |
|
|
493 | if (!debug && applet_isReady_list["$appletName"]) {return(1)}; // memorize readiness in non-debug mode |
|
|
494 | if ( typeof(applet.$config) == "function") { |
|
|
495 | debug_add( "applet.config is " + typeof(applet.$config) ); |
|
|
496 | ready = 1; |
|
|
497 | } |
|
|
498 | if( typeof(applet.$getState) == "function") { |
|
|
499 | debug_add( "applet.getState is " + typeof(applet.$getState) ); |
|
|
500 | ready =1; |
|
|
501 | } |
|
|
502 | if (typeof(applet.isActive) == "function" && applet.isActive ) { |
|
|
503 | debug_add( "applet.isActive is " + typeof(applet.isActive) ); |
|
|
504 | ready =1; |
|
|
505 | } |
|
|
506 | if (typeof(applet_reportsLoaded_list["$appletName"]) !="undefined" && applet_reportsLoaded_list["$appletName"] != 0 ) { |
|
|
507 | debug_add( "applet reports that it is loaded " + applet_reportsLoaded_list["$appletName"] ); |
|
|
508 | ready =1; |
|
|
509 | } |
|
|
510 | applet_isReady_list["$appletName"]= ready; |
|
|
511 | return(ready); |
|
|
512 | } |
|
|
513 | |
461 | applet_initializeAction_list["$appletName"] = function () { |
514 | applet_initializeAction_list["$appletName"] = function (state) { |
462 | applet_setState_list["$appletName"](); |
515 | applet_setState_list["$appletName"](state); |
463 | }; |
516 | }; |
464 | |
517 | |
465 | applet_submitAction_list["$appletName"] = function () { |
518 | applet_submitAction_list["$appletName"] = function () { |
|
|
519 | if (! applet_isReady_list["$appletName"] ) { |
|
|
520 | alert("$appletName is not ready"); |
|
|
521 | } |
466 | applet_getState_list["$appletName"](); |
522 | applet_getState_list["$appletName"](); |
467 | getQE("$returnFieldName").value = getApplet("$appletName").sendData(); |
523 | //getQE("$returnFieldName").value = getApplet("$appletName").sendData(); //FIXME -- not needed in general? |
468 | }; |
524 | }; |
469 | </script> |
525 | </script> |
470 | |
526 | |
471 | END_HEADER_SCRIPT |
527 | END_HEADER_SCRIPT |
472 | |
528 | |
… | |
… | |
589 | width = "$width" |
645 | width = "$width" |
590 | height = "$height" |
646 | height = "$height" |
591 | MAYSCRIPT |
647 | MAYSCRIPT |
592 | > |
648 | > |
593 | $javaParameters |
649 | $javaParameters |
|
|
650 | |
|
|
651 | Sorry, the Applet could not be started. Please make sure that |
|
|
652 | Java 1.4.2 (or later) is installed and activated. |
|
|
653 | (<a href="http://java.sun.com/getjava">click here to install Java now</a>) |
594 | </applet> |
654 | </applet> |
595 | END_OBJECT_TEXT |
655 | END_OBJECT_TEXT |
596 | |
656 | |
597 | sub new { |
657 | sub new { |
598 | my $class = shift; |
658 | my $class = shift; |