[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 5661 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.8 2008/03/26 02:42:20 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.
405 405
406use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; 406use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
407 407
408 <script language="JavaScript"> 408 <script language="JavaScript">
409 409
410 // set debug mode for this applet
411 set_debug($debugMode);
412
410 ////////////////////////////////////////////////////////// 413 //////////////////////////////////////////////////////////
411 //CONFIGURATIONS 414 //CONFIGURATIONS
412 // 415 //
413 // configurations are "permanent" 416 // configurations are "permanent"
414 ////////////////////////////////////////////////////////// 417 //////////////////////////////////////////////////////////
415 418
416 applet_config_list["$appletName"] = function() { 419 applet_config_list["$appletName"] = function() {
417 debug_add("applet_config_list:\n configure $appletName . $config ( $base64_config )" 420 debug_add("applet_config_list:\n attempt to configure $appletName . $config ( $base64_config ) if config function is defined: "
418 + typeof(getApplet("$appletName").$config)
419 ); 421 );
420 try { 422 try {
421 if (( typeof(getApplet("$appletName").$config) == "function" ) ) { 423 if (( typeof(getApplet("$appletName").$config) == "function" ) ) {
422 debug_add("configure $appletName"); 424 debug_add("CONFIGURE $appletName");
423 getApplet("$appletName").$config(Base64.decode("$base64_config")); 425 getApplet("$appletName").$config(Base64.decode("$base64_config"));
424 } 426 }
425 } catch(e) { 427 } catch(e) {
426 alert("Error executing configuration command $config for $appletName: " + e ); 428 alert("Error executing configuration command $config for $appletName: " + e );
427 } 429 }
432 // state can vary as the applet is manipulated -- it is reset from the questions _state values 434 // state can vary as the applet is manipulated -- it is reset from the questions _state values
433 // 435 //
434 ////////////////////////////////////////////////////////// 436 //////////////////////////////////////////////////////////
435 437
436 applet_setState_list["$appletName"] = function(state) { 438 applet_setState_list["$appletName"] = function(state) {
437 debug_add("Begin setState"); 439 debug_add("Begin setState for applet $appletName");
440 debug_add("Obtain state from $appletName"+"_state");
438 state = state || getQE("$appletName"+"_state").value; 441 state = state || getQE("$appletName"+"_state").value;
439 if ( base64Q(state) ) { 442 if ( base64Q(state) ) {
440 state=Base64.decode(state); 443 state=Base64.decode(state);
441 } 444 }
442 if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml 445 if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml
455 } else if (debug) { 458 } else if (debug) {
456 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");
457 } 460 }
458 }; 461 };
459 applet_getState_list["$appletName"] = function () { 462 applet_getState_list["$appletName"] = function () {
460 if (debug) { alert("getState for applet $appletName");} 463 debug_add("get current state for applet $appletName and store it in $appletName"+"_state");
461 var applet = getApplet("$appletName"); 464 var applet = getApplet("$appletName");
462 try { 465 try {
463 if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function 466 if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function
464 state = applet.$getState(); // get state in xml format 467 state = applet.$getState(); // get state in xml format
465 } 468 }
466 if (debug) alert("state is " + state); 469
467 if (!debug) {state = Base64.encode(state) }; // replace state by encoded version unless in debug mode 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
468 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)
469 } catch (e) { 473 } catch (e) {
470 alert("Error in getting state for $appletName " + e ); 474 alert("Error in getting state for $appletName " + e );
471 } 475 }
472 }; 476 };
473 477
501 } 505 }
502 if (typeof(applet_reportsLoaded_list["$appletName"]) !="undefined" && applet_reportsLoaded_list["$appletName"] != 0 ) { 506 if (typeof(applet_reportsLoaded_list["$appletName"]) !="undefined" && applet_reportsLoaded_list["$appletName"] != 0 ) {
503 debug_add( "applet reports that it is loaded " + applet_reportsLoaded_list["$appletName"] ); 507 debug_add( "applet reports that it is loaded " + applet_reportsLoaded_list["$appletName"] );
504 ready =1; 508 ready =1;
505 } 509 }
506 applet_isReady_list["$appletName"]=ready; 510 applet_isReady_list["$appletName"]= ready;
507 return(ready); 511 return(ready);
508 } 512 }
509 513
510 applet_initializeAction_list["$appletName"] = function (state) { 514 applet_initializeAction_list["$appletName"] = function (state) {
511 applet_setState_list["$appletName"](state); 515 applet_setState_list["$appletName"](state);
512 }; 516 };
513 517
514 applet_submitAction_list["$appletName"] = function () { 518 applet_submitAction_list["$appletName"] = function () {
519 if (! applet_isReady_list["$appletName"] ) {
520 alert("$appletName is not ready");
521 }
515 applet_getState_list["$appletName"](); 522 applet_getState_list["$appletName"]();
516 getQE("$returnFieldName").value = getApplet("$appletName").sendData(); //FIXME -- not needed in general? 523 //getQE("$returnFieldName").value = getApplet("$appletName").sendData(); //FIXME -- not needed in general?
517 }; 524 };
518 </script> 525 </script>
519 526
520END_HEADER_SCRIPT 527END_HEADER_SCRIPT
521 528
638 width = "$width" 645 width = "$width"
639 height = "$height" 646 height = "$height"
640 MAYSCRIPT 647 MAYSCRIPT
641 > 648 >
642 $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>)
643 </applet> 654 </applet>
644END_OBJECT_TEXT 655END_OBJECT_TEXT
645 656
646sub new { 657sub new {
647 my $class = shift; 658 my $class = shift;

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9