[LON-CAPA-cvs] cvs: loncom /homework edit.pm /interface loncommon.pm lonindexer.pm lonsearchcat.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 24 Oct 2003 21:09:24 -0000


This is a MIME encoded message

--albertel1067029764
Content-Type: text/plain

albertel		Fri Oct 24 17:09:24 2003 EDT

  Modified files:              
    /loncom/homework	edit.pm 
    /loncom/interface	loncommon.pm lonindexer.pm lonsearchcat.pm 
  Log:
  - needed for BUG#1473, the 'Select' link can now also get you the title of a resource back
  
  
  
--albertel1067029764
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20031024170924.txt"

Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.67 loncom/homework/edit.pm:1.68
--- loncom/homework/edit.pm:1.67	Wed Oct  8 12:46:38 2003
+++ loncom/homework/edit.pm	Fri Oct 24 17:09:24 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.67 2003/10/08 16:46:38 albertel Exp $
+# $Id: edit.pm,v 1.68 2003/10/24 21:09:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -731,17 +731,21 @@
 #----------------------------------------------------- browse
 sub browse {
     # insert a link to call up the filesystem browser (lonindexer)
-    my ($id, $mode) = @_;
+    my ($id, $mode, $titleid) = @_;
     my $form    = 'lonhomework';
     my $element;
     if (! defined($mode) || $mode eq 'attribute') {
         $element = &Apache::lonnet::escape("$id\_$Apache::lonxml::curdepth");
     } elsif ($mode eq 'textnode') {  # for data between <tag> ... </tag>
         $element = &Apache::lonnet::escape('homework_edit_'.
-                                           $Apache::lonxml::curdepth);
+                                           $Apache::lonxml::curdepth);	
+    }
+    my $titleelement;
+    if ($titleid) {
+	$titleelement=",'','','".&Apache::lonnet::escape("$titleid\_$Apache::lonxml::curdepth")."'";
     }
     my $result = <<"ENDBUTTON";
-<a href=\"javascript:openbrowser('$form','$element')\"\>Select</a>
+<a href=\"javascript:openbrowser('$form','$element'$titleelement)\"\>Select</a>
 ENDBUTTON
     return $result;
 }
@@ -749,7 +753,7 @@
 #----------------------------------------------------- browse
 sub search {
     # insert a link to call up the filesystem browser (lonindexer)
-    my ($id, $mode) = @_;
+    my ($id, $mode, $titleid) = @_;
     my $form    = 'lonhomework';
     my $element;
     if (! defined($mode) || $mode eq 'attribute') {
@@ -758,8 +762,12 @@
         $element = &Apache::lonnet::escape('homework_edit_'.
                                            $Apache::lonxml::curdepth);
     }
+    my $titleelement;
+    if ($titleid) {
+	$titleelement=",'".&Apache::lonnet::escape("$titleid\_$Apache::lonxml::curdepth")."'";
+    }
     my $result = <<"ENDBUTTON";
-<a href=\"javascript:opensearcher('$form','$element')\"\>Search</a>
+<a href=\"javascript:opensearcher('$form','$element'$titleelement)\"\>Search</a>
 ENDBUTTON
     return $result;
 }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.134 loncom/interface/loncommon.pm:1.135
--- loncom/interface/loncommon.pm:1.134	Fri Oct 24 09:35:37 2003
+++ loncom/interface/loncommon.pm	Fri Oct 24 17:09:24 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.134 2003/10/24 13:35:37 matthew Exp $
+# $Id: loncommon.pm,v 1.135 2003/10/24 21:09:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -274,7 +274,7 @@
 sub browser_and_searcher_javascript {
     return <<END;
     var editbrowser = null;
-    function openbrowser(formname,elementname,only,omit) {
+    function openbrowser(formname,elementname,only,omit,titleelement) {
         var url = '/res/?';
         if (editbrowser == null) {
             url += 'launch=1&';
@@ -288,6 +288,9 @@
         if (omit != null) {
             url += 'omit=' + omit + '&';
         }
+        if (titleelement != null) {
+            url += 'titleelement=' + titleelement + '&';
+        }
         url += 'element=' + elementname + '';
         var title = 'Browser';
         var options = 'scrollbars=1,resizable=1,menubar=0';
@@ -296,7 +299,7 @@
         editbrowser.focus();
     }
     var editsearcher;
-    function opensearcher(formname,elementname) {
+    function opensearcher(formname,elementname,titleelement) {
         var url = '/adm/searchcat?';
         if (editsearcher == null) {
             url += 'launch=1&';
@@ -304,6 +307,9 @@
         url += 'catalogmode=interactive&';
         url += 'mode=edit&';
         url += 'form=' + formname + '&';
+        if (titleelement != null) {
+            url += 'titleelement=' + titleelement + '&';
+        }
         url += 'element=' + elementname + '';
         var title = 'Search';
         var options = 'scrollbars=1,resizable=1,menubar=0';
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.78 loncom/interface/lonindexer.pm:1.79
--- loncom/interface/lonindexer.pm:1.78	Sat Sep 27 09:20:46 2003
+++ loncom/interface/lonindexer.pm	Fri Oct 24 17:09:24 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Directory Indexer
 #
-# $Id: lonindexer.pm,v 1.78 2003/09/27 13:20:46 www Exp $
+# $Id: lonindexer.pm,v 1.79 2003/10/24 21:09:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -118,7 +118,7 @@
     # Get the parameters from the query string
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
 	     ['catalogmode','launch','acts','mode','form','element',
-              'only','omit']);
+              'only','omit','titleelement']);
     #-------------------------------------------------------------------
     my $closebutton='';
     my $groupimportbutton='';
@@ -179,11 +179,12 @@
 	# $element is the name of the element in $formname which receives
 	#       the URL.
 	# &Apache::lonxml::debug('Checking mode, form, element');
-	&setvalues(\%hash,'form.mode'   ,\%ENV,'form.mode'   );
-	&setvalues(\%hash,'form.form'   ,\%ENV,'form.form'   );
-	&setvalues(\%hash,'form.element',\%ENV,'form.element');
-	&setvalues(\%hash,'form.only'   ,\%ENV,'form.only'   );
-	&setvalues(\%hash,'form.omit'   ,\%ENV,'form.omit'   );
+	&setvalues(\%hash,'form.mode'        ,\%ENV,'form.mode'   );
+	&setvalues(\%hash,'form.form'        ,\%ENV,'form.form'   );
+	&setvalues(\%hash,'form.element'     ,\%ENV,'form.element');
+	&setvalues(\%hash,'form.titleelement',\%ENV,'form.titleelement');
+	&setvalues(\%hash,'form.only'        ,\%ENV,'form.only'   );
+	&setvalues(\%hash,'form.omit'        ,\%ENV,'form.omit'   );
 
         # Deal with 'omit' and 'only' 
         if (exists $ENV{'form.omit'}) {
@@ -194,12 +195,14 @@
         }
         
 	my $mode = $ENV{'form.mode'};
-	my ($form,$element);
+	my ($form,$element,$titleelement);
 	if ($mode eq 'edit' || $mode eq 'parmset') {
-	    $form    = $ENV{'form.form'};
-	    $element = $ENV{'form.element'};
+	    $form         = $ENV{'form.form'};
+	    $element      = $ENV{'form.element'};
+	    $titleelement = $ENV{'form.titleelement'};
 	}
-	&Apache::lonxml::debug("mode=$mode form=$form element=$element");
+	&Apache::lonxml::debug("mode=$mode form=$form element=$element
+                                titleelement=$titleelement");
 # ------ set catalogmodefunctions to have extra needed javascript functionality
 	my $catalogmodefunctions='';
 	if ($ENV{'form.catalogmode'} eq 'interactive' or
@@ -248,6 +251,7 @@
 // mode = $mode
 function select_data(title,url) {
     changeURL(url);
+    changeTitle(title);
     self.close();
 }
 
@@ -262,8 +266,20 @@
 	    alert("The file you selected is: "+val);
     }
 }
-
 END
+                if (!$titleelement) {
+		    $catalogmodefunctions.='function changeTitle(val) {}';
+		} else {
+		    $catalogmodefunctions.=<<END;
+function changeTitle(val) {
+    if (window.opener.document) {
+	    window.opener.document.forms["$form"].elements["$titleelement"].value=val;
+    } else {
+	    alert("The title of the file you selected is: "+val);
+    }
+}
+END
+                }
             } elsif ($mode eq 'parmset') {
                 my $location = "/adm/groupsort?catalogmode=interactive&";
                 $location .= "form=$form&element=$element&mode=parmset&acts=";
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.190 loncom/interface/lonsearchcat.pm:1.191
--- loncom/interface/lonsearchcat.pm:1.190	Tue Oct  7 16:30:13 2003
+++ loncom/interface/lonsearchcat.pm	Fri Oct 24 17:09:24 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.190 2003/10/07 20:30:13 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.191 2003/10/24 21:09:24 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -200,7 +200,7 @@
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
              ['catalogmode','launch','acts','mode','form','element','pause',
               'phase','persistent_db_id','table','start','show',
-              'cleargroupsort']);
+              'cleargroupsort','titleelement']);
     ##
     ## The following is a trick - we wait a few seconds if asked to so
     ##     the daemon running the search can get ahead of the daemon
@@ -282,6 +282,10 @@
         $hidden_fields .= '<input type="hidden" name="element" value="'.
                 $ENV{'form.element'}.'" />'."\n";
     }
+    if (exists($ENV{'form.titleelement'})) {
+        $hidden_fields .= '<input type="hidden" name="titleelement" value="'.
+                $ENV{'form.titleelement'}.'" />'."\n";
+    }
     if (exists($ENV{'form.mode'})) {
         $hidden_fields .= '<input type="hidden" name="mode" value="'.
                 $ENV{'form.mode'}.'" />'."\n";
@@ -2688,8 +2692,16 @@
 
 =item 'form.form'
 
+Contains the name of the form that has the input fields to set
+
 =item 'form.element'
 
+the name of the input field to put the URL into
+
+=item 'form.titleelement'
+
+the name of the input field to put the title into
+
 =back
 
 =cut
@@ -2726,14 +2738,31 @@
         } elsif ($ENV{'form.mode'} eq 'edit') {
             my $form = $ENV{'form.form'};
             my $element = $ENV{'form.element'};
+            my $titleelement = $ENV{'form.titleelement'};
+	    my $changetitle;
+	    if (!$titleelement) {
+		$changetitle='function changeTitle(val) {}';
+	    } else {
+		    $changetitle=<<END;
+function changeTitle(val) {
+    if (parent.targetwin.document) {
+        parent.targetwin.document.forms["$form"].elements["$titleelement"].value=val;
+    } else {
+	var url = 'forms[\"$form\"].elements[\"$titleelement\"].value';
+        alert("Unable to transfer data to "+url);
+    }
+}
+END
+            }
+
             $result.=<<SCRIPT;
 <script type="text/javascript">
 function select_data(title,url) {
     changeURL(url);
+    changeTitle(title);
     parent.close();
 }
-function changeTitle(val) {
-}
+$changetitle
 function changeURL(val) {
     if (parent.targetwin.document) {
         parent.targetwin.document.forms["$form"].elements["$element"].value=val;

--albertel1067029764--