[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf startup.pl /interface lonmenu.pm lonsearchcat.pm lonwishlist.pm lonwishlistdisplay.pm doc/loncapafiles loncapafiles.lpml
wenzelju
wenzelju@source.lon-capa.org
Thu, 27 Jan 2011 14:38:45 -0000
This is a MIME encoded message
--wenzelju1296139125
Content-Type: text/plain
wenzelju Thu Jan 27 14:38:45 2011 EDT
Added files:
/loncom/interface lonwishlistdisplay.pm
Modified files:
/doc/loncapafiles loncapafiles.lpml
/loncom loncapa_apache.conf startup.pl
/loncom/interface lonmenu.pm lonsearchcat.pm lonwishlist.pm
Log:
- Split lonwishlist into two modules, one for displaying (handler) and one utility-module, to avoid problems with Apache::constants when calling methods from lonwishlist (e.g. need to call lonwishlist-method in lonmenu and lonmenu is used in printout.pl -> outside of mod_perl).
- Moving entries in wishlist: corrected warning shown when no entry is selected
- Some code optimizations
- Still some things do not work perfect -> in progress
--wenzelju1296139125
Content-Type: text/plain
Content-Disposition: attachment; filename="wenzelju-20110127143845.txt"
Index: doc/loncapafiles/loncapafiles.lpml
diff -u doc/loncapafiles/loncapafiles.lpml:1.725 doc/loncapafiles/loncapafiles.lpml:1.726
--- doc/loncapafiles/loncapafiles.lpml:1.725 Tue Jan 18 00:21:52 2011
+++ doc/loncapafiles/loncapafiles.lpml Thu Jan 27 14:38:36 2011
@@ -2,7 +2,7 @@
"http://lpml.sourceforge.net/DTD/lpml.dtd">
<!-- loncapafiles.lpml -->
-<!-- $Id: loncapafiles.lpml,v 1.725 2011/01/18 00:21:52 www Exp $ -->
+<!-- $Id: loncapafiles.lpml,v 1.726 2011/01/27 14:38:36 wenzelju Exp $ -->
<!--
@@ -7585,12 +7585,20 @@
<target dist='default'>home/httpd/lib/perl/Apache/lonwishlist.pm</target>
<categoryname>handler</categoryname>
<description>
-Interface to modify the wishlist (add new links and folders,
+Utilities to modify the wishlist (add new links and folders,
edit, move, sort or delete existing links and folders).
Links from the wishlist can be imported into courses.</description>
<status>works/unverified</status>
</file>
<file>
+<source>loncom/interface/lonwishlistdisplay.pm</source>
+<target dist='default'>home/httpd/lib/perl/Apache/lonwishlistdisplay.pm</target>
+<categoryname>handler</categoryname>
+<description>
+Module for displaying the wishlist.</description>
+<status>works/unverified</status>
+</file>
+<file>
<source>loncom/automation/Autocreate.pl</source>Autocreate.pl
<target dist='default'>home/httpd/perl/Autocreate.pl</target>
<categoryname>script</categoryname>
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.201 loncom/loncapa_apache.conf:1.202
--- loncom/loncapa_apache.conf:1.201 Tue Jan 18 00:21:57 2011
+++ loncom/loncapa_apache.conf Thu Jan 27 14:38:40 2011
@@ -1,7 +1,7 @@
##
## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
##
-## $Id: loncapa_apache.conf,v 1.201 2011/01/18 00:21:57 www Exp $
+## $Id: loncapa_apache.conf,v 1.202 2011/01/27 14:38:40 wenzelju Exp $
##
#
@@ -1241,7 +1241,7 @@
Require valid-user
PerlAuthzHandler Apache::lonacc
SetHandler perl-script
-PerlHandler Apache::lonwishlist
+PerlHandler Apache::lonwishlistdisplay
ErrorDocument 403 /adm/login
ErrorDocument 406 /adm/roles
ErrorDocument 500 /adm/errorhandler
Index: loncom/startup.pl
diff -u loncom/startup.pl:1.37 loncom/startup.pl:1.38
--- loncom/startup.pl:1.37 Tue Aug 24 09:11:35 2010
+++ loncom/startup.pl Thu Jan 27 14:38:40 2011
@@ -1,5 +1,5 @@
#!/usr/bin/perl
-# $Id: startup.pl,v 1.37 2010/08/24 09:11:35 wenzelju Exp $
+# $Id: startup.pl,v 1.38 2011/01/27 14:38:40 wenzelju Exp $
BEGIN {
eval "use Apache2::compat();";
@@ -115,6 +115,7 @@
use Apache::lonwrapper();
use Apache::admannotations();
use Apache::lonwishlist();
+use Apache::lonwishlistdisplay();
use Apache::style();
use Apache::lontex();
use Apache::matchresponse();
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.345 loncom/interface/lonmenu.pm:1.346
--- loncom/interface/lonmenu.pm:1.345 Tue Jan 18 22:59:06 2011
+++ loncom/interface/lonmenu.pm Thu Jan 27 14:38:44 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the menu
#
-# $Id: lonmenu.pm,v 1.345 2011/01/18 22:59:06 www Exp $
+# $Id: lonmenu.pm,v 1.346 2011/01/27 14:38:44 wenzelju Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -155,6 +155,7 @@
use Apache::lonlocal;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities();
+use Apache::lonwishlist();
use vars qw(@desklines %category_names %category_members %category_positions
$readdesk @primary_menu @secondary_menu);
@@ -1105,52 +1106,10 @@
my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
&mt('Switch server?');
- my $start_page_wishlistlink =
- &Apache::loncommon::start_page('Set link to wishlist',undef,
- {'only_body' => 1,
- 'js_ready' => 1,
- 'bgcolor' => '#FFFFFF',});
-
- my $warningLink = &mt('You must insert a title!');
-
- # HTML-Markup for 'Set a link for this resource to wishlist'
- # this is written via JavaScript document.write (function set_wishlistlink)
- # 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();" >'.
- &Apache::lonhtmlcommon::start_pick_box().
- &Apache::lonhtmlcommon::row_title(&mt('Link Title'));
-
- my $in_page_wishlistlink2 = &Apache::lonhtmlcommon::row_closure().
- &Apache::lonhtmlcommon::row_title(&mt('Path'));
-
- my $in_page_wishlistlink3 = &Apache::lonhtmlcommon::row_closure().
- &Apache::lonhtmlcommon::row_title(&mt('Note')).
- '<textarea name="note" rows="3" cols="35" style="width:100%"></textarea>'.
- &Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box().
- '<br/><br/>'.
- '<input type="submit" value="'.&mt('Save in').'" />'.
- '<select name="folders">'.
- $folders{'folders'}.
- '</select>'.
- '<input type="button" value="'.&mt('cancel').'" onclick="javascript:window.close();" />'.
- '</form>';
-
- # remove all \n for inserting on javascript document.write
- $in_page_wishlistlink1 =~ s/\n//g;
- $in_page_wishlistlink2 =~ s/\n//g;
- $in_page_wishlistlink3 =~ s/\n//g;
-
- my $end_page_wishlistlink =
- &Apache::loncommon::end_page({'js_ready' => 1});
+ my $wishlistpopup;
+ if (&Apache::lonwishlist::getWishlist() ne 'error') {
+ $wishlistpopup = &Apache::lonwishlist::makePopUpNewLink();
+ }
return (<<ENDUTILITY)
@@ -1276,32 +1235,7 @@
}
function set_wishlistlink(title, path) {
- if (!title) {
- title=document.title;
- }
- if (!path) {
- path=location.pathname;
- }
- title = title.replace(/^LON-CAPA /,'');
- wishlistlink=window.open('','wishlistNewLink','width=560,height=350,scrollbars=0');
- wishlistlink.document.write(
- '$start_page_wishlistlink'
- +'<script type="text\/javascript">'
- +'function newlinksubmit(){'
- +'var title = document.getElementsByName("title")[0].value;'
- +'if (!title) {'
- +'alert("$warningLink");'
- +'return false;}'
- +'return true;}'
- +'<\/scr'+'ipt>'
- +'$in_page_wishlistlink1'
- +'<input type="text" name="title" size="45" value="'+title+'"/>'
- +'$in_page_wishlistlink2'
- +'<input type="text" name="path" size="45" value="'+path+'" '
- +'readonly="readonly" style="background-color: #DDDDDD"/>'
- +'$in_page_wishlistlink3'
- +'$end_page_wishlistlink' );
- wishlistlink.document.close();
+ $wishlistpopup
}
function open_Wishlist_Import(rat) {
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.327 loncom/interface/lonsearchcat.pm:1.328
--- loncom/interface/lonsearchcat.pm:1.327 Mon Jan 17 20:18:02 2011
+++ loncom/interface/lonsearchcat.pm Thu Jan 27 14:38:44 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Search Catalog
#
-# $Id: lonsearchcat.pm,v 1.327 2011/01/17 20:18:02 www Exp $
+# $Id: lonsearchcat.pm,v 1.328 2011/01/27 14:38:44 wenzelju Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -78,6 +78,7 @@
use Parse::RecDescent;
use Apache::lonnavmaps;
use Apache::lonindexer();
+use Apache::lonwishlist();
use LONCAPA;
######################################################################
@@ -3058,83 +3059,17 @@
</script>
SCRIPT
- # HTML-Markup for 'Set a link for this resource to wishlist'
- # this is written via JavaScript document.write (function set_wishlistlink)
- # 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,
- 'js_ready' => 1,
- 'bgcolor' => '#FFFFFF',});
-
- my $warningLink = &mt('You must insert a title!');
-
- 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();" >'.
- &Apache::lonhtmlcommon::start_pick_box().
- &Apache::lonhtmlcommon::row_title(&mt('Link Title'));
-
- my $in_page_wishlistlink2 = &Apache::lonhtmlcommon::row_closure().
- &Apache::lonhtmlcommon::row_title(&mt('Path'));
-
- my $in_page_wishlistlink3 = &Apache::lonhtmlcommon::row_closure().
- &Apache::lonhtmlcommon::row_title(&mt('Note')).
- '<textarea name="note" rows="3" cols="35" style="width:100%"></textarea>'.
- &Apache::lonhtmlcommon::row_closure(1).
- &Apache::lonhtmlcommon::end_pick_box().
- '<br/><br/>'.
- '<input type="submit" value="'.&mt('Save in').'" />'.
- '<select name="folders">'.
- $folders{'folders'}.
- '</select>'.
- '<input type="button" value="'.&mt('cancel').'" onclick="javascript:window.close();" />'.
- '</form>';
-
- # remove all \n for inserting on javascript document.write
- $in_page_wishlistlink1 =~ s/\n//g;
- $in_page_wishlistlink2 =~ s/\n//g;
- $in_page_wishlistlink3 =~ s/\n//g;
-
- my $end_page_wishlistlink =
- &Apache::loncommon::end_page({'js_ready' => 1});
+ my $wishlistpopup;
+ if (&Apache::lonwishlist::getWishlist() ne 'error') {
+ $wishlistpopup = &Apache::lonwishlist::makePopUpNewLink();
+ }
# Add JavaScript-function to set link for a ressource to wishlist
$js.=<<SCRIPT;
<script type="text/javascript">
// <![CDATA[
function set_wishlistlink(title, path){
- if(!title){
- title=document.title;
- }
- if(!path){
- path=location.pathname;
- }
- wishlistlink=window.open('','wishlistNewLink','width=560,height=350,scrollbars=0');
- wishlistlink.document.write(
- '$start_page_wishlistlink'
- +'<script type="text\/javascript">'
- +'function newlinksubmit(){'
- +'var title = document.getElementsByName("title")[0].value;'
- +'if (!title) {'
- +'alert("$warningLink");'
- +'return false;}'
- +'return true;}'
- +'<\/scr'+'ipt>'
- +'$in_page_wishlistlink1'
- +'<input type="text" name="title" size="45" value="'+title+'"/>'
- +'$in_page_wishlistlink2'
- +'<input type="text" name="path" size="45" value="'+path+'" '
- +'readonly="readonly" style="background-color: #DDDDDD"/>'
- +'$in_page_wishlistlink3'
- +'$end_page_wishlistlink' );
- wishlistlink.document.close();
+ $wishlistpopup;
}
// ]]>
Index: loncom/interface/lonwishlist.pm
diff -u loncom/interface/lonwishlist.pm:1.8 loncom/interface/lonwishlist.pm:1.9
--- loncom/interface/lonwishlist.pm:1.8 Wed Aug 25 12:38:45 2010
+++ loncom/interface/lonwishlist.pm Thu Jan 27 14:38:44 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
-# Routines to control the wishlist
+# Utility-routines for wishlist
#
-# $Id: lonwishlist.pm,v 1.8 2010/08/25 12:38:45 wenzelju Exp $
+# $Id: lonwishlist.pm,v 1.9 2011/01/27 14:38:44 wenzelju Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -39,12 +39,13 @@
The wishlist-module uses the CPAN-module "Tree" for easily handling the directory-structure of the wishlist. Each node in the tree has an index to be referenced by.
+=back
+
=cut
package Apache::lonwishlist;
use strict;
-use Apache::Constants qw(:common);
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
@@ -124,11 +125,6 @@
# 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);
}
@@ -193,7 +189,11 @@
# Create a new entry
sub newEntry() {
- my ($title, $path, $note) = @_;
+ my ($rootgiven, $title, $path, $note) = @_;
+
+ $root = $rootgiven;
+ @childrenRt = $root->children();
+
my $date = gmtime();
# Create Entry-Object
my $entry = Entry->new(title => $title, path => $path, note => $note, date => $date);
@@ -204,53 +204,69 @@
if ($folderIndex ne '') {
@allFolders = ();
&getFoldersToArray(\@childrenRt);
- my $folderToInsertOn = &Tree::getNodeByIndex($folderIndex,\@allFolders);
+ my $folderToInsertOn = &Apache::Tree::getNodeByIndex($folderIndex,\@allFolders);
$folderToInsertOn->add_child($tree);
}
else {
$root->add_child($tree);
}
- &saveChanges();
+ return &saveChanges();
}
# Delete entries
sub deleteEntries {
+ my $rootgiven = shift;
my $marked = shift;
- &getNodesToArray(\@childrenRt);
+ $root = $rootgiven;
+ @childrenRt = $root->children();
+
+ &getNodesToArray(\@childrenRt);
foreach my $m (@$marked) {
- my $found = &Tree::getNodeByIndex($m, \@allNodes);
- &Tree::removeNode($found);
+ my $found = &Apache::Tree::getNodeByIndex($m, \@allNodes);
+ # be sure, that entry exists (may have been deleted before, e.g. in an other browsertab)
+ if (defined $found) {
+ &Apache::Tree::removeNode($found);
+ }
}
@allNodes = ();
- &saveChanges();
+ return &saveChanges();
}
# Sort entries
sub sortEntries {
+ my $rootgiven = shift;
my $indexNode = shift;
my $at = shift;
+
+ $root = $rootgiven;
+ @childrenRt = $root->children();
&getNodesToArray(\@childrenRt);
- my $foundNode = &Tree::getNodeByIndex($indexNode, \@allNodes);
+ my $foundNode = &Apache::Tree::getNodeByIndex($indexNode, \@allNodes);
- &Tree::moveNode($foundNode,$at,undef);
+ &Apache::Tree::moveNode($foundNode,$at,undef);
@allNodes = ();
+ return &saveChanges();
}
# Move entries
sub moveEntries {
+ my $rootgiven = shift;
my $indexNodesToMove = shift;
my $indexParent = shift;
my @nodesToMove = ();
+ $root = $rootgiven;
+ @childrenRt = $root->children();
+
# get all nodes that should be moved
&getNodesToArray(\@childrenRt);
foreach my $index (@$indexNodesToMove) {
- my $foundNode = &Tree::getNodeByIndex($index, \@allNodes);
+ my $foundNode = &Apache::Tree::getNodeByIndex($index, \@allNodes);
push(@nodesToMove, $foundNode);
}
@@ -266,36 +282,46 @@
}
if (!$parentIsIn) {
if ($indexParent ne "root") {
- $foundParent = &Tree::getNodeByIndex($indexParent, \@allNodes);
- &Tree::moveNode($node,undef,$foundParent);
+ $foundParent = &Apache::Tree::getNodeByIndex($indexParent, \@allNodes);
+ &Apache::Tree::moveNode($node,undef,$foundParent);
}
else {
- &Tree::moveNode($node,undef,$root);
+ &Apache::Tree::moveNode($node,undef,$root);
}
}
}
@allNodes = ();
+ return &saveChanges();
}
# Set a new title for an entry
sub setNewTitle {
- my ($nodeindex, $newTitle) = @_;
+ my ($rootgiven, $nodeindex, $newTitle) = @_;
+
+ $root = $rootgiven;
+ @childrenRt = $root->children();
+
&getNodesToArray(\@childrenRt);
- my $found = &Tree::getNodeByIndex($nodeindex, \@allNodes);
+ my $found = &Apache::Tree::getNodeByIndex($nodeindex, \@allNodes);
$found->value()->title($newTitle);
@allNodes = ();
+ return &saveChanges();
}
# Set a new path for an entry
sub setNewPath {
- my ($nodeindex, $newPath) = @_;
+ my ($rootgiven, $nodeindex, $newPath) = @_;
+
+ $root = $rootgiven;
+ @childrenRt = $root->children();
+
&getNodesToArray(\@childrenRt);
- my $found = &Tree::getNodeByIndex($nodeindex, \@allNodes);
+ my $found = &Apache::Tree::getNodeByIndex($nodeindex, \@allNodes);
if ($found->value()->path()) {
$found->value()->path($newPath);
- return 1;
+ return &saveChanges();
}
@allNodes = ();
return 0;
@@ -304,23 +330,29 @@
# Set a new note for an entry
sub setNewNote {
- my ($nodeindex, $newNote) = @_;
+ my ($rootgiven, $nodeindex, $newNote) = @_;
+
+ $root = $rootgiven;
+ @childrenRt = $root->children();
+
&getNodesToArray(\@childrenRt);
- my $found = &Tree::getNodeByIndex($nodeindex, \@allNodes);
+ my $found = &Apache::Tree::getNodeByIndex($nodeindex, \@allNodes);
$found->value()->note($newNote);
@allNodes = ();
+ return &saveChanges();
}
# Save all changes
sub saveChanges {
@childrenRt = $root->children();
- &Tree::TreeIndex(\@childrenRt);
- &Tree::setCountZero();
- &Tree::RootToHash(\@childrenRt);
- &Tree::TreeToHash(\@childrenRt);
+ &Apache::Tree::TreeIndex(\@childrenRt);
+ &Apache::Tree::setCountZero();
+ &Apache::Tree::RootToHash(\@childrenRt);
+ &Apache::Tree::TreeToHash(\@childrenRt);
&deleteWishlist();
&putWishlist(\%TreeToHash);
+ return $root;
}
@@ -349,7 +381,7 @@
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).
- =back
+=back
=cut
@@ -553,7 +585,8 @@
my $warningFolder = &mt('You must insert a title!');
my $warningDelete = &mt('Are you sure you want to delete the selected entries? Deleting a folder also deletes all entries within this folder!');
my $warningSave = &mt('You have unsaved changes. You can either save these changes now by clicking "ok" or click "cancel" if you do not want to save your changes.');
- my $warningMove = &mt('You must select a destination folder!');
+ my $warningMoveS = &mt('You must select at minimum one entry to move!');
+ my $warningMoveD = &mt('You must select a destination folder!');
$foldersOption = '';
my $js = &Apache::lonhtmlcommon::scripttag(<<JAVASCRIPT);
@@ -626,7 +659,7 @@
r = linksOK();
}
else if (action == 'move') {
- r = selectDestinationFolder();
+ r = selectDestinationFolder(mode);
}
document.getElementsByName('list')[0].setAttribute("action", "/adm/wishlist?mode="+mode);
if (r) {
@@ -1030,7 +1063,7 @@
}
}
- function selectDestinationFolder() {
+ function selectDestinationFolder(mode) {
var mark = document.getElementsByName('mark');
var i = 0;
for (i = 0; i < mark.length; i++) {
@@ -1039,7 +1072,12 @@
return true;
}
}
- alert('$warningMove');
+ if (mode == 'move') {
+ alert('$warningMoveS');
+ }
+ else {
+ alert('$warningMoveD');
+ }
return false;
}
@@ -1453,9 +1491,13 @@
# Returns the HTML-Markup for wishlist
sub makePage {
+ my $rootgiven = shift;
my $mode = shift;
my $marked = shift;
+ $root = $rootgiven;
+ @childrenRt = $root->children();
+
# breadcrumbs and start_page
&Apache::lonhtmlcommon::clear_breadcrumbs();
&Apache::lonhtmlcommon::add_breadcrumb(
@@ -1609,6 +1651,103 @@
}
+# Returns the HTML-Markup for the PopUp, shown when a new link should set, when NOT
+# beeing in the wishlist-interface (method is called in lonmenu and lonsearchcat)
+sub makePopUpNewLink{
+
+ # Get all existing folders to offer posibility to set a new link
+ # into a folder
+ my %TreeHashLink = &Apache::lonwishlist::getWishlist();
+ my $rootLink = &Apache::Tree::HashToTree(\%TreeHashLink);
+ my @childrenRtLink = $rootLink->children();
+
+ $foldersOption = '';
+ @allFolders = ();
+ &getFoldersToArray(\@childrenRtLink);
+ &getFoldersForOption(\@childrenRtLink);
+
+ my $options = '<option value="" selected="selected">('.&mt('Top level').')</option>'.$foldersOption;
+ $foldersOption = '';
+ @allFolders = ();
+
+ # HTML-Markup for 'Set a link for this resource to wishlist'
+ # this is written via JavaScript document.write (function set_wishlistlink)
+ # 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 $start_page_wishlistlink =
+ &Apache::loncommon::start_page('Set link to wishlist',undef,
+ {'only_body' => 1,
+ 'js_ready' => 1,
+ 'bgcolor' => '#FFFFFF',});
+
+ my $warningLink = &mt('You must insert a title!');
+
+ 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();" >'.
+ &Apache::lonhtmlcommon::start_pick_box().
+ &Apache::lonhtmlcommon::row_title(&mt('Link Title'));
+
+ my $in_page_wishlistlink2 = &Apache::lonhtmlcommon::row_closure().
+ &Apache::lonhtmlcommon::row_title(&mt('Path'));
+
+ my $in_page_wishlistlink3 = &Apache::lonhtmlcommon::row_closure().
+ &Apache::lonhtmlcommon::row_title(&mt('Note')).
+ '<textarea name="note" rows="3" cols="35" style="width:100%"></textarea>'.
+ &Apache::lonhtmlcommon::row_closure(1).
+ &Apache::lonhtmlcommon::end_pick_box().
+ '<br/><br/>'.
+ '<input type="submit" value="'.&mt('Save in').'" />'.
+ '<select name="folders">'.
+ $options.
+ '</select>'.
+ '<input type="button" value="'.&mt('cancel').'" onclick="javascript:window.close();" />'.
+ '</form>';
+ $options = '';
+
+ # remove all \n for inserting on javascript document.write
+ $in_page_wishlistlink1 =~ s/\n//g;
+ $in_page_wishlistlink2 =~ s/\n//g;
+ $in_page_wishlistlink3 =~ s/\n//g;
+
+ my $end_page_wishlistlink =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+ # Add JavaScript-function to set link for a ressource to wishlist
+ my $js.=<<SCRIPT;
+ if(!title){
+ title=document.title;
+ }
+ if(!path){
+ path=location.pathname;
+ }
+ title = title.replace(/^LON-CAPA /,'');
+ wishlistlink=window.open('','wishlistNewLink','width=560,height=350,scrollbars=0');
+ wishlistlink.document.write(
+ '$start_page_wishlistlink'
+ +'<script type="text\/javascript">'
+ +'function newlinksubmit(){'
+ +'var title = document.getElementsByName("title")[0].value;'
+ +'if (!title) {'
+ +'alert("$warningLink");'
+ +'return false;}'
+ +'return true;}'
+ +'<\/scr'+'ipt>'
+ +'$in_page_wishlistlink1'
+ +'<input type="text" name="title" size="45" value="'+title+'"/>'
+ +'$in_page_wishlistlink2'
+ +'<input type="text" name="path" size="45" value="'+path+'" '
+ +'readonly="readonly" style="background-color: #DDDDDD"/>'
+ +'$in_page_wishlistlink3'
+ +'$end_page_wishlistlink' );
+ wishlistlink.document.close();
+SCRIPT
+
+ return $js;
+}
+
# Returns the HTML-Markup for the page, shown when a link was set
sub makePageSet {
# start_page
@@ -1635,7 +1774,11 @@
# Returns the HTML-Markup for the page, shown when links should be imported into a course
sub makePageImport {
+ my $rootgiven = shift;
my $rat = shift;
+
+ $root = $rootgiven;
+ @childrenRt = $root->children();
# start_page
my $startPage = &Apache::loncommon::start_page('Wishlist',undef,
{'only_body' => 1});
@@ -1656,7 +1799,18 @@
.'</span></p>';
}
my %wishlist = &getWishlist();
- my $fnum = (keys %wishlist)-1;
+
+ #FIXME Saved string containing all folders in wishlist.db-file (key 'folders') in first version of lonwishlist
+ #After splitting lonwishlist into two modules, this is not necessary anymore. So, dependent from when the wishlist
+ #was first called (i.e. when wishlist.db was created), there might be an entry 'folders' or not. Number of links in
+ #wishlist.db depends on wether this entry exists or not...JW
+ my $fnum;
+ if (defined $wishlist{'folders'}) {
+ $fnum = (keys %wishlist)-2;
+ }
+ else {
+ $fnum = (keys %wishlist)-1;
+ }
$inner .= '<form method="post" name="groupsort">'.
'<input type="hidden" value="'.$fnum.'" name="fnum">'.
@@ -1711,133 +1865,10 @@
return $page;
}
-# ----------------------------------------------------- Main Handler, package lonwishlist
-sub handler {
- my ($r) = @_;
- &Apache::loncommon::content_type($r,'text/html');
- $r->send_http_header;
-
- if (&getWishlist() ne 'error') {
- # get wishlist entries from user-data db-file and build a tree out of these entries
- %TreeHash = &getWishlist();
- $root = &Tree::HashToTree();
- @childrenRt = $root->children();
-
- # greate a new entry
- if ($env{'form.title'}) {
- &newEntry($env{'form.title'}, $env{'form.path'}, $env{'form.note'});
- }
-
- # get unprocessed_cgi (i.e. marked entries, mode ...)
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','mark','markedToMove','mode','newtitle','note','rat']);
-
- # change the order of entries within a level, that means sorting the entries
- my $changeOrder = 0;
- if (defined $env{'form.sel'}) {
- my @sel = &Apache::loncommon::get_env_multiple('form.sel');
- my $indexNode;
- my $at;
- for (my $s=0; $s<($#sel+1); $s++) {
- if ($sel[$s] ne '') {
- $indexNode = $s;
- $at = $sel[$s]-1;
- }
- }
- if ($at ne '') {
- $changeOrder = 1;
- &sortEntries($indexNode,$at);
- &saveChanges();
- }
- }
-
- # get all marked (checkboxes) entries
- my @marked = ();
- if (defined $env{'form.mark'}) {
- @marked = &Apache::loncommon::get_env_multiple('form.mark');
- }
-
- # move entries from one folder to another
- if (defined $env{'form.markedToMove'}) {
- my $markedToMove = $env{'form.markedToMove'};
- my @ToMove = split(/\,/,$markedToMove);
- my $moveTo = $env{'form.mark'};
- if (defined $moveTo){
- &moveEntries(\@ToMove,$moveTo);
- &saveChanges();
- }
- $changeOrder = 1;
-
- }
-
- # delete entries
- if ($env{'form.action'} eq 'delete') {
- &deleteEntries(\@marked);
- }
-
-
- # get all titles and notes and save them
- # only save, if user wants to save changes
- # do not save, when current action is 'delete' or 'sort' or 'move'
- my @newTitles = ();
- my @newPaths = ();
- my @newNotes = ();
- if ((defined $env{'form.newtitle'} || defined $env{'form.newpath'} || defined $env{'form.newnote'})
- && ($env{'form.action'} ne 'noSave') && ($env{'form.action'} ne 'delete') && !$changeOrder) {
- @newTitles = &Apache::loncommon::get_env_multiple('form.newtitle');
- @newPaths = &Apache::loncommon::get_env_multiple('form.newpath');
- @newNotes = &Apache::loncommon::get_env_multiple('form.newnote');
- my $node = 0;
- foreach my $t (@newTitles) {
- &setNewTitle($node, $t);
- $node++;
- }
- $node = 0;
- my $path = 0;
- for (my $i = 0; $i < ($#newTitles+1); $i++ ) {
- if (&setNewPath($node, $newPaths[$path])) {
- $path++;
- }
- $node++;
- }
- $node = 0;
- foreach my $n (@newNotes) {
- &setNewNote($node, $n);
- $node++;
- }
- &saveChanges();
- }
-
- # Create HTML-markup
- my $page;
- if ($env{'form.mode'} eq 'edit') {
- $page = &makePage("edit");
- }
- elsif ($env{'form.mode'} eq 'move') {
- $page = &makePage("move", \@marked);
- }
- elsif ($env{'form.mode'} eq 'import') {
- $page = &makePageImport($env{'form.rat'});
- }
- elsif ($env{'form.mode'} eq 'set') {
- $page = &makePageSet();
- }
- else {
- $page = &makePage("view");
- }
- @marked = ();
- $r->print($page);
- }
- # An error occured, print an error-page
- else {
- my $errorPage = &makeErrorPage();
- $r->print($errorPage);
- }
- return OK;
-}
# ----------------------------------------------------- package Tree
# Extend CPAN-Module Tree by function like 'moveNode' or 'deleteNode'
-package Tree;
+package Apache::Tree;
=pod
@@ -1904,9 +1935,9 @@
my $nodes = shift;
my $found;
- for my $n (@$nodes) {
+ foreach my $n (@$nodes) {
my $curIndex = $n->value()->nindex();
- if ($n->value()->nindex() == $index) {
+ if ($curIndex == $index) {
$found = $n;
}
}
@@ -2020,15 +2051,16 @@
# build a tree-object for each entry in the hash
# afterwards call &buildTree to connect the tree-objects
sub HashToTree {
+ my $TreeHash = shift;
my @TreeNodes = ();
my $root;
- foreach my $key (keys %TreeHash) {
+ foreach my $key (keys %$TreeHash) {
if ($key eq 'root') {
$root = Tree->new("root");
}
elsif ($key ne 'folders') {
- my @attributes = @{ $TreeHash{$key} };
+ my @attributes = @{ $$TreeHash{$key} };
my $tmpNode;
$tmpNode = Tree->new(Entry->new(title=>$attributes[0],
path=>$attributes[1],
@@ -2042,13 +2074,13 @@
shift(@attributes);
shift(@attributes);
shift(@attributes);
- $TreeHash{$key} = [ @attributes ];
+ $$TreeHash{$key} = [ @attributes ];
}
}
# if there are nodes, build up the tree-structure
- if (defined $TreeHash{'root'} && $TreeHash{'root'} ne '') {
- my @childrenRtIn = @{ $TreeHash{'root'} };
- &buildTree(\$root, \@childrenRtIn,\@TreeNodes,\%TreeHash);
+ if (defined $$TreeHash{'root'} && $$TreeHash{'root'} ne '') {
+ my @childrenRtIn = @{ $$TreeHash{'root'} };
+ &buildTree(\$root, \@childrenRtIn,\@TreeNodes,$TreeHash);
}
return $root;
}
Index: loncom/interface/lonwishlistdisplay.pm
+++ loncom/interface/lonwishlistdisplay.pm
# The LearningOnline Network with CAPA
# Routines to display the wishlist (handler)
#
# $Id: lonwishlistdisplay.pm,v 1.1 2011/01/27 14:38:44 wenzelju Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::lonwishlistdisplay;
use strict;
use Apache::Constants qw(:common);
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonhtmlcommon;
use Apache::lonlocal;
use Apache::lonwishlist;
use LONCAPA;
use Tree;
# Global variables
my $root;
my @childrenRt;
my %TreeHash;
# ----------------------------------------------------- Main Handler, package lonwishlistdisplay
sub handler {
my ($r) = @_;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
if (&Apache::lonwishlist::getWishlist() ne 'error') {
# get wishlist entries from user-data db-file and build a tree out of these entries
%TreeHash = &Apache::lonwishlist::getWishlist();
$root = &Apache::Tree::HashToTree(\%TreeHash);
@childrenRt = $root->children();
# create a new entry
if ($env{'form.title'}) {
$root = &Apache::lonwishlist::newEntry($root, $env{'form.title'}, $env{'form.path'}, $env{'form.note'});
}
# get unprocessed_cgi (i.e. marked entries, mode ...)
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','mark','markedToMove','mode','newtitle','note','rat']);
# change the order of entries within a level, that means sorting the entries
my $changeOrder = 0;
if (defined $env{'form.sel'}) {
my @sel = &Apache::loncommon::get_env_multiple('form.sel');
my $indexNode;
my $at;
for (my $s=0; $s<($#sel+1); $s++) {
if ($sel[$s] ne '') {
$indexNode = $s;
$at = $sel[$s]-1;
}
}
if ($at ne '') {
$changeOrder = 1;
$root = &Apache::lonwishlist::sortEntries($root, $indexNode,$at);
}
}
# get all marked (checkboxes) entries
my @marked = ();
if (defined $env{'form.mark'}) {
@marked = &Apache::loncommon::get_env_multiple('form.mark');
}
# move entries from one folder to another
if (defined $env{'form.markedToMove'}) {
my $markedToMove = $env{'form.markedToMove'};
my @ToMove = split(/\,/,$markedToMove);
my $moveTo = $env{'form.mark'};
if (defined $moveTo){
$root = &Apache::lonwishlist::moveEntries($root, \@ToMove,$moveTo);
}
$changeOrder = 1;
}
# delete entries
if ($env{'form.action'} eq 'delete') {
$root = &Apache::lonwishlist::deleteEntries($root, \@marked);
}
# get all titles and notes and save them
# only save, if user wants to save changes
# do not save, when current action is 'delete' or 'sort' or 'move'
my @newTitles = ();
my @newPaths = ();
my @newNotes = ();
if ((defined $env{'form.newtitle'} || defined $env{'form.newpath'} || defined $env{'form.newnote'})
&& ($env{'form.action'} ne 'noSave') && ($env{'form.action'} ne 'delete') && !$changeOrder) {
@newTitles = &Apache::loncommon::get_env_multiple('form.newtitle');
@newPaths = &Apache::loncommon::get_env_multiple('form.newpath');
@newNotes = &Apache::loncommon::get_env_multiple('form.newnote');
my $node = 0;
foreach my $t (@newTitles) {
$root = &Apache::lonwishlist::setNewTitle($root, $node, $t);
$node++;
}
$node = 0;
my $path = 0;
for (my $i = 0; $i < ($#newTitles+1); $i++ ) {
if (&Apache::lonwishlist::setNewPath($root, $node, $newPaths[$path])) {
$path++;
}
$node++;
}
$node = 0;
foreach my $n (@newNotes) {
$root = &Apache::lonwishlist::setNewNote($root, $node, $n);
$node++;
}
}
# Create HTML-markup
my $page;
if ($env{'form.mode'} eq 'edit') {
$page = &Apache::lonwishlist::makePage($root, "edit");
}
elsif ($env{'form.mode'} eq 'move') {
$page = &Apache::lonwishlist::makePage($root, "move", \@marked);
}
elsif ($env{'form.mode'} eq 'import') {
$page = &Apache::lonwishlist::makePageImport($root, $env{'form.rat'});
}
elsif ($env{'form.mode'} eq 'set') {
$page = &Apache::lonwishlist::makePageSet();
}
else {
$page = &Apache::lonwishlist::makePage($root, "view");
}
@marked = ();
$r->print($page);
}
# An error occured, print an error-page
else {
my $errorPage = &Apache::lonwishlist::makeErrorPage();
$r->print($errorPage);
}
return OK;
}
1;
__END__
--wenzelju1296139125--