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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Thu, 27 Feb 2003 19:42:59 -0000


bowersj2		Thu Feb 27 14:42:59 2003 EDT

  Modified files:              
    /loncom/interface	lonwizard.pm 
  Log:
  Changes to the multiselect routine, to use checkboxes. 
  
  
Index: loncom/interface/lonwizard.pm
diff -u loncom/interface/lonwizard.pm:1.12 loncom/interface/lonwizard.pm:1.13
--- loncom/interface/lonwizard.pm:1.12	Fri Feb 21 16:27:28 2003
+++ loncom/interface/lonwizard.pm	Thu Feb 27 14:42:59 2003
@@ -626,7 +626,7 @@
 
 =over 4
 
-=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, choiceHash): messageBefore is the HTML text that will be displayed before the choice display, messageAfter will display after. Keys will be sorted according to human name. nextState is the state to proceed to after the choice. varName is the name of the wizard var to store the computer_name answer in. choiceHash is the hash described above. It is optional because you may override it.
+=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, choiceHash, multichoice): messageBefore is the HTML text that will be displayed before the choice display, messageAfter will display after. Keys will be sorted according to human name. nextState is the state to proceed to after the choice. varName is the name of the wizard var to store the computer_name answer in. choiceHash is the hash described above. It is optional because you may override it. multichoice is true if the user can make multiple choices, false otherwise. (Multiple choices will be seperated with ||| in the wizard variable.
 
 =back
 
@@ -642,6 +642,7 @@
     $self->{NEXT_STATE} = shift;
     $self->{VAR_NAME} = shift;
     $self->{CHOICE_HASH} = shift;
+    $self->{MULTICHOICE} = shift;
     $self->{NO_CHOICES} = 0;
     
     return $self;
@@ -686,7 +687,25 @@
     my $self = shift;
     my $result = "";
     my $var = $self->{VAR_NAME};
+    my $buttons = '';
 
+    if ($self->{MULTICHOICE}) {
+        $result = <<SCRIPT;
+<script>
+    function checkall(value) {
+	for (i=0; i<document.forms.wizform.elements.length; i++) {
+            document.forms.wizform.elements[i].checked=value;
+        }
+    }
+</script>
+SCRIPT
+        $buttons = <<BUTTONS;
+<input type="button" onclick="checkall(true)" value="Select All" />
+<input type="button" onclick="checkall(false)" value="Unselect All" />
+<br />
+BUTTONS
+    }
+        
     if (defined $self->{ERROR_MSG}) {
         $result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />';
     }
@@ -695,16 +714,27 @@
 	$result .= $self->{MESSAGE_BEFORE} . '<br /><br />';
     }
 
+    $result .= $buttons;
+
     my $choices = $self->{CHOICE_HASH};
     my @keys = keys (%$choices);
 
-    $result .= "<select name=\"$var.forminput\" size=\"10\">\n";
+    my $multichoice = '';
+    if ($self->{MULTICHOICE}) {
+        $multichoice = 'multichoice="true" ';
+    }
+
+    my $type = "radio";
+    if ($self->{MULTICHOICE}) { $type = 'checkbox'; }
     foreach (@keys)
     {
-	$result .= "<option value=\"" . HTML::Entities::encode($choices->{$_}) 
-            . "\">" . HTML::Entities::encode($_) . "</option>\n";
+        
+        $result .= "<input type='$type' name='" .
+            $self->{VAR_NAME} . '.forminput' .
+            "' value=\"" . 
+            HTML::Entities::encode($choices->{$_}) 
+            . "\"/> " . HTML::Entities::encode($_) . "<br />\n";
     }
-    $result .= "</select>\n\n";
 
     if (defined $self->{MESSAGE_AFTER})
     {
@@ -744,9 +774,11 @@
 
 =over 4
 
-=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, varName, choiceList, messageBefore, messageAfter): varName is the name of the wizard variable the state will set with the choice made. choiceHash is list reference of a list of list references to three element lists, where the first element is what the wizard var varName will be set to, the second is the HTML that will be displayed for that choice, and the third is the destination state. messageBefore is an optional HTML string that will be placed before the message, messageAfter an optional HTML string that will be placed before.
+=item overridden method B<new>(parentLonWizReference, stateName, stateTitle, varName, choiceList, messageBefore, messageAfter): varName is the name of the wizard variable the state will set with the choice made. choiceHash is list reference of a list of list references to three element lists, where the first element is what the wizard var varName will be set to, the second is the HTML that will be displayed for that choice, and the third is the destination state. The special setting 'ILLEGAL' can be used in the first place to state that it is not a legal chocie (see lonprintout.pm for real-life usage of that). messageBefore is an optional HTML string that will be placed before the message, messageAfter an optional HTML string that will be placed before.
 
-An example of a legit choiceList: C<my $choicelist = [ ["flunk", "Flunk Student", "FLUNK_STATE"], ["pass", "Pass Student", "PASS_STATE"] ];>
+Note that ILLEGAL is desirable because some choices may not always be good choices, but they should not necessarily disappear with no explanantion of why they are no good. In lonprintout.pm, for instance, the choice "Problems from current sequence" may be no good because there are no problems in the sequence, but it should not silently disappear; it should announce that there are no problems in the sequence.
+
+An example of a legit choiceList: C<my $choicelist = [ ["flunk", "Flunk Student", "FLUNK_STATE"], ["pass", "Pass Student", "PASS_STATE"]  ];>
 
 =back
 
@@ -1230,6 +1262,8 @@
 # it renders the same states, so it doesn't go in just this state, and
 # you can lean on the browser back button to make sure it all chains
 # correctly.
+# Either that, or force all folders open and don't allow the user
+# to close them.
 
 sub render {
     my $self = shift;
@@ -1299,6 +1333,8 @@
 
 This is generally intended for use on a specific sequence, not the entire course, as for technical reasons the user can't open and close folders, so they must all be shown as open. To fix this would require making the folders image form submitters and remembering the selected state of each resource, which is not impossible but is too much error-prone work to do until it seems many people will want that feature.
 
+Note this class is generally useful for multi-choice selections, by overridding "determineChoices" to return the choice hash.
+
 =over 4
 
 =item overridden method B<new>(parentLonWizReference, stateName, stateTitle, messageBefore, messageAfter, nextState, varName, filterFunction, choiceFunction, map): Arguments like resource_choice. map is the ID number of a specific map that, if given is all that will be shown to the user, instead of the whole course.
@@ -1421,7 +1457,7 @@
     my $proto = shift;
     my $class = ref($proto) || $proto;
     my $self = bless $proto->SUPER::new(shift, shift, shift, shift,
-                                        shift, shift, shift);
+                                        shift, shift, shift, undef, shift);
     return $self;
 }