[LON-CAPA-cvs] cvs: loncom /interface lonindexer.pm /xml lonxml.pm

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 06 Mar 2002 20:28:20 -0000


matthew		Wed Mar  6 15:28:20 2002 EDT

  Modified files:              
    /loncom/xml	lonxml.pm 
    /loncom/interface	lonindexer.pm 
  Log:
  Changes to support new browsing functionality in construction space.
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.154 loncom/xml/lonxml.pm:1.155
--- loncom/xml/lonxml.pm:1.154	Tue Feb 26 16:00:38 2002
+++ loncom/xml/lonxml.pm	Wed Mar  6 15:28:19 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.154 2002/02/26 21:00:38 albertel Exp $
+# $Id: lonxml.pm,v 1.155 2002/03/06 20:28:19 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -316,6 +316,8 @@
 
 sub registerurl {
     my $forcereg=shift;
+    my $target = shift;
+    my $result = '';
     if ($ENV{'request.publicaccess'}) {
 	return 
          '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';
@@ -347,7 +349,7 @@
 ENDPARM
             }
 	}
-	return (<<ENDREGTHIS);
+	$result = (<<ENDREGTHIS);
      
 <script language="JavaScript">
 // BEGIN LON-CAPA Internal
@@ -399,7 +401,7 @@
 ENDREGTHIS
 
     } else {
-        return (<<ENDDONOTREGTHIS);
+        $result = (<<ENDDONOTREGTHIS);
 
 <script language="JavaScript">
 // BEGIN LON-CAPA Internal
@@ -426,8 +428,30 @@
 // END LON-CAPA Internal
 </script>
 ENDDONOTREGTHIS
-
     }
+    if ($target eq 'edit') {
+        $result .=<<"ENDBROWSERSCRIPT";
+<script>
+    var editform;
+    function openbrowser(formname,elementname) {
+        var url = '/res/?';
+        if (editform == null) {
+            url += 'launch=1&';
+        }
+        url += 'catalogmode=interactive&';
+        url += 'mode=edit&';
+        url += 'form=' + formname + '&';
+        url += 'element=' + elementname + '';
+        var title = 'Browser';
+        var options = 'scrollbars=1,resizable=1,menubar=0';
+        options += ',width=700,height=600';
+        editform = open(url,title,options,'1');
+        editform.focus();
+    }
+</script>
+ENDBROWSERSCRIPT
+    }
+    return $result;
 }
 
 sub loadevents() {
Index: loncom/interface/lonindexer.pm
diff -u loncom/interface/lonindexer.pm:1.34 loncom/interface/lonindexer.pm:1.35
--- loncom/interface/lonindexer.pm:1.34	Thu Jan 17 09:10:44 2002
+++ loncom/interface/lonindexer.pm	Wed Mar  6 15:28:19 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Directory Indexer
 #
-# $Id: lonindexer.pm,v 1.34 2002/01/17 14:10:44 harris41 Exp $
+# $Id: lonindexer.pm,v 1.35 2002/03/06 20:28:19 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -106,8 +106,9 @@
     my $uri=$r->uri;
 
 # -------------------------------------- see if called from an interactive mode
-    &get_unprocessed_cgi();
-
+    # Get the parameters from the query string
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+    #-------------------------------------------------------------------
     my $closebutton='';
     my $groupimportbutton='';
     my $colspan=''; 
@@ -154,12 +155,36 @@
 onClick="javascript:select_group()">
 END
         }
-
+	# Additions made by Matthew to make the browser a little easier to deal
+	# with in the future.
+	#
+	# $mode (at this time) indicates if we are in edit mode.
+	# $form is the name of the form that the URL is placed when the
+	#       selection is made.
+	# $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');
+
+	my $mode = $ENV{'form.mode'};
+	my ($form,$element);
+	if ($mode eq 'edit') {
+	    $form    = $ENV{'form.form'};
+	    $element = $ENV{'form.element'};
+	}
+	&Apache::lonxml::debug("mode=$mode form=$form element=$element");
 # ------ set catalogmodefunctions to have extra needed javascript functionality
 	my $catalogmodefunctions='';
 	if ($ENV{'form.catalogmode'} eq 'interactive' or
 	    $ENV{'form.catalogmode'} eq 'groupimport') {
-	    $catalogmodefunctions=<<END;
+	    # The if statement below sets us up to use the old version
+	    # by default (ie. if $mode is undefined).  This is the easy
+	    # way out.  Hopefully in the future I'll find a way to get 
+	    # the calls dealt with in a more comprehensive manner.
+	    if (!defined($mode) || $mode ne 'edit') {
+		$catalogmodefunctions=<<"END";
 function select_data(title,url) {
     changeTitle(title);
     changeURL(url);
@@ -169,16 +194,42 @@
     window.location="/adm/groupsort?catalogmode=groupimport&acts="+document.forms.fileattr.acts.value;
 }
 function changeTitle(val) {
-    if (opener.inf.document.forms.resinfo.elements.t) {
-        opener.inf.document.forms.resinfo.elements.t.value=val;
+    if (opener.inf) {
+        if (opener.inf.document.forms.resinfo.elements.t) {
+            opener.inf.document.forms.resinfo.elements.t.value=val;
+        }
+    }
+}
+function changeURL(val) {
+    if (opener.inf) {
+        if (opener.inf.document.forms.resinfo.elements.u) {
+	    opener.inf.document.forms.resinfo.elements.u.value=val;
+        }
     }
 }
+END
+            } else { # we are in 'edit' mode
+		$catalogmodefunctions=<<END;
+// mode = $mode
+function select_data(title,url) {
+    changeURL(url);
+    self.close();
+}
+
+function select_group() {
+    window.location="/adm/groupsort?catalogmode=interactive&form=$form&element=$element&mode=edit&acts="+document.forms.fileattr.acts.value;
+}
+
 function changeURL(val) {
-    if (opener.inf.document.forms.resinfo.elements.u) {
-	opener.inf.document.forms.resinfo.elements.u.value=val;
+    if (window.opener.document) {
+	window.opener.document.forms["$form"].elements["$element"].value=val;
+    } else {
+	    alert("The file you selected is: "+val);
     }
 }
+
 END
+             }
         }
 	if ($ENV{'form.catalogmode'} eq 'groupimport') {
 	    $catalogmodefunctions.=<<END;
@@ -603,8 +654,8 @@
 		if ($metafile == 1);
 	    $title=$listname unless $title;
 	    my $titleesc=$title;
-	    $titleesc=~s/\'/\\'/;
-            $r->print("<a href=\"javascript:select_data('",
+	    $titleesc=~s/\'/\\'/; #' (clean up this spare quote
+            $r->print("<a href=\"javascript:select_data(\'",
                       $titleesc,"','",$filelink,"')\">");
 	    $r->print("<img src='",$iconpath,"select.gif' border='0' /></a>".
 		      "\n");
@@ -747,21 +798,12 @@
     $dnum++;
 }
 
-# ----------- grab unprocessed CGI variables that may have been appended to URL
-sub get_unprocessed_cgi {
-    foreach (split(/&/,$ENV{'QUERY_STRING'})) {
-       my ($name, $value) = split(/=/,$_);
-       $value =~ tr/+/ /;
-       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
-       if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
-           $ENV{'form.'.$name}=$value;
-       }
-    }
-}
-
 # --------- settings whenever the user causes the indexer window to be launched
 sub start_fresh_session {
     delete $hash{'mode_catalog'};
+    delete $hash{'form_mode'};
+    delete $hash{'form_form'};
+    delete $hash{'form_element'};
     foreach (keys %hash) {
 	if ($_ =~ /^pre_/) {
 	    delete $hash{$_};
@@ -772,6 +814,19 @@
     }
 }
 
+# ------------------------------------------------------------------- setvalues
+sub setvalues {
+    # setvalues is used in registerurl to synchronize the database
+    # hash and environment hashes
+    my ($H1,$h1key,$H2,$h2key) =@_;
+    #
+    if (exists $H2->{$h2key}) {
+	$H1->{$h1key} = $H2->{$h2key};
+    } elsif (exists $H1->{$h1key}) {
+	$H2->{$h2key} = $H1->{$h1key};
+    } 
+}
+
 1;
 
 =head1 NAME
@@ -905,11 +960,6 @@
 =item *
 
 begin_form - prints the beginning of a form for directory or file link
-
-=item *
-
-get_unprocessed_cgi - grab unprocessed CGI variables that may have been
-appended to URL
 
 =item *