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

banghart lon-capa-cvs@mail.lon-capa.org
Tue, 08 Aug 2006 19:36:55 -0000


banghart		Tue Aug  8 15:36:55 2006 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  	rewrite sub make_anchor to simplify and generalize calling
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.148 loncom/interface/portfolio.pm:1.149
--- loncom/interface/portfolio.pm:1.148	Sun Aug  6 13:23:56 2006
+++ loncom/interface/portfolio.pm	Tue Aug  8 15:36:54 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.148 2006/08/06 17:23:56 banghart Exp $
+# $Id: portfolio.pm,v 1.149 2006/08/08 19:36:54 banghart Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -66,12 +66,15 @@
 # receives a file name and path stub from username/userfiles/portfolio/
 # returns an anchor tag consisting encoding filename and currentpath
 sub make_anchor {
-    my ($url, $filename, $current_path, $current_mode, $field_name,
-        $continue_select) = @_;
-    if ($continue_select ne 'true') {$continue_select = 'false'};
-    my $anchor = '<a href="'.$url.'?selectfile='.$filename.'&amp;currentpath='.$current_path.'&amp;mode='.$current_mode.'&amp;continue='.$continue_select.'&amp;fieldname='.$field_name;
+    my ($url, $anchor_fields, $inner_text) = @_;
+    if ($$anchor_fields{'continue'} ne 'true') {$$anchor_fields{'continue'} = 'false'};
+    my $anchor = '<a href="'.$url.'?';
+    foreach my $field_name (keys(%$anchor_fields)) {
+        $anchor .= $field_name.'='.$$anchor_fields{$field_name}.'&amp;';
+    }
+    $anchor =~ s\&amp;$\\;
     $anchor .= &group_args();
-    $anchor .= '">'.$filename.'</a>';
+    $anchor .= '">'.$inner_text.'</a>';
     return $anchor;
 }
 
@@ -129,12 +132,28 @@
 TABLE
     }
     my @tree = split (/\//,$current_path);
-    $r->print('<span class="LC_current_location">'.&make_anchor($url,$port_path,'/',$env{"form.mode"},$env{"form.fieldname"},$env{"form.continue"}).'/');
+    my %anchor_fields = ();
+    %anchor_fields = (
+        'selectfile'    => $port_path,
+        'currentpath'   => '/',
+        'mode'          => $env{"form.mode"},
+        'fieldname'     => $env{"form.fieldname"},
+        'continue'      => $env{"form.continue"}
+    );
+    $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
     if (@tree > 1){
         my $newCurrentPath = '';
         for (my $i = 1; $i< @tree; $i++){
             $newCurrentPath .= $tree[$i].'/';
-            $r->print(&make_anchor($url,$tree[$i],'/'.$newCurrentPath, $env{"form.mode"},$env{"form.fieldname"}, $env{"form.continue"}).'/');
+            my %anchor_fields = ();
+            %anchor_fields = (
+                'selectfile' => $tree[$i],
+                'currentpath' => '/',
+                'mode' => $env{"form.mode"},
+                'fieldname' => $env{"form.fieldname"},
+                'continue' => $env{"form.continue"}
+            );
+            $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
         }
     }
     $r->print('</span>');
@@ -264,7 +283,15 @@
                 }
 		$r->print('<tr class="LC_browser_folder"><td '.$colspan.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_closed.gif" /></td>');
                 $r->print('<td>Go to ...</td>');
-                $r->print('<td>'.$version_flag{$filename}.'</td><td>'.&make_anchor($url,$filename.'/',$current_path.$filename.'/',$env{'form.mode'},$env{"form.fieldname"},$env{'form.continue'}).'</td>'); 
+                my %anchor_fields = ();
+                %anchor_fields = (
+                    'selectfile'    => $filename.'/',
+                    'currentpath'   => $current_path.$filename.'/',
+                    'mode'          => $env{"form.mode"},
+                    'fieldname'     => $env{"form.fieldname"},
+                    'continue'      => $env{"form.continue"}
+                );  
+                $r->print('<td>'.$version_flag{$filename}.'</td><td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>'); 
                 $r->print('</tr>'); 
             } else {
 		my $css_class = 'LC_browser_file';