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

raeburn raeburn@source.lon-capa.org
Mon, 23 Nov 2009 22:02:50 -0000


This is a MIME encoded message

--raeburn1259013770
Content-Type: text/plain

raeburn		Mon Nov 23 22:02:50 2009 EDT

  Modified files:              
    /loncom/interface	coursecatalog.pm 
  Log:
  - Replace links in catalog trail of categories/sub-categories with select boxes to
    facilitate changing (sub-)category at higher level in hierarchy.
  
  
--raeburn1259013770
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20091123220250.txt"

Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.57 loncom/interface/coursecatalog.pm:1.58
--- loncom/interface/coursecatalog.pm:1.57	Mon Nov 23 21:45:18 2009
+++ loncom/interface/coursecatalog.pm	Mon Nov 23 22:02:50 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler for displaying the course catalog interface
 #
-# $Id: coursecatalog.pm,v 1.57 2009/11/23 21:45:18 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.58 2009/11/23 22:02:50 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -334,78 +334,68 @@
     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>';
+    my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr><td>';
     my $has_subcats;
     my $selitem;
-    for (my $i=0; $i<$deeper; $i++) {
-        $currcat_str .= '<input type="hidden" name="currcat_'.$i.'" value="'.$env{'form.currcat_'.$i}.'" />';
-        my ($cattitle,$shallower);
-        if ($i == 0) {
-            if (ref($cats[0]) eq 'ARRAY') {
-                if (@{$cats[0]} > 1) {
-                    $cattitle = &mt('Main Categories');
-                }
+    if (ref($cats[0]) eq 'ARRAY') {
+        if (@{$cats[0]} == 0) {
+            $catlinks .= &mt('No categories defined in this domain'); 
+        } elsif (@{$cats[0]} == 1) {
+            if ($cats[0][0] eq 'instcode') {
+                $catlinks .= &mt('Official courses (with institutional codes)');
+                $env{'form.currcat_0'} = 'instcode::0';
+            } elsif ($cats[0][0] eq 'communities') {
+                $catlinks .= &mt('Communities');
+                $env{'form.currcat_0'} = 'communities::0';
+            } else {
+                my $name = $cats[0][0];
+                my $item = &escape($name).'::0';
+                $catlinks .= $name;
+                $env{'form.currcat_0'} = $item;
             }
+            $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
         } else {
-            $shallower = $i-1;
-            my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
-            $cattitle = $cat;
-        }
-        if ($cattitle ne '') {
-            $catlinks .= '<td valign="top"><a href="javascript:setCatDepth('."'$shallower'".')">'.$cattitle.'</a>'.$crumbsymbol.'</td>';
-        }
-    }
-    if ($deeper == 0) {
-        $catlinks .= '<td>';
-        if (ref($cats[0]) eq 'ARRAY') {
-            if ((@{$cats[0]} == 1) && (@cats == 1)) {
-                if ($cats[0][0] eq 'instcode') {
-                    $catlinks .= &mt('Official courses (with institutional codes)').
-                                 '<input type="hidden" name="currcat_0" value="instcode::0" />';
-                    $env{'form.currcat_0'} = 'instcode::0';
-                } elsif ($cats[0][0] eq 'communities') {
-                    $catlinks .= &mt('Communities').
-                                 '<input type="hidden" name="currcat_0" value="instcode::0" />';
-                    $env{'form.currcat_0'} = 'communities::0';
-                } else {
-                    my $name = $cats[0][0];
-                    my $item = &escape($name).'::0';
-                    $catlinks .= $name.
-                             '<input type="hidden" name="currcat_0" value="'.$item.'" />';
-                    $env{'form.currcat_0'} = $item;
-                }
+            $catlinks .= &main_category_selector(@cats);
+            if (($env{'form.currcat_0'} ne '') && 
+                ($env{'form.currcat_0'} ne 'instcode::0')) {
+                $catlinks .= $crumbsymbol;
             } else {
-                $has_subcats = 1;
-                my $buttontext = &mt('Show subcategories');
-                $selitem = 'currcat_0';
-                $catlinks .= '<select name="'.$selitem.'">'."\n";
-                if (@{$cats[0]} > 1) {
-                    $catlinks .= '<option value="" selected="selected">'.&mt('Select').'</option>'."\n";
-                    $buttontext = &mt('Pick main category');
-                }
-                for (my $i=0; $i<@{$cats[0]}; $i++) {
-                    my $name = $cats[0][$i];
-                    my $item = &escape($name).'::0';
-                    $catlinks .= '<option value="'.$item.'">';
-                    if ($name eq 'instcode') {
-                        $catlinks .= &mt('Official courses (with institutional codes)');
-                    } elsif ($name eq 'communities') {
-                        $catlinks .= &mt('Communities');
-                    } else {
-                        $catlinks .= $name;
+                $catlinks .= '</td>';
+            }
+        }
+    } else {
+        $catlinks .= &mt('Official courses (with institutional codes)');
+                     $env{'form.currcat_0'} = 'instcode::0';
+         $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
+    }
+    if ($deeper) {
+        for (my $i=1; $i<=$deeper; $i++) {
+            my $shallower = $i-1;
+            next if ($shallower == 0);
+            my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
+            if ($cat ne '') {
+                $catlinks .= '<td valign="top">'.
+                             '<select name="currcat_'.$shallower.'" onchange="'.
+                             'setCatDepth('."'$shallower'".');this.form.submit();">';
+                if (ref($cats[$shallower]{$container}) eq 'ARRAY') {
+                    $catlinks .= '<option value="">'.&mt('De-select').'</option>';
+                    for (my $j=0; $j<@{$cats[$shallower]{$container}}; $j++) {
+                        my $name = $cats[$shallower]{$container}[$j];
+                        my $item = &escape($name).':'.$container.':'.$shallower;
+                        my $selected = '';
+                        if ($item eq $env{'form.currcat_'.$shallower}) {
+                            $selected = ' selected="selected"';
+                        }
+                        $catlinks .= 
+                           '<option value="'.$item.'"'.$selected.'>'.$name.'</option>';
                     }
-                    $catlinks .= '</option>'."\n";
                 }
-                $catlinks .= '</select>'."\n".
-                             '&nbsp;<input type="submit" name="gocats" value="'.
-                             $buttontext.'" />';
+                $catlinks .= '</select>';
             }
-        } else {
-            $catlinks .= &mt('Official courses (with institutional codes)').
-                         '<input type="hidden" name="currcat_0" value="instcode::0" />';
-            $env{'form.currcat_0'} = 'instcode::0';
+            unless ($i == $deeper) {
+                $catlinks .= $crumbsymbol;
+            } 
         }
-    } else {
         my ($cat,$container,$depth);
         if ($env{'form.currcat_'.$currdepth} eq '') {
             my $shallower = $currdepth - 1;
@@ -413,40 +403,66 @@
         } else {
             ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$currdepth});
         }
-        my $deeper = $depth +1;
-        my $currcat = $cat;
-        if ($cat eq 'instcode') {
-            $currcat = &mt('Official courses (with institutional codes)');
-        } elsif ($cat eq 'communities') {
-            $currcat = &mt('Communities');
-        }
-        $catlinks .= '<td><b>'.$currcat.'</b>';
-        if (ref($cats[$deeper]{$cat}) eq 'ARRAY') {
+        my $deeperlevel = $depth +1;
+        if (ref($cats[$deeperlevel]{$cat}) eq 'ARRAY') {
             $has_subcats = 1;
             my $buttontext = &mt('Show subcategories');
-            $selitem = 'currcat_'.$deeper;
-            $catlinks .= ':&nbsp;<select name="'.$selitem.'">';
-            if (@{$cats[$deeper]{$cat}} > 1) {
+            my $selitem = 'currcat_'.$deeperlevel;
+            $catlinks .= '&nbsp;<select name="'.$selitem.'" onchange="this.form.submit()">';
+            if (@{$cats[$deeperlevel]{$cat}}) {
                 $catlinks .= '<option value="" selected="selected">'.
-                             &mt('Select').'</option>';
-                $buttontext = &mt('Pick subcategory');
+                             &mt('Subcategory ...').'</option>';
             }
-            for (my $k=0; $k<@{$cats[$deeper]{$cat}}; $k++) {
-                my $name = $cats[$deeper]{$cat}[$k];
-                my $item = &escape($name).':'.&escape($cat).':'.$deeper;
+            for (my $k=0; $k<@{$cats[$deeperlevel]{$cat}}; $k++) {
+                my $name = $cats[$deeperlevel]{$cat}[$k];
+                my $item = &escape($name).':'.&escape($cat).':'.$deeperlevel;
                 $catlinks .= '<option value="'.$item.'">'.$name.'</option>'."\n";
             }
-            $catlinks .= '</select>'."\n".
-                         '&nbsp;<input type="submit" name="gocats" value="'.
-                         $buttontext.'" />';
+            $catlinks .= '</select>'."\n";
         } elsif ($cat ne 'instcode') {
             $catlinks .= '&nbsp;'.&mt('(No subcategories)');
         }
+    } else {
+        $selitem = 'currcat_0';
     }
     $catlinks .= $currcat_str.'</td></tr></table></td>';
     return ($catlinks,$has_subcats,$selitem);
 }
 
+sub main_category_selector {
+    my (@cats) = @_;
+    my $maincatlinks = '<select name="currcat_0" onchange="setCatDepth('."'0'".');this.form.submit();">'."\n";
+    if (ref($cats[0]) eq 'ARRAY') {
+        if (@{$cats[0]} > 1) {
+            my $selected = '';
+            if ($env{'form.currcat_0'} eq '') {
+                $selected = ' selected="selected"';    
+            }
+            $maincatlinks .= 
+                '<option value=""'.$selected.'>'.&mt('Select').'</option>'."\n";
+        }
+        for (my $i=0; $i<@{$cats[0]}; $i++) {
+            my $name = $cats[0][$i];
+            my $item = &escape($name).'::0';
+            my $selected;
+            if ($env{'form.currcat_0'} eq $item) {
+                $selected = ' selected="selected"';
+            }
+            $maincatlinks .= '<option value="'.$item.'"'.$selected.'>';
+            if ($name eq 'instcode') {
+                $maincatlinks .= &mt('Official courses (with institutional codes)');
+            } elsif ($name eq 'communities') {
+                $maincatlinks .= &mt('Communities');
+            } else {
+                $maincatlinks .= $name;
+            }
+            $maincatlinks .= '</option>'."\n";
+        }
+        $maincatlinks .= '</select>'."\n";
+    }
+    return $maincatlinks;
+}
+
 sub get_depth_values {
     my $currdepth = 0;
     my $deeper = 0;

--raeburn1259013770--