--- loncom/interface/lonhtmlcommon.pm 2012/05/28 19:11:00 1.316 +++ loncom/interface/lonhtmlcommon.pm 2013/07/22 11:46:23 1.352 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common html routines # -# $Id: lonhtmlcommon.pm,v 1.316 2012/05/28 19:11:00 raeburn Exp $ +# $Id: lonhtmlcommon.pm,v 1.352 2013/07/22 11:46:23 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -61,12 +61,18 @@ use Time::HiRes; use Apache::lonlocal; use Apache::lonnet; use HTML::Entities(); -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); sub java_not_enabled { - return "\n".''. - &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.'). - "\n"; + if (($env{'browser.mobile'}) && ($env{'browser.mobile'} =~ /^ipad|ipod|iphone$/i)) { + return "\n".''. + &mt('The required Java applet could not be started, because Java is not supported by your mobile device.'). + "\n"; + } else { + return "\n".''. + &mt('The required Java applet could not be started. Please make sure to have Java installed and active in your browser.'). + "\n"; + } } sub coursepreflink { @@ -209,9 +215,21 @@ dependencies for a web page uploaded dir =cut sub dependencycheck_js { - my ($symb,$title) = @_; - my $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"'). - '&title='.&HTML::Entities::encode($title,'<>&"'); + my ($symb,$title,$url,$folderpath,$uri) = @_; + my $link; + if ($symb) { + $link = '/adm/dependencies?symb='.&HTML::Entities::encode($symb,'<>&"'); + } elsif ($folderpath) { + $link = '/adm/dependencies?folderpath='.&HTML::Entities::encode($folderpath,'<>&"'); + $url = $uri; + } elsif ($uri =~ m{^/public/$match_domain/$match_courseid/syllabus$}) { + $link = '/adm/dependencies'; + } + $link .= (($link=~/\?/)?'&':'?').'title='. + &HTML::Entities::encode($title,'<>&"'); + if ($url) { + $link .= '&url='.&HTML::Entities::encode($url,'<>&"'); + } return < // + + + + + ENDJQUERY return $s; } @@ -1225,13 +1249,25 @@ sub htmlarea_lang { return $lang; } +# return javacsript to activate elements of .colorchooser with jpicker: +# Caller is responsible for enclosing this in '; return $output; @@ -1453,7 +1533,8 @@ sub show_return_link { unless ($env{'request.course.id'}) { return 0; } if ($env{'request.noversionuri'}=~m{^/priv/} || - $env{'request.uri'}=~m{^/~}) { return 1; } + $env{'request.uri'}=~m{^/priv/}) { return 1; } + return if ($env{'request.noversionuri'} eq '/adm/supplemental'); if (($env{'request.noversionuri'} =~ m{^/adm/(viewclasslist|navmaps)($|\?)}) || ($env{'request.noversionuri'} =~ m{^/adm/.*/aboutme($|\?)})) { @@ -1600,6 +1681,14 @@ returns: nothing $description = $env{'course.'.$env{'request.course.id'}.'.description'}; $no_mt_descr = 1; + if ($env{'request.noversionuri'} =~ + m{^/public/($match_domain)/($match_courseid)/syllabus$}) { + unless (($env{'course.'.$env{'request.course.id'}.'.domain'} eq $1) && + ($env{'course.'.$env{'request.course.id'}.'.num'} eq $2)) { + $description = 'Menu'; + $no_mt_descr = 0; + } + } } $menulink = { href =>'/adm/menu', title =>'Go to main menu', @@ -1615,11 +1704,13 @@ returns: nothing } } my $links; - if ((&show_return_link) && (!$CourseBreadcrumbs)) { + if ((&show_return_link) && (!$CourseBreadcrumbs) && (ref($last) eq 'HASH')) { my $alttext = &mt('Go Back'); - $links=&htmltag( 'a',"$alttext", + $links=&htmltag( 'a',''.$alttext.'', { href => '/adm/flip?postdata=return:', - title => &mt("Back to most recent content resource") }); + title => &mt('Back to most recent content resource'), + class => 'LC_menubuttons_link', + }); $links=&htmltag('li',$links); } $links.= join "", @@ -1648,8 +1739,10 @@ returns: nothing # 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}); + if ($lasttext ne '') { + $links .= &htmltag( 'li', htmltag($CourseBreadcrumbs ? 'b' : 'h1', + $lasttext), {title => $lasttext}); + } my $icons = ''; $faq = $last->{'faq'} if (exists($last->{'faq'})); @@ -1670,11 +1763,12 @@ returns: nothing # - - unless ($CourseBreadcrumbs) { - $links = &htmltag('ol', $links, { id => "LC_MenuBreadcrumbs" }); - } else { - $links = &htmltag('ul', $links, { class => "LC_CourseBreadcrumbs" }); + if ($links ne '') { + unless ($CourseBreadcrumbs) { + $links = &htmltag('ol', $links, { id => "LC_MenuBreadcrumbs" }); + } else { + $links = &htmltag('ul', $links, { class => "LC_CourseBreadcrumbs" }); + } } @@ -1686,11 +1780,24 @@ returns: nothing .$links ; } - - &render_tools(\$links); - $links = &htmltag('div', $links, - { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ; - &render_advtools(\$links); + my $nav_and_tools = 0; + foreach my $item ('navigation','tools') { + if (ref($tools{$item}) eq 'ARRAY') { + $nav_and_tools += scalar(@{$tools{$item}}) + } + } + if (($links ne '') || ($nav_and_tools)) { + &render_tools(\$links); + $links = &htmltag('div', $links, + { id => "LC_breadcrumbs" }) unless ($CourseBreadcrumbs) ; + } + my $adv_tools = 0; + if (ref($tools{'advtools'}) eq 'ARRAY') { + $adv_tools = scalar(@{$tools{'advtools'}}); + } + if (($links ne '') || ($adv_tools)) { + &render_advtools(\$links); + } # Return the @Crumbs stack to what we started with push(@Crumbs,$last); @@ -1818,6 +1925,87 @@ returns: nothing } # End of scope for @Crumbs +sub docs_breadcrumbs { + my ($allowed,$crstype,$contenteditor,$title,$precleared)=@_; + my ($folderpath,@folders,$supplementalflag); + @folders = split('&',$env{'form.folderpath'}); + if ($env{'form.folderpath'} =~ /^supplemental/) { + $supplementalflag = 1; + } + my $plain=''; + my $container = 'sequence'; + my ($randompick,$isencrypted,$ishidden,$is_random_order) = (-1,0,0,0); + my @docs_crumbs; + while (@folders) { + my $folder=shift(@folders); + my $foldername=shift(@folders); + if ($folderpath) {$folderpath.='&';} + $folderpath.=$folder.'&'.$foldername; + my $url; + if ($allowed) { + $url = '/adm/coursedocs?folderpath='; + } else { + $url = '/adm/supplemental?folderpath='; + } + $url .= &escape($folderpath); + my $name=&unescape($foldername); +# each of randompick number, hidden, encrypted, random order, is_page +# are appended with ":"s to the foldername + $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)\:?(\d*)$//; + unless ($supplementalflag) { + if ($contenteditor) { + if ($1 ne '') { + $randompick=$1; + } else { + $randompick=-1; + } + if ($2) { $ishidden=1; } + if ($3) { $isencrypted=1; } + if ($4 ne '') { $is_random_order = 1; } + if ($5 == 1) {$container = 'page'; } + } + } + if ($folder eq 'supplemental') { + $name = &mt('Supplemental Content'); + } + if ($contenteditor) { + $plain.=$name.' > '; + } + push(@docs_crumbs, + {'href' => $url, + 'title' => $name, + 'text' => $name, + 'no_mt' => 1, + }); + } + if ($title) { + push(@docs_crumbs, + {'title' => $title, + 'text' => $title, + 'no_mt' => 1,} + ); + } + if (wantarray) { + unless ($precleared) { + &clear_breadcrumbs(); + } + &add_breadcrumb(@docs_crumbs); + if ($contenteditor) { + $plain=~s/\>\;\s*$//; + } + my $menulink = 0; + if (!$allowed && !$contenteditor) { + $menulink = 1; + } + return (&breadcrumbs(undef,undef,$menulink,'nohelp',undef,undef, + $contenteditor), + $randompick,$ishidden,$isencrypted,$plain, + $is_random_order,$container); + } else { + return \@docs_crumbs; + } +} + ############################################################ ############################################################ @@ -2045,14 +2233,14 @@ sub course_selection { my $courseform=''.&Apache::loncommon::selectcourse_link ($formname,'pickcourse','pickdomain','coursedesc','',1,$crstype).''; - $output .= ''.$allcrs.'
'; + $output .= '
'; if ($totcodes > 0) { my $numtitles = @$codetitles; if ($numtitles > 0) { - $output .= ''.&mt('Pick courses by category:').'
'; + $output .= '
'; $output .= ''; @@ -2090,7 +2278,15 @@ sub course_selection { $output .= '
'.$$codetitles[0].'
'."\n". '
'.$$codetitles[$i].'
'."\n". ''."\n". '

'; } } - $output .= ''.$pickspec.' '.$courseform.'  selected.
'."\n"; + $output .= + '' + .' '.$courseform.'  ' + .&mt('[_1] selected.', + '' + .'') + .'
'."\n"; return $output; } @@ -2211,6 +2407,49 @@ sub resource_info_box { return $return; } +# display_usage +# +# Generates a div containing a block, filled to show percentage of current quota used +# +# Quotas available for user portfolios, group portfolios, authoring spaces, and course +# content stored directly within a course (i.e., excluding published content). +# + +sub display_usage { + my ($current_disk_usage,$disk_quota) = @_; + my $usage = $current_disk_usage/1000; + my $quota = $disk_quota/1000; + my $percent; + if ($disk_quota == 0) { + $percent = 100.0; + } else { + $percent = 100*($current_disk_usage/$disk_quota); + } + $usage = sprintf("%.2f",$usage); + $quota = sprintf("%.2f",$quota); + $percent = sprintf("%.0f",$percent); + my ($color,$cssclass); + if ($percent <= 60) { + $color = '#00A000'; + } elsif ($percent > 60 && $percent < 90) { + $color = '#FFD300'; + $cssclass = 'class="LC_warning"'; + } elsif( $percent >= 90) { + $color = '#FF0000'; + $cssclass = 'class="LC_error"'; + } + my $prog_width = $percent; + if ($prog_width > 100) { + $prog_width = 100; + } + return ' +
'.&mt('Currently using [_1] of the [_2] available.',$usage.' MB ('.$percent.'%)',$quota.' MB')."\n". +'
'."\n". +'
'."\n". +'
'."\n". +'
'; +} + ############################################## ############################################## @@ -2709,7 +2948,7 @@ sub resize_scrollbox_js { scroll => 'contentscroll', boxh => 'contenteditor', ); - $paddingwfrac = 0.09; + $paddingwfrac = 0.09; $offsetwfrac = 0.015; $offsetv = 20; $minw = 250; @@ -2748,6 +2987,7 @@ function resize_scrollbox(scrollboxname, var scrolltableid = 'table_'+scrollboxname; var scrollbox; var scrolltable; + var ismobile = '$env{'browser.mobile'}'; if (document.getElementById("$names{'boxw'}") == null) { return; @@ -2784,6 +3024,7 @@ FIRST } $output .= <<"SECOND"; var listwchange; + var scrollchange; if (chkw == 1) { var boxw = document.getElementById("$names{'boxw'}").offsetWidth; var itemw; @@ -2795,6 +3036,7 @@ FIRST var scrollboxw = scrollbox.offsetWidth; var scrollboxscrollw = scrollbox.scrollWidth; + var scrollstart = scrollboxw; var offsetw = parseInt(vpw * $offsetwfrac); var paddingw = parseInt(vpw * $paddingwfrac); @@ -2869,36 +3111,24 @@ PARAMSONE } } + if (newscrollboxw != scrollboxw) { + scrollchange = 1; + } + if (itemid.offsetWidth != itemwstart) { listwchange = 1; } -THIRD - if ($context eq 'docs') { - $output .= <<"DOCSTWO"; - if (activeTab == 'cc1') { - if (document.getElementById('cc_hrule') != null) { - document.getElementById('cc_hrule').style.width=actabw+"px"; - } - } else { - if (activeTab == 'bb1') { - if (document.getElementById('bb_hrule') != null) { - document.getElementById('bb_hrule').style.width=actabw+"px"; - } - } else { - if (activeTab == 'ee2') { - if (document.getElementById('ee_hrule') != null) { - document.getElementById('ee_hrule').style.width=actabw+"px"; - } - } - } - } -DOCSTWO - } - $output .= <<"FOURTH"; } if ((chkh == 1) || (listwchange)) { + var itemid = document.getElementById("$names{'item'}"); + if (itemid != null) { + itemh = itemid.offsetHeight; + } var primaryheight = document.getElementById('LC_nav_bar').offsetHeight; - var secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight; + var secondaryheight; + if (document.getElementById('LC_secondary_menu') != null) { + secondaryheight = document.getElementById('LC_secondary_menu').offsetHeight; + } var crumbsheight = document.getElementById('LC_breadcrumbs').offsetHeight; var dccidheight = 0; if (document.getElementById('dccid') != null) { @@ -2914,6 +3144,7 @@ DOCSTWO var scrollboxheight = scrollbox.offsetHeight; var scrollboxscrollheight = scrollbox.scrollHeight; + var scrollboxh = scrollboxheight; var minvscrollbox = $minv; var offsetv = $offsetv; @@ -2944,6 +3175,13 @@ DOCSTWO scrollbox.style.height = newscrollheight+"px"; } } + var newscrollboxh = scrollbox.offsetHeight; + if (scrollboxh != newscrollboxh) { + scrollchange = 1; + } + } + if (ismobile && scrollchange) { + \$("#div_$names{'scroll'}").getNiceScroll().onResize(); } return; } @@ -2954,10 +3192,93 @@ function callResize() { timer=setTimeout('resize_scrollbox("$names{'scroll'}","1","1")',500); } -FOURTH +THIRD return $output; } +############################################## +############################################## + +sub javascript_jumpto_resource { + my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'. + &mt('Switch server?'); + return (<&'); + if ($symb) { + $cfile .= '&symb='.&HTML::Entities::encode($symb,'"<>&'); + } elsif ($folderpath) { + $cfile .= '&folderpath='.&HTML::Entities::encode($folderpath,'"<>&'); + } + if ($forceedit) { + $cfile .= '&forceedit=1'; + } + if ($forcereg) { + $cfile .= '&register=1'; + } + $jscall = "need_switchserver('$cfile');"; + } + } else { + unless ($cfile =~ m{^/priv/}) { + if ($symb) { + $cfile .= (($cfile=~/\?/)?'&':'?')."symb=$symb"; + } elsif ($folderpath) { + $cfile .= (($cfile=~/\?/)?'&':'?'). + 'folderpath='.&HTML::Entities::encode(&escape($folderpath),'"<>&'); + if ($title) { + $cfile .= (($cfile=~/\?/)?'&':'?'). + 'title='.&HTML::Entities::encode(&escape($title),'"<>&'); + } + if ($idx) { + $cfile .= (($cfile=~/\?/)?'&':'?').'idx='.$idx; + } + if ($suppurl) { + $cfile .= (($cfile=~/\?/)?'&':'?'). + 'suppurl='.&HTML::Entities::encode(&escape($suppurl)); + } + } + if ($forceedit) { + $cfile .= (($cfile=~/\?/)?'&':'?').'forceedit=1'; + } + if ($forcereg) { + $cfile .= (($cfile=~/\?/)?'&':'?').'register=1'; + } + if ($todocs) { + $cfile .= (($cfile=~/\?/)?'&':'?').'todocs=1'; + } + } + $jscall = "go('$cfile')"; + } + return $jscall; +} ############################################## ############################################## @@ -3325,6 +3646,40 @@ sub funclist_from_array { { listattr => {class => 'LC_funclist'} }); } +=pod + +=item &actionbox( \@array ) + +Constructs a XHTML list from \@array with the first item being visually +highlighted and set to the value 'Actions'. The list is wrapped in a division. + +The actionlist is used to offer contextual actions, mostly at the bottom +of a page, on which the outcome of an processed action is shown, +e.g. a file operation in Authoring Space. + +=over + +=item \@array + +A reference to the array containing text. Details: sub funclist_from_array + +=back + +Returns: XHTML div as string. + +=back + +=cut + +sub actionbox { + my ($items) = @_; + return unless(ref($items) eq 'ARRAY'); + return + '
' + .&funclist_from_array($items, {legend => &mt('Actions')}) + .'
'; +} + 1; __END__