[LON-CAPA-cvs] cvs: loncom /interface lonwishlist.pm

raeburn raeburn at source.lon-capa.org
Wed Jun 6 22:28:04 EDT 2012


raeburn		Thu Jun  7 02:28:04 2012 EDT

  Modified files:              
    /loncom/interface	lonwishlist.pm 
  Log:
  - Import Resources from Stored Links.
    - Instructions converted to bullet points.
    - Checkboxes disabled for items which may not be accessed 
      (e.g., Import into a Community restricted to resources in which user
       has author/co-author/assistant co-author role).
    - Links and icon grayed out for items which are no longer accessible
      (e.g., republished as obsolete by author).
  
  
-------------- next part --------------
Index: loncom/interface/lonwishlist.pm
diff -u loncom/interface/lonwishlist.pm:1.14 loncom/interface/lonwishlist.pm:1.15
--- loncom/interface/lonwishlist.pm:1.14	Tue May 22 16:31:38 2012
+++ loncom/interface/lonwishlist.pm	Thu Jun  7 02:28:04 2012
@@ -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::loncommon();
 use Apache::lonhtmlcommon;
 use Apache::lonlocal;
-use LONCAPA;
+use LONCAPA qw(:DEFAULT :match);
 use Tree;
 
 
@@ -466,11 +466,13 @@
      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 @@
 
     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 @@
     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 $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 @@
 
  
         # checkboxes
-        $wishlistHTMLimport .= '<td>'.
-                               '<input type="checkbox" name="check" id="check'.$index.'" value="'.$index.'" '.
-                               'onclick="selectAction('."'row".$index."'".')" />'.
+        $wishlistHTMLimport .= '<td>';
+        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 .= '<input type="checkbox" name="check" id="check'.$index.'" value="'.$index.'" '.
+                               $disabled.$onclick.' />'.
                                '<input type="hidden" name="title'.$index.'" value="'.&escape($n->value()->title()).'" />'.
                                '<input type="hidden" name="filelink'.$index.'" value="'.&escape($n->value()->path()).'" />'.
-                               '<input type="hidden" name="id'.$index.'" />'.
-                               '</td>';
+                               '<input type="hidden" name="id'.$index.'" />';
+        $wishlistHTMLimport .= '</td>';
 
         # entry is a folder
         if ($n->value()->path() eq '') {
@@ -1366,10 +1403,12 @@
         }
         # entry is a link
         else {
-            $wishlistHTMLimport .= '<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px; min-width: 220px;">'.
-                                   '<a href="javascript:preview('."'".$n->value()->path()."'".');">'.
-                                   '<img src="/res/adm/pages/wishlist-link.png" id="img'.$index.'" alt="link" />'.
-                                   $n->value()->title().'</a></td>';
+            $wishlistHTMLimport .= '<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px; min-width: 220px;">';
+            unless ($nopick{$n->value()->path()}) {
+                $wishlistHTMLimport .= '<a href="javascript:preview('."'".$n->value()->path()."'".');">';
+            }
+            $wishlistHTMLimport .= '<img src="/res/adm/pages/'.$image.'" id="img'.$index.'" alt="link" />'.
+                                   '<span '.$style.'>'.$n->value()->title().'</span></a></td>';
                                    $form++;
         }
 
@@ -1398,10 +1437,11 @@
         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 @@
     my $inner = '<h1>'.&mt('Import Resources from Stored Links').'</h1>';
     if (!$rat) {
         $inner .=
-            '<p class="LC_info">'.
-            &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.').
-            '</p>';
+            '<ul>'.
+            '<li class="LC_info">'.&mt('Use the checkboxes corresponding to a folder to '.
+                'easily check all links within the folder.').'</li>'.
+            '<li class="LC_info">'.&mt('The folder structure itself cannot be imported.').'</li>'.
+            '<li class="LC_info">'.&mt('All checked links will be imported into the current folder of your course.').'</li>'.
+            '</ul>';
     }
     else {
         $inner .=
-            '<p class="LC_info">'.
-            &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.').
-            '</p>';
+            '<ul>'.
+            '<li class="LC_info">'.&mt('Use the checkboxes corresponding to a folder to '.
+                'easily check all links within this folder.').'</li>'.
+            '<li class="LC_info">'.&mt('The folder structure itself cannot be imported.').'</li>'.
+            '</ul>';
     }
     my %wishlist = &getWishlist();
 
@@ -1824,13 +1864,17 @@
 
     
     # wishlist-table
-    &wishlistImport(\@childrenRt);
+    my $numskipped = 0;
+    &wishlistImport(\@childrenRt,\$numskipped);
     if ($wishlistHTMLimport ne '') {
         $inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLimport.'</table>';
     }
     else {
         $inner .= '<span class="LC_info">'.&mt("Your Stored Links list is currently empty.").'</span>';
     }
+    if ($numskipped > 0) {
+        $inner .= '<p class="LC_info">'.&mt('Note: where a Stored Link is unavailable for import in the current context it is grayed out.').'</p>';
+    }
     $wishlistHTMLimport = '';
 
     $inner .= '</form>';


More information about the LON-CAPA-cvs mailing list