[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm lonmenu.pm lonsearchcat.pm
raeburn
raeburn at source.lon-capa.org
Sat May 28 23:19:00 EDT 2022
raeburn Sun May 29 03:19:00 2022 EDT
Modified files:
/loncom/interface lonmenu.pm loncommon.pm lonsearchcat.pm
Log:
- Bug 6907
When context is LTI Provider, or deep-linked, and display is embedded in
another web page, set target to _parent for inline menu links, and help
item when displayng search results within LON-CAPA's own frames.
-------------- next part --------------
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.520 loncom/interface/lonmenu.pm:1.521
--- loncom/interface/lonmenu.pm:1.520 Sat May 28 16:25:45 2022
+++ loncom/interface/lonmenu.pm Sun May 29 03:19:00 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.520 2022/05/28 16:25:45 raeburn Exp $
+# $Id: lonmenu.pm,v 1.521 2022/05/29 03:19:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -99,7 +99,7 @@
=over
-=item prep_menuitems(\@menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr)
+=item prep_menuitems(\@menuitem,$target,$listclass,$linkattr)
This routine wraps a menuitem in proper HTML. It is used by primary_menu() and
secondary_menu().
@@ -220,9 +220,9 @@
my @inlineremote;
sub prep_menuitem {
- my ($menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr) = @_;
+ my ($menuitem,$target,$listclass,$linkattr) = @_;
return '' unless(ref($menuitem) eq 'ARRAY');
- my $link;
+ my ($link,$targetattr);
if ($$menuitem[1]) { # graphical Link
$link = "<img class=\"LC_noBorder\""
. " src=\"" . &Apache::loncommon::lonhttpdurl($$menuitem[1]) . "\""
@@ -230,16 +230,13 @@
} else { # textual Link
$link = &mt($$menuitem[3]);
}
- my $target = ' target="_top"';
- if ($ltitarget eq 'iframe') {
- $target ='';
- } elsif ($deeplinktarget eq '_self') {
- $target = ' target="'.$deeplinktarget.'"';
+ if ($target ne '') {
+ $targetattr = ' target="'.$target.'"';
}
return ($listclass?'<li class="'.$listclass.'">':'<li>').'<a'
# highlighting for new messages
. ( $$menuitem[4] eq 'newmsg' ? ' class="LC_new_message"' : '')
- . qq| href="$$menuitem[0]"$target $linkattr>$link</a></li>|;
+ . qq| href="$$menuitem[0]"$targetattr $linkattr>$link</a></li>|;
}
# primary_menu() evaluates @primary_menu and returns a two item array,
@@ -249,7 +246,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,$links_disabled) = @_;
+ my ($crstype,$ltimenu,$menucoll,$menuref,$links_disabled,$links_target) = @_;
my (%menu,%ltiexc,%menuopts);
# each element of @primary contains following array:
# (link url, icon path, alt text, link text, condition, position)
@@ -267,10 +264,9 @@
my %roles_in_env;
$rolecount = &Apache::lonroles::roles_from_env(\%roles_in_env,$update);
}
- my ($lti,$ltitarget,$deeplinktarget);
+ my $lti;
if ($env{'request.lti.login'}) {
$lti = 1;
- $ltitarget = $env{'request.lti.target'};
if (ref($ltimenu) eq 'HASH') {
foreach my $item ('fullname','logout') {
unless ($ltimenu->{$item}) {
@@ -279,8 +275,26 @@
}
}
}
- if ($env{'request.deeplink.login'}) {
- $deeplinktarget = $env{'request.deeplink.target'};
+ my ($listclass,$linkattr,$target);
+ if ($links_disabled) {
+ $listclass = 'LCisDisabled';
+ $linkattr = 'aria-disabled="true"';
+ }
+ if ($links_target ne '') {
+ $target = $links_target;
+ } else {
+ my ($ltitarget,$deeplinktarget);
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
+ }
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
+ if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
+ $target = '_self';
+ } else {
+ $target = '_top';
+ }
}
if (($menucoll) && (ref($menuref) eq 'HASH')) {
%menuopts = %{$menuref};
@@ -337,18 +351,10 @@
}
}
}
- my ($listclass,$linkattr);
- if ($links_disabled) {
- $listclass = 'LCisDisabled';
- $linkattr = 'aria-disabled="true"';
- }
if (defined($primary_submenu{$title})) {
- my ($link,$target);
+ my $link;
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- unless (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
- $target = '_top';
- }
} else {
$link = '#';
}
@@ -396,7 +402,7 @@
'helpdeskmail',
$defdom,$origmail);
if ($to ne '') {
- $menu{$position} .= &prep_menuitem($menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr);
+ $menu{$position} .= &prep_menuitem($menuitem,$target,$listclass,$linkattr);
}
} else {
$menu{$position} .= ($listclass?'<li class="'.$listclass.'">':'<li>').
@@ -409,9 +415,9 @@
$$menuitem[0] = '/adm/login';
}
}
- $menu{$position} .= prep_menuitem($menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr);
+ $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
} else {
- $menu{$position} .= prep_menuitem($menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr);
+ $menu{$position} .= prep_menuitem($menuitem,$target,$listclass,$linkattr);
}
}
my @output = ('','');
@@ -450,7 +456,8 @@
}
sub secondary_menu {
- my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,$links_disabled) = @_;
+ my ($httphost,$ltiscope,$ltimenu,$noprimary,$menucoll,$menuref,
+ $links_disabled,$links_target) = @_;
my $menu;
my $crstype = &Apache::loncommon::course_type();
@@ -527,7 +534,7 @@
%menuopts = %{$menuref};
}
- my ($listclass,$linkattr);
+ my ($listclass,$linkattr,$target);
if ($links_disabled) {
$listclass = 'LCisDisabled';
$linkattr = 'aria-disabled="true"';
@@ -542,12 +549,22 @@
}
}
- my ($roleswitcher_js,$roleswitcher_form,$ltitarget,$deeplinktarget);
- if ($env{'request.lti.login'}) {
- $ltitarget = $env{'request.lti.target'};
- }
- if ($env{'request.deeplink.login'}) {
- $deeplinktarget = $env{'request.deeplink.target'};
+ my ($roleswitcher_js,$roleswitcher_form);
+ if ($links_target ne '') {
+ $target = $links_target;
+ } else {
+ my ($ltitarget,$deeplinktarget);
+ if ($env{'request.lti.login'}) {
+ $ltitarget = $env{'request.lti.target'};
+ }
+ if ($env{'request.deeplink.login'}) {
+ $deeplinktarget = $env{'request.deeplink.target'};
+ }
+ if (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
+ $target = '_self';
+ } else {
+ $target = '_top';
+ }
}
foreach my $menuitem (@secondary_menu) {
@@ -603,12 +620,9 @@
}
}
if (defined($secondary_submenu{$title})) {
- my ($link,$target);
+ my $link;
if ($menuitem->[0] ne '') {
$link = $menuitem->[0];
- unless (($ltitarget eq 'iframe') || ($deeplinktarget eq '_self')) {
- $target = '_top';
- }
} else {
$link = '#';
}
@@ -657,7 +671,7 @@
&roles_selector(
$env{'course.' . $env{'request.course.id'} . '.domain'},
$env{'course.' . $env{'request.course.id'} . '.num'},
- $httphost,$menucoll,$menuref
+ $httphost,$target,$menucoll,$menuref
);
if (($$menuitem[5]) && (!$menuopts{$$menuitem[5]})) {
next unless ($has_opa_priv);
@@ -691,7 +705,7 @@
}
$$menuitem[0] = &HTML::Entities::encode($$menuitem[0],'&<>"');
}
- $menu .= &prep_menuitem(\@$menuitem,$ltitarget,$deeplinktarget,$listclass,$linkattr);
+ $menu .= &prep_menuitem(\@$menuitem,$target,$listclass,$linkattr);
}
}
if ($menu =~ /\[url\].*\[symb\]/) {
@@ -731,12 +745,12 @@
sub create_submenu {
my ($link,$target,$title,$submenu,$translate,$addclass,$listclass,$linkattr) = @_;
return unless (ref($submenu) eq 'ARRAY');
- my $disptarget;
- if ($target ne '') {
- $disptarget = ' target="'.$target.'"';
+ my $targetattr;
+ if (($target ne '') && ($link ne '#')) {
+ $targetattr = ' target="'.$target.'"';
}
my $menu = '<li class="LC_hoverable '.$addclass.'">'.
- '<a href="'.$link.'"'.$disptarget.'>'.
+ '<a href="'.$link.'"'.$targetattr.'>'.
'<span class="LC_nobreak">'.$title.
'<span class="LC_fontsize_small" style="font-weight:normal;">'.
' ▼</span></span></a>'.
@@ -813,16 +827,17 @@
}
$href =~ s/\[returnurl\]/$returnurl/;
}
+ my $targetattr;
unless (($href eq '') || ($href =~ /^\#/)) {
- if ($target eq '_top') {
- $target = ' target="_top"';
+ if ($target ne '') {
+ $targetattr = ' target="'.$target.'"';
}
}
$menu .= '<li ';
$menu .= ($listclass?'class="'.$listclass.'" ':'');
$menu .= 'style="margin:0;padding:0;'. $bordertop . $borderbot .'">';
- $menu .= '<a href="'.$href.'"'.$target.' '.$linkattr.'>' . $title . '</a>';
+ $menu .= '<a href="'.$href.'"'.$targetattr.' '.$linkattr.'>' . $title . '</a>';
$menu .= '</li>';
}
}
@@ -2490,7 +2505,7 @@
unless ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
(($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
$target = ' target="_top"';
- $printtarget = ' target="_parent"';
+ $printtarget = ' target="_top"';
}
}
return(<<ENDCONSTSPACEFORM);
@@ -2526,7 +2541,7 @@
}
sub roles_selector {
- my ($cdom,$cnum,$httphost,$menucoll,$menuref) = @_;
+ my ($cdom,$cnum,$httphost,$target,$menucoll,$menuref) = @_;
my $crstype = &Apache::loncommon::course_type();
my $now = time;
my (%courseroles,%seccount,%courseprivs,%roledesc);
@@ -2632,11 +2647,15 @@
}
}
if ((keys(%seccount) > 1) || ($numdiffsec > 1)) {
+ my $targetattr;
+ if ($target ne '') {
+ $targetattr = ' target="'.$target.'"';
+ }
my @submenu;
$js = &jump_to_role($cdom,$cnum,\%seccount,\%courseroles,\%courseprivs,
\%roledesc,$privref,$menucoll,$menuref);
$form =
- '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles">'."\n".
+ '<form name="rolechooser" method="post" action="'.$httphost.'/adm/roles"'.$targetattr.'>'."\n".
' <input type="hidden" name="destinationurl" value="'.
&HTML::Entities::encode($destinationurl).'" />'."\n".
' <input type="hidden" name="gotorole" value="1" />'."\n".
@@ -2699,7 +2718,7 @@
}
}
if (@submenu > 0) {
- $switcher = &create_submenu('#','',&mt('Switch role'),\@submenu);
+ $switcher = &create_submenu('#',$target,&mt('Switch role'),\@submenu);
}
}
return ($js,$form,$switcher,$has_opa_priv);
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1379 loncom/interface/loncommon.pm:1.1380
--- loncom/interface/loncommon.pm:1.1379 Fri May 27 04:35:36 2022
+++ loncom/interface/loncommon.pm Sun May 29 03:19:00 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.1379 2022/05/27 04:35:36 raeburn Exp $
+# $Id: loncommon.pm,v 1.1380 2022/05/29 03:19:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1307,13 +1307,16 @@
# Add the text
my $target = ' target="_top"';
- if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
- $target = '';
- }
- if (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self')) {
- $target = '';
+ if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
+ (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
+ if (($env{'request.noversionuri'} eq '/adm/searchcat') &&
+ ($env{'form.phase'} =~ /^(sort|run_search)$/)) {
+ $target = ' target="_parent"';
+ } else {
+ $target = '';
+ }
}
- if ($text ne "") {
+ if ($text ne "") {
$template.='<span class="LC_help_open_topic">'
.'<a'.$target.' href="'.$link.'">'
.$text.'</a>';
@@ -6528,7 +6531,8 @@
unless ($args->{'no_primary_menu'}) {
my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref,
- $args->{'links_disabled'});
+ $args->{'links_disabled'},
+ $args->{'links_target'});
if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
if ($dc_info) {
@@ -6561,7 +6565,8 @@
$bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
$args->{'no_primary_menu'},
$menucoll,$menuref,
- $args->{'links_disabled'});
+ $args->{'links_disabled'},
+ $args->{'links_target'});
}
$bodytag .= Apache::lonmenu::serverform();
$bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
@@ -9242,6 +9247,7 @@
links_disabled -> Links in primary and secondary menus are disabled
(Can enable them once page has loaded - see lonroles.pm
for an example).
+ links_target -> Target for links, e.g., _parent (optional).
=back
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.354 loncom/interface/lonsearchcat.pm:1.355
--- loncom/interface/lonsearchcat.pm:1.354 Wed Aug 26 00:42:39 2020
+++ loncom/interface/lonsearchcat.pm Sun May 29 03:19:00 2022
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.354 2020/08/26 00:42:39 raeburn Exp $
+# $Id: lonsearchcat.pm,v 1.355 2022/05/29 03:19:00 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -178,6 +178,15 @@
if (@allowed_searches ==2) {
$crumb_text = 'Portfolio and Catalog Search';
}
+ my $target = '_top';
+ if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
+ (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
+ if ($env{'form.phase'} =~ /^(sort|run_search)$/) {
+ $target = '_parent';
+ } else {
+ $target = '';
+ }
+ }
&Apache::lonhtmlcommon::add_breadcrumb
({href=>'/adm/searchcat?'.
&Apache::loncommon::inhibit_menu_check().
@@ -185,7 +194,7 @@
'&launch='.$env{'form.launch'}.
'&mode='.$env{'form.mode'},
text=>"$crumb_text",
- target=>'_top',
+ target=>$target,
bug=>'Searching',});
#
if ($env{'form.phase'} !~ m/(basic|adv|course)_search/) {
@@ -2087,7 +2096,14 @@
&Apache::lonnet::logthis(&Apache::lonmysql::get_error());
return;
}
- my $start_page = &Apache::loncommon::start_page('Results',undef);
+ my $target = '_top';
+ my $args;
+ if ((($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) ||
+ (($env{'request.deeplink.login'}) && ($env{'request.deeplink.target'} eq '_self'))) {
+ $target = '_parent';
+ $args = {'links_target' => $target};
+ }
+ my $start_page = &Apache::loncommon::start_page('Results',undef,$args);
my $breadcrumbs=
&Apache::lonhtmlcommon::breadcrumbs('Searching','Searching',
$env{'form.catalogmode'} ne 'import');
@@ -2095,7 +2111,7 @@
my $result = <<END;
$start_page
$breadcrumbs
-<form name="statusform" action="" method="post" target="_top">
+<form name="statusform" action="" method="post" target="$target">
<input type="hidden" name="catalogmode" value="import" />
<input type="hidden" name="acts" value="" />
END
More information about the LON-CAPA-cvs
mailing list