[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 5994 Revision 6013
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.14 2009/01/28 17:07:08 gage Exp $ 4# $CVSHeader: pg/lib/Applet.pm,v 1.16 2009/02/19 03:04:22 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.
197 codebase=>'', 197 codebase=>'',
198# appletId =>'', #always use identical applet Id's and applet Names 198# appletId =>'', #always use identical applet Id's and applet Names
199 params =>undef, 199 params =>undef,
200 width => 550, 200 width => 550,
201 height => 400, 201 height => 400,
202 bgcolor => "#869ca7",
202 base64_state => undef, # this is an state to use for initializing the first occurence of the question. 203 base64_state => undef, # this is an state to use for initializing the first occurence of the question.
203 base64_config => undef, # this is the initial (and final?) configuration 204 base64_config => undef, # this is the initial (and final?) configuration
204 getStateAlias => 'getXML', 205 getStateAlias => 'getXML',
205 setStateAlias => 'setXML', 206 setStateAlias => 'setXML',
206 configAlias => 'config', 207 configAlias => 'config',
309sub width { 310sub width {
310 my $self = shift; 311 my $self = shift;
311 $self->{width} = shift ||$self->{width}; # replace the current width if non-empty 312 $self->{width} = shift ||$self->{width}; # replace the current width if non-empty
312 $self->{width}; 313 $self->{width};
313} 314}
315sub bgcolor {
316 my $self = shift;
317 $self->{bgcolor} = shift ||$self->{bgcolor}; # replace the current background color if non-empty
318 $self->{bgcolor};
319}
314sub archive { 320sub archive {
315 my $self = shift; 321 my $self = shift;
316 $self->{archive} = shift ||$self->{archive}; # replace the current archive if non-empty 322 $self->{archive} = shift ||$self->{archive}; # replace the current archive if non-empty
317 $self->{archive}; 323 $self->{archive};
318} 324}
359#FIXME 365#FIXME
360# need to be able to adjust header material 366# need to be able to adjust header material
361 367
362sub insertHeader { 368sub insertHeader {
363 my $self = shift; 369 my $self = shift;
370
364 my $codebase = $self->codebase; 371 my $codebase = $self->codebase;
365 my $appletId = $self->appletId; 372 my $appletId = $self->appletId;
366 my $appletName = $self->appletName; 373 my $appletName = $self->appletName;
367 my $base64_initialState = $self->base64_state; 374 my $base64_initialState = $self->base64_state;
368 my $initializeAction = $self->initializeActionAlias; 375 my $initializeAction = $self->initializeActionAlias;
369 my $submitAction = $self->submitActionAlias; 376 my $submitActionAlias = $self->submitActionAlias;
370 my $submitActionScript = $self->submitActionScript; 377 my $submitActionScript = $self->submitActionScript;
371 my $setState = $self->setStateAlias; 378 my $setStateAlias = $self->setStateAlias;
372 my $getState = $self->getStateAlias; 379 my $getStateAlias = $self->getStateAlias;
373 my $config = $self->configAlias; 380 my $configAlias = $self->configAlias;
374 my $base64_config = $self->base64_config; 381 my $base64_config = $self->base64_config;
375 my $debugMode = ($self->debug) ? "1": "0"; 382 my $debugMode = ($self->debug) ? "1": "0";
376 my $returnFieldName = $self->{returnFieldName}; 383 my $returnFieldName = $self->{returnFieldName};
377 my $answerBox = $self->{answerBox}; 384 my $answerBox = $self->{answerBox};
378 my $headerText = $self->header(); 385 my $headerText = $self->header();
386
387
388 $submitActionScript =~ s/"/\\"/g; # escape quotes for ActionScript
389 # other variables should not have quotes.
390
391 $submitActionScript =~ s/\n/ /g; # replace returns with spaces -- returns in the wrong spot can cause trouble with javaScript
392 $submitActionScript =~ s/\r/ /g; # replace returns with spaces -- returns can cause trouble
379 393
380 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook 394 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook
381 395
382 return $headerText; 396 return $headerText;
383 397
391 my $appletId = $self->{appletName}; 405 my $appletId = $self->{appletName};
392 my $appletName = $self->{appletName}; 406 my $appletName = $self->{appletName};
393 my $archive = $self->{archive}; 407 my $archive = $self->{archive};
394 my $width = $self->{width}; 408 my $width = $self->{width};
395 my $height = $self->{height}; 409 my $height = $self->{height};
410 my $applet_bgcolor = $self->{bgcolor};
396 my $javaParameters = ''; 411 my $javaParameters = '';
397 my $flashParameters = ''; 412 my $flashParameters = '';
398 my %param_hash = %{$self->params()}; 413 my %param_hash = %{$self->params()};
399 foreach my $key (keys %param_hash) { 414 foreach my $key (keys %param_hash) {
400 $javaParameters .= qq!<param name ="$key" value = "$param_hash{$key}">\n!; 415 $javaParameters .= qq!<param name ="$key" value = "$param_hash{$key}">\n!;
422######################################################## 437########################################################
423 438
424use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; 439use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
425 <script src="/webwork2_files/js/Base64.js" language="javascript"> 440 <script src="/webwork2_files/js/Base64.js" language="javascript">
426 </script> 441 </script>
427 <script src="/webwork2_files/js/ww_applet_support.js"> 442 <script src="/webwork2_files/js/ww_applet_support.js" language="javascript">
428 //upload functions stored in /opt/webwork/webwork2/htdocs/js ... 443 //upload functions stored in /opt/webwork/webwork2/htdocs/js ...
429 </script> 444 </script>
430 <script language="JavaScript"> 445 <script language="JavaScript">
431 446
432 // set debug mode for this applet 447 // set debug mode for this applet
444 ww_applet_list["$appletName"].code = "$code"; 459 ww_applet_list["$appletName"].code = "$code";
445 ww_applet_list["$appletName"].codebase = "$codebase"; 460 ww_applet_list["$appletName"].codebase = "$codebase";
446 ww_applet_list["$appletName"].appletID = "$appletID"; 461 ww_applet_list["$appletName"].appletID = "$appletID";
447 ww_applet_list["$appletName"].base64_state = "$base64_initializationState"; 462 ww_applet_list["$appletName"].base64_state = "$base64_initializationState";
448 ww_applet_list["$appletName"].base64_config = "$base64_config"; 463 ww_applet_list["$appletName"].base64_config = "$base64_config";
449 ww_applet_list["$appletName"].getStateAlias = "$getState"; 464 ww_applet_list["$appletName"].getStateAlias = "$getStateAlias";
450 ww_applet_list["$appletName"].setStateAlias = "$setState"; 465 ww_applet_list["$appletName"].setStateAlias = "$setStateAlias";
451 ww_applet_list["$appletName"].configAlias = "$config"; 466 ww_applet_list["$appletName"].configAlias = "$configAlias";
452 ww_applet_list["$appletName"].initializeActionAlias = "$initializeAction"; 467 ww_applet_list["$appletName"].initializeActionAlias = "$initializeAction";
453 ww_applet_list["$appletName"].submitActionAlias = "$submitAction"; 468 ww_applet_list["$appletName"].submitActionAlias = "$submitActionAlias";
454 ww_applet_list["$appletName"].submitActionScript = "$submitActionScript"; 469 ww_applet_list["$appletName"].submitActionScript = "$submitActionScript";
455 ww_applet_list["$appletName"].answerBox = "$answerBox"; 470 ww_applet_list["$appletName"].answerBox = "$answerBox";
456 ww_applet_list["$appletName"].debug = "$debugMode"; 471 ww_applet_list["$appletName"].debug = "$debugMode";
457 472
458
459 //////////////////////////////////////////////////////////
460 //CONFIGURATIONS
461 //
462 // configurations are "permanent"
463 //////////////////////////////////////////////////////////
464
465// applet_config_list["$appletName"] = function() {
466// debug_add("applet_config_list:\n attempt to configure $appletName . $config ( $base64_config ) if config function is defined: "
467// );
468// try {
469// if (( typeof(getApplet("$appletName").$config) == "function" ) ) {
470// debug_add("CONFIGURE $appletName");
471// getApplet("$appletName").$config(Base64.decode("$base64_config"));
472// }
473// } catch(e) {
474// alert("Error executing configuration command $config for $appletName: " + e );
475// }
476// }
477// ////////////////////////////////////////////////////////////
478// //
479// //STATE:
480// // state can vary as the applet is manipulated -- it is reset from the questions _state values
481// //
482// //////////////////////////////////////////////////////////
483//
484// applet_setState_list["$appletName"] = function(state) {
485// debug_add("Begin setState for applet $appletName");
486// debug_add("Obtain state from $appletName"+"_state");
487// state = state || getQE("$appletName"+"_state").value;
488// if ( base64Q(state) ) {
489// state=Base64.decode(state);
490// }
491// if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml
492//
493// debug_add("applet_setState_list: \n set (decoded) state for $appletName to " +
494// state +"\nfunction type is " +typeof(getApplet("$appletName").$setState)
495// );
496// try {
497// if (( typeof(getApplet("$appletName").$setState) =="function" ) ) {
498// debug_add("setState for $appletName");
499// getApplet("$appletName").$setState( state );
500// }
501// } catch(e) {
502// alert("Error in setting state of $appletName using command $setState : " + e );
503// }
504// } else if (debug) {
505// alert("new state was empty string or did not begin with <xml-- state was not reset");
506// }
507// };
508// applet_getState_list["$appletName"] = function () {
509// debug_add("get current state for applet $appletName and store it in $appletName"+"_state");
510// var applet = getApplet("$appletName");
511// try {
512// if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function
513// state = applet.$getState(); // get state in xml format
514// debug_add("state has type " + typeof(state));
515// state = String(state); // geogebra returned an object type instead of a string type
516// debug_add("state converted to type " + typeof(state));
517// }
518//
519// if (!debug) {
520// state = Base64.encode(state);
521// }; // replace state by encoded version unless in debug mode
522//
523// debug_add("state is "+state); // this should still be in plain text
524// getQE("$appletName"+"_state").value = state; //place state in input item (debug: textarea, otherwise: hidden)
525// } catch (e) {
526// alert("Error in getting state for $appletName " + e );
527// }
528// };
529//
530// ////////////////////////////////////////////////////////////
531// //
532// //INITIALIZE
533// //
534// ////////////////////////////////////////////////////////////
535//
536//
537// applet_checkLoaded_list["$appletName"] = function() { // this function returns 0 unless:
538// // applet has already been flagged as ready in applet_isReady_list
539// // applet.config is defined (or alias for .config)
540// // applet.setState is defined
541// // applet.isActive is defined
542// // applet reported that it is loaded by calling loadQ()
543// var ready = 0;
544// var applet = getApplet("$appletName");
545// if (!debug && applet_isReady_list["$appletName"]) {return(1)}; // memorize readiness in non-debug mode
546// if ( typeof(applet.$config) == "function") {
547// debug_add( "applet.config is " + typeof(applet.$config) );
548// ready = 1;
549// }
550// if( typeof(applet.$getState) == "function") {
551// debug_add( "applet.getState is " + typeof(applet.$getState) );
552// ready =1;
553// }
554// if (typeof(applet.isActive) == "function" && applet.isActive ) {
555// debug_add( "applet.isActive is " + typeof(applet.isActive) );
556// ready =1;
557// }
558// if (typeof(applet_reportsLoaded_list["$appletName"]) !="undefined" && applet_reportsLoaded_list["$appletName"] != 0 ) {
559// debug_add( "applet reports that it is loaded " + applet_reportsLoaded_list["$appletName"] );
560// ready =1;
561// }
562// applet_isReady_list["$appletName"]= ready;
563// return(ready);
564// }
565//
566// applet_initializeAction_list["$appletName"] = function (state) {
567// applet_setState_list["$appletName"](state);
568// };
569//
570// applet_submitAction_list["$appletName"] = function () {
571// if (! applet_isReady_list["$appletName"] ) {
572// alert("$appletName is not ready");
573// }
574// applet_getState_list["$appletName"]();
575// $submitActionScript
576// //getQE("$answerBox").value = getApplet("$appletName").getAnswer(); //FIXME -- not needed in general?
577// };
578 </script> 473 </script>
579 474
580END_HEADER_SCRIPT 475END_HEADER_SCRIPT
581 476
582package FlashApplet; 477package FlashApplet;
604 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 499 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
605 id="$appletName" width="500" height="375" 500 id="$appletName" width="500" height="375"
606 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> 501 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
607 <param name="movie" value="$codebase/$appletName.swf" /> 502 <param name="movie" value="$codebase/$appletName.swf" />
608 <param name="quality" value="high" /> 503 <param name="quality" value="high" />
609 <param name="bgcolor" value="#869ca7" /> 504 <param name="bgcolor" value="$applet_bgcolor" />
610 <param name="allowScriptAccess" value="sameDomain" /> 505 <param name="allowScriptAccess" value="sameDomain" />
611 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" 506 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor"
612 width="$width" height="$height" name="$appletName" align="middle" id="$appletName" 507 width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
613 play="true" loop="false" quality="high" allowScriptAccess="sameDomain" 508 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
614 type="application/x-shockwave-flash" 509 type="application/x-shockwave-flash"
615 pluginspage="http://www.macromedia.com/go/getflashplayer"> 510 pluginspage="http://www.macromedia.com/go/getflashplayer">
616 </embed> 511 </embed>
626 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 521 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
627 id="$appletName" width="500" height="375" 522 id="$appletName" width="500" height="375"
628 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> 523 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
629 <param name="movie" value="$codebase/$appletName.swf" /> 524 <param name="movie" value="$codebase/$appletName.swf" />
630 <param name="quality" value="high" /> 525 <param name="quality" value="high" />
631 <param name="bgcolor" value="#869ca7" /> 526 <param name="bgcolor" value="$applet_bgcolor" />
632 <param name="allowScriptAccess" value="sameDomain" /> 527 <param name="allowScriptAccess" value="sameDomain" />
633 <param name="FlashVars" value="$flashParameters"/> 528 <param name="FlashVars" value="$flashParameters"/>
634 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" 529 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="$applet_bgcolor"
635 width="$width" height="$height" name="$appletName" align="middle" id="$appletName" 530 width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
636 play="true" loop="false" quality="high" allowScriptAccess="sameDomain" 531 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
637 type="application/x-shockwave-flash" 532 type="application/x-shockwave-flash"
638 pluginspage="http://www.macromedia.com/go/getflashplayer" 533 pluginspage="http://www.macromedia.com/go/getflashplayer"
639 FlashVars="$flashParameters"> 534 FlashVars="$flashParameters">
696 archive = "$archive" 591 archive = "$archive"
697 name = "$appletName" 592 name = "$appletName"
698 id = "$appletName" 593 id = "$appletName"
699 width = "$width" 594 width = "$width"
700 height = "$height" 595 height = "$height"
596 bgcolor = "$applet_bgcolor"
701 MAYSCRIPT 597 MAYSCRIPT
702 > 598 >
703 $javaParameters 599 $javaParameters
704 600
705 Sorry, the Applet could not be started. Please make sure that 601 Sorry, the Applet could not be started. Please make sure that

Legend:
Removed from v.5994  
changed lines
  Added in v.6013

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9