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

wenzelju wenzelju@source.lon-capa.org
Wed, 25 Aug 2010 12:38:45 -0000


wenzelju		Wed Aug 25 12:38:45 2010 EDT

  Modified files:              
    /loncom/interface	lonmenu.pm lonsearchcat.pm lonwishlist.pm 
  Log:
  Save string for folder-dropdown-list (when setting a new link viewing a resource) in user-data. So a call from lonwishlist-routine in lonmenu/lonsearchcat is not necessary (i.e. no issue with modules not supporting Apache::Constants).
  
  
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.337 loncom/interface/lonmenu.pm:1.338
--- loncom/interface/lonmenu.pm:1.337	Tue Aug 24 09:11:38 2010
+++ loncom/interface/lonmenu.pm	Wed Aug 25 12:38:45 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.337 2010/08/24 09:11:38 wenzelju Exp $
+# $Id: lonmenu.pm,v 1.338 2010/08/25 12:38:45 wenzelju Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1123,6 +1123,10 @@
     # it is split into 3 parts and the inputfields for title and path are left out
     # these fields are inserted later to set the values for title and path
     # automatically via JavaScript (document.title and location.pathname) 
+    my %folders = &Apache::lonnet::get('wishlist',['folders']);
+    if ($folders{'folders'} eq '') {
+        $folders{'folders'} = '<option value="" selected="selected">('.&mt('Top level').')</option>';
+    }
     my $in_page_wishlistlink1 = '<h1>'.&mt('Set a link to wishlist').'</h1>'.
                                 '<form method="post" name="newlink" action="/adm/wishlist?mode=set" '.
                                 'onsubmit="return newlinksubmit();" >'.
@@ -1140,7 +1144,7 @@
                                 '<br/><br/>'.
                                 '<input type="submit" value="'.&mt('Save in').'" />'.
                                 '<select name="folders">'.
-                                &Apache::lonwishlist::getfoldersOption().
+                                $folders{'folders'}.
                                 '</select>'.
                                 '<input type="button" value="'.&mt('cancel').'" onclick="javascript:window.close();" />'.
                                 '</form>';
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.325 loncom/interface/lonsearchcat.pm:1.326
--- loncom/interface/lonsearchcat.pm:1.325	Fri Aug 13 13:32:36 2010
+++ loncom/interface/lonsearchcat.pm	Wed Aug 25 12:38:45 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.325 2010/08/13 13:32:36 wenzelju Exp $
+# $Id: lonsearchcat.pm,v 1.326 2010/08/25 12:38:45 wenzelju Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3369,6 +3369,10 @@
     # it is split into 3 parts and the inputfields for title and path are left out
     # these fields are inserted later to set the values for title and path
     # automatically via JavaScript (document.title and location.pathname) 
+    my %folders = &Apache::lonnet::get('wishlist',['folders']);
+    if ($folders{'folders'} eq '') {
+        $folders{'folders'} = '<option value="" selected="selected">('.&mt('Top level').')</option>';
+    }
     my $start_page_wishlistlink = 
         &Apache::loncommon::start_page('Set link to wishlist',undef,
 				       {'only_body' => 1,
@@ -3394,7 +3398,7 @@
                                 '<br/><br/>'.
                                 '<input type="submit" value="'.&mt('Save in').'" />'.
                                 '<select name="folders">'.
-                                &Apache::lonwishlist::getfoldersOption().
+                                $folders{'folders'}.
                                 '</select>'.
                                 '<input type="button" value="'.&mt('cancel').'" onclick="javascript:window.close();" />'.
                                 '</form>';
Index: loncom/interface/lonwishlist.pm
diff -u loncom/interface/lonwishlist.pm:1.7 loncom/interface/lonwishlist.pm:1.8
--- loncom/interface/lonwishlist.pm:1.7	Fri Aug 20 10:38:41 2010
+++ loncom/interface/lonwishlist.pm	Wed Aug 25 12:38:45 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the wishlist
 #
-# $Id: lonwishlist.pm,v 1.7 2010/08/20 10:38:41 wenzelju Exp $
+# $Id: lonwishlist.pm,v 1.8 2010/08/25 12:38:45 wenzelju Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,6 +61,7 @@
 my @allFolders;
 my @allNodes;
 my $indentConst = 20;
+my $foldersOption;
 
 =pod
 
@@ -70,7 +71,7 @@
 
 =item * &getWishlist()
 
-     Get the wishlist-data via lonnet::dump() and returns the got data in a hash.
+     Get the wishlist-data via lonnet::getkeys() and lonnet::get() and returns the got data in a hash.
 
 
 =item * &putWishlist(wishlist)
@@ -90,14 +91,18 @@
 
 # Read wishlist from user-data
 sub getWishlist {
-    my %wishlist = &Apache::lonnet::dump('wishlist');
+    my @keys = &Apache::lonnet::getkeys('wishlist');
+    my %wishlist = &Apache::lonnet::get('wishlist',\@keys);
     foreach my $i ( keys %wishlist) {
         #File not found. This appears at the first time using the wishlist
         #Create file and put 'root' into it
        if ($i =~m/^error:No such file/) {
            &Apache::lonnet::logthis($i.'! Create file by putting in the "root" of the directory tree.');
            &Apache::lonnet::put('wishlist', {'root' => ''});
-           %wishlist = &Apache::lonnet::dump('wishlist');
+           my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>';
+           &Apache::lonnet::put('wishlist', {'folders' => $options});
+           @keys = &Apache::lonnet::getkeys('wishlist');
+           %wishlist = &Apache::lonnet::get('wishlist',\@keys);
        }
        elsif ($i =~ /^(con_lost|error|no_such_host)/i) {
            &Apache::lonnet::logthis('ERROR while attempting to get wishlist: '.$i);
@@ -105,7 +110,7 @@
        }
     }
 
-    # if we got no keys in hash returned by dump(), return error.
+    # if we got no keys in hash returned by get(), return error.
     # wishlist will not be loaded, instead the user will be asked to try again later
     if ((keys %wishlist) == 0) {
         &Apache::lonnet::logthis('ERROR while attempting to get wishlist: no keys retrieved!');
@@ -119,6 +124,11 @@
 # Write wishlist to user-data
 sub putWishlist {
     my $wishlist = shift;
+    $foldersOption = '';
+    &getFoldersForOption(\@childrenRt);
+    my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;
+    $foldersOption = '';
+    $$wishlist{'folders'} = $options;
     &Apache::lonnet::put('wishlist',$wishlist);
 }
 
@@ -327,11 +337,6 @@
      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 * &getfoldersOption()
-
-     Returns the option-tag build by &getFoldersForOption(nodes). Use it to transfer this to other modules (e.g. lonmenu.pm). 
-
-
 =item * &getFoldersToArray(children)
 
      Puts all nodes that represent folders in the wishlist into an array. 
@@ -352,7 +357,6 @@
 # Return the names for all exiting folders in option-tags, so
 # a new link or a new folder can be created in an existing folder
 my $indent = 0;
-my $foldersOption;
 sub getFoldersForOption {
     my $nodes = shift;
 
@@ -373,22 +377,6 @@
 }
 
 
-sub getfoldersOption {
-   if (&getWishlist ne 'error') {
-       %TreeHash = &getWishlist();
-       $root = &Tree::HashToTree();
-       @childrenRt = $root->children();
-       &getFoldersForOption(\@childrenRt);
-       my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;
-       $foldersOption = '';
-       return $options;
-   }
-   else {
-       return '';
-   }
-}
-
-
 # Put all folder-nodes to an array
 sub getFoldersToArray {
     my $children = shift;
@@ -2039,7 +2027,7 @@
         if ($key eq 'root') {
             $root = Tree->new("root");
         }
-        else {
+        elsif ($key ne 'folders') {
         my @attributes = @{ $TreeHash{$key} };
         my $tmpNode;
             $tmpNode = Tree->new(Entry->new(title=>$attributes[0],