[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonhtmlcommon.pm lonmenu.pm

droeschl droeschl@source.lon-capa.org
Tue, 19 Jan 2010 19:00:02 -0000


This is a MIME encoded message

--droeschl1263927602
Content-Type: text/plain

droeschl		Tue Jan 19 19:00:02 2010 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonhtmlcommon.pm lonmenu.pm 
  Log:
  - Bug #6064 Breadcrumbs will be visually cut off if text is too long to fit into one line.
  - Bug #6081 Breadcrumbs that don't have an href attribute are no longer wrapped with <a> tag.
  - Added some POD in lonhtmlcommon and repaired errors and warnings reported by podchecker.
  - new functions in lonhtmlcommon:
    o list_from_array: constructs a XHTML list from arraydata
    o funclist_from_array: constructs a XHTML list from arraydata with first item highlighted (see other funclist functions)
  
  
--droeschl1263927602
Content-Type: text/plain
Content-Disposition: attachment; filename="droeschl-20100119190002.txt"

Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.932 loncom/interface/loncommon.pm:1.933
--- loncom/interface/loncommon.pm:1.932	Tue Jan 19 16:06:49 2010
+++ loncom/interface/loncommon.pm	Tue Jan 19 19:00:02 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.932 2010/01/19 16:06:49 raeburn Exp $
+# $Id: loncommon.pm,v 1.933 2010/01/19 19:00:02 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4584,8 +4584,6 @@
             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
         }
 
-        #SD testing
-        #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
         return $bodytag;
     }
 
@@ -4912,7 +4910,7 @@
 }
 
 table#LC_title_bar,
-table.LC_breadcrumbs,
+table.LC_breadcrumbs, /* obsolete? */
 table#LC_title_bar.LC_with_remote {
   width: 100%;
   border-color: $pgbg;
@@ -4925,46 +4923,26 @@
   margin: 0;
 }
 
-/* #SD START (work in progress)*/
-
-ul.LC_bct {
+ul.LC_breadcrumb_tools_outerlist {
     margin: 0;
     padding: 0;
+    position: relative;
+    list-style: none;
 }
-ul.LC_bct ol {
-    display: inline;
-}
-ul.LC_bct ul {
-    display: inline;
-    padding: 0;
-}
-ul.LC_bct li {
-    list-style-type: none;
+ul.LC_breadcrumb_tools_outerlist li {
     display: inline;
 }
 
-
-ul.LC_breadcrumb_tools {
-}
-
-li.LC_breadcrumb_tools {
-}
-li.LC_breadcrumb_tools img{
-    vertical-align: middle;
-}
-
-.LC_breadcrumb_tools_A {
-    margin: 0 0 0 1em;
-}
-.LC_breadcrumb_tools_B {
-    float: right;
-    margin-top: 0.4em;
+.LC_breadcrumb_tools_navigation {
+    padding: 0;
+    margin: 0;
+    float: left;
 }
-.LC_breadcrumb_tools_C {
-    margin: 0 1em 0 0;
+.LC_breadcrumb_tools_tools {
+    padding: 0;
+    margin: 0;
     float: right;
 }
-/* #SD END */
 
 table#LC_title_bar td {
   background: $tabbg;
@@ -4995,9 +4973,7 @@
   background: $sidebg;
   border-bottom: 1px solid $lg_border_color;
   line-height: 2.5em;
-     /* SD working here 
-     height: 2.5em;
-     overflow: hidden; */
+  overflow: hidden;
   margin: 0;
   padding: 0;
 }
@@ -6169,18 +6145,14 @@
 ol#LC_PathBreadcrumbs {
   padding-left: 10px;
   margin: 0;
-  list-style-position: inside;
-    /* SD working here 
-    white-space: nowrap; */
+  height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
 }
 
 ol#LC_MenuBreadcrumbs li,
 ol#LC_PathBreadcrumbs li,
 ul.LC_CourseBreadcrumbs li {
   display: inline;
-  white-space: nowrap;
-    /* SD working here  
-    white-space: normal; */ 
+  white-space: normal;  
 }
 
 ol#LC_MenuBreadcrumbs li a,
@@ -6433,6 +6405,11 @@
     padding: 0.5em 1em 0.5em 0;
 }
 
+ul.LC_funclist > li:first-child {
+    font-weight:bold; 
+    margin-left:0.8em;
+}
+
 ul.LC_funclist + ul.LC_funclist {
     /* 
        left border as a seperator if we have more than
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.260 loncom/interface/lonhtmlcommon.pm:1.261
--- loncom/interface/lonhtmlcommon.pm:1.260	Fri Jan  8 22:05:42 2010
+++ loncom/interface/lonhtmlcommon.pm	Tue Jan 19 19:00:02 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.260 2010/01/08 22:05:42 faziophi Exp $
+# $Id: lonhtmlcommon.pm,v 1.261 2010/01/19 19:00:02 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -81,8 +81,6 @@
 ##############################################
 ##############################################
 
-=pod
-
 =item confirm_success
 
 Successful completion of an operation message
@@ -139,7 +137,6 @@
 
 Javascript used to open pop-up window containing dragmath applet which 
 can be used to paste LaTeX into a textarea.
- 
 =cut
 
 sub dragmath_js {
@@ -1489,28 +1486,29 @@
             }
         }
         my $links = join "", 
-                 map {
-                     $faq  = $_->{'faq'}  if (exists($_->{'faq'}));
-                     $bug  = $_->{'bug'}  if (exists($_->{'bug'}));
-                     $help = $_->{'help'} if (exists($_->{'help'}));
-
-                     my $result = htmltag( 'a', 
-                                           $_->{no_mt} ? 
-                                            $_->{text} : mt($_->{text}), 
-                                           { 
-                                               href   => $_->{href},
-                                               title  => $_->{no_mt} ? 
-                                                $_->{title} : mt($_->{title}),
-                                               target => $_->{target},
-                                           });
-                     $result = htmltag( 'li', "$result $crumbsymbol");
-                     } @Crumbs;
+             map {
+                 $faq  = $_->{'faq'}  if (exists($_->{'faq'}));
+                 $bug  = $_->{'bug'}  if (exists($_->{'bug'}));
+                 $help = $_->{'help'} if (exists($_->{'help'}));
+
+                 my $result = $_->{no_mt} ? $_->{text} : mt($_->{text});
+
+                 if ($_->{href}){
+                     $result = htmltag( 'a', $result, 
+                       { href   => $_->{href},
+                         title  => $_->{no_mt} ? $_->{title} : mt($_->{title}),
+                         target => $_->{target}, });
+                 }
+
+                 $result = htmltag( 'li', "$result $crumbsymbol");
+             } @Crumbs;
 
         #should the last Element be translated?
-        $links  .= htmltag( 'li', 
-                        htmltag( 'b', 
-                                 $last->{'no_mt'} ? 
-                                 $last->{'text'} : mt($last->{'text'}) ));
+
+        my $lasttext = $last->{'no_mt'} ? $last->{'text'} 
+                     : mt( $last->{'text'} );
+
+        $links .= htmltag( 'li', htmltag('b', $lasttext), {title => $lasttext});
 
         my $icons = '';
         $faq  = $last->{'faq'}  if (exists($last->{'faq'}));
@@ -1545,12 +1543,10 @@
                              .$links;
         }
         
-        #SD START (work in progress!)
-        add_tools(\$links);
-        #SD END
+        render_tools(\$links);
         $links = htmltag('div', $links, 
                         { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ;
-        add_advtools(\$links);
+        render_advtools(\$links);
 
         # Return the @Crumbs stack to what we started with
         push(@Crumbs,$last);
@@ -1568,55 +1564,104 @@
         push(@Crumbs,@_);
     }
     
+=item add_breadcrumb_tool($category, $html)
+
+Adds $html to $category of the breadcrumb toolbar container.
+
+$html is usually a link to a page that invokes a function on the currently 
+displayed data (e.g. print when viewing a problem)
+
+Currently there are 3 possible values for $category: 
+
+=over 
+
+=item navigation 
+left of breadcrumbs line
+
+=item tools 
+right of breadcrumbs line
+
+=item advtools 
+advanced tools shown in a separate box below breadcrumbs line 
+
+=back
+ 
+returns: nothing
+
+=cut
 
-    #SD START (work in progress!)
     sub add_breadcrumb_tool {
-        my ($category, $html) = @_;
-        return unless $html;
+        my ($category, @html) = @_;
+        return unless @html;
         if (!defined(%tools)) { 
-            my %tools = ( A => [], B => [], C => []);
+            %tools = ( navigation => [], tools => [], advtools => []);
         }
-        push @{$tools{$category}}, $html;
+
+        #this cleans data received from lonmenu::innerregister
+        @html = grep {defined $_ && $_ ne ''} @html;
+        for (@html) { 
+            s/align="(right|left)"//; 
+            s/<span.*?\/span>// if $category ne 'advtools'; 
+        } 
+
+        push @{$tools{$category}}, @html;
     }
 
+=item clear_breadcrumb_tools()
+
+Clears the breadcrumb toolbar container.
+
+returns: nothing
+
+=cut
+
     sub clear_breadcrumb_tools {
         undef(%tools);
     }
 
-    sub add_tools {
-        my ($links) = @_;
+=item render_tools(\$breadcrumbs)
+
+Creates html for breadcrumb tools (categories navigation and tools) and inserts 
+\$breadcrumbs at the correct position.
+
+input: \$breadcrumbs - a reference to the string containing prepared 
+breadcrumbs.
+
+returns: nothing
+=cut
+
+#TODO might split this in separate functions for each category
+    sub render_tools {
+        my ($breadcrumbs) = @_;
         return unless defined %tools;
-        my $html = '<ul class="LC_bct">';
-        for my $category ('A','B') {
-            $html .= '<li class="LC_breadcrumb_tools">'
-                   . '<ul class="LC_breadcrumb_tools'
-                   . " LC_breadcrumb_tools_$category\">";
-            for my $item (@{$tools{$category}}){
-                #SD ugly! I'll fix that later on
-                $item =~ s/align="(right|left)"//;
-                $item =~ s/<span(.*?)\/span>//;
-                $html .= "<li>$item</li>";
-            }
-            $html .= '</ul></li>';
-            if ($category eq 'A') { $html .= "<li>$$links</li>"; }
-        }
-        $$links = $html.'</ul>';
-    }
-
-    sub add_advtools {
-        my ($links) = @_;
-        return unless (defined $tools{'C'}) and (scalar (@{$tools{'C'}}) > 0);
-        my $html = start_funclist();
-        for my $item (@{$tools{'C'}}){
-                next unless $item;
-                $item =~ s/align="(right|left)"//;
-                $html .= add_item_funclist($item);
-        }
-        $html   .= end_funclist();
-        $html    = Apache::loncommon::head_subbox($html);
-        $$links .= $html;
+
+        my $navigation = list_from_array($tools{navigation}, 
+                   { listattr => { class=>"LC_breadcrumb_tools_navigation" } });
+        my $tools = list_from_array($tools{tools}, 
+                   { listattr => { class=>"LC_breadcrumb_tools_tools" } });
+        $$breadcrumbs = list_from_array([$navigation, $tools, $$breadcrumbs], 
+                   { listattr => { class=>'LC_breadcrumb_tools_outerlist' } });
+    }
+
+=item render_advtools(\$breadcrumbs)
+
+Creates html for advanced tools (category advtools) and inserts \$breadcrumbs 
+at the correct position.
+
+input: \$breadcrumbs - a reference to the string containing prepared 
+breadcrumbs (after render_tools call).
+
+returns: nothing
+=cut
+
+    sub render_advtools {
+        my ($breadcrumbs) = @_;
+        return unless     (defined $tools{'advtools'}) 
+                      and (scalar(@{$tools{'advtools'}}) > 0);
+
+        $$breadcrumbs .= Apache::loncommon::head_subbox(
+                            funclist_from_array($tools{'advtools'}) );
     }
-    #SD END
 
 } # End of scope for @Crumbs
 
@@ -1996,7 +2041,6 @@
 
 ##############################################
 ##############################################
-                                                                             
 # echo_form_input
 #
 # Generates html markup to add form elements from the referrer page
@@ -2061,7 +2105,6 @@
 
 ##############################################
 ##############################################
-                                                                             
 # set_form_elements
 #
 # Generates javascript to set form elements to values based on
@@ -2279,7 +2322,7 @@
 # USAGE: inittags(@tags);
 #
 # EXAMPLES:
-#  - my ($h1, $h2, $h3) = initTags( qw( h1 h2 h3 ) )
+#  - my ($h1, $h2, $h3) = inittags( qw( h1 h2 h3 ) )
 #    $h1->("This is a headline") #Returns: <h1>This is a headline</h1>
 #
 # NOTES: See sub htmltag for further information.
@@ -2328,6 +2371,38 @@
 };
 
 
+=item list_from_array( \@array, { listattr =>{}, itemattr =>{} } )
+
+Constructs a XHTML list from \@array.
+
+input: 
+
+=over
+
+=item \@array 
+
+A reference to the array containing text that will be wrapped in <li></li> tags.
+
+=item { listattr => {}, itemattr =>{} } 
+
+Attributes for <ul> and <li> passed in as hash references. 
+See htmltag() for more details.
+
+=back
+ 
+returns: XHTML list as String. 
+
+=cut   
+
+# \@items, {listattr => { class => 'abc', id => 'xyx' }, itemattr => {class => 'abc', id => 'xyx'}}
+sub list_from_array {
+    my ($items, $args) = @_;
+    my ($ul, $li) = inittags( qw(ul li) );
+    my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items;
+    return $ul->( $listitems, $args->{listattr} );
+}
+
+
 ##############################################
 ##############################################
 
@@ -2357,12 +2432,6 @@
 #
 # Outputs: A scalar containing the html markup for the menu.
 
-# ---- Remove when done ----
-# This routine is part of the redesign of LON-CAPA and it's 
-# subject to change during this project.
-# Don't rely on its current functionality as it might be 
-# changed or removed.
-# --------------------------
 sub generate_menu {
     my @menu = @_;
     # subs for specific html elements
@@ -2485,9 +2554,6 @@
     return '<li>'.$content.'</li>'."\n";
 }
 
-##############################################
-##############################################
-
 =pod
 
 =item &end_funclist
@@ -2503,16 +2569,46 @@
 Inputs: ./.
 
 Returns: HTML code with function list end
-
 =cut
 
-##############################################
-##############################################
-
 sub end_funclist {
     return "</ul>\n";
 }
 
+=pod
+
+=item funclist_from_array( \@array, {legend => 'text for legend'} )
+
+Constructs a XHTML list from \@array with the first item being visually
+highlighted and set to the value of legend or 'Functions' if legend is
+empty. 
+
+=over
+
+=item \@array
+
+A reference to the array containing text that will be wrapped in <li></li> tags.
+
+=item { legend => 'text' }
+
+A string that's used as visually highlighted first item. 'Functions' is used if
+it's value evaluates to false.
+
+=back
+ 
+returns: XHTML list as string. 
+
+=back
+
+=cut  
+
+sub funclist_from_array {
+    my ($items, $args) = @_;
+    $args->{legend} ||= mt('Functions');
+    return list_from_array( [$args->{legend}, @$items], 
+               { listattr => {class => 'LC_funclist'} });
+}   
+
 1;
 
 __END__
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.311 loncom/interface/lonmenu.pm:1.312
--- loncom/interface/lonmenu.pm:1.311	Tue Dec 22 14:35:25 2009
+++ loncom/interface/lonmenu.pm	Tue Jan 19 19:00:02 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.311 2009/12/22 14:35:25 www Exp $
+# $Id: lonmenu.pm,v 1.312 2010/01/19 19:00:02 droeschl Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -842,39 +842,19 @@
 	    my $inlinebuttons='';
     if ($addremote) {
 
-        #SD START (work in progress!)
         Apache::lonhtmlcommon::clear_breadcrumb_tools();
-        # Arrows for navigation
-        Apache::lonhtmlcommon::add_breadcrumb_tool( 'A', $inlineremote[21] );
-        Apache::lonhtmlcommon::add_breadcrumb_tool( 'A', $inlineremote[23] );
-        if(hidden_button_check() ne 'yes'){
-            # notes
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[93]);
-            # bookmark
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[91]);
-            # evaluate
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[81]);
-            # feedback
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[82]);
-            # print
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[83]);
-            # metadata
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'B', $inlineremote[63]);
-
-            # ?
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[61]);
-            # ?
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[71]);
-            # ?
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[72]);
-            # ?
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[73]);
-            # ?
-            Apache::lonhtmlcommon::add_breadcrumb_tool( 'C', $inlineremote[92]);
 
+            Apache::lonhtmlcommon::add_breadcrumb_tool(
+                'navigation', @inlineremote[21,23]);
+
+        if(hidden_button_check() ne 'yes') {
+            Apache::lonhtmlcommon::add_breadcrumb_tool(
+                'tools', @inlineremote[93,91,81,82,83,63]);
+
+            Apache::lonhtmlcommon::add_breadcrumb_tool(
+                'advtools', @inlineremote[61,71,72,73,92]);
         }
 
-        #SD END
 #       # Registered, textual output
 #        if ( $env{'environment.icons'} eq 'iconsonly' ) {
 #            $inlinebuttons = (<<ENDARROWSINLINE);
@@ -909,7 +889,6 @@
 #            }
 #        }
     }
-        #SD see below
         $breadcrumb = &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0);
 	    $result =(<<ENDREGTEXT);
 <script type="text/javascript">

--droeschl1263927602--