[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 5625 Revision 5661
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.8 2008/03/26 02:42:20 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
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 //////////////////////////////////////////////////////////
407 //CONFIGURATIONS 411 //CONFIGURATIONS
408 // 412 //
409 // configurations are "permanent" 413 // configurations are "permanent"
414 //////////////////////////////////////////////////////////
415
410 applet_config_list["$appletName"] = function() { 416 applet_config_list["$appletName"] = function() {
411 if (debug) { alert("configure $appletName . $config ( $base64_config )");} 417 debug_add("applet_config_list:\n configure $appletName . $config ( $base64_config )"
418 + typeof(getApplet("$appletName").$config)
419 );
412 try { 420 try {
413 if (debug || !( typeof(getApplet("$appletName").$config) == "undefined" ) ) { 421 if (( typeof(getApplet("$appletName").$config) == "function" ) ) {
414 422 debug_add("configure $appletName");
415 getApplet("$appletName").$config(Base64.decode("$base64_config")); 423 getApplet("$appletName").$config(Base64.decode("$base64_config"));
416 } 424 }
417 } catch(e) { 425 } catch(e) {
418 alert("error executing configuration command $config for $appletName: " + e ); 426 alert("Error executing configuration command $config for $appletName: " + e );
419 } 427 }
420 } 428 }
429 ////////////////////////////////////////////////////////////
421 // 430 //
422 //STATE 431 //STATE:
432 // state can vary as the applet is manipulated -- it is reset from the questions _state values
423 // 433 //
424 // state can vary as the applet is manipulated. 434 //////////////////////////////////////////////////////////
435
425 applet_setState_list["$appletName"] = function(state) { 436 applet_setState_list["$appletName"] = function(state) {
426 if (debug) { alert("set state for $appletName to " + state);} 437 debug_add("Begin setState");
427 state = state || getQE("$appletName"+"_state").value 438 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) ) { 439 if ( base64Q(state) ) {
430 state=Base64.decode(state); 440 state=Base64.decode(state);
431 } 441 }
432 alert("set (decoded) state for $appletName to " + state); 442 if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml
443
444 debug_add("applet_setState_list: \n set (decoded) state for $appletName to " +
445 state +"\nfunction type is " +typeof(getApplet("$appletName").$setState)
446 );
433 try { 447 try {
434 if (debug || !( typeof(getApplet("$appletName").$setState) =="undefined" ) ) { 448 if (( typeof(getApplet("$appletName").$setState) =="function" ) ) {
449 debug_add("setState for $appletName");
435 getApplet("$appletName").$setState( state ); 450 getApplet("$appletName").$setState( state );
436 } 451 }
437 } catch(e) { 452 } catch(e) {
438 alert("Error in setting state of $appletName using command $setState : " + e ); 453 alert("Error in setting state of $appletName using command $setState : " + e );
439 } 454 }
440 } else if (debug) { 455 } else if (debug) {
441 alert("new state was empty string or did not begin with <xml-- state was not reset"); 456 alert("new state was empty string or did not begin with <xml-- state was not reset");
442 } 457 }
443 }; 458 };
444 applet_getState_list["$appletName"] = function () { 459 applet_getState_list["$appletName"] = function () {
445 if (debug) { alert("getState for applet $appletName");} 460 if (debug) { alert("getState for applet $appletName");}
446 try {
447 var applet = getApplet("$appletName"); 461 var applet = getApplet("$appletName");
448 var state; 462 try {
449 if (!( typeof(getApplet("$appletName").$getState) =="undefined" ) ) { 463 if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function
450 state = applet.$getState(); // get state in xml format 464 state = applet.$getState(); // get state in xml format
451 } 465 }
466 if (debug) alert("state is " + state);
452 if (!debug) {state = Base64.encode(state) }; // replace state by encoded version 467 if (!debug) {state = Base64.encode(state) }; // replace state by encoded version unless in debug mode
453 getQE("$appletName"+"_state").value = state; //place in state htmlItem (debug: textarea, otherwise hidden) 468 getQE("$appletName"+"_state").value = state; //place in state htmlItem (debug: textarea, otherwise hidden)
454 } catch (e) { 469 } catch (e) {
455 alert("Error in getting state for $appletName " + e ); 470 alert("Error in getting state for $appletName " + e );
456 } 471 }
457 }; 472 };
473
474 ////////////////////////////////////////////////////////////
458 // 475 //
459 //INITIALIZE 476 //INITIALIZE
460 // 477 //
478 ////////////////////////////////////////////////////////////
479
480
481 applet_checkLoaded_list["$appletName"] = function() { // this function returns 0 unless:
482 // applet has already been flagged as ready in applet_isReady_list
483 // applet.config is defined (or alias for .config)
484 // applet.setState is defined
485 // applet.isActive is defined
486 // applet reported that it is loaded by calling loadQ()
487 var ready = 0;
488 var applet = getApplet("$appletName");
489 if (!debug && applet_isReady_list["$appletName"]) {return(1)}; // memorize readiness in non-debug mode
490 if ( typeof(applet.$config) == "function") {
491 debug_add( "applet.config is " + typeof(applet.$config) );
492 ready = 1;
493 }
494 if( typeof(applet.$getState) == "function") {
495 debug_add( "applet.getState is " + typeof(applet.$getState) );
496 ready =1;
497 }
498 if (typeof(applet.isActive) == "function" && applet.isActive ) {
499 debug_add( "applet.isActive is " + typeof(applet.isActive) );
500 ready =1;
501 }
502 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"] );
504 ready =1;
505 }
506 applet_isReady_list["$appletName"]=ready;
507 return(ready);
508 }
509
461 applet_initializeAction_list["$appletName"] = function () { 510 applet_initializeAction_list["$appletName"] = function (state) {
462 applet_setState_list["$appletName"](); 511 applet_setState_list["$appletName"](state);
463 }; 512 };
464 513
465 applet_submitAction_list["$appletName"] = function () { 514 applet_submitAction_list["$appletName"] = function () {
466 applet_getState_list["$appletName"](); 515 applet_getState_list["$appletName"]();
467 getQE("$returnFieldName").value = getApplet("$appletName").sendData(); 516 getQE("$returnFieldName").value = getApplet("$appletName").sendData(); //FIXME -- not needed in general?
468 }; 517 };
469 </script> 518 </script>
470 519
471END_HEADER_SCRIPT 520END_HEADER_SCRIPT
472 521

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9