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

www www@source.lon-capa.org
Sat, 26 Mar 2011 16:09:33 -0000


www		Sat Mar 26 16:09:33 2011 EDT

  Modified files:              
    /loncom/interface	lonquickgrades.pm 
  Log:
  Rule editor
  
  
Index: loncom/interface/lonquickgrades.pm
diff -u loncom/interface/lonquickgrades.pm:1.79 loncom/interface/lonquickgrades.pm:1.80
--- loncom/interface/lonquickgrades.pm:1.79	Fri Mar 25 22:06:34 2011
+++ loncom/interface/lonquickgrades.pm	Sat Mar 26 16:09:33 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Quick Student Grades Display
 #
-# $Id: lonquickgrades.pm,v 1.79 2011/03/25 22:06:34 www Exp $
+# $Id: lonquickgrades.pm,v 1.80 2011/03/26 16:09:33 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -475,10 +475,12 @@
     unless ($cangrade) { return %categories; }
 # First store everything
     foreach my $id (split(/\,/,$categories{'order'})) {
+# Set names, types, and weight (there is only one of each per category)
         %categories=&set_category_name($cangrade,$id,$env{'form.name_'.$id},%categories);
         %categories=&set_category_total($cangrade,$id,$env{'form.totaltype_'.$id},$env{'form.total_'.$id},%categories);
         %categories=&set_category_weight($cangrade,$id,$env{'form.weight_'.$id},%categories);
-# More changes here
+# Set values for category rules (before names may change)
+        %categories=&set_category_rules($cangrade,$id,%categories);
     }
 
 # Now deal with commands
@@ -692,21 +694,25 @@
 
 # === Calculation Rule Editing
 
-sub pretty_prt_rule {
-    my ($cangrade,$id,$code,$value)=@_;
-    my $cid=$id.'_'.$code;
-    my %lt=&Apache::lonlocal::texthash(
+sub category_rule_codes {
+    return &Apache::lonlocal::texthash(
                 'droplow'  => 'Drop N lowest grade assignments',
                 'drophigh' => 'Drop N highest grade assignments',
                 'capabove' => 'Cap percentage above N percent',
                 'capbelow' => 'Cap percentage below N percent');
+}
+
+sub pretty_prt_rule {
+    my ($cangrade,$id,$code,$value)=@_;
+    my $cid=$id.'_'.$code;
+    my %lt=&category_rule_codes();
     my $ret='<span class="LC_nobreak">';
     if ($cangrade) {
         $ret.='<select name="sel_'.$cid.'">';
         foreach my $calc (''=>'',sort(keys(%lt))) {
             $ret.='<option value="'.$calc.'"'.($calc eq $code?' selected="selected"':'').' />'.$lt{$calc}.'</input>';
         }
-        $ret.='</select> N=<input type="text" size="5" name="val_'.$cid.'" /></span>';
+        $ret.='</select> N=<input type="text" size="5" name="val_'.$cid.'" value="'.$value.'" /></span>';
     } else {
         $ret.=$lt{$code}.'; N='.$value;
     }
@@ -751,6 +757,21 @@
     return %categories;
 }
 
+sub set_category_rules {
+    my ($cangrade,$id,%categories)=@_;
+    unless ($cangrade) { return %categories; }
+    my %lt=&category_rule_codes();
+    my @newrules=();
+    foreach my $code ('',(keys(%lt))) {
+        if ($env{'form.sel_'.$id.'_'.$code}) {
+            push(@newrules,$env{'form.sel_'.$id.'_'.$code}.':'.$env{'form.val_'.$id.'_'.$code});
+        }
+    }
+    $categories{$id.'_calculations'}=join(',',sort(@newrules));
+    return %categories;
+}
+
+
 # === Category Editing
 
 #