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

albertel lon-capa-cvs@mail.lon-capa.org
Sun, 25 Jun 2006 21:50:25 -0000


albertel		Sun Jun 25 17:50:25 2006 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  - adding a <skip> mechanism so that states can defiine for themselves when they shouldn't be seen
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.154 loncom/interface/lonhelper.pm:1.155
--- loncom/interface/lonhelper.pm:1.154	Tue May 30 17:54:22 2006
+++ loncom/interface/lonhelper.pm	Sun Jun 25 17:50:25 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.154 2006/05/30 21:54:22 albertel Exp $
+# $Id: lonhelper.pm,v 1.155 2006/06/25 21:50:25 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1023,6 +1023,81 @@
 }
 1;
 
+package Apache::lonhelper::skip;
+
+=pod
+
+=head1 Elements
+
+=head2 Element: skipX<skip>
+
+The <skip> tag allows you define conditions under which the current state 
+should be skipped over and define what state to skip to.
+
+  <state name="SKIP">
+    <skip>
+       <clause>
+         #some code that decides whether to skip the state or not
+       </clause>
+       <nextstate>FINISH</nextstate>
+    </skip>
+    <message nextstate="FINISH">A possibly skipped state</message>
+  </state>
+
+=cut
+
+no strict;
+@ISA = ("Apache::lonhelper::element");
+use strict;
+
+BEGIN {
+    &Apache::lonhelper::register('Apache::lonhelper::skip',
+				 ('skip'));
+}
+
+sub new {
+    my $ref = Apache::lonhelper::element->new();
+    bless($ref);
+}
+
+sub start_skip {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+    if ($target ne 'helper') {
+        return '';
+    }
+    # let <cluase> know what text to skip to
+    $paramHash->{SKIPTAG}='/skip';
+    return '';
+}
+
+sub end_skip {
+    my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+
+    if ($target ne 'helper') {
+        return '';
+    }
+    Apache::lonhelper::skip->new();
+    return '';
+}
+
+sub render {
+    my $self = shift;
+    return '';
+}
+# If a NEXTSTATE is set, switch to it
+sub preprocess {
+    my ($self) = @_;
+
+    if (defined($self->{NEXTSTATE})) {
+        $helper->changeState($self->{NEXTSTATE});
+    }
+
+    return 1;
+}
+
+1;
+
 package Apache::lonhelper::choices;
 
 =pod
@@ -1610,8 +1685,6 @@
 	$date->min(0);
     }
 
-    &Apache::lonnet::logthis("date mode ");
-
     if ($anytime) {
 	$onclick = "onclick=\"javascript:updateCheck(this.form,'${var}anytime',false)\"";
     }
@@ -3130,7 +3203,8 @@
     die 'Error in clause of condition, Perl said: ' . $@ if $@;
     if (!&$clause($helper, $paramHash)) {
         # Discard all text until the /condition.
-        &Apache::lonxml::get_all_text('/condition', $parser);
+	my $end_tag = $paramHash->{SKIPTAG} || '/condition';
+        &Apache::lonxml::get_all_text($end_tag, $parser);
     }
 }