[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 18 Dec 2006 21:48:48 -0000


albertel		Mon Dec 18 16:48:48 2006 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  - change wizard to helper
  - add a help attribute to the <state>
  - <helpicon> wasn't displaying the internal text
  - if the firstthing in a state was a <helpicon> the
     nextstate wasn't taking effect
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.159 loncom/interface/lonhelper.pm:1.160
--- loncom/interface/lonhelper.pm:1.159	Tue Dec 12 15:41:08 2006
+++ loncom/interface/lonhelper.pm	Mon Dec 18 16:48:47 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.159 2006/12/12 20:41:08 albertel Exp $
+# $Id: lonhelper.pm,v 1.160 2006/12/18 21:48:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -81,25 +81,28 @@
 human name of the state, and will be displayed as the header on top of 
 the screen for the user.
 
+State tags may also optionally have an attribute "help" which should be
+the filename of a help file, this will add a blue ? to the title.
+
 =head2 Example Helper Skeleton
 
 An example of the tags so far:
 
  <helper title="Example Helper">
    <state name="START" title="Demonstrating the Example Helper">
-     <!-- notice this is the START state the wizard requires -->
+     <!-- notice this is the START state the helper requires -->
      </state>
    <state name="GET_NAME" title="Enter Student Name">
      </state>
    </helper>
 
-Of course this does nothing. In order for the wizard to do something, it is
-necessary to put actual elements into the wizard. Documentation for each
+Of course this does nothing. In order for the helper to do something, it is
+necessary to put actual elements into the helper. Documentation for each
 of these elements follows.
 
 =head1 Creating a Helper With Code, Not XML
 
-In some situations, such as the printing wizard (see lonprintout.pm), 
+In some situations, such as the printing helper (see lonprintout.pm), 
 writing the helper in XML would be too complicated, because of scope 
 issues or the fact that the code actually outweighs the XML. It is
 possible to create a helper via code, though it is a little odd.
@@ -334,7 +337,8 @@
     }
 
     Apache::lonhelper::state->new($token->[2]{'name'},
-                                  $token->[2]{'title'});
+                                  $token->[2]{'title'},
+				  $token->[2]{'help'});
     return '';
 }
 
@@ -577,6 +581,7 @@
 
     # Phase 4: Display.
     my $stateTitle=&mt($state->title());
+    my $stateHelp=     $state->help();
     my $browser_searcher_js = 
 	'<script type="text/javascript">'."\n".
 	&Apache::loncommon::browser_and_searcher_javascript().
@@ -591,9 +596,12 @@
 
 
     if (!$state->overrideForm()) { $result.="<form name='helpform' method='POST'>"; }
+    if ($stateHelp) {
+	$stateHelp = &Apache::loncommon::help_open_topic($stateHelp);
+    }
     $result .= <<HEADER;
         <table border="0" width='100%'><tr><td>
-        <h2><i>$stateTitle</i></h2>
+        <h2><i>$stateTitle</i>$stateHelp</h2>
 HEADER
 
     $result .= "<table cellpadding='10' width='100%'><tr><td rowspan='2' valign='top'>";
@@ -680,6 +688,7 @@
 
     $self->{NAME} = shift;
     $self->{TITLE} = shift;
+    $self->{HELP} = shift;
     $self->{ELEMENTS} = [];
 
     bless($self, $class);
@@ -701,6 +710,11 @@
     return $self->{TITLE};
 }
 
+sub help {
+    my $self = shift;
+    return $self->{HELP};
+}
+
 sub preprocess {
     my $self = shift;
     for my $element (@{$self->{ELEMENTS}}) {
@@ -792,7 +806,7 @@
 the element itself, and possibly the settings the element has (such as 
 multichoice vs. single choice for <choices> tags). 
 
-This is also intended for things like the course initialization wizard, where the
+This is also intended for things like the course initialization helper, where the
 user is setting various parameters. By correctly grabbing current settings 
 and including them into the helper, it allows the user to come back to the
 helper later and re-execute it, without needing to worry about overwriting
@@ -1100,12 +1114,21 @@
 
     my $text;
     if ( $self->{HELP_TEXT} ne '') {
-	$text=&mtn($text);
+	$text=&mtn($self->{HELP_TEXT});
     }
 
     return &Apache::loncommon::help_open_topic($self->{HELP_FILE},
 					       $text);
 }
+sub postprocess {
+    my $self = shift;
+    if (defined($self->{NEXTSTATE})) {
+        $helper->changeState($self->{NEXTSTATE});
+    }
+
+    return 1;
+}
+
 1;
 
 package Apache::lonhelper::skip;
@@ -3500,7 +3523,7 @@
 
 package Apache::lonhelper::parmwizfinal;
 
-# This is the final state for the parmwizard. It is not generally useful,
+# This is the final state for the parm helper. It is not generally useful,
 # so it is not perldoc'ed. It does its own processing.
 # It is represented with <parmwizfinal />, and
 # should later be moved to lonparmset.pm .