--- loncom/interface/lonwishlist.pm 2010/08/10 14:30:20 1.1
+++ loncom/interface/lonwishlist.pm 2010/08/16 08:58:39 1.2
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the wishlist
#
-# $Id: lonwishlist.pm,v 1.1 2010/08/10 14:30:20 wenzelju Exp $
+# $Id: lonwishlist.pm,v 1.2 2010/08/16 08:58:39 wenzelju Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,6 +36,7 @@ use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
+use LONCAPA;
use Tree;
@@ -51,16 +52,14 @@ my $indentConst = 20;
# Read wishlist from user-data
sub getWishlist {
- my @wishlistkeys = &Apache::lonnet::getkeys('wishlist');
- my %wishlist = &Apache::lonnet::get('wishlist',\@wishlistkeys);
- foreach my $i (%wishlist) {
+ my %wishlist = &Apache::lonnet::dump('wishlist');
+ 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' => ''});
- @wishlistkeys = &Apache::lonnet::getkeys('wishlist');
- %wishlist = &Apache::lonnet::get('wishlist',\@wishlistkeys);
+ %wishlist = &Apache::lonnet::dump('wishlist');
}
elsif ($i =~ /^(con_lost|error|no_such_host)/i) {
&Apache::lonnet::logthis('ERROR while attempting to get wishlist: '.$i);
@@ -68,7 +67,8 @@ sub getWishlist {
}
}
- #If hash is empty, put 'root' into it, so we got a node to start the tree
+ # if we got no keys in hash returned by dump(), 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!');
return 'error';
@@ -148,6 +148,7 @@ sub moveEntries {
my $indexParent = shift;
my @nodesToMove = ();
+ # get all nodes that should be moved
&getNodesToArray(\@childrenRt);
foreach my $index (@$indexNodesToMove) {
my $foundNode = &Tree::getNodeByIndex($index, \@allNodes);
@@ -241,7 +242,7 @@ sub getfoldersOption {
$root = &Tree::HashToTree();
@childrenRt = $root->children();
&getFoldersForOption(\@childrenRt);
- my $options = ''.$foldersOption;
+ my $options = ''.$foldersOption;
$foldersOption = '';
return $options;
}
@@ -321,7 +322,7 @@ sub JSforWishlist {
'
'.
''.
''.
''.
@@ -341,7 +342,7 @@ sub JSforWishlist {
'
'.
''.
''.
''.
@@ -413,7 +414,7 @@ sub JSforWishlist {
r = true;
}
document.getElementsByName('list')[0].setAttribute("action", "/adm/wishlist?mode="+mode);
- if(r){
+ if (r) {
document.getElementsByName('list')[0].submit();
}
}
@@ -799,6 +800,39 @@ sub JSforWishlist {
return false;
}
+ function preview(url) {
+ var newWin = window.open(url+'?inhibitmenu=yes','preview','width=560,height=350,scrollbars=yes');
+ newWin.focus();
+ }
+
+ function finish_import() {
+ opener.document.forms.simpleedit.importdetail.value='';
+ for (var num = 0; num < document.forms.groupsort.fnum.value; num++) {
+ if (eval("document.forms.groupsort.check"+num+".checked") && eval("document.forms.groupsort.filelink"+num+".value") != '') {
+ opener.document.forms.simpleedit.importdetail.value+='&'+
+ eval("document.forms.groupsort.title"+num+".value")+'='+
+ eval("document.forms.groupsort.filelink"+num+".value")+'='+
+ eval("document.forms.groupsort.id"+num+".value");
+ }
+ }
+ opener.document.forms.simpleedit.submit();
+ self.close();
+ }
+
+ function checkAll() {
+ var checkboxes = document.getElementsByName('check');
+ for (var i = 0; i < checkboxes.length; i++) {
+ checkboxes[i].checked = "checked";
+ }
+ }
+
+ function uncheckAll() {
+ var checkboxes = document.getElementsByName('check');
+ for (var i = 0; i < checkboxes.length; i++) {
+ checkboxes[i].checked = "";
+ }
+ }
+
JAVASCRIPT
return $js;
}
@@ -834,8 +868,9 @@ sub wishlistView {
# entry is a link
else {
$wishlistHTMLview .= '
'.&mt('You have selected the red marked entries to be moved to another folder. '. + 'Now choose the new destination folder.').'
'; &wishlistMove(\@childrenRt, $marked); $inner .= ''.&mt("You haven't marked any entry to move.").'
'. ''; } } @@ -1199,7 +1307,7 @@ sub makePage { # end_page my $endPage = &Apache::loncommon::end_page(); - # put all page-elements togther + # put all page-elements together my $page = $startPage.$breadcrumbs.$js.$inner.$endPage; return $page; @@ -1223,13 +1331,60 @@ sub makePageSet { # end_page my $endPage = &Apache::loncommon::end_page(); - # put all page-elements togther + # put all page-elements together my $page = $startPage.$inner.$endPage; return $page; } +# Returns the HTML-Markup for the page, shown when links should be imported into a course +sub makePageImport { + # start_page + my $startPage = &Apache::loncommon::start_page('Wishlist',undef, + {'only_body' => 1}); + + # get javascript-code for wishlist-interactions + my $js = &JSforWishlist(); + + my $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 can't be imported. ". + "All checked links will be imported into the current folder of your course.").'
'; + + my %wishlist = &getWishlist(); + my $fnum = (keys %wishlist)-1; + + $inner .= ''; + + # end_page + my $endPage = &Apache::loncommon::end_page(); + + # put all page-elements together + my $page = $startPage.$js.$inner.$endPage; + + return $page; +} + + # Returns the HTML-Markup for error-page sub makeErrorPage { # breadcrumbs and start_page @@ -1250,7 +1405,7 @@ sub makeErrorPage { # end_page my $endPage = &Apache::loncommon::end_page(); - # put all page-elements togther + # put all page-elements together my $page = $startPage.$breadcrumbs.$inner.$endPage; return $page; @@ -1349,6 +1504,9 @@ sub handler { elsif ($env{'form.mode'} eq 'move') { $page = &makePage("move", \@marked); } + elsif ($env{'form.mode'} eq 'import') { + $page = &makePageImport(); + } elsif ($env{'form.mode'} eq 'set') { $page = &makePageSet(); } @@ -1518,7 +1676,7 @@ sub HashToTree { } } # if there are nodes, build up the tree-structure - if (defined $TreeHash{'root'}) { + if (defined $TreeHash{'root'} && $TreeHash{'root'} ne '') { my @childrenRtIn = @{ $TreeHash{'root'} }; &buildTree(\$root, \@childrenRtIn,\@TreeNodes,\%TreeHash); }