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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Sat, 11 Mar 2006 19:51:40 -0000


bowersj2		Sat Mar 11 14:51:40 2006 EDT

  Modified files:              
    /loncom/interface/statistics	lonstudentassessment.pm 
  Log:
  Fix bug 4338: Links in the chart default to opening new windows, but 
  it's controllable by the users.
  
  
Index: loncom/interface/statistics/lonstudentassessment.pm
diff -u loncom/interface/statistics/lonstudentassessment.pm:1.133 loncom/interface/statistics/lonstudentassessment.pm:1.134
--- loncom/interface/statistics/lonstudentassessment.pm:1.133	Sun Mar  5 14:43:12 2006
+++ loncom/interface/statistics/lonstudentassessment.pm	Sat Mar 11 14:51:38 2006
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstudentassessment.pm,v 1.133 2006/03/05 19:43:12 bowersj2 Exp $
+# $Id: lonstudentassessment.pm,v 1.134 2006/03/11 19:51:38 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -650,6 +650,17 @@
                   &mt('Unable to retrieve course information.').
                   '</h3>');
     }
+
+    # If we're showing links, show a checkbox to open in new
+    # windows.
+    if ($show_links ne 'no') {
+        $r->print(<<NEW_WINDOW_CHECKBOX);
+<script>new_window = true;</script>
+<p>Show links in new window: 
+<input type="checkbox" checked="1" onclick="new_window=this.checked" /></p>
+NEW_WINDOW_CHECKBOX
+    }
+
     #
     $r->print("<h3>".$env{'course.'.$env{'request.course.id'}.'.description'}.
               "&nbsp;&nbsp;".localtime(time)."</h3>");
@@ -1928,11 +1939,12 @@
                 if (length($symbol) > 1) {
                     &Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
                 }
-                $symbol = '<a href="/adm/grades'.
+                my $link = '/adm/grades'.
                     '?symb='.&Apache::lonnet::escape($resource->symb).
                         '&student='.$student->{'username'}.
                             '&userdom='.$student->{'domain'}.
-                                '&command=submission">'.$symbol.'</a>';
+                                '&command=submission';
+                $symbol = &link($symbol, $link);
             }
             $value .= $symbol;
         }
@@ -1947,6 +1959,37 @@
     return ($Str,$performance_length,$sum,$max,\@TriesData);
 }
 
+=pod
+
+=item &link
+
+Inputs:
+
+=over 4
+
+=item $text
+
+=item $target
+
+=back
+
+Takes the text and creates a link to the $text that honors
+the value of 'new window' if clicked on, but uses a real 
+'href' so middle and right clicks still work.
+
+$target and $text are assumed to be already correctly escaped; i.e., it
+can be dumped out directly into the output stream as-is.
+
+=cut
+
+sub link {
+    my ($text,$target) = @_;
+    return 
+        "<a href='$target' onclick=\"t=this.href;if(new_window)"
+        ."{window.open(t)}else{return void(window."
+        ."location=t)};return false;\">$text</a>";
+}
+
 #######################################################
 #######################################################
 
@@ -2051,11 +2094,12 @@
             push (@ScoreData,$partscore);
             #
             if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
-                $symbol = '<a href="/adm/grades'.
+                my $link = '/adm/grades' .
                     '?symb='.&Apache::lonnet::escape($symb).
                     '&student='.$student->{'username'}.
                     '&userdom='.$student->{'domain'}.
-                    '&command=submission">'.$symbol.'</a>';
+                    '&command=submission';
+                $symbol = &link($symbol, $link);
             }
             $Str .= $symbol;
         }