[LON-CAPA-cvs] cvs: loncom /homework chemresponse.pm edit.pm

albertel lon-capa-cvs@mail.lon-capa.org
Sun, 04 May 2003 22:14:53 -0000


albertel		Sun May  4 18:14:53 2003 EDT

  Modified files:              
    /loncom/homework	edit.pm chemresponse.pm 
  Log:
  - edit mode of chemresponse now works
  - needed to modify html_element_name to stop javascript from being an ass
  - new editable arg type hidden_arg
  
  
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.47 loncom/homework/edit.pm:1.48
--- loncom/homework/edit.pm:1.47	Wed Apr 30 15:40:47 2003
+++ loncom/homework/edit.pm	Sun May  4 18:14:53 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.47 2003/04/30 19:40:47 matthew Exp $
+# $Id: edit.pm,v 1.48 2003/05/04 22:14:53 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -448,7 +448,8 @@
   foreach my $arg (@args) {
     #just want the string that it was set to
     my $value=$token->[2]->{$arg};
-    my $newvalue=$ENV{"form.$Apache::lonxml::curdepth.$arg"};
+    my $element=&html_element_name($arg);
+    my $newvalue=$ENV{"form.$element"};
     &Apache::lonxml::debug(" for:$arg: cur is :$value: new is :$newvalue:");
     if ($value ne $newvalue) {
       $token->[2]->{$arg}=$newvalue;
@@ -483,7 +484,16 @@
 
 sub html_element_name {
     my ($name) = @_;
-    return $Apache::lonxml::curdepth.'.'.$name;
+    return $name.'_'.$Apache::lonxml::curdepth;
+}
+
+sub hidden_arg {
+    my ($name,$token) = @_;
+    my $result;
+    my $arg=$token->[2]{$name};
+    $result='<input name="'.&html_element_name($name).
+	'" type="hidden" value="'.$arg.'" />';
+    return $result;
 }
 
 sub text_arg {
Index: loncom/homework/chemresponse.pm
diff -u loncom/homework/chemresponse.pm:1.1 loncom/homework/chemresponse.pm:1.2
--- loncom/homework/chemresponse.pm:1.1	Sun May  4 04:45:22 2003
+++ loncom/homework/chemresponse.pm	Sun May  4 18:14:53 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # chemical equation style response
 #
-# $Id: chemresponse.pm,v 1.1 2003/05/04 08:45:22 albertel Exp $
+# $Id: chemresponse.pm,v 1.2 2003/05/04 22:14:53 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,7 +36,21 @@
 }
 
 sub seperate_jme_window {
-    my ($id,$molecule)=@_;
+    my ($smile_input,$jme_input,$molecule)=@_;
+    my $smilesection;
+    if (defined($smile_input)) {
+	$smilesection=<<SMILESECTION;
+	opener.document.lonhomework.$smile_input.value = smiles;
+SMILESECTION
+    }
+    my $jmesection;
+    if (defined($jme_input)) {
+	$jmesection=<<JMESECTION;
+	jmeFile = document.applets.JME.jmeFile();
+	opener.document.lonhomework.$jme_input.value = jmeFile;
+JMESECTION
+    }
+
     my $body=<<CHEMPAGE;
 <html>
 <head>
@@ -47,14 +61,13 @@
     if (smiles == "") {
 	alert("Nothing to submit");
     } else {
-	jmeFile = document.applets.JME.jmeFile();
-	opener.document.lonhomework.HWVAL_$id.value = smiles;
-	opener.document.lonhomework.MOLECULE_$id.value = jmeFile;
+        $smilesection
+        $jmesection
 	window.close();
     }
 }
 function openHelpWindow() {
-    window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600")
+    window.open("/adm/jme/jme_help.html","","scrollbars=yes,resizable=yes,width=500,height=600");
 }
 </script>
 </head>
@@ -98,8 +111,33 @@
 	    $molecule=&Apache::lonxml::get_param('molecule',$parstack,
 						 $safeeval);
 	}
-	$result=&seperate_jme_window($id,$molecule);
+	$result=&seperate_jme_window("HWVAL_$id","MOLECULE_$id",$molecule);
 	$result.= '<input type="hidden" name="MOLECULE_'.$id.'" value="" />';
+    } elsif ($target eq 'edit') {
+	$result .=&Apache::edit::tag_start($target,$token);
+	$result .=&Apache::edit::text_arg('Starting Molecule:','molecule',
+					  $token,40);
+	my $molecule=&Apache::lonxml::get_param('molecule',$parstack,
+						$safeeval);
+	$result .=&seperate_jme_window(undef,
+		      &Apache::edit::html_element_name('molecule'),
+		      $molecule);
+	$result .='<br />';
+	$result .=&Apache::edit::text_arg('Correct Answer:','answer',
+					  $token,40);
+	$result .=&Apache::edit::hidden_arg('jmeanswer',$token);
+	my $jmeanswer=&Apache::lonxml::get_param('jmeanswer',$parstack,
+						 $safeeval);
+	$result .=&seperate_jme_window(
+                      &Apache::edit::html_element_name('answer'),
+                      &Apache::edit::html_element_name('jmeanswer'),
+		      $jmeanswer);
+	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
+    } elsif ($target eq 'modified') {
+	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
+						     $safeeval,'molecule',
+						     'answer','jmeanswer');
+	if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
     }
     return $result;
 }
@@ -127,6 +165,8 @@
 	    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
 	    $Apache::lonhomework::results{"resource.$partid.$id.molecule"}=$ENV{"form.MOLECULE_$id"};
 	}
+    } elsif ($target eq "edit") {
+	$result.= &Apache::edit::tag_end($target,$token,'');
     }
     &Apache::response::end_response;
     return $result;