version 1.1, 2010/08/10 14:30:20
|
version 1.2, 2010/08/16 08:58:39
|
Line 36 use Apache::lonnet;
|
Line 36 use Apache::lonnet;
|
use Apache::loncommon(); |
use Apache::loncommon(); |
use Apache::lonhtmlcommon; |
use Apache::lonhtmlcommon; |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
use LONCAPA; |
use Tree; |
use Tree; |
|
|
|
|
Line 51 my $indentConst = 20;
|
Line 52 my $indentConst = 20;
|
|
|
# Read wishlist from user-data |
# Read wishlist from user-data |
sub getWishlist { |
sub getWishlist { |
my @wishlistkeys = &Apache::lonnet::getkeys('wishlist'); |
my %wishlist = &Apache::lonnet::dump('wishlist'); |
my %wishlist = &Apache::lonnet::get('wishlist',\@wishlistkeys); |
foreach my $i ( keys %wishlist) { |
foreach my $i (%wishlist) { |
|
#File not found. This appears at the first time using the wishlist |
#File not found. This appears at the first time using the wishlist |
#Create file and put 'root' into it |
#Create file and put 'root' into it |
if ($i =~m/^error:No such file/) { |
if ($i =~m/^error:No such file/) { |
&Apache::lonnet::logthis($i.'! Create file by putting in the "root" of the directory tree.'); |
&Apache::lonnet::logthis($i.'! Create file by putting in the "root" of the directory tree.'); |
&Apache::lonnet::put('wishlist', {'root' => ''}); |
&Apache::lonnet::put('wishlist', {'root' => ''}); |
@wishlistkeys = &Apache::lonnet::getkeys('wishlist'); |
%wishlist = &Apache::lonnet::dump('wishlist'); |
%wishlist = &Apache::lonnet::get('wishlist',\@wishlistkeys); |
|
} |
} |
elsif ($i =~ /^(con_lost|error|no_such_host)/i) { |
elsif ($i =~ /^(con_lost|error|no_such_host)/i) { |
&Apache::lonnet::logthis('ERROR while attempting to get wishlist: '.$i); |
&Apache::lonnet::logthis('ERROR while attempting to get wishlist: '.$i); |
Line 68 sub getWishlist {
|
Line 67 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) { |
if ((keys %wishlist) == 0) { |
&Apache::lonnet::logthis('ERROR while attempting to get wishlist: no keys retrieved!'); |
&Apache::lonnet::logthis('ERROR while attempting to get wishlist: no keys retrieved!'); |
return 'error'; |
return 'error'; |
Line 148 sub moveEntries {
|
Line 148 sub moveEntries {
|
my $indexParent = shift; |
my $indexParent = shift; |
my @nodesToMove = (); |
my @nodesToMove = (); |
|
|
|
# get all nodes that should be moved |
&getNodesToArray(\@childrenRt); |
&getNodesToArray(\@childrenRt); |
foreach my $index (@$indexNodesToMove) { |
foreach my $index (@$indexNodesToMove) { |
my $foundNode = &Tree::getNodeByIndex($index, \@allNodes); |
my $foundNode = &Tree::getNodeByIndex($index, \@allNodes); |
Line 241 sub getfoldersOption {
|
Line 242 sub getfoldersOption {
|
$root = &Tree::HashToTree(); |
$root = &Tree::HashToTree(); |
@childrenRt = $root->children(); |
@childrenRt = $root->children(); |
&getFoldersForOption(\@childrenRt); |
&getFoldersForOption(\@childrenRt); |
my $options = '<option value="" selected="selected"></option>'.$foldersOption; |
my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption; |
$foldersOption = ''; |
$foldersOption = ''; |
return $options; |
return $options; |
} |
} |
Line 321 sub JSforWishlist {
|
Line 322 sub JSforWishlist {
|
'<br/><br/>'. |
'<br/><br/>'. |
'<input type="submit" value="'.$lt{'si'}.'" />'. |
'<input type="submit" value="'.$lt{'si'}.'" />'. |
'<select name="folders">'. |
'<select name="folders">'. |
'<option value="" selected="selected"></option>'. |
'<option value="" selected="selected">('.&mt('Top level').')</option>'. |
$foldersOption. |
$foldersOption. |
'</select>'. |
'</select>'. |
'<input type="button" value="'.$lt{'cl'}.'" onclick="javascript:window.close();" />'. |
'<input type="button" value="'.$lt{'cl'}.'" onclick="javascript:window.close();" />'. |
Line 341 sub JSforWishlist {
|
Line 342 sub JSforWishlist {
|
'<br/><br/>'. |
'<br/><br/>'. |
'<input type="submit" value="'.$lt{'si'}.'" />'. |
'<input type="submit" value="'.$lt{'si'}.'" />'. |
'<select name="folders">'. |
'<select name="folders">'. |
'<option value="" selected="selected"></option>'. |
'<option value="" selected="selected">('.&mt('Top level').')</option>'. |
$foldersOption. |
$foldersOption. |
'</select>'. |
'</select>'. |
'<input type="button" value="'.$lt{'cl'}.'" onclick="javascript:window.close();" />'. |
'<input type="button" value="'.$lt{'cl'}.'" onclick="javascript:window.close();" />'. |
Line 413 sub JSforWishlist {
|
Line 414 sub JSforWishlist {
|
r = true; |
r = true; |
} |
} |
document.getElementsByName('list')[0].setAttribute("action", "/adm/wishlist?mode="+mode); |
document.getElementsByName('list')[0].setAttribute("action", "/adm/wishlist?mode="+mode); |
if(r){ |
if (r) { |
document.getElementsByName('list')[0].submit(); |
document.getElementsByName('list')[0].submit(); |
} |
} |
} |
} |
Line 799 sub JSforWishlist {
|
Line 800 sub JSforWishlist {
|
return false; |
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 |
JAVASCRIPT |
return $js; |
return $js; |
} |
} |
Line 834 sub wishlistView {
|
Line 868 sub wishlistView {
|
# entry is a link |
# entry is a link |
else { |
else { |
$wishlistHTMLview .= '<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px; min-width: 220px;">'. |
$wishlistHTMLview .= '<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" />'. |
'<img src="/res/adm/pages/wishlist-link.png" id="img'.$index.'" alt="link" />'. |
'<a href="'.$n->value()->path().'">'.$n->value()->title().'</a></td>'; |
$n->value()->title().'</a></td>'; |
} |
} |
|
|
# note-icon, different icons for an entries with note and those without |
# note-icon, different icons for an entries with note and those without |
Line 999 sub wishlistMove {
|
Line 1034 sub wishlistMove {
|
} |
} |
# entry is a link |
# entry is a link |
else { |
else { |
if (!$isIn) { |
|
$wishlistHTMLmove .= '<td></td>'. |
|
'<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px; min-width: 220px;">'; |
|
} |
|
# higlight the title, if the link was selected to be moved |
# higlight the title, if the link was selected to be moved |
else { |
my $highlight = ''; |
$wishlistHTMLmove .= '<td></td>'. |
if ($isIn) { |
'<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px; min-width: 220px;'. |
$highlight = 'style="color:red;"'; |
'color:red;">'; |
|
} |
} |
# link-image and title |
# link-image and title |
$wishlistHTMLmove .= '<img src="/res/adm/pages/wishlist-link.png" id="img'.$index.'" alt="link"/>'. |
$wishlistHTMLmove .= '<td></td>'. |
$n->value()->title().'</td>'; |
'<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<=0?$indentConst:$indent).'px; min-width: 220px;">'. |
|
'<a href="javascript:preview('."'".$n->value()->path()."'".');" '.$highlight.'>'. |
|
'<img src="/res/adm/pages/wishlist-link.png" id="img'.$index.'" alt="link"/>'. |
|
$n->value()->title().'</a></td>'; |
} |
} |
|
|
# note-icon, different icons for an entries with note and those without |
# note-icon, different icons for an entries with note and those without |
Line 1045 sub wishlistMove {
|
Line 1078 sub wishlistMove {
|
} |
} |
} |
} |
|
|
|
|
|
|
|
# HTML-Markup for table if in import-mode |
|
my $wishlistHTMLimport; |
|
my $indent = $indentConst; |
|
my $form = 1; |
|
sub wishlistImport { |
|
my $nodes = shift; |
|
|
|
foreach my $n (@$nodes) { |
|
my $index = $n->value()->nindex(); |
|
|
|
# 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 |
|
$wishlistHTMLimport .= ($n->parent()->value() eq 'root')?&Apache::loncommon::start_data_table_row('','row'.$index) |
|
:&Apache::loncommon::continue_data_table_row('LC_hidden','row'.$index); |
|
|
|
|
|
# checkboxes |
|
$wishlistHTMLimport .= '<td>'. |
|
'<input type="checkbox" name="check" id="check'.$index.'" value="'.$index.'" '. |
|
'onclick="selectAction('."'row".$index."'".')"/>'. |
|
'<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>'; |
|
|
|
# entry is a folder |
|
if ($n->value()->path() eq '') { |
|
$wishlistHTMLimport .= '<td id="padd'.$index.'" style="padding-left:'.(($indent-$indentConst)<0?0:($indent-$indentConst)).'px; min-width: 220px;">'. |
|
'<a href="javascript:;" onclick="folderAction('."'row".$index."'".')" style="vertical-align:top">'. |
|
'<img src="/adm/lonIcons/arrow.closed.gif" id="img'.$index.'" alt = "" class="LC_icon"/>'. |
|
'<img src="/adm/lonIcons/navmap.folder.closed.gif" id="imgFolder'.$index.'" alt="folder"/>'. |
|
$n->value()->title().'</a></td>'; |
|
} |
|
# 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>'; |
|
$form++; |
|
} |
|
|
|
# note-icon, different icons for an entries with note and those without |
|
my $noteIMG = 'anot.png'; |
|
|
|
if ($n->value()->note() ne '') { |
|
$noteIMG = 'anot2.png'; |
|
} |
|
|
|
$wishlistHTMLimport .= '<td style="padding-left:10px;"><a href="javascript:;" onclick="setDisplayNote('."'note".$index."'".')">'. |
|
'<img id="noteImg'.$index.'" src="/res/adm/pages/'.$noteIMG.'" alt="'.&mt('Note').'" title="'.&mt('Note').'" '. |
|
' class="LC_icon"/></a></td>'; |
|
|
|
$wishlistHTMLimport .= &Apache::loncommon::end_data_table_row(); |
|
|
|
# start row containing the textarea for the note, do not display note on default, readonly in import-mode |
|
$wishlistHTMLimport .= &Apache::loncommon::continue_data_table_row('LC_hidden','note'.$index). |
|
'<td></td><td>'. |
|
'<textarea id="noteText'.$index.'" cols="25" rows="3" style="width:100%" '. |
|
'name="newnote" readonly="readonly">'. |
|
$n->value()->note().'</textarea></td><td></td>'; |
|
$wishlistHTMLimport .= &Apache::loncommon::end_data_table_row(); |
|
|
|
# if the entry is a folder, it could have other entries as content. if it has, call wishlistImport for those entries |
|
my @children = $n->children(); |
|
if ($#children >=0) { |
|
$indent += 20; |
|
&wishlistImport(\@children); |
|
$indent -= 20; |
|
} |
|
} |
|
} |
|
|
# Returns the HTML-Markup for wishlist |
# Returns the HTML-Markup for wishlist |
sub makePage { |
sub makePage { |
my $mode = shift; |
my $mode = shift; |
Line 1142 sub makePage {
|
Line 1250 sub makePage {
|
'<input type="hidden" id="action" name="action" value=""/>'; |
'<input type="hidden" id="action" name="action" value=""/>'; |
|
|
# only display subbox in view- or edit-mode |
# only display subbox in view- or edit-mode |
if ($mode ne 'move') { |
if ($mode eq 'view' || $mode eq 'edit') { |
$inner .= $subbox; |
$inner .= $subbox; |
} |
} |
|
|
Line 1155 sub makePage {
|
Line 1263 sub makePage {
|
$inner .= &Apache::loncommon::end_data_table(); |
$inner .= &Apache::loncommon::end_data_table(); |
} |
} |
else { |
else { |
$inner .= '<span class="LC_info">'.&mt("Your wihlist ist currently empty.").'</span>'; |
$inner .= '<span class="LC_info">'.&mt("Your wishlist ist currently empty.").'</span>'; |
} |
} |
$wishlistHTMLedit = ''; |
$wishlistHTMLedit = ''; |
} |
} |
Line 1165 sub makePage {
|
Line 1273 sub makePage {
|
$inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLview.'</table>'; |
$inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLview.'</table>'; |
} |
} |
else { |
else { |
$inner .= '<span class="LC_info">'.&mt("Your wihlist ist currently empty.").'</span>'; |
$inner .= '<span class="LC_info">'.&mt("Your wishlist ist currently empty.").'</span>'; |
} |
} |
$wishlistHTMLview = ''; |
$wishlistHTMLview = ''; |
} |
} |
Line 1177 sub makePage {
|
Line 1285 sub makePage {
|
if ($markStr) { |
if ($markStr) { |
$markStr = substr($markStr, 0, length($markStr)-1); |
$markStr = substr($markStr, 0, length($markStr)-1); |
$inner .= '<input type="hidden" value="'.$markStr.'" name="markedToMove"/>'; |
$inner .= '<input type="hidden" value="'.$markStr.'" name="markedToMove"/>'; |
$inner .= '<span class="LC_info">'.&mt('You have selected the red marked entries to be moved to another folder. '. |
$inner .= '<p><span class="LC_info">'.&mt('You have selected the red marked entries to be moved to another folder. '. |
'Now choose the new destination folder.').'</span><br/><br/>'; |
'Now choose the new destination folder.').'</span></p>'; |
&wishlistMove(\@childrenRt, $marked); |
&wishlistMove(\@childrenRt, $marked); |
$inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLmove.'</table><br/><br/>'; |
$inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLmove.'</table><br/><br/>'; |
$inner .= '<input type="button" value="'.&mt('Move').'" onclick="setFormAction('."'','view'".'); selectDestinationFolder()"/>'. |
$inner .= '<input type="button" value="'.&mt('Move').'" onclick="setFormAction('."'','view'".'); selectDestinationFolder()"/>'. |
Line 1188 sub makePage {
|
Line 1296 sub makePage {
|
'<td>'.&mt('Top level').'</td><td></td></tr>'; |
'<td>'.&mt('Top level').'</td><td></td></tr>'; |
} |
} |
else { |
else { |
$inner .= '<span class="LC_info">'.&mt("You haven't marked any entry to move.").'</span><br/>'. |
$inner .= '<p><span class="LC_info">'.&mt("You haven't marked any entry to move.").'</span></p>'. |
'<input type="button" value="'.&mt('Back').'" onclick="go('."'/adm/wishlist'".')"/>'; |
'<input type="button" value="'.&mt('Back').'" onclick="go('."'/adm/wishlist'".')"/>'; |
} |
} |
} |
} |
Line 1199 sub makePage {
|
Line 1307 sub makePage {
|
# end_page |
# end_page |
my $endPage = &Apache::loncommon::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; |
my $page = $startPage.$breadcrumbs.$js.$inner.$endPage; |
|
|
return $page; |
return $page; |
Line 1223 sub makePageSet {
|
Line 1331 sub makePageSet {
|
# end_page |
# end_page |
my $endPage = &Apache::loncommon::end_page(); |
my $endPage = &Apache::loncommon::end_page(); |
|
|
# put all page-elements togther |
# put all page-elements together |
my $page = $startPage.$inner.$endPage; |
my $page = $startPage.$inner.$endPage; |
|
|
return $page; |
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 = '<h1>'.&mt('Import Resources from Wishlist').'</h1>'; |
|
$inner .= '<p><span 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 can't be imported. ". |
|
"All checked links will be imported into the current folder of your course.").'</span></p>'; |
|
|
|
my %wishlist = &getWishlist(); |
|
my $fnum = (keys %wishlist)-1; |
|
|
|
$inner .= '<form method="post" name="groupsort">'. |
|
'<input type="hidden" value="'.$fnum.'" name="fnum">'. |
|
'<input type="button" onclick="javascript:checkAll()" id="checkallbutton" value="'.&mt('Check All').'">'. |
|
'<input type="button" onclick="javascript:uncheckAll()" id="uncheckallbutton" value="'.&mt('Uncheck All').'">'. |
|
'<input type="button" value="'.&mt('Import Checked').'" onclick="finish_import();">'. |
|
'<input type="button" value="'.&mt('Cancel').'" onclick="window.close();"><br/><br/>'; |
|
|
|
|
|
# wishlist-table |
|
&wishlistImport(\@childrenRt); |
|
if ($wishlistHTMLimport ne '') { |
|
$inner .= '<table class="LC_data_table LC_tableOfContent">'.$wishlistHTMLimport.'</table>'; |
|
} |
|
else { |
|
$inner .= '<span class="LC_info">'.&mt("Your wishlist ist currently empty.").'</span>'; |
|
} |
|
$wishlistHTMLimport = ''; |
|
|
|
$inner .= '</form>'; |
|
|
|
# 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 |
# Returns the HTML-Markup for error-page |
sub makeErrorPage { |
sub makeErrorPage { |
# breadcrumbs and start_page |
# breadcrumbs and start_page |
Line 1250 sub makeErrorPage {
|
Line 1405 sub makeErrorPage {
|
# end_page |
# end_page |
my $endPage = &Apache::loncommon::end_page(); |
my $endPage = &Apache::loncommon::end_page(); |
|
|
# put all page-elements togther |
# put all page-elements together |
my $page = $startPage.$breadcrumbs.$inner.$endPage; |
my $page = $startPage.$breadcrumbs.$inner.$endPage; |
|
|
return $page; |
return $page; |
Line 1349 sub handler {
|
Line 1504 sub handler {
|
elsif ($env{'form.mode'} eq 'move') { |
elsif ($env{'form.mode'} eq 'move') { |
$page = &makePage("move", \@marked); |
$page = &makePage("move", \@marked); |
} |
} |
|
elsif ($env{'form.mode'} eq 'import') { |
|
$page = &makePageImport(); |
|
} |
elsif ($env{'form.mode'} eq 'set') { |
elsif ($env{'form.mode'} eq 'set') { |
$page = &makePageSet(); |
$page = &makePageSet(); |
} |
} |
Line 1518 sub HashToTree {
|
Line 1676 sub HashToTree {
|
} |
} |
} |
} |
# if there are nodes, build up the tree-structure |
# if there are nodes, build up the tree-structure |
if (defined $TreeHash{'root'}) { |
if (defined $TreeHash{'root'} && $TreeHash{'root'} ne '') { |
my @childrenRtIn = @{ $TreeHash{'root'} }; |
my @childrenRtIn = @{ $TreeHash{'root'} }; |
&buildTree(\$root, \@childrenRtIn,\@TreeNodes,\%TreeHash); |
&buildTree(\$root, \@childrenRtIn,\@TreeNodes,\%TreeHash); |
} |
} |