--- loncom/interface/lonwishlist.pm 2010/08/16 08:58:39 1.2
+++ loncom/interface/lonwishlist.pm 2010/08/17 12:32:58 1.5
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Routines to control the wishlist
#
-# $Id: lonwishlist.pm,v 1.2 2010/08/16 08:58:39 wenzelju Exp $
+# $Id: lonwishlist.pm,v 1.5 2010/08/17 12:32:58 wenzelju Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -26,7 +26,20 @@
# http://www.lon-capa.org/
#
+=pod
+=head1 NAME
+
+Apache::lonwishlist - Wishlist-Module
+
+=head1 SYNOPSIS
+
+The wishlist offers a possibility to store links to resources from the resource-pool and external websites in a hierarchical list.
+It is only available for user with access to the resource-pool. The list can be structured by folders.
+
+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.
+
+=cut
package Apache::lonwishlist;
@@ -49,6 +62,31 @@ my @allFolders;
my @allNodes;
my $indentConst = 20;
+=pod
+
+=head2 Routines for getting and putting the wishlist data from and accordingly to users data.
+
+=over 4
+
+=item * &getWishlist()
+
+ Get the wishlist-data via lonnet::dump() and returns the got data in a hash.
+
+
+=item * &putWishlist(wishlist)
+
+ Parameter is a reference to a hash. Puts the wishlist-data contained in the given hash via lonnet::put() to user-data.
+
+
+=item * &deleteWishlist()
+
+ Deletes all entries from the user-data for wishlist. Do this before putting in new data.
+
+
+=back
+
+=cut
+
# Read wishlist from user-data
sub getWishlist {
@@ -92,6 +130,57 @@ sub deleteWishlist {
}
+=pod
+
+=head2 Routines for changing the directory struture of the wishlist.
+
+=over 4
+
+=item * &newEntry(title, path, note)
+
+ Creates a new entry in the wishlist containing the given informations. Additionally saves the date of creation in the entry.
+
+
+=item * &deleteEntries(marked)
+
+ Parameter is a reference to an array containing the indices of all nodes that should be removed from the tree.
+
+
+=item * &sortEntries(indexNode, at)
+
+ Changes the position of a node given by indexNode within its siblings. New position is given by at.
+
+
+=item * &moveEntries(indexNodesToMove, indexParent)
+
+ Parameter is a reference to an array containing the indices of all nodes that should be moved. indexParent specifies the node that will become the new Parent for these nodes.
+
+
+=item * &setNewTitle(nodeindex, newTitle)
+
+ Sets the title for the node given by nodeindex to newTitle.
+
+
+=item * &setNewPath(nodeindex, newPath)
+
+ Sets the path for the node given by nodeindex to newPath.
+
+
+=item * &setNewNote(nodeindex, newNote)
+
+ Sets the note for the node given by nodeindex to newNote.
+
+
+=item * &saveChanges()
+
+ Prepares the wishlist-hash to save it via &putWishlist(wishlist).
+
+
+=back
+
+=cut
+
+
# Create a new entry
sub newEntry() {
my ($title, $path, $note) = @_;
@@ -189,6 +278,20 @@ sub setNewTitle {
}
+# Set a new path for an entry
+sub setNewPath {
+ my ($nodeindex, $newPath) = @_;
+ &getNodesToArray(\@childrenRt);
+ my $found = &Tree::getNodeByIndex($nodeindex, \@allNodes);
+ if ($found->value()->path()) {
+ $found->value()->path($newPath);
+ return 1;
+ }
+ @allNodes = ();
+ return 0;
+}
+
+
# Set a new note for an entry
sub setNewNote {
my ($nodeindex, $newNote) = @_;
@@ -212,6 +315,40 @@ sub saveChanges {
}
+=pod
+
+=head2 Routines for handling the directory structure
+
+=over 4
+
+=item * &getFoldersForOption(nodes)
+
+ Return the titles for all exiting folders in an option-tag, used to offer the users a possibility to create a new link or folder in an existing folder.
+ 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.
+ 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 * &getNodesToArray(children)
+
+ Puts all existing nodes into an array (apart from the root node, because this one does not represent an entry in the wishlist).
+ 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
+
+=cut
+
+
# 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;
@@ -280,6 +417,67 @@ sub getNodesToArray {
}
+=pod
+
+=head2 Routines for the user-interface of the wishlist
+
+=over 4
+
+=item * &JSforWishlist()
+
+ Returns JavaScript-functions needed for wishlist actions like open and close folders.
+
+
+=item * &wishlistView(nodes)
+
+ Returns the table-HTML-markup for the wishlist in mode "view".
+ 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 * &wishlistEdit(nodes)
+
+ Returns the table-HTML-markup for the wishlist in mode "edit".
+ 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 * &wishlistMove(nodes, marked)
+
+ Returns the table-HTML-markup for the wishlist in mode "move". Highlights all entry "selected to move" contained in marked (reference to array).
+ 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)
+
+ 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).
+
+
+=item * &makePage(mode, marked)
+
+ Returns the HTML-markup for the whole wishlist depending on mode. If mode is "move" we need the marked entries to be highlighted a "selected to move".
+ Calls &wishlistView(nodes), &wishlistEdit(nodes) or &wishlistMove(nodes, marked).
+
+
+=item * &makePageSet()
+
+ Returns the HTML-Markup for the page shown when a link was set by using the icon when viewing a resource.
+
+
+=item * &makePageImport()
+
+ Returns the HTML-Markup for the page shown when links should be imported into courses.
+
+
+=item * &makeErrorPage ()
+
+ Returns the HTML-Markup for an error-page shown if the wishlist could not be loaded.
+
+
+=back
+
+=cut
+
+
# Return a script-tag containing Javascript-function
# needed for wishlist actions like 'new link' ect.
sub JSforWishlist {
@@ -352,6 +550,17 @@ sub JSforWishlist {
$inPageNewLink =~ s/\n//g;
$inPageNewFolder =~ s/\n//g;
+ # it is checked, wether a path links to a LON-CAPA-resource or an external website. links to course-contents are not allowed
+ # because they probably will return a kind of 'no access' (unless the user is already in the course, the path links to).
+ # also importing these kind of links into a course does not make much sense.
+ # to find out if a path (not starting with /res/...) links to course-contents, the same filter as in lonwrapper is used,
+ # that means that it is checked wether a path contains .problem, .quiz, .exam etc.
+ # this is good for most cases but crashes as soon as a real external website contains one of this pattern in its URL.
+ # so maybe there's a better way to find out wether a given URL belongs to a LON-CAPA-server or not ...?
+ my $warningLinkNotAllowed1 = &mt('You can only insert links to LON-CAPA resources from the resource-pool '.
+ 'or to external websites. Paths to LON-CAPA resources must be of the form /res/dom/usr... . '.
+ 'Paths to external websites must contain the network protocol (e.g. http://...).');
+ my $warningLinkNotAllowed2 = &mt('The following link is not allowed: ');
my $warningLink = &mt('You must insert a title and a path!');
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!');
@@ -370,6 +579,15 @@ sub JSforWishlist {
+'if (!path || !title) {'
+'alert("$warningLink");'
+'return false;}'
+ +'var linkOK = (path.match(/^http:(\\\\/\\\\/)/) || path.match(/^https:(\\\\/\\\\/)/))'
+ +'&& !(path.match(/\\.problem/) || path.match(/\\.exam/)'
+ +'|| path.match(/\\.quiz/) || path.match(/\\.assess/)'
+ +'|| path.match(/\\.survey/) || path.match(/\\.form/)'
+ +'|| path.match(/\\.library/) || path.match(/\\.page/)'
+ +'|| path.match(/\\.sequence/));'
+ +'if (!path.match(/^(\\\\/res\\\\/)/) && !linkOK) {'
+ +'alert("$warningLinkNotAllowed1");'
+ +'return false;}'
+'else {'
+'window.close();'
+'return true;}}'
@@ -409,9 +627,18 @@ sub JSforWishlist {
if (d) {
if (!confirm('$warningSave')) {
setAction('noSave');
+ r = true;
+ }
+ else {
+ r = linksOK();
}
}
- r = true;
+ }
+ else if (action == 'saveOK') {
+ r = linksOK();
+ }
+ else if (action == 'move') {
+ r = selectDestinationFolder();
}
document.getElementsByName('list')[0].setAttribute("action", "/adm/wishlist?mode="+mode);
if (r) {
@@ -433,6 +660,15 @@ sub JSforWishlist {
return true;
}
}
+ var newpath = document.getElementsByName('newpath');
+ var i = 0;
+ for (i=0;i'.
- '
';
+ '
'.
+ ''.
+ '
';
}
# entry is a link
@@ -953,12 +1216,11 @@ sub wishlistEdit {
$wishlistHTMLedit .= ' '.
' '.
- ' '.
+ '';
+ '
'.
+ '
';
}
-
- # input-field for title
- $wishlistHTMLedit .= '';
-
+
# note-icon, different icons for an entries with note and those without
my $noteIMG = 'anot.png';
@@ -974,7 +1236,7 @@ sub wishlistEdit {
# start row containing the textarea for the note
$wishlistHTMLedit .= &Apache::loncommon::continue_data_table_row('LC_hidden','note'.$index).
- ' '.
+ ' '.
' ';
@@ -1168,10 +1430,7 @@ sub makePage {
'onload' => 'javascript:onLoadAction('."'".$mode."'".');',
'onunload' => 'javascript:window.name = '."'loncapaclient'"}});
- my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Wishlist '.
- ''.
- ' ');
+ my $breadcrumbs = &Apache::lonhtmlcommon::breadcrumbs('Wishlist '.&Apache::loncommon::help_open_topic('Wishlist'));
# get javascript-code for wishlist-interactions
my $js = &JSforWishlist();
@@ -1192,7 +1451,7 @@ sub makePage {
# icon for edit-mode, display when in view-mode
if ($mode eq 'view') {
$functions .= &Apache::lonhtmlcommon::add_item_funclist(''.
+ 'onclick="setFormAction('."'save','edit'".');" class="LC_menubuttons_link">'.
'
'.
'');
@@ -1200,7 +1459,7 @@ sub makePage {
# icon for view-mode, display when in edit-mode
else {
$functions .= &Apache::lonhtmlcommon::add_item_funclist(''.
+ 'onclick="setFormAction('."'save','view'".');" class="LC_menubuttons_link">'.
'
'.
'');
@@ -1236,7 +1495,7 @@ sub makePage {
# icon for saving changes
$functions .= &Apache::lonhtmlcommon::add_item_funclist(''.
+ 'onclick="setFormAction('."'saveOK','".$mode."'".'); " class="LC_menubuttons_link">'.
'
'.
'');
@@ -1289,7 +1548,7 @@ sub makePage {
'Now choose the new destination folder.').'