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

raeburn raeburn at source.lon-capa.org
Mon Nov 15 17:36:38 EST 2021


raeburn		Mon Nov 15 22:36:38 2021 EDT

  Modified files:              
    /loncom/interface	loncommon.pm lonmenu.pm 
    /loncom/auth	lonroles.pm 
  Log:
  - Menu links on page displaying progress indicator while course role loads
    set to be unclickable until course is loaded.
  - "Continue" link shown on page once course is loaded.   
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1368 loncom/interface/loncommon.pm:1.1369
--- loncom/interface/loncommon.pm:1.1368	Mon Oct 18 22:29:20 2021
+++ loncom/interface/loncommon.pm	Mon Nov 15 22:36:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1368 2021/10/18 22:29:20 raeburn Exp $
+# $Id: loncommon.pm,v 1.1369 2021/11/15 22:36:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1416,7 +1416,7 @@
 }
 
 sub top_nav_help {
-    my ($text) = @_;
+    my ($text,$linkattr) = @_;
     $text = &mt($text);
     my $stay_on_page = 1;
 
@@ -1430,7 +1430,7 @@
     if ($link) {
         return <<"END";
 $banner_link
-<a href="$link" title="$title">$text</a>
+<a href="$link" title="$title" $linkattr>$text</a>
 END
     } else {
         return ' '.$text.' ';
@@ -6266,7 +6266,8 @@
             Apache::lonmenu::utilityfunctions($httphost), 'start');
 
         unless ($args->{'no_primary_menu'}) {
-            my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref);
+            my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
+                                                              $args->{'links_disabled'});
 
             if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
                 if ($dc_info) {
@@ -6298,7 +6299,8 @@
             unless ($args->{'no_inline_menu'}) {
                 $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
                                                             $args->{'no_primary_menu'},
-                                                            $menucoll,$menuref);
+                                                            $menucoll,$menuref,
+                                                            $args->{'links_disabled'});
             }
             $bodytag .= Apache::lonmenu::serverform();
             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
@@ -8375,6 +8377,18 @@
 		cursor:pointer;
 }
 
+.LCisDisabled {
+  cursor: not-allowed;
+  opacity: 0.5;
+}
+
+a[aria-disabled="true"] {
+  color: currentColor;
+  display: inline-block;  /* For IE11/ MS Edge bug */
+  pointer-events: none;
+  text-decoration: none;
+}
+
 pre.LC_wordwrap {
   white-space: pre-wrap;
   white-space: -moz-pre-wrap;
@@ -8963,6 +8977,9 @@
                                will contain https://<hostname> if server uses
                                https (as per hosts.tab), but request is for http
              hostname       -> hostname, originally from $r->hostname(), (optional).
+             links_disabled -> Links in primary and secondary menus are disabled
+                               (Can enable them once page has loaded - see lonroles.pm
+                               for an example).
 
 =back
 
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.510 loncom/interface/lonmenu.pm:1.511
--- loncom/interface/lonmenu.pm:1.510	Tue Sep 21 22:54:26 2021
+++ loncom/interface/lonmenu.pm	Mon Nov 15 22:36:37 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.510 2021/09/21 22:54:26 raeburn Exp $
+# $Id: lonmenu.pm,v 1.511 2021/11/15 22:36:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -220,7 +220,7 @@
 my @inlineremote;
 
 sub prep_menuitem {
-    my ($menuitem,$ltitarget) = @_;
+    my ($menuitem,$ltitarget,$listclass,$linkattr) = @_;
     return '' unless(ref($menuitem) eq 'ARRAY');
     my $link;
     if ($$menuitem[1]) { # graphical Link
@@ -234,10 +234,10 @@
     if ($ltitarget eq 'iframe') {
         $target ='';
     }
-    return '<li><a' 
+    return ($listclass?'<li class="'.$listclass.'">':'<li>').'<a'
            # highlighting for new messages
            . ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '') 
-           . qq| href="$$menuitem[0]"$target>$link</a></li>|;
+           . qq| href="$$menuitem[0]"$target $linkattr>$link</a></li>|;
 }
 
 # primary_menu() evaluates @primary_menu and returns a two item array,
@@ -247,7 +247,7 @@
 # @primary_menu is filled within the BEGIN block of this module with 
 # entries from mydesk.tab
 sub primary_menu {
-    my ($crstype,$ltimenu,$menucoll,$menuref) = @_;
+    my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled) = @_;
     my (%menu,%ltiexc,%menuopts);
     # each element of @primary contains following array:
     # (link url, icon path, alt text, link text, condition, position)
@@ -332,6 +332,11 @@
                 }
             }
         }
+        my ($listclass,$linkattr);
+        if ($links_disabled) {
+            $listclass = 'LCisDisabled';
+            $linkattr = 'aria-disabled="true"';
+        }
         if (defined($primary_submenu{$title})) {
             my ($link,$target);
             if ($menuitem->[0] ne '') {
@@ -364,13 +369,17 @@
                     }
                     next if (($env{'request.course.id'}) && ($menucoll) && ($title eq 'Personal') &&
                              (!@primsub));
+                    if ($title eq 'Personal') {
+                        $title = &mt($title);
+                    }
                 } else {
                     $title = &mt($title);
                 }
                 if (@primsub > 0) {
-                    $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1);
+                    $menu{$position} .= &create_submenu($link,$target,$title,\@primsub,1,undef,$listclass,$linkattr);
                 } elsif ($link) {
-                    $menu{$position} .= '<li><a href="'.$link.'" target="'.$target.'">'.$title.'</a></li>';
+                    $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
+                                        '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.$title.'</a></li>';
                 }
             }
         } elsif ($$menuitem[3] eq 'Help') { # special treatment for helplink
@@ -382,10 +391,12 @@
                                                                   'helpdeskmail',
                                                                   $defdom,$origmail);
                 if ($to ne '') {
-                    $menu{$position} .= &prep_menuitem($menuitem,$ltitarget); 
+                    $menu{$position} .= &prep_menuitem($menuitem,$ltitarget,$listclass,$linkattr); 
                 }
             } else {
-                $menu{$position} .= '<li>'.&Apache::loncommon::top_nav_help('Help').'</li>';
+                $menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
+                                    &Apache::loncommon::top_nav_help('Help',$linkattr).
+                                    '</li>';
             }
         } elsif ($$menuitem[3] eq 'Log In') {
             if ($public) {
@@ -393,9 +404,9 @@
                     $$menuitem[0] = '/adm/login';
                 }
             }
-            $menu{$position} .= prep_menuitem($menuitem,$ltitarget);
+            $menu{$position} .= prep_menuitem($menuitem,$ltitarget,$listclass,$linkattr);
         } else {
-            $menu{$position} .= prep_menuitem($menuitem,$ltitarget);
+            $menu{$position} .= prep_menuitem($menuitem,$ltitarget,$listclass,$linkattr);
         }
     }
     my @output = ('','');
@@ -434,7 +445,7 @@
 }
 
 sub secondary_menu {
-    my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref) = @_;
+    my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,$links_disabled) = @_;
     my $menu;
 
     my $crstype = &Apache::loncommon::course_type();
@@ -511,6 +522,12 @@
         %menuopts = %{$menuref};
     }
 
+    my ($listclass,$linkattr);
+    if ($links_disabled) {
+        $listclass = 'LCisDisabled';
+        $linkattr = 'aria-disabled="true"';
+    }
+
     my ($canmodifycoauthor); 
     if ($env{'request.role'} eq "au./$env{'user.domain'}/") {
         my $extent = "$env{'user.domain'}/$env{'user.name'}";
@@ -617,9 +634,12 @@
                     }
                 }
                 if (@scndsub > 0) {
-                    $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1);
+                    $menu .= &create_submenu($link,$target,&mt($title),\@scndsub,1,undef,
+                                             $listclass,$linkattr);
                 } elsif ($link ne '#') {
-                    $menu .= '<li><a href="'.$link.'" target="'.$target.'">'.&mt($title).'</a></li>';
+                    $menu .= ($listclass?'<li class="'.$listclass.'">':'').
+                             '<a href="'.$link.'" target="'.$target.'" '.$linkattr.'>'.
+                             &mt($title).'</a></li>';
                 }
             }
         } elsif ($$menuitem[3] eq 'Roles' && $env{'request.course.id'}) {
@@ -663,7 +683,7 @@
                 }
                 $$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
             }
-            $menu .= &prep_menuitem(\@$menuitem,$ltitarget);
+            $menu .= &prep_menuitem(\@$menuitem,$ltitarget,$listclass,$linkattr);
         }
     }
     if ($menu =~ /\[url\].*\[symb\]/) {
@@ -701,7 +721,7 @@
 }
 
 sub create_submenu {
-    my ($link,$target,$title,$submenu,$translate,$addclass) = @_;
+    my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
     return unless (ref($submenu) eq 'ARRAY');
     my $disptarget;
     if ($target ne '') {
@@ -716,7 +736,7 @@
 
     # $link and $title are only used in the initial string written in $menu
     # as seen above, not needed for nested submenus
-    $menu .= &build_submenu($target, $submenu, $translate, '1');
+    $menu .= &build_submenu($target, $submenu, $translate, '1', $listclass, $linkattr);
     $menu .= '</ul></li>';
 
     return $menu;
@@ -726,7 +746,7 @@
 # build the dropdown (and nested submenus) recursively
 # see perldoc create_submenu documentation for further information
 sub build_submenu {
-    my ($target, $submenu, $translate, $first_level) = @_; 
+    my ($target, $submenu, $translate, $first_level, $listclass, $linkattr) = @_; 
     unless (@{$submenu}) {
         return '';
     }
@@ -791,8 +811,10 @@
                     }
                 }
 
-                $menu .= '<li style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
-                $menu .= '<a href="'.$href.'"'.$target.'>' .  $title . '</a>';
+                $menu .= '<li '.
+                $menu .= ($listclass?'class="'.$listclass.'" ':'');
+                $menu .= 'style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
+                $menu .= '<a href="'.$href.'"'.$target.' '.$linkattr.'>' .  $title . '</a>';
                 $menu .= '</li>';
             }
         }
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.353 loncom/auth/lonroles.pm:1.354
--- loncom/auth/lonroles.pm:1.353	Wed Nov  3 01:04:02 2021
+++ loncom/auth/lonroles.pm	Mon Nov 15 22:36:38 2021
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.353 2021/11/03 01:04:02 raeburn Exp $
+# $Id: lonroles.pm,v 1.354 2021/11/15 22:36:38 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -158,12 +158,21 @@
     my $brcrum = [{'href' => '',
                    'text' => $title},];
     my $start_page = &Apache::loncommon::start_page($title,undef,
-                                                    {'bread_crumbs' => $brcrum,});
+                                                    {'bread_crumbs' => $brcrum,
+                                                     'bread_crumbs_nomenu' => 1,
+                                                     'links_disabled' => 1});
     $r->print(<<ENDREDIR);
 $start_page
 <script type="text/javascript">
 // <![CDATA[
 $swinfo
+
+document.body.addEventListener('click', function (event) {
+  // filter out clicks on any other elements
+  if (event.target.nodeName == 'A' && event.target.getAttribute('aria-disabled') == 'true') {
+    event.preventDefault();
+  }
+});
 // ]]>
 </script>
 ENDREDIR
@@ -172,8 +181,7 @@
 
 sub finish_loading_course {
     my ($r,$msg,$url) = @_;
-#FIXME add continue link, and add jquery to enable menu links when page is loaded
-    my $link;
+    my $link = '<div id="LC_course_loaded" style="display:none"><a href="'.$url.'">'.&mt('Continue').'</a></div>';
     my $end_page = &Apache::loncommon::end_page();
     my $js_url = &js_escape($url);
     $r->print(<<END);
@@ -181,6 +189,9 @@
 <script type="text/javascript">
 // <![CDATA[
 \$(document).ready(function() {
+    \$("#LC_course_loaded").css("display","block");
+    \$('.isDisabled > a').removeAttr("aria-disabled");
+    \$('.isDisabled').removeClass("isDisabled");
     var url = "$js_url";
     \$(location).attr('href',url);
 });


More information about the LON-CAPA-cvs mailing list