[LON-CAPA-cvs] cvs: loncom /interface coursecatalog.pm
raeburn
raeburn at source.lon-capa.org
Mon Feb 24 18:20:17 EST 2025
raeburn Mon Feb 24 23:20:17 2025 EDT
Modified files:
/loncom/interface coursecatalog.pm
Log:
- WCAG 2 compliance.
-------------- next part --------------
Index: loncom/interface/coursecatalog.pm
diff -u loncom/interface/coursecatalog.pm:1.107 loncom/interface/coursecatalog.pm:1.108
--- loncom/interface/coursecatalog.pm:1.107 Mon Feb 24 13:40:33 2025
+++ loncom/interface/coursecatalog.pm Mon Feb 24 23:20:17 2025
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler for displaying the course catalog interface
#
-# $Id: coursecatalog.pm,v 1.107 2025/02/24 13:40:33 raeburn Exp $
+# $Id: coursecatalog.pm,v 1.108 2025/02/24 23:20:17 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,6 +37,7 @@
use Apache::lonlocal;
use Apache::courseclassifier;
use Apache::lonacc;
+use HTML::Entities();
use LONCAPA;
use LONCAPA::lonauthcgi;
@@ -87,7 +88,7 @@
({href=>"/adm/coursecatalog",
text=>"Course/Community Catalog"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
- $r->print('<div>'.&mt('Access to catalog LON-CAPA courses/communities unavailable for: "[_1]" on servers run by: "[_2]".',
+ $r->print('<div role="main">'.&mt('Access to catalog LON-CAPA courses/communities unavailable for: "[_1]" on servers run by: "[_2]".',
$domdesc,$serverdomdesc).'</div>');
$r->print(&Apache::loncommon::end_page());
return OK;
@@ -118,18 +119,30 @@
text=>"Course/Community Catalog"});
$r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
if ($knownuser || $canviewall) {
- $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
+ $r->print('<div role="main">'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
} else {
if ($domdefaults{'catauth'} eq 'none') {
- $r->print('<div>'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
+ $r->print('<div role="main">'.&mt('No catalog of LON-CAPA courses/communities is provided for: [_1]',$domdesc).'</div>');
} else {
- $r->print('<div>'.&mt('The catalog of LON-CAPA courses/communities provided for: "[_1]" is only available to users who are logged in.',$domdesc).'</div>');
+ $r->print('<div role="main">'.&mt('The catalog of LON-CAPA courses/communities provided for: "[_1]" is only available to users who are logged in.',$domdesc).'</div>');
}
}
$r->print(&Apache::loncommon::end_page());
return OK;
}
+ for (my $i=0; $i<=$env{'form.catalog_maxdepth'}; $i++) {
+ if ($env{'form.currcat_'.$i} eq '-1') {
+ $env{'form.currcat_'.$i} = '';
+ }
+ if (exists($env{'form.initialcurrcat_'.$i})) {
+ if ($env{'form.currcat_'.$i} ne $env{'form.initialcurrcat_'.$i}) {
+ $env{'form.catalog_maxdepth'} = $i;
+ last;
+ }
+ }
+ }
+
my $cnum;
if ($cattype eq 'codesrch') {
my ($uniquecode,$codemsg,$brtext);
@@ -260,37 +273,14 @@
} else {
my ($catlinks,$has_subcats,$selitem) = &category_breadcrumbs($codedom, at cats);
my $wasacctext = &get_wasactive_text();
+ my %js_lt = &Apache::lonlocal::texthash(
+ 'noch' => 'No changes made in drop-down lists',
+ 'chsu' => 'Choose a subcategory to display',
+ 'chca' => 'Choose a category to display',
+ );
+ &js_escape(\%js_lt);
my $catjs = <<"ENDSCRIPT";
-function setCatDepth(depth) {
- var depth = parseInt(depth);
- if (depth !== NaN) {
- if (depth > 0) {
- var possmaxd = 0;
- var toplevel = new Array($toplevelstr);
- var maxdepths = new Array($maxdepthstr);
- if (toplevel.length) {
- for (var i=0; i<toplevel.length; i++) {
- var item = unescape(toplevel[i]);
- if (item == document.coursecats.currcat_0.value) {
- possmaxd = maxdepths[i];
- break;
- }
- }
- }
- if (depth > possmaxd) {
- depth = possmaxd;
- }
- }
- document.coursecats.catalog_maxdepth.value = depth;
- } else {
- document.coursecats.currcat_0.value = '';
- document.coursecats.catalog_maxdepth.value = '';
- }
- document.coursecats.submit();
- return;
-}
-
function changeSort(caller) {
document.$formname.sortby.value = caller;
document.$formname.submit();
@@ -342,21 +332,39 @@
} else {
my (%add_entries);
my ($currdepth,$deeper) = &get_depth_values();
- if ($selitem) {
- my $alert = &mt('Choose a subcategory to display');
- if (!$deeper) {
- $alert = &mt('Choose a category to display');
- }
- &js_escape(\$alert);
- $catjs .= <<ENDJS;
+ my $alert = $js_lt{'chsu'};
+ if (!$deeper) {
+ $alert = $js_lt{'chca'};
+ }
+ $catjs .= <<"ENDJS";
function check_selected() {
- if (document.coursecats.$selitem.options[document.coursecats.$selitem.selectedIndex].value == "") {
- alert('$alert');
+ var currdepth = parseInt('$currdepth');
+ var countchanged = 0;
+ for (var i=0; i<=currdepth; i++) {
+ var selidx = document.coursecats.elements['currcat_'+i].selectedIndex;
+ var selvalue = document.coursecats.elements['currcat_'+i].options[selidx].value;
+ if (i<currdepth) {
+ var initialvalue = document.coursecats.elements['initialcurrcat_'+i].value;
+ if (selvalue != initialvalue) {
+ countchanged ++;
+ }
+ } else {
+ if (countchanged == 0) {
+ if (selvalue == "") {
+ alert('$alert');
+ return false;
+ } else {
+ countchanged ++;
+ }
+ }
+ }
+ }
+ if (countchanged == 0) {
+ alert("$js_lt{'noch'}");
return false;
}
}
ENDJS
- }
my $js = '<script type="text/javascript">'."\n".
'// <![CDATA['."\n".
"$catjs\n".
@@ -393,8 +401,9 @@
$canviewall,$hostname));
}
}
+ $r->print('</div>');
}
- $r->print('<br />'.&Apache::loncommon::end_page());
+ $r->print(&Apache::loncommon::end_page());
return OK;
}
@@ -492,8 +501,8 @@
}
foreach my $key (sort(keys(%env))) {
- if ($key =~ /^form\.(.+)$/) {
- unless ($possibles{$1}) {
+ if ($key =~ /^form\.currcat_(.+)$/) {
+ unless ($possibles{'currcat_'.$1}) {
delete($env{$key});
}
}
@@ -702,6 +711,7 @@
{text=>$brtexttwo});
$r->print(
&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog').
+ '<div role="main">'.
'<h2>'.$textthree.'</h2>'.
&print_course_listing($codedom,undef,$trails,$allitems,undef,$codetitles,undef,$hostname).
'<br />'.
@@ -710,7 +720,7 @@
'<a href = "javascript:document.coursecatalog.submit()">'.$textfour.'</a>']).
&Apache::lonhtmlcommon::echo_form_input(['coursenum','catalogfilter',
'showdetails','courseid']).
- '</form>');
+ '</form></div>');
return;
}
@@ -853,19 +863,21 @@
({href=>"/adm/coursecatalog",
text=>"Course/Community Catalog"});
}
- $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course/Community Catalog').
+ '<div role="main">');
if ($cattype eq 'std') {
- my $onchange = 'this.form.submit()';
$r->print('<form name="coursecatdom" method="post" action="/adm/coursecatalog">'.
- '<table border="0"><tr><td><b>'.&mt('Domain:').'</b></td><td>'.
- &Apache::loncommon::select_dom_form($codedom,'showdom','',1,$onchange));
- if (!$onchange) {
- $r->print(' <input type="submit" name="godom" value="'.&mt('Change').'" />');
- }
- $r->print('</td></tr></table></form>');
+ '<table border="0"><tr><th align="left"><label for="showdom">'.&mt('Domain:').'</label></th><td>'.
+ &Apache::loncommon::select_dom_form($codedom,'showdom','',1,'','','','','showdom').
+ ' <input type="submit" name="godom" value="'.&mt('Change').'" />'."\n".
+ '<input type="hidden" name="initialshowdom" value="'.$codedom.'" />'."\n".
+ '</td></tr></table></form>');
+ }
+ my $onsubmit;
+ unless ($env{'form.currcat_0'} eq 'instcode::0') {
+ $onsubmit = ' onsubmit="return check_selected();"';
}
- $r->print('<form name="coursecats" method="post" action="/adm/coursecatalog"'.
- ' onsubmit="return check_selected();">'.
+ $r->print('<form name="coursecats" method="post" action="/adm/coursecatalog"'.$onsubmit.'>'.
'<table border="0"><tr>'.$catlinks.'</tr></table></form>');
return;
}
@@ -877,9 +889,10 @@
my $currcat_str =
'<input type="hidden" name="catalog_maxdepth" value="'.$deeper.'" />'.
'<input type="hidden" name="showdom" value="'.$dom.'" />';
- my $catlinks = '<td valign="top"><b>'.&mt('Catalog:').'</b></td><td><table><tr><td>';
+ my $catlinks = '<th class="LC_middle LC_left">'.&mt('Catalog:').'</th><td><div class="LC_leftfloat">';
my $has_subcats;
my $selitem;
+ my $update_button;
if (ref($cats[0]) eq 'ARRAY') {
if (@{$cats[0]} == 0) {
$catlinks .= &mt('No categories defined in this domain');
@@ -901,6 +914,7 @@
}
$currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
} else {
+ $update_button = 1;
$catlinks .= &main_category_selector(@cats);
if (($env{'form.currcat_0'} ne '') &&
($env{'form.currcat_0'} ne 'instcode::0')) {
@@ -910,7 +924,7 @@
} else {
$catlinks .= &mt('Official courses (with institutional codes)');
$env{'form.currcat_0'} = 'instcode::0';
- $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
+ $currcat_str .= '<input type="hidden" name="currcat_0" value="'.$env{'form.currcat_0'}.'" />';
}
if ($deeper) {
for (my $i=1; $i<=$deeper; $i++) {
@@ -918,11 +932,10 @@
next if ($shallower == 0);
my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$env{'form.currcat_'.$shallower});
if ($cat ne '') {
- $catlinks .= '<td valign="top">'.
- '<select name="currcat_'.$shallower.'" onchange="'.
- 'setCatDepth('."'$shallower'".');this.form.submit();">';
+ my $labeltext = &HTML::Entities::encode(&mt('Level [_1] category',$shallower),'<>&"');
+ $catlinks .= '<select name="currcat_'.$shallower.'" aria-label="'.$labeltext.'">';
if (ref($cats[$shallower]{$container}) eq 'ARRAY') {
- $catlinks .= '<option value="">'.&mt('De-select').'</option>';
+ $catlinks .= '<option value="-1">'.&mt('De-select').'</option>';
for (my $j=0; $j<@{$cats[$shallower]{$container}}; $j++) {
my $name = $cats[$shallower]{$container}[$j];
my $item = &escape($name).':'.&escape($container).':'.$shallower;
@@ -934,7 +947,8 @@
'<option value="'.$item.'"'.$selected.'>'.$name.'</option>';
}
}
- $catlinks .= '</select>';
+ $catlinks .= '</select>'.
+ '<input type="hidden" name="initialcurrcat_'.$shallower.'" value="'.$env{'form.currcat_'.$shallower}.'" />';
}
unless ($i == $deeper) {
$catlinks .= $crumbsymbol;
@@ -952,7 +966,8 @@
$has_subcats = 1;
my $buttontext = &mt('Show subcategories');
my $selitem = 'currcat_'.$deeperlevel;
- $catlinks .= ' <select name="'.$selitem.'" onchange="this.form.submit()">';
+ my $labeltext = &HTML::Entities::encode(&mt('Level [_1] category',$deeperlevel),'<>&"');
+ $catlinks .= ' <select name="'.$selitem.'" aria-label="'.$labeltext.'">';
if (@{$cats[$deeperlevel]{$cat}}) {
$catlinks .= '<option value="" selected="selected">'.
&mt('Subcategory ...').'</option>';
@@ -969,13 +984,18 @@
} else {
$selitem = 'currcat_0';
}
- $catlinks .= $currcat_str.'</td></tr></table></td>';
+ $catlinks .= $currcat_str;
+ if ($update_button) {
+ $catlinks .= ' <input type="submit" name="gocat" value="'.&mt('Update').'" />'."\n";
+ }
+ $catlinks .= '</div></td>';
return ($catlinks,$has_subcats,$selitem);
}
sub main_category_selector {
my (@cats) = @_;
- my $maincatlinks = '<select name="currcat_0" onchange="setCatDepth('."'0'".');this.form.submit();">'."\n";
+ my $labeltext = &HTML::Entities::encode(&mt('Top level category'),'<>&"');
+ my $maincatlinks = '<select name="currcat_0" aria-label="'.$labeltext.'">'."\n";
if (ref($cats[0]) eq 'ARRAY') {
if (@{$cats[0]} > 1) {
my $selected = '';
@@ -1004,7 +1024,8 @@
}
$maincatlinks .= '</option>'."\n";
}
- $maincatlinks .= '</select>'."\n";
+ $maincatlinks .= '</select>'."\n".
+ '<input type="hidden" name="initialcurrcat_0" value="'.$env{'form.currcat_0'}.'" />'."\n";
}
return $maincatlinks;
}
@@ -1030,7 +1051,7 @@
if ($is_dc || $canviewall) {
$output .= '<fieldset><legend>'.&mt('Options').'</legend>';
}
- $output .= '<table><tr><td valign="top">';
+ $output .= '<div class="LC_floatleft" style="text-align: top">';
if (($env{'form.currcat_0'} ne 'instcode::0') &&
($env{'form.currcat_0'} ne '') && ($has_subcats)) {
my $include_subcat_status;
@@ -1091,8 +1112,9 @@
}
} else {
$statusdisplay = 'none';
- $cellborder = 'border-left: 0px';
+ $cellborder = 'border-left: 0px;';
}
+ $cellborder .= ' vertical-align: top;';
if ($env{'form.currcat_0'} eq 'communities::0') {
$details_text = &mt('Show full details for each community (domain staff only)');
$hidden_text = &mt('Include communities set to be hidden from catalog (domain staff only)');
@@ -1112,9 +1134,9 @@
$output .= '<span class="LC_nobreak">'.
'<label><input type="checkbox" name="showdetails" value="1" '.
$showdetails_status.'onclick="toggleStatuses();" />'.
- $details_text.'</label></span></td>'."\n".
- '<td id="statuscell" valign="top" style="'.$cellborder.'">'.
- '<div id="statuschoice" style="display:'.$statusdisplay.'">';
+ $details_text.'</label></span></div>'."\n".
+ '<div class="LC_floatleft" id="statuscell" style="'.$cellborder.'">'.
+ '<div class="LC_floatleft" id="statuschoice" style="display:'.$statusdisplay.'; margin-left: 10px">';
if (ref($orderref) eq 'ARRAY') {
if (@{$orderref} > 0) {
foreach my $type (@{$orderref}) {
@@ -1144,13 +1166,14 @@
date => 'immediately prior to specific date:',
);
my @statuses = &Apache::loncommon::get_env_multiple('form.showcounts');
- $output .= '<span id="choosewasacctext" class="LC_nobreak">';
+ my $wasactivetext;
if ($checked) {
- $output .= &get_wasactive_text();
+ $wasactivetext = &get_wasactive_text();
}
- $output .= '</span>'.
- '<div id="choosewasactive" style="display:'.$wasactivedisplay.'">'.
- '<table>';
+ $output .= '<div id="choosewasactive" style="display:'.$wasactivedisplay.'">'."\n".
+ '<fieldset style="margin-left: 4px">'."\n".
+ '<legend id="choosewasacctext" style="font-weight: normal">'."\n".
+ $wasactivetext.'</legend>'."\n";
my @milestones = ('accessend');
if (&Apache::lonnet::auto_run(undef,$codedom)) {
push(@milestones,'enrollend');
@@ -1166,8 +1189,7 @@
$checked = ' checked="checked"';
}
$output .=
- '<tr><td width="10"> </td><td>'.
- '<span class="LC_nobreak"><label>'.
+ '<span class="LC_nobreak" style="padding-left:10px;"><label>'.
'<input type="radio" value="'.$item.'" name="wasactive"'.$checked.' />'.
$milestonetext{$item}.'</label></span>';
if ($item eq 'date') {
@@ -1185,19 +1207,19 @@
'','','',1,'',
'','',1);
}
- $output .= '</td></tr>';
+ $output .= '<br />';
}
- $output .= '</table></div>';
+ $output .= '</fieldset></div>';
}
$output .= '<br />';
}
}
}
- $output .= '</div></td>';
+ $output .= '</div></div>';
} else {
- $output .= '</td>';
+ $output .= '</div>';
}
- $output .= '</tr></table></fieldset></div>'.
+ $output .= '</fieldset></div>'.
'<div style="clear:both;margin:0;"></div>';
return $output;
}
@@ -1256,11 +1278,11 @@
}
sub get_wasactive_text {
- my $wasacctext = ' -- ';
+ my $wasacctext;
if ($env{'form.currcat_0'} eq 'communities::0') {
- $wasacctext .= &mt('where member access status was current ...');
+ $wasacctext .= &mt('count where member access status was current ...');
} else {
- $wasacctext .= &mt('where student access status was current ...');
+ $wasacctext .= &mt('count where student access status was current ...');
}
return $wasacctext;
}
@@ -1414,7 +1436,7 @@
if (defined($sortname{$item})) {
$output .= '<a href="javascript:changeSort('."'$sortname{$item}'".')">'.&mt($item).'</a>';
} elsif ($item eq 'Count') {
- $output .= ' ';
+ $output .= '#';
} else {
$output .= &mt($item);
}
More information about the LON-CAPA-cvs
mailing list