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

raeburn raeburn@source.lon-capa.org
Tue, 05 May 2009 05:30:00 -0000


This is a MIME encoded message

--raeburn1241501400
Content-Type: text/plain

raeburn		Tue May  5 05:30:00 2009 EDT

  Modified files:              
    /loncom/interface	courseclassifier.pm lonpickcourse.pm 
  Log:
  Case where there are linked select boxes for Year, Semester etc. to generate instcode filter.
    - Add radio button to toggle between "official" and unofficial" courses.
    - Appropriate instcodefilter now set when "unofficial" is selected.
    - Javascript to keep select boxes and radio buttons in consistent state. 
  
  
--raeburn1241501400
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090505053000.txt"

Index: loncom/interface/courseclassifier.pm
diff -u loncom/interface/courseclassifier.pm:1.6 loncom/interface/courseclassifier.pm:1.7
--- loncom/interface/courseclassifier.pm:1.6	Fri May  1 01:30:08 2009
+++ loncom/interface/courseclassifier.pm	Tue May  5 05:30:00 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utilities for classifying courses based on institutional code
 #
-# $Id: courseclassifier.pm,v 1.6 2009/05/01 01:30:08 raeburn Exp $
+# $Id: courseclassifier.pm,v 1.7 2009/05/05 05:30:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -445,7 +445,7 @@
 }
 
 sub instcode_selectors_data {
-    my ($codedom,$formname,$cat_items,$codetitles,$cat_titles,$cat_order) = @_;
+    my ($codedom,$formname,$cat_items,$codetitles,$cat_titles,$cat_order,$officialjs) = @_;
     my ($jscript,%coursecodes,%codes,%idlist,%idnums,%idlist_titles,
         %by_year,%by_sem,%by_dept);
     my ($numtitles,$lasttitle);
@@ -478,7 +478,35 @@
                     $level = &recurse_options($codetitles->[$k],$idlist{$codetitles->[$k]},$level,$cat,$cat_items,\@data,\%by_year,\%by_sem,\%by_dept);
                 }
                 $scripttext .= &build_javascript(\%by_year,\%by_sem,\%by_dept,$cat_order,$codetitles);
-                $jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist);
+                if ($officialjs) {
+                    $jscript .= '
+
+function toggleOfficial() {';
+                    for (my $i=0; $i<@{$codetitles}-1; $i++) {
+                        $jscript .= '
+            document.'.$formname.'.'.$codetitles->[$i].'.selectedIndex = 0;';
+                    }
+    $jscript .=  '
+}
+
+function setOfficial(caller) {
+    if (caller.options[caller.selectedIndex].value != 0) {
+        if (document.'.$formname.'.official.length > 0) {
+            for (var j=0; j<document.'.$formname.'.official.length; j++) {
+                if (document.'.$formname.'.official[j].value == 1) {
+                    document.'.$formname.'.official[j].checked = true;
+                }
+            }
+        }
+    }
+    return;
+}
+
+';
+
+                    $officialjs = 'setOfficial(caller);';
+                }
+                $jscript .= &javascript_select_filler($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs);
                 if ($env{'form.state'} eq 'listing') {
                     $jscript .= '
 function setElements() {
@@ -532,7 +560,7 @@
                 @longitems = @items;
             }
             $output .= '<td align="center">'.$codetitles->[$k].'<br />'."\n".
-                       '<select name="'.$codetitles->[$k].'" onChange="courseSet()"'.
+                       '<select name="'.$codetitles->[$k].'" onChange="courseSet(this)"'.
                        '>'."\n".'<option value="0" />All'."\n";
             for (my $i=0; $i<@items; $i++) {
                 if ($longitems[$i] eq '') {
@@ -640,10 +668,10 @@
 }
 
 sub javascript_select_filler {
-    my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist) = @_;
+    my ($formname,$scripttext,$codetitles,$longtitles_str,$allidlist,$officialjs) = @_;
     my $output = <<END;
 
-function courseSet() {
+function courseSet(caller) {
     var longtitles = new Array ("$longtitles_str");
     var valyr = document.$formname.Year.options[document.$formname.Year.selectedIndex].value
     var valsem  = document.$formname.Semester.options[document.$formname.Semester.selectedIndex].value
@@ -774,6 +802,7 @@
         }
         document.$formname.Number.selectedIndex = 0
     }
+    $officialjs
 }
 END
     return $output;
Index: loncom/interface/lonpickcourse.pm
diff -u loncom/interface/lonpickcourse.pm:1.79 loncom/interface/lonpickcourse.pm:1.80
--- loncom/interface/lonpickcourse.pm:1.79	Mon May  4 13:24:12 2009
+++ loncom/interface/lonpickcourse.pm	Tue May  5 05:30:00 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Pick a course
 #
-# $Id: lonpickcourse.pm,v 1.79 2009/05/04 13:24:12 raeburn Exp $
+# $Id: lonpickcourse.pm,v 1.80 2009/05/05 05:30:00 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -521,10 +521,12 @@
              );
 
     $typeselectform =  '<select name="type" size="1">'."\n";
+    my $officialjs;
     if ($type eq 'Course') {
         if ($env{'form.fixeddom'}) {
+            $officialjs = 1;
             ($instcodeform,$jscript,$$numtitlesref) = 
-                &instcode_selectors($codedom,'filterpicker');
+                &instcode_selectors($codedom,'filterpicker',$officialjs);
         }
         if ($instcodeform eq '') {
             $instcodeform = 
@@ -631,16 +633,27 @@
 }
 
 sub instcode_selectors {
-    my ($codedom,$formname) = @_;
+    my ($codedom,$formname,$officialjs) = @_;
     my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
     my ($jscript,$totcodes,$numtitles,$lasttitle) =
         &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
-                           \%cat_items,\@codetitles,\%cat_titles,\%cat_order);
+                           \%cat_items,\@codetitles,\%cat_titles,\%cat_order,$officialjs);
     if ($numtitles > 0) {
-        $output = &Apache::courseclassifier::build_instcode_selectors($numtitles,
-                  $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
-                  '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
-                  '<input type="hidden" name="state" value="listing" />'."\n";
+        my $unofficial = ' checked="checked" ';
+        my $official = '';
+        if ($env{'form.official'}) {
+            $official = $unofficial;
+            $unofficial = '';
+        }
+        $output .= '<span class="LC_nobreak">'.&mt('Official course:').'&nbsp;<label>'.
+                   '<input type="radio" name="official" value="1"'.$official.' />'.
+                   &mt('Yes').'</label>'.('&nbsp;'x3).'<label>'.
+                   '<input type="radio" name="official" value="0"'.$unofficial.
+                   ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
+                   &Apache::courseclassifier::build_instcode_selectors($numtitles,
+                   $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
+                   '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
+                   '<input type="hidden" name="state" value="listing" />'."\n";
  
     }
     return ($output,$jscript,$numtitles);
@@ -657,24 +670,26 @@
             $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
                                            $filter->{'ownerdomfilter'};
         }
-        foreach my $item ('descriptfilter','instcodefilter','coursefilter',
-                          'combownerfilter') {
+        foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
             if (!$filter->{$item}) {
                 $filter->{$item}='.';
             }
         }
-        if ($type eq '') { $type = '.'; }
         my $timefilter = 
            ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
         my ($instcodefilter,$regexpok);
         if ($numtitles) {
-            $instcodefilter = 
-                &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},
-                                                               $numtitles);
-            $regexpok = 1;
+            if ($env{'form.official'}) {
+                $instcodefilter = 
+                    &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},
+                                                                   $numtitles);
+                $regexpok = 1;
+            }
         } else {
             $instcodefilter = $filter->{'instcodefilter'};
         }
+        if ($instcodefilter eq '') { $instcodefilter = '.'; }
+        if ($type eq '') { $type = '.'; }
         %courses = 
             &Apache::lonnet::courseiddump($filter->{'domainfilter'},
                                           $filter->{'descriptfilter'},

--raeburn1241501400--