[LON-CAPA-cvs] cvs: loncom /html/adm/helper parameter.helper /interface lonhelper.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 21 Jan 2005 22:59:55 -0000


albertel		Fri Jan 21 17:59:55 2005 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
    /loncom/html/adm/helper	parameter.helper 
  Log:
  - implement BUG#2123, Parameter helper needs to work with problem parts
  	- additionally the helper now passes along info so that table display mode at the end is limited to just the resource/part/parameter that was changed
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.94 loncom/interface/lonhelper.pm:1.95
--- loncom/interface/lonhelper.pm:1.94	Thu Jan 20 15:20:35 2005
+++ loncom/interface/lonhelper.pm	Fri Jan 21 17:59:54 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.94 2005/01/20 20:20:35 albertel Exp $
+# $Id: lonhelper.pm,v 1.95 2005/01/21 22:59:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1715,7 +1715,9 @@
 suppressEmptySequences argument to the render routine, which will cause
 folders that have all of their contained resources filtered out to also
 be filtered out. The 'addstatus' attribute, if true, will add the icon
-and long status display columns to the display.
+and long status display columns to the display. The 'addparts'
+attribute will add in a part selector beside problems that have more
+than 1 part.
 
 =head3 SUB-TAGS
 
@@ -1782,6 +1784,10 @@
     $paramHash->{'suppressEmptySequences'} = $token->[2]{'suppressEmptySequences'};
     $paramHash->{'toponly'} = $token->[2]{'toponly'};
     $paramHash->{'addstatus'} = $token->[2]{'addstatus'};
+    $paramHash->{'addparts'} = $token->[2]{'addparts'};
+    if ($paramHash->{'addparts'}) {
+	$helper->declareVar($paramHash->{'variable'}.'_part');
+    }
     $paramHash->{'closeallpages'} = $token->[2]{'closeallpages'};
     return '';
 }
@@ -1955,9 +1961,10 @@
     my $filterFunc     = $self->{FILTER_FUNC};
     my $choiceFunc     = $self->{CHOICE_FUNC};
     my $valueFunc      = $self->{VALUE_FUNC};
-    my $multichoice   = $self->{'multichoice'};
+    my $multichoice    = $self->{'multichoice'};
     my $option_vars    = $self->{OPTION_VARS};
     my $option_texts   = $self->{OPTION_TEXTS};
+    my $addparts       = $self->{'addparts'};
     my $headings_done  = 0;
 
     # Evaluate the map url as needed
@@ -2019,12 +2026,51 @@
 		$checked = 1;
 	    }
             $col .= "value='" . $resource_name  . "' /></td>";
+
             return $result.$col;
         }
     };
+    my $renderPartsFunc = sub {
+        my ($resource, $part, $params) = @_;
+	my $col= "<td>";
+	my $id=$resource->{ID};
+	my $resource_name =   
+	    &HTML::Entities::encode(&$valueFunc($resource),"<>&\"'");
+	if ($addparts && (scalar(@{$resource->parts}) > 1)) {
+	    $col .= "<select onclick=\"javascript:updateRadio(this.form,'${var}.forminput','$resource_name');updateHidden(this.form,'$id','${var}');\" name='part_$id.forminput'>\n";
+	    $col .= "<option value=\"$part\">All Parts</option>\n";
+	    foreach my $part (@{$resource->parts}) {
+		$col .= "<option value=\"$part\">Part: $part</option>\n";
+	    }
+	    $col .= "</select>";
+	}
+	$col .= "</td>";
+    };
+    $result.=(<<RADIO);
+<script type="text/javascript">
+    function updateRadio(form,name,value) {
+	var radiobutton=form[name];
+	for (var i=0; i<radiobutton.length; i++) {
+	    if (radiobutton[i].value == value) {
+		radiobutton[i].checked = true;
+		break;
+	    }
+	}
+    }
+    function updateHidden(form,id,name) {
+	var select=form['part_'+id+'.forminput'];
+	var hidden=form[name+'_part.forminput'];
+	var which=select.selectedIndex;
+	hidden.value=select.options[which].value;
+    }
+</script>
+<input type="hidden" name="${var}_part.forminput" />;
 
+RADIO
     $ENV{'form.condition'} = !$self->{'toponly'};
-    my $cols = [$renderColFunc, Apache::lonnavmaps::resource()];
+    my $cols = [$renderColFunc];
+    if ($self->{'addparts'}) { push(@$cols, $renderPartsFunc); }
+    push(@$cols, Apache::lonnavmaps::resource());
     if ($self->{'addstatus'}) {
 	push @$cols, (Apache::lonnavmaps::part_status_summary());
 	
@@ -3217,7 +3263,7 @@
     my $resourceString;
     my $symb;
     my $paramlevel;
-
+    
     # Print the granularity, depending on the action
     if ($vars->{GRANULARITY} eq 'whole_course') {
         $resourceString .= '<li>'.&mt('for <b>all resources in the course</b>').'</li>';
@@ -3237,15 +3283,27 @@
     } else {
         my $navmap = Apache::lonnavmaps::navmap->new();
         my $res = $navmap->getById($vars->{RESOURCE_ID});
+        my $part = $vars->{RESOURCE_ID_part};
+	if ($part ne 'All Parts' && $part) { $parm_name=~s/^0/$part/; } else { $part=&mt('All Parts'); }
         $symb = $res->symb();
         my $title = $res->compTitle();
-        $resourceString .= '<li>'.&mt('for the resource named [_1]',"<b>$title</b>").'</li>';
+        $resourceString .= '<li>'.&mt('for the resource named [_1] part [_2]',"<b>$title</b>","<b>$part</b>").'</li>';
         $level = 7;
         $affectedResourceId = $vars->{RESOURCE_ID};
         $paramlevel = 'full';
     }
 
     my $result = "<form name='helpform' method='get' action='/adm/parmset#$affectedResourceId&$parm_name&$level'>\n";
+    if ($vars->{GRANULARITY} eq 'resource') {
+	$result .= "<input type='hidden' name='symb' value='".
+	    HTML::Entities::encode($symb,"'<>&\"") . "' />\n";
+	$result .= "<input type='hidden' name='pscat' value='".
+	    HTML::Entities::encode($vars->{ACTION_TYPE},"'<>&\"") . "' />\n";
+	my $part = $vars->{RESOURCE_ID_part};
+	if ($part eq 'All Parts' || !$part) { $part=0; }
+	$result .= "<input type='hidden' name='psprt' value='".
+	    HTML::Entities::encode($part,"'<>&\"") . "' />\n";
+    }
     $result .= '<p>'.&mt('Confirm that this information is correct, then click &quot;Finish Helper&quot; to complete setting the parameter.').'<ul>';
     
     # Print the type of manipulation:
Index: loncom/html/adm/helper/parameter.helper
diff -u loncom/html/adm/helper/parameter.helper:1.12 loncom/html/adm/helper/parameter.helper:1.13
--- loncom/html/adm/helper/parameter.helper:1.12	Tue Apr 27 13:58:35 2004
+++ loncom/html/adm/helper/parameter.helper	Fri Jan 21 17:59:54 2005
@@ -73,7 +73,7 @@
   <state name="CHOOSE_RESOURCE" title="Select Problem">
     <message>Select the problem you wish to set the parameter for:</message>
 
-    <resource variable="RESOURCE_ID" nextstate="CHOOSE_ACTION">
+    <resource variable="RESOURCE_ID" nextstate="CHOOSE_ACTION" addparts="true">
       <nextstate>CHOOSE_ACTION</nextstate>
       <filterfunc>return $res->is_map || $res->is_problem()</filterfunc>
       <choicefunc>return $res->is_problem()</choicefunc>