--- loncom/interface/lonhtmlcommon.pm 2010/12/05 21:58:49 1.253.2.8 +++ loncom/interface/lonhtmlcommon.pm 2009/12/11 17:25:01 1.254 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.253.2.8 2010/12/05 21:58:49 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.254 2009/12/11 17:25:01 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -383,7 +383,8 @@ dname_hour, dname_min, and dname_sec. The current setting for this time parameter. A unix format time (time in seconds since the beginning of Jan 1st, 1970, GMT. -An undefined value is taken to indicate the value is the current time. +An undefined value is taken to indicate the value is the current time +unless it is requested to leave it empty. See $includeempty. Also, to be explicit, a value of 'now' also indicates the current time. =item $special @@ -393,6 +394,9 @@ the date_setter. See lonparmset for exa =item $includeempty +If it is set (true) and no date/time value is provided, +the date/time fields are left empty. + =item $state Specifies the initial state of the form elements. Either 'disabled' or empty. @@ -410,44 +414,42 @@ The method used to restrict user input w ############################################## sub date_setter { my ($formname,$dname,$currentvalue,$special,$includeempty,$state, - $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink,$hide_timezone) = @_; + $no_hh_mm_ss,$defhour,$defmin,$defsec,$nolink) = @_; my $now = time; - my $wasdefined=1; + + my $tzname; + my ($sec,$min,$hour,$mday,$month,$year) = ('','',undef,'','',''); + # other potentially useful values: wkday,yrday,is_daylight_savings + if (! defined($state) || $state ne 'disabled') { $state = ''; } if (! defined($no_hh_mm_ss)) { $no_hh_mm_ss = 0; } + if ($currentvalue eq 'now') { - $currentvalue = $now; + $currentvalue = $now; } - if ((!defined($currentvalue)) || ($currentvalue eq '')) { - $wasdefined=0; - if ($includeempty) { - $currentvalue = 0; - } else { - $currentvalue = $now; - } + + # Default value: Set empty date field to current time + # unless empty inclusion is requested + if ((!$includeempty) && (!$currentvalue)) { + $currentvalue = $now; } - # other potentially useful values: wkday,yrday,is_daylight_savings - my $tzname; - my ($sec,$min,$hour,$mday,$month,$year)=('','',undef,'','',''); + # Do we have a date? Split it! if ($currentvalue) { - ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); - } - unless ($wasdefined) { - ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($now); - if (($defhour) || ($defmin) || ($defsec)) { - $sec=($defsec?$defsec:0); - $min=($defmin?$defmin:0); - $hour=($defhour?$defhour:0); - } elsif (!$includeempty) { - $sec=0; - $min=0; - $hour=0; - } + ($tzname,$sec,$min,$hour,$mday,$month,$year) = &get_timedates($currentvalue); + + # No values provided for hour, min, sec? Use default 0 + if (($defhour) || ($defmin) || ($defsec)) { + $sec = ($defsec ? $defsec : 0); + $min = ($defmin ? $defmin : 0); + $hour = ($defhour ? $defhour : 0); + } } + + # Create Output my $result = "\n\n"; $result .= < @@ -563,10 +565,7 @@ ENDJS $cal_link = qq{}; } # - my $tzone; - unless ($hide_timezone) { - $tzone = ' '.$tzname.' '; - } + my $tzone = ' '.$tzname.' '; if ($no_hh_mm_ss) { $result .= &mt('[_1] [_2] [_3] ', $monthselector,$dayselector,$yearselector). @@ -646,7 +645,7 @@ Returns: Unix time represented in the fo ############################################## ############################################## sub get_date_from_form { - my ($dname,$timezone) = @_; + my ($dname) = @_; my ($sec,$min,$hour,$day,$month,$year); # if (defined($env{'form.'.$dname.'_second'})) { @@ -696,13 +695,7 @@ sub get_date_from_form { if (($year<1970) || ($year>2037)) { return undef; } if (defined($sec) && defined($min) && defined($hour) && defined($day) && defined($month) && defined($year)) { - if (defined($timezone)) { - if (&Apache::lonlocal::gettimezone($timezone) eq 'local') { - $timezone = &Apache::lonlocal::gettimezone(); - } - } else { - $timezone = &Apache::lonlocal::gettimezone(); - } + my $timezone = &Apache::lonlocal::gettimezone(); my $dt = DateTime->new( year => $year, month => $month, day => $day, @@ -1387,43 +1380,25 @@ returns: nothing # The first one should be the course or a menu link if (!defined($menulink)) { $menulink=1; } if ($menulink) { - if ($menulink eq '_nomenu') { - return unless($last); + my $description = 'Menu'; + my $no_mt_descr = 0; + if (exists($env{'request.course.id'}) && + $env{'request.course.id'} ne '') { + $description = + $env{'course.'.$env{'request.course.id'}.'.description'}; + $no_mt_descr = 1; + } + $menulink = { href =>'/adm/menu', + title =>'Go to main menu', + target =>'_top', + text =>$description, + no_mt =>$no_mt_descr, }; + if($last) { + #$last set, so we have some crumbs + unshift(@Crumbs,$menulink); } else { - my $description = 'Menu'; - my $href = '/adm/menu'; - my $tooltip = 'Go to main menu'; - my $no_mt_descr = 0; - if ((exists($env{'request.course.id'})) && - ($env{'request.course.id'} ne '') && - !($env{'form.context'} eq 'requestcrs')) { - if ((&Apache::loncommon::needs_gci_custom()) || ($env{'user.domain'} =~ /^\w+citest$/)) { - if ($env{'environment.remotenavmap'} eq 'on') { - # open link using javascript when remote navmap is activated - $href = "javascript:gonav('/adm/navmaps');"; - } else { - $href = '/adm/navmaps'; - } - $tooltip = 'Contents'; - } - if ($env{'course.'.$env{'request.course.id'}.'.description'} ne '') { - $description = - $env{'course.'.$env{'request.course.id'}.'.description'}; - $no_mt_descr = 1; - } - } - $menulink = { href => $href, - title => $tooltip, - target => '_top', - text => $description, - no_mt => $no_mt_descr, }; - if ($last) { - #$last set, so we have some crumbs - unshift(@Crumbs,$menulink); - } else { - #only menulink crumb present - $last = $menulink; - } + #only menulink crumb present + $last = $menulink; } } my $links = join "", @@ -1432,30 +1407,23 @@ returns: nothing $bug = $_->{'bug'} if (exists($_->{'bug'})); $help = $_->{'help'} if (exists($_->{'help'})); - my $result = $_->{no_mt} ? $_->{text} : mt($_->{text}); - - if ($_->{href}){ - $result = htmltag( 'a', $result, + 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; + } @Crumbs; #should the last Element be translated? - - my $lasttext = $last->{'no_mt'} ? $last->{'text'} - : mt( $last->{'text'} ); - - # last breadcrumb is the first order heading of a page - # for course breadcrumbs it's just bold - $links .= htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1', - $lasttext), {title => $lasttext}); + $links .= htmltag( 'li', + htmltag( 'b', + $last->{'no_mt'} ? + $last->{'text'} : mt($last->{'text'}) )); my $icons = ''; $faq = $last->{'faq'} if (exists($last->{'faq'})); @@ -1490,10 +1458,12 @@ returns: nothing .$links; } - render_tools(\$links); + #SD START (work in progress!) + add_tools(\$links); + #SD END $links = htmltag('div', $links, { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ; - render_advtools(\$links); + add_advtools(\$links); # Return the @Crumbs stack to what we started with push(@Crumbs,$last); @@ -1511,107 +1481,55 @@ returns: nothing 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; - if (!defined(%tools)) { - %tools = ( navigation => [], tools => [], advtools => []); - } - - #this cleans data received from lonmenu::innerregister - @html = grep {defined $_ && $_ ne ''} @html; - for (@html) { - s/align="(right|left)"//; - s/// if $category ne 'advtools'; + my ($category, $html) = @_; + return unless $html; + if (!defined(%tools)) { + my %tools = ( A => [], B => [], C => []); } - - push @{$tools{$category}}, @html; + push @{$tools{$category}}, $html; } -=item clear_breadcrumb_tools() - -Clears the breadcrumb toolbar container. - -returns: nothing - -=cut - sub clear_breadcrumb_tools { undef(%tools); } -=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) = @_; + sub add_tools { + my ($links) = @_; return unless defined %tools; - - 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,$legend) - -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,$legend) = @_; - return unless (defined $tools{'advtools'}) - and (scalar(@{$tools{'advtools'}}) > 0); - my $args; - if ($legend) { - $args = {legend => $legend}; - } - $$breadcrumbs .= Apache::loncommon::head_subbox( - funclist_from_array($tools{'advtools'},$args)); + my $html = '
    '; + for my $category ('A','B') { + $html .= '
  • ' + . '
      "; + for my $item (@{$tools{$category}}){ + #SD ugly! I'll fix that later on + $item =~ s/align="(right|left)"//; + $item =~ s///; + $html .= "
    • $item
    • "; + } + $html .= '
  • '; + if ($category eq 'A') { $html .= "
  • $$links
  • "; } + } + $$links = $html.'
'; + } + + 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; } + #SD END } # End of scope for @Crumbs @@ -1744,6 +1662,7 @@ ENDTWO } # End: row_count block for pick_box + sub role_select_row { my ($roles,$title,$css_class,$show_separate_custom,$cdom,$cnum) = @_; my $crstype = 'Course'; @@ -1990,6 +1909,7 @@ sub topic_bar { ############################################## ############################################## + # echo_form_input # # Generates html markup to add form elements from the referrer page @@ -2054,6 +1974,7 @@ sub echo_form_input { ############################################## ############################################## + # set_form_elements # # Generates javascript to set form elements to values based on @@ -2271,7 +2192,7 @@ sub htmltag{ # 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:

This is a headline

# # NOTES: See sub htmltag for further information. @@ -2320,39 +2241,6 @@ sub scripttag { }; -=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
  • tags. - -=item { listattr => {}, itemattr =>{} } - -Attributes for
      and
    • 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) = @_; - return unless scalar @$items; - my ($ul, $li) = inittags( qw(ul li) ); - my $listitems = join '', map { $li->($_, $args->{itemattr}) } @$items; - return $ul->( $listitems, $args->{listattr} ); -} - - ############################################## ############################################## @@ -2382,6 +2270,12 @@ sub list_from_array { # # 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 @@ -2397,15 +2291,11 @@ sub generate_menu { # create the markup for the current $link and push it into @links. # each entry consists of an image and a text optionally followed # by a help link. - my $src; - if ($$link{icon} ne '') { - $src = '/res/adm/pages/'.$$link{icon}; - } push(@links,$li->( $a->( $img->("", { class => "LC_noBorder LC_middle", - src => $src, + src => "/res/adm/pages/$$link{icon}", alt => mt(defined($$link{alttext}) ? $$link{alttext} : $$link{linktext}) }), { @@ -2508,6 +2398,9 @@ sub add_item_funclist { return '
    • '.$content.'
    • '."\n"; } +############################################## +############################################## + =pod =item &end_funclist @@ -2523,46 +2416,16 @@ add_item_funclist Inputs: ./. Returns: HTML code with function list end + =cut +############################################## +############################################## + sub end_funclist { return "
    \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
  • 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__