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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 30 Jun 2008 04:07:09 -0000


This is a MIME encoded message

--raeburn1214798829
Content-Type: text/plain

raeburn		Mon Jun 30 00:07:09 2008 EDT

  Modified files:              
    /loncom/interface	coursecatalog.pm 
  Log:
  - New subroutine: &additional_filters() generates checkboxes to apply in course 
    search (self-enroll only, DC only: display hidden & show all details).
  - "Go" buttons for updating domain used for coursecatalog and category to search
    replaced with "Change"
  - "Display course" button displayed for both searches for official courses and
    for manually assigned categories.
  - Some javascript changes so changeSort() and setCourseId() are available for
    both types of search. copy_filters() function no longer needed.
  
  
--raeburn1214798829
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080630000709.txt"

Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.32 loncom/interface/coursecatalog.pm:1.33
--- loncom/interface/coursecatalog.pm:1.32	Fri Jun 27 00:59:45 2008
+++ loncom/interface/coursecatalog.pm	Mon Jun 30 00:07:06 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.32 2008/06/27 04:59:45 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.33 2008/06/30 04:07:06 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -84,6 +84,17 @@
 }
 
 ENDSCRIPT
+        if ($env{'form.state'} eq 'listing') {
+            $catjs .= qq|
+function changeSort(caller) {
+    document.$formname.sortby.value = caller;
+    document.$formname.submit();
+}
+function setCourseId(caller) {
+    document.$formname.coursenum.value = caller;
+    document.$formname.submit();
+}\n|;
+        }
         my $numtitles;
         if ($env{'form.currcat_0'} eq 'instcode::0') {
             $numtitles = &instcode_course_selector($r,$codedom,$formname,$domdesc,
@@ -96,6 +107,24 @@
             $catjs = '<script type="text/javascript">'."\n".$catjs."\n".'</script>';
             &cat_header($r,$codedom,$catjs,\%add_entries,$catlinks);
             if ($env{'form.currcat_0'} ne '') {
+                $r->print('<form name="'.$formname.
+                          '" method="post" action="/adm/coursecatalog">'.
+                          &additional_filters($codedom)."\n");
+                my ($currdepth,$deeper) = &get_depth_values();
+                $r->print('<input type="hidden" name="catalog_maxdepth" value="'.
+                          $deeper.'" />'."\n");
+                for (my $i=0; $i<$deeper; $i++) {
+                    $r->print('<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />'."\n");
+                }
+                $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
+                          '<input type="hidden" name="sortby" value="" />'."\n".
+                          '<input type="hidden" name="state" value="listing" />'."\n".
+                          '<input type="hidden" name="showdom" value="'.
+                          $env{'form.showdom'}.'" />'.
+                          '<input type="submit" name="catalogfilter" value="'.
+                          &mt('Display courses').'" /></form><br /><br />');
+            }
+            if ($env{'form.state'} eq 'listing') {
                 $r->print(&print_course_listing($codedom));
             }
         }
@@ -212,51 +241,7 @@
                     $jscript .= '}';
                 }
             }
-            if ($env{'form.state'} eq 'listing') {
-                $jscript .= qq|
-function changeSort(caller) {
-    document.$formname.sortby.value = caller;
-    copy_filters();
-    document.$formname.submit();
-}
-function setCourseId(caller) {
-    document.$formname.coursenum.value = caller;
-    copy_filters();
-    document.$formname.submit(); 
-}\n|;
-            }
-        }
-        $jscript .= qq| 
-function copy_filters() { 
-   if (document.coursecats.showselfenroll.checked) {
-       document.$formname.showselfenroll.value = '1';
-   } else {
-       document.$formname.showselfenroll.value = '';
-   }
-|;
-        if (&user_is_dc($codedom)) {
-            $jscript .= qq|
-   if (document.coursecats.showhidden.checked) {
-       document.$formname.showhidden.value = '1';
-   } else {
-       document.$formname.showhidden.value = '';
-   }
-   if (document.coursecats.showdetails.checked) {
-       document.$formname.showdetails.value = '1';
-   } else {
-       document.$formname.showdetails.value = '';
-   }
-|;
         }
-        $jscript .= qq| 
-}
-
-function display_courses() {
-    copy_filters();
-    document.$formname.submit();
-}
-
-|;
         $js = '<script type"text/javascript">'."\n$jscript\n$catjs\n".
               '</script>';
         if (($env{'form.state'} eq 'listing') && ($numtitles > 0)) {
@@ -268,11 +253,7 @@
                   '<input type="hidden" name="catalog_maxdepth" value="'.$cat_maxdepth.'" />'."\n".
                   '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'."\n".
                   '<input type="hidden" name="currcat_0" value="instcode::0" />'.
-                  '<input type="hidden" name="showselfenroll" value="" />'."\n");
-        if (&user_is_dc($codedom)) {
-            $r->print('<input type="hidden" name="showhidden" value="" />'."\n".
-                      '<input type="hidden" name="showdetails" value="" />'."\n");
-        }
+                  &additional_filters($codedom));
         if ($numtitles > 0) {
             $r->print('<b>'.&mt('Choose which course(s) to list.').'</b><br />');
             $r->print('<table><tr>');
@@ -312,12 +293,14 @@
             }
             $r->print('<br />');
         }
-        $r->print('<input type="hidden" name="coursenum" value="" /><input type="hidden" name="sortby" value="" /><input type="hidden" name="state" value="listing" /><input type="hidden" name="form.currcat_0" value="instcode::0" />');
-        if ($numtitles > 0) {
-            $r->print('<input type="button" name="catalogfilter" value="'.&mt('Display courses').'" onclick="javascript:display_courses()" />');
-        }
-        $r->print('<input type="hidden" name="numtitles" value="'.
-                  $numtitles.'" /></form>');
+        $r->print('<input type="hidden" name="coursenum" value="" />'."\n".
+                  '<input type="hidden" name="sortby" value="" />'."\n".
+                  '<input type="hidden" name="state" value="listing" />'."\n".
+                  '<input type="hidden" name="form.currcat_0" value="instcode::0" />'."\n".
+                  '<input type="submit" name="catalogfilter" value="'.
+                  &mt('Display courses').'" />'.
+                  '<input type="hidden" name="numtitles" value="'.$numtitles.
+                  '" /></form>');
         if (($numtitles > 0) && ($env{'form.state'} eq 'listing')) {
             $r->print('<br />');
         }
@@ -362,29 +345,9 @@
               '<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
               '<td><b>'.&mt('Domain:').'</b></td><td>'.
               &Apache::loncommon::select_dom_form($codedom,'showdom','',1).
-	      '&nbsp;<input type="submit" name="godom" value="'.&mt('Go').'"></td></form></tr>'.
-	      '<form name="coursecats" method="post" action="/adm/coursecatalog"><tr>'.
-              $catlinks.'</tr>');
-    my $show_selfenroll_status;
-    if ($env{'form.showselfenroll'}) {
-        $show_selfenroll_status = 'checked="checked" ';
-    }
-    if (&user_is_dc($codedom)) {
-        my $showdetails_status;
-        if ($env{'form.showdetails'}) {
-            $showdetails_status = 'checked="checked" ';
-        }
-        my $showhidden_status;
-        if ($env{'form.showhidden'}) {
-             $showhidden_status = 'checked="checked" ';
-        }
-        $r->print('<tr><td colspan="2"><label><input type="checkbox" name="showdetails" value="1" '.$showdetails_status.'/>'.&mt('Show full details for each course (DC only)').'</label></td></tr><tr><td colspan="2"><label><input type="checkbox" name="showhidden" value="1" '.$showhidden_status.'/>'.&mt('Include courses set to be hidden from catalog (DC only)').'</label></td></tr>');
-    }
-    $r->print('<tr><td colspan="2">'.
-              '<label><input type="checkbox" name="showselfenroll" value="1" '.
-              $show_selfenroll_status.'/>'.
-              &mt('Only show courses which allow self-enrollment').
-              '</label></td></tr></form></table><br />');
+	      '&nbsp;<input type="submit" name="godom" value="'.&mt('Change').'"></td></form></tr>'.
+	      '<tr><form name="coursecats" method="post" action="/adm/coursecatalog">'.
+              $catlinks.'</form></tr></table>');
     return;
 }
 
@@ -400,18 +363,8 @@
     }
     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,
                                            \@jsarray);
-    my $currdepth = 0;
-    my $deeper = 0;
-    my $currcat_str;
-    if ($env{'form.catalog_maxdepth'} ne '') {
-        $currdepth = $env{'form.catalog_maxdepth'};
-        if ($env{'form.currcat_'.$currdepth} eq '') {
-            $deeper = $currdepth;
-        } else {
-            $deeper = $currdepth + 1;
-        }
-    }
-    $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
+    my ($currdepth,$deeper) = &get_depth_values();
+    my $currcat_str = '<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" /><input type="hidden" name="showdom" value="'.$dom.'" />';
     my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr>';
     for (my $i=0; $i<$deeper; $i++) {
         $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
@@ -457,7 +410,7 @@
                     $catlinks .= '</option>'."\n";
                 }
                 $catlinks .= '</select>'."\n".
-                             '&nbsp;<input type="submit" name="gocats" value="'.&mt('Display courses').'" />';
+                             '&nbsp;<input type="submit" name="gocats" value="'.&mt('Change').'" />';
             }
         } else {
             $catlinks .= &mt('Official courses (with institutional codes)').
@@ -487,13 +440,62 @@
                 $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
             }
             $catlinks .= '</select>'."\n".
-                         '&nbsp;<input type="submit" name="gocats" value="'.&mt('Display courses').'" />';
+                         '&nbsp;<input type="submit" name="gocats" value="'.&mt('Change').'" />';
         }
     }
     $catlinks .= $currcat_str.'</td></tr></table></td>';
     return $catlinks;
 }
 
+sub get_depth_values {
+    my $currdepth = 0;
+    my $deeper = 0;
+    if ($env{'form.catalog_maxdepth'} ne '') {
+        $currdepth = $env{'form.catalog_maxdepth'};
+        if ($env{'form.currcat_'.$currdepth} eq '') {
+            $deeper = $currdepth;
+        } else {
+            $deeper = $currdepth + 1;
+        }
+    }
+    return ($currdepth,$deeper);
+}
+
+sub additional_filters {
+    my ($codedom) = @_;
+    my $output = '<table>';
+    my $show_selfenroll_status;
+    if ($env{'form.showselfenroll'}) {
+        $show_selfenroll_status = 'checked="checked" ';
+    }
+    if (&user_is_dc($codedom)) {
+        my $showdetails_status;
+        if ($env{'form.showdetails'}) {
+            $showdetails_status = 'checked="checked" ';
+        }
+        my $showhidden_status;
+        if ($env{'form.showhidden'}) {
+             $showhidden_status = 'checked="checked" ';
+        }
+        my $dc_title = &Apache::lonnet::plaintext('dc');
+        $output .= '<tr><td>'."\n".
+                   '<label><input type="checkbox" name="showdetails" value="1" '.
+                   $showdetails_status.'/>'."\n".
+                   &mt('Show full details for each course ([_1] only)',$dc_title).
+                   '</label>'."\n".'</td></tr><tr><td>'.
+                   '<label><input type="checkbox" name="showhidden" value="1" '.
+                   $showhidden_status.'/>'.
+                   &mt('Include courses set to be hidden from catalog ([_1] only)',$dc_title).
+                   '</label>'."\n".'</td></tr>';
+    }
+    $output .= '<tr><td>'.
+               '<label><input type="checkbox" name="showselfenroll" value="1" '.
+               $show_selfenroll_status.'/>'.
+               &mt('Only show courses which allow self-enrollment').
+               '</label></td></tr></table><br />';
+    return $output;
+}
+
 sub user_is_dc {
     my ($codedom) = @_;
     if (exists($env{'user.role.dc./'.$codedom.'/'})) {
@@ -661,7 +663,7 @@
     if ($env{'form.coursenum'} ne '') {
         %courses = &Apache::lonnet::courseiddump($domain,'.',1,'.','.',
                                                  $env{'form.coursenum'},
-                                                 undef,undef,'Course',1);
+                                                 undef,undef,'.',1);
         if (keys(%courses) == 0) {
             $output .= &mt('The courseID provided does not match a course in this domain.');
             return $output;

--raeburn1214798829--