--- loncom/interface/lonwishlist.pm 2012/05/22 16:31:38 1.14 +++ loncom/interface/lonwishlist.pm 2012/06/07 02:28:04 1.15 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Utility-routines for wishlist # -# $Id: lonwishlist.pm,v 1.14 2012/05/22 16:31:38 bisitz Exp $ +# $Id: lonwishlist.pm,v 1.15 2012/06/07 02:28:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,7 +50,7 @@ use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon; use Apache::lonlocal; -use LONCAPA; +use LONCAPA qw(:DEFAULT :match); use Tree; @@ -466,11 +466,13 @@ sub getNodesToArray { Recursive call starting with all children of the root of the tree (parameter nodes is reference to an array containing the nodes of the current level). -=item * &wishlistImport(nodes) +=item * &wishlistImport(nodes, numskipped) Returns the table-HTML-markup for the wishlist in mode "import". - Recursive call starting with all children of the root of the tree (parameter nodes is reference to an array containing the nodes of the current level). - + Recursive call starting with all children of the root of the tree (parameter nodes is reference to an array containing the nodes of the current level). + Side effect: increments the scalar ref: numskipped with a count of items in + Stored Links unavailable for selection, (e.g., now marked obsolete or + inaccessible in Community context). =item * &makePage(mode, marked) @@ -810,7 +812,9 @@ sub JSforWishlist { function setChecked(row,checked) { var childCHECK = document.getElementById(row.id.replace('row','check')); - childCHECK.checked = checked; + if (!childCHECK.disabled) { + childCHECK.checked = checked; + } } function getPreviousFolderRows(row) { @@ -1010,14 +1014,18 @@ sub JSforWishlist { function checkAll() { var checkboxes = document.getElementsByName('check'); for (var i = 0; i < checkboxes.length; i++) { - checkboxes[i].checked = "checked"; + if (!checkboxes[i].disabled) { + checkboxes[i].checked = "checked"; + } } } function uncheckAll() { var checkboxes = document.getElementsByName('check'); for (var i = 0; i < checkboxes.length; i++) { - checkboxes[i].checked = ""; + if (!checkboxes[i].disabled) { + checkboxes[i].checked = ""; + } } } @@ -1336,10 +1344,30 @@ my $wishlistHTMLimport; my $indent = $indentConst; my $form = 1; sub wishlistImport { - my $nodes = shift; + my ($nodes,$numskipped) = @_; + + my ($is_community,%nopick); + if ($env{'request.course.id'}) { + if (&Apache::loncommon::course_type() eq 'Community') { + $is_community = 1; + } + } foreach my $n (@$nodes) { my $index = $n->value()->nindex(); + if ($n->value()->path() =~ m{^(/res/$match_domain/$match_username/)}) { + if ($is_community) { + unless (&Apache::lonnet::allowed('bro',$n->value()->path())) { + $nopick{$n->value()->path()} = $n->value()->title(); + $$numskipped ++; + } + } else { + unless (&Apache::lonnet::allowed('bre',$n->value()->path())) { + $nopick{$n->value()->path()} = $n->value()->title(); + $$numskipped ++; + } + } + } # start row, use data_table routines to set class to LC_even or LC_odd automatically. this row contains a checkbox, the title and the note-icon. # only display the top level entries on load @@ -1348,13 +1376,22 @@ sub wishlistImport { # checkboxes - $wishlistHTMLimport .= ''. - ''. + $wishlistHTMLimport .= ''; + my ($disabled,$onclick,$image,$style); + if ($nopick{$n->value()->path()}) { + $disabled = ' disabled="disabled"'; + $image = 'wishlist-link-lighter.png'; + $style = 'style="color:#808080;"'; + } else { + $onclick = ' onclick="selectAction('."'row".$index."'".')"'; + $image = 'wishlist-link.png'; + } + $wishlistHTMLimport .= ''. ''. ''. - ''. - ''; + ''; + $wishlistHTMLimport .= ''; # entry is a folder if ($n->value()->path() eq '') { @@ -1366,10 +1403,12 @@ sub wishlistImport { } # entry is a link else { - $wishlistHTMLimport .= ''. - 'value()->path()."'".');">'. - 'link'. - $n->value()->title().''; + $wishlistHTMLimport .= ''; + unless ($nopick{$n->value()->path()}) { + $wishlistHTMLimport .= 'value()->path()."'".');">'; + } + $wishlistHTMLimport .= 'link'. + ''.$n->value()->title().''; $form++; } @@ -1398,10 +1437,11 @@ sub wishlistImport { my @children = $n->children(); if ($#children >=0) { $indent += 20; - &wishlistImport(\@children); + &wishlistImport(\@children,$numskipped); $indent -= 20; } } + return; } # Returns the HTML-Markup for wishlist @@ -1786,20 +1826,20 @@ sub makePageImport { my $inner = '

'.&mt('Import Resources from Stored Links').'

'; if (!$rat) { $inner .= - '

'. - &mt('Please note that you can use the checkboxes corresponding to a folder to '. - 'easily check all links within this folder.'. - ' The folder structure itself cannot be imported.'). - ' '.&mt('All checked links will be imported into the current folder of your course.'). - '

'; + ''; } else { $inner .= - '

'. - &mt('Please note that you can use the checkboxes corresponding to a folder to '. - 'easily check all links within this folder.'. - ' The folder structure itself cannot be imported.'). - '

'; + ''; } my %wishlist = &getWishlist(); @@ -1824,13 +1864,17 @@ sub makePageImport { # wishlist-table - &wishlistImport(\@childrenRt); + my $numskipped = 0; + &wishlistImport(\@childrenRt,\$numskipped); if ($wishlistHTMLimport ne '') { $inner .= ''.$wishlistHTMLimport.'
'; } else { $inner .= ''.&mt("Your Stored Links list is currently empty.").''; } + if ($numskipped > 0) { + $inner .= '

'.&mt('Note: where a Stored Link is unavailable for import in the current context it is grayed out.').'

'; + } $wishlistHTMLimport = ''; $inner .= '';