[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 6029 Revision 6030
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.20 2009/03/10 20:58:46 gage Exp $ 4# $CVSHeader: pg/lib/Applet.pm,v 1.21 2009/03/15 19:25:03 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.
29 appletName => $appletName, 29 appletName => $appletName,
30 appletId => $appletName, 30 appletId => $appletName,
31 setStateAlias => 'setXML', 31 setStateAlias => 'setXML',
32 getStateAlias => 'getXML', 32 getStateAlias => 'getXML',
33 setConfigAlias => 'config', 33 setConfigAlias => 'config',
34 answerBoxAlias => 'receivedField', 34 answerBoxAlias => 'answerBox',
35 submitActionScript => qq{ getQE('answerBox').value = getApplet("$appletName").getAnswer() },
35); 36);
36 37
37################################### 38###################################
38# Configure applet 39# Configure applet
39################################### 40###################################
46################################### 47###################################
47#insert applet into body 48#insert applet into body
48################################### 49###################################
49 50
50TEXT( MODES(TeX=>'object code', HTML=>$applet->insertAll( 51TEXT( MODES(TeX=>'object code', HTML=>$applet->insertAll(
52 includeAnswerBox => 1
51 debug=>0, 53 debug=>0,
52 reset_button=>1, 54 reinitialize_button=>1,
53 ))); 55 )));
54 56
55 57
56=head1 DESCRIPTION 58=head1 DESCRIPTION
57 59
149 to configure the applet [name =>'value, ...] 151 to configure the applet [name =>'value, ...]
150 152
151 header stores the text to be added to the header section of the html page 153 header stores the text to be added to the header section of the html page
152 object stores the text which places the applet on the html page 154 object stores the text which places the applet on the html page
153 155
154 debug in debug mode several alerts mark progress through the procedure of calling the applet 156 debugMode in debug mode several alerts mark progress through the procedure of calling the applet
155 157
156 config configuration are those customizable attributes of the applet which don't 158 configuration configuration contains those customizable attributes of the applet which don't
157 change as it is used. When stored in hidden answer fields 159 change as it is used. When stored in hidden answer fields
158 it is usually stored in base64 encoded format. 160 it is usually stored in base64 encoded format.
159 base64_config base64 encode version of the contents of config 161
160
161 configAlias (default: setConfig ) names the applet command called with the contents of $self->config 162 configAlias (default: setConfig ) names the applet command called with the contents of $self->config
162 to configure the applet. The parameters are passed to the applet in plain text using <xml> 163 to configure the applet. The parameters are passed to the applet in plain text using <xml>
163 The outer tags must be <xml> ..... </xml> 164 The outer tags must be <xml> ..... </xml>
164 setConfigAlias (default: setConfig) -- a synonym for configAlias 165 setConfigAlias (default: setConfig) -- a synonym for configAlias
165 getConfigAlias (default: getConfig) -- retrieves the configuration from the applet. This is used 166 getConfigAlias (default: getConfig) -- retrieves the configuration from the applet. This is used
173 174
174 getStateAlias (default: getState) alias for command called to read the current state of the applet. 175 getStateAlias (default: getState) alias for command called to read the current state of the applet.
175 The state is passed in plain text xml format with outer tags: <xml>....</xml> 176 The state is passed in plain text xml format with outer tags: <xml>....</xml>
176 setStateAlias (default: setState) alias for the command called to reset the state of the applet. 177 setStateAlias (default: setState) alias for the command called to reset the state of the applet.
177 The state is passed in plain text in xml format with outer tags: <xml>....</xml> 178 The state is passed in plain text in xml format with outer tags: <xml>....</xml>
178
179 base64_state returns the base64 encoded version of the state stored in the applet object.
180 179
181 initializeActionAlias -- (default: initializeAction) the name of the javaScript subroutine called to initialize the applet (some overlap with config/ and setState 180 initializeActionAlias -- (default: initializeAction) the name of the javaScript subroutine called to initialize the applet (some overlap with config/ and setState
182 submitActionAlias -- (default: submitAction)the name of the javaScript subroutine called when the submit button of the 181 submitActionAlias -- (default: submitAction)the name of the javaScript subroutine called when the submit button of the
183 .pg question is pressed. 182 .pg question is pressed.
184 answerBoxAlias -- name of answer box to return answer to: default defaultAnswerBox 183 answerBoxAlias -- name of answer box to return answer to: default defaultAnswerBox
361# appletId =>'', #always use identical applet Id's and applet Names 360# appletId =>'', #always use identical applet Id's and applet Names
362 params =>undef, 361 params =>undef,
363 width => 550, 362 width => 550,
364 height => 400, 363 height => 400,
365 bgcolor => "#869ca7", 364 bgcolor => "#869ca7",
366 base64_state => undef, # this is a state to use for initializing the first occurence of the question. 365# base64_state => undef, # this is a state to use for initializing the first occurence of the question.
367 base64_config => undef, # this is the initial (and final?) configuration 366# base64_config => undef, # this is the initial (and final?) configuration
368# configuration => '', # configuration defining the applet 367 configuration => '', # configuration defining the applet
369 initialState => '', # initial state. (I'm considering storing everything as ascii and converting on the fly to base64 when needed.) 368 initialState => '', # initial state.
370 getStateAlias => 'getXML', 369 getStateAlias => 'getXML',
371 setStateAlias => 'setXML', 370 setStateAlias => 'setXML',
372 configAlias => '', # deprecated 371 configAlias => '', # deprecated
373 getConfigAlias => 'getConfig', 372 getConfigAlias => 'getConfig',
374 setConfigAlias => 'setConfig', 373 setConfigAlias => 'setConfig',
393 } 392 }
394 if ($self->{configAlias}) { # backward compatibility 393 if ($self->{configAlias}) { # backward compatibility
395 warn "use setConfigAlias instead of configAlias"; 394 warn "use setConfigAlias instead of configAlias";
396 $self->{configAlias}=''; 395 $self->{configAlias}='';
397 } 396 }
398 $self->config('<xml></xml>'); 397 $self->configuration('<xml></xml>');
399 return $self; 398 return $self;
400} 399}
401 400
402sub header { 401sub header {
403 my $self = shift; 402 my $self = shift;
530 my $self = shift; 529 my $self = shift;
531 my $str = shift; 530 my $str = shift;
532 $self->{initialState} = $str ||$self->{initialState}; # replace the current string if non-empty 531 $self->{initialState} = $str ||$self->{initialState}; # replace the current string if non-empty
533 $self->{initialState}; 532 $self->{initialState};
534} 533}
535
536sub config { 534sub configuration {
537 my $self = shift; 535 my $self = shift;
538 my $str = shift; 536 my $str = shift;
539 $self->{base64_config} = encode_base64($str) || $self->{base64_config}; # replace the current string if non-empty 537 $self->{configuration} = $str || $self->{configuration}; # replace the current string if non-empty
540 $self->{base64_config} =~ s/\n//g; 538 $self->{configuration} =~ s/\n//g;
541 decode_base64($self->{base64_config}); 539 $self->{configuration};
542} 540}
541
543####################### 542#######################
544# soon to be deprecated? 543# soon to be deprecated?
545####################### 544#######################
545
546sub config {
547 my $self = shift;
548 my $str = shift;
549 warn "use $self->configuration instead of $self->config. Internally this string is ascii, not base64 encoded", join(' ', caller());
550# $self->{base64_config} = encode_base64($str) || $self->{base64_config}; # replace the current string if non-empty
551# $self->{base64_config} =~ s/\n//g;
552# decode_base64($self->{base64_config});
553}
546sub state { 554sub state {
547 my $self = shift; 555 my $self = shift;
548 my $str = shift; 556 my $str = shift;
557 warn "use $self->initialState instead of $self->state. Internally this string is ascii, not base64 encoded", join(' ', caller());
549 $self->{base64_state} = encode_base64($str) ||$self->{base64_state}; # replace the current string if non-empty 558# $self->{base64_state} = encode_base64($str) ||$self->{base64_state}; # replace the current string if non-empty
550 $self->{base64_state} =~ s/\n//g; 559# $self->{base64_state} =~ s/\n//g;
551 decode_base64($self->{base64_state}); 560# decode_base64($self->{base64_state});
552} 561}
553sub base64_state{ 562sub base64_state{
554 my $self = shift; 563 my $self = shift;
555 $self->{base64_state} = shift ||$self->{base64_state}; # replace the current string if non-empty 564 warn "use $self->InitialState instead of $self->state. Internally this string is ascii, not base64 encoded", join(' ', caller());
556 $self->{base64_state}; 565
566
557} 567}
558 568
559sub base64_config { 569sub base64_config {
560 my $self = shift; 570 my $self = shift;
561 $self->{base64_config} = shift ||$self->{base64_config}; # replace the current string if non-empty 571 warn "use $self->configuration instead of $self->config. Internally this string is ascii, not base64 encoded";
562 $self->{base64_config} =$self->{base64_config};
563 $self->{base64_config};
564} 572}
565 573
566sub returnFieldName { 574sub returnFieldName {
567 my $self = shift; 575 my $self = shift;
568 warn "use answerBoxName instead of returnFieldName"; 576 warn "use answerBoxName instead of returnFieldName";
579 my $self = shift; 587 my $self = shift;
580 588
581 my $codebase = $self->codebase; 589 my $codebase = $self->codebase;
582 my $appletId = $self->appletId; 590 my $appletId = $self->appletId;
583 my $appletName = $self->appletName; 591 my $appletName = $self->appletName;
584 my $base64_initialState = $self->base64_state;
585 my $initializeActionAlias = $self->initializeActionAlias; 592 my $initializeActionAlias = $self->initializeActionAlias;
586 my $submitActionAlias = $self->submitActionAlias;
587 my $submitActionScript = $self->submitActionScript; 593 my $submitActionScript = $self->submitActionScript;
588 my $setStateAlias = $self->setStateAlias; 594 my $setStateAlias = $self->setStateAlias;
589 my $getStateAlias = $self->getStateAlias; 595 my $getStateAlias = $self->getStateAlias;
590 596
591 my $setConfigAlias = $self->setConfigAlias; 597 my $setConfigAlias = $self->setConfigAlias;
592 my $getConfigAlias = $self->getConfigAlias; 598 my $getConfigAlias = $self->getConfigAlias;
593 my $maxInitializationAttempts = $self->maxInitializationAttempts; 599 my $maxInitializationAttempts = $self->maxInitializationAttempts;
594 my $base64_config = $self->base64_config;
595 my $debugMode = ($self->debugMode) ? "1": "0"; 600 my $debugMode = ($self->debugMode) ? "1": "0";
596 my $answerBoxAlias = $self->{answerBoxAlias}; 601 my $answerBoxAlias = $self->{answerBoxAlias};
597 my $headerText = $self->header(); 602 my $headerText = $self->header();
598 603
599 604
600 $submitActionScript =~ s/"/\\"/g; # escape quotes for ActionScript 605 #$submitActionScript =~ s/"/\\"/g; # escape quotes for ActionScript
601 # other variables should not have quotes. 606 # other variables should not have quotes.
602 607
603 $submitActionScript =~ s/\n/ /g; # replace returns with spaces -- returns in the wrong spot can cause trouble with javaScript 608 $submitActionScript =~ s/\n/ /g; # replace returns with spaces -- returns in the wrong spot can cause trouble with javaScript
604 $submitActionScript =~ s/\r/ /g; # replace returns with spaces -- returns can cause trouble 609 $submitActionScript =~ s/\r/ /g; # replace returns with spaces -- returns can cause trouble
605 my $base64_submitActionScript = encode_base64($submitActionScript); 610 my $base64_submitActionScript = encode_base64($submitActionScript);
611 my $base64_configuration = encode_base64($self->configuration);
612 my $base64_initialState = encode_base64($self->initialState);
613
606 $base64_submitActionScript =~s/\n//g; 614 $base64_submitActionScript =~s/\n//g;
615 $base64_initialState =~s/\n//g; # base64 encoded xml
616 $base64_configuration =~s/\n//g; # base64 encoded xml
607 617
608 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook 618 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook
609 619
610 return $headerText; 620 return $headerText;
611 621
672 682
673 ww_applet_list["$appletName"].code = "$code"; 683 ww_applet_list["$appletName"].code = "$code";
674 ww_applet_list["$appletName"].codebase = "$codebase"; 684 ww_applet_list["$appletName"].codebase = "$codebase";
675 ww_applet_list["$appletName"].appletID = "$appletID"; 685 ww_applet_list["$appletName"].appletID = "$appletID";
676 ww_applet_list["$appletName"].base64_state = "$base64_initializationState"; 686 ww_applet_list["$appletName"].base64_state = "$base64_initializationState";
677 ww_applet_list["$appletName"].initialState = Base64.decode("$base64_intialState"); 687 ww_applet_list["$appletName"].initialState = Base64.decode("$base64_initialState");
678 ww_applet_list["$appletName"].base64_config = "$base64_config"; 688 ww_applet_list["$appletName"].configuration = Base64.decode("$base64_configuration");;
679 ww_applet_list["$appletName"].getStateAlias = "$getStateAlias"; 689 ww_applet_list["$appletName"].getStateAlias = "$getStateAlias";
680 ww_applet_list["$appletName"].setStateAlias = "$setStateAlias"; 690 ww_applet_list["$appletName"].setStateAlias = "$setStateAlias";
681 ww_applet_list["$appletName"].setConfigAlias = "$setConfigAlias"; 691 ww_applet_list["$appletName"].setConfigAlias = "$setConfigAlias";
682 ww_applet_list["$appletName"].getConfigAlias = "$getConfigAlias"; 692 ww_applet_list["$appletName"].getConfigAlias = "$getConfigAlias";
683 ww_applet_list["$appletName"].initializeActionAlias = "$initializeActionAlias"; 693 ww_applet_list["$appletName"].initializeActionAlias = "$initializeActionAlias";
684 ww_applet_list["$appletName"].submitActionAlias = "$submitActionAlias"; 694 ww_applet_list["$appletName"].submitActionAlias = "$submitActionAlias";
685 ww_applet_list["$appletName"].submitActionScript = Base64.decode("$submitActionScript_base64"); 695 ww_applet_list["$appletName"].submitActionScript = Base64.decode("$base64_submitActionScript");
686 ww_applet_list["$appletName"].answerBoxAlias = "$answerBoxAlias"; 696 ww_applet_list["$appletName"].answerBoxAlias = "$answerBoxAlias";
687 ww_applet_list["$appletName"].maxInitializationAttempts = $maxInitializationAttempts; 697 ww_applet_list["$appletName"].maxInitializationAttempts = $maxInitializationAttempts;
688 ww_applet_list["$appletName"].debugMode = "$debugMode"; 698 ww_applet_list["$appletName"].debugMode = "$debugMode";
689 699
690 </script> 700 </script>

Legend:
Removed from v.6029  
changed lines
  Added in v.6030

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9