[system] / trunk / pg / lib / Applet.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/Applet.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5624 Revision 5667
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.6 2008/03/25 21:59:06 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 => 'setState', 198 setStateAlias => 'setXML',
199 configAlias => 'config', 199 configAlias => 'config',
200 initializeActionAlias => 'setXML', 200 initializeActionAlias => 'setXML',
201 submitActionAlias => 'getXML', 201 submitActionAlias => 'getXML',
202 returnFieldName => 'receivedField', 202 returnFieldName => 'receivedField',
203 headerText => DEFAULT_HEADER_TEXT(), 203 headerText => DEFAULT_HEADER_TEXT(),
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
212sub header { 214sub 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
402use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; 406use 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) {
439 debug_add("Begin setState for applet $appletName");
440 debug_add("Obtain state from $appletName"+"_state");
426 state = state || getQE("$appletName"+"_state").value 441 state = state || getQE("$appletName"+"_state").value;
427 if (state.match("\S") ) { // if state is not all white space
428 if ( base64Q(state) ) { 442 if ( base64Q(state) ) {
429 state=Base64.decode(state); 443 state=Base64.decode(state);
430 } 444 }
431 if (debug) { alert("set 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 );
432 try { 450 try {
433 if (debug || !( typeof(getApplet("$appletName").$setState) =="undefined" ) ) { 451 if (( typeof(getApplet("$appletName").$setState) =="function" ) ) {
452 debug_add("setState for $appletName");
434 getApplet("$appletName").$setState( state ); 453 getApplet("$appletName").$setState( state );
435 } 454 }
436 } catch(e) { 455 } catch(e) {
437 alert("Error in setting state of $appletName using command $setState : " + e ); 456 alert("Error in setting state of $appletName using command $setState : " + e );
438 } 457 }
439 } 458 } else if (debug) {
459 alert("new state was empty string or did not begin with <xml-- state was not reset");
460 }
440 }; 461 };
441 applet_getState_list["$appletName"] = function () { 462 applet_getState_list["$appletName"] = function () {
442 if (debug) { alert("getState for applet $appletName");} 463 debug_add("get current state for applet $appletName and store it in $appletName"+"_state");
443 try {
444 var applet = getApplet("$appletName"); 464 var applet = getApplet("$appletName");
445 var state; 465 try {
446 if (!( typeof(getApplet("$appletName").$getState) =="undefined" ) ) { 466 if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function
447 state = applet.$getState(); // get state in xml format 467 state = applet.$getState(); // get state in xml format
448 } 468 }
469
449 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
450 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)
451 } catch (e) { 473 } catch (e) {
452 alert("Error in getting state for $appletName " + e ); 474 alert("Error in getting state for $appletName " + e );
453 } 475 }
454 }; 476 };
477
478 ////////////////////////////////////////////////////////////
455 // 479 //
456 //INITIALIZE 480 //INITIALIZE
457 // 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
458 applet_initializeAction_list["$appletName"] = function () { 514 applet_initializeAction_list["$appletName"] = function (state) {
459 applet_setState_list["$appletName"](); 515 applet_setState_list["$appletName"](state);
460 }; 516 };
461 517
462 applet_submitAction_list["$appletName"] = function () { 518 applet_submitAction_list["$appletName"] = function () {
519 if (! applet_isReady_list["$appletName"] ) {
520 alert("$appletName is not ready");
521 }
463 applet_getState_list["$appletName"](); 522 applet_getState_list["$appletName"]();
464 getQE("$returnFieldName").value = getApplet("$appletName").sendData(); 523 //getQE("$returnFieldName").value = getApplet("$appletName").sendData(); //FIXME -- not needed in general?
465 }; 524 };
466 </script> 525 </script>
467 526
468END_HEADER_SCRIPT 527END_HEADER_SCRIPT
469 528
586 width = "$width" 645 width = "$width"
587 height = "$height" 646 height = "$height"
588 MAYSCRIPT 647 MAYSCRIPT
589 > 648 >
590 $javaParameters 649 $javaParameters
650
651 Sorry, the Applet could not be started. Please make sure that
652Java 1.4.2 (or later) is installed and activated.
653(<a href="http://java.sun.com/getjava">click here to install Java now</a>)
591 </applet> 654 </applet>
592END_OBJECT_TEXT 655END_OBJECT_TEXT
593 656
594sub new { 657sub new {
595 my $class = shift; 658 my $class = shift;

Legend:
Removed from v.5624  
changed lines
  Added in v.5667

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9