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

www www@source.lon-capa.org
Sat, 09 Oct 2010 00:00:04 -0000


www		Sat Oct  9 00:00:04 2010 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  Handing back spline data in form fields for server evaluation
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.8 loncom/homework/functionplotresponse.pm:1.9
--- loncom/homework/functionplotresponse.pm:1.8	Fri Oct  8 23:26:04 2010
+++ loncom/homework/functionplotresponse.pm	Sat Oct  9 00:00:04 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.8 2010/10/08 23:26:04 www Exp $
+# $Id: functionplotresponse.pm,v 1.9 2010/10/09 00:00:04 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -125,8 +125,8 @@
 function updatePointCoordinates_$id(coordinateName) {
             var x = document.ggbApplet_$id.getXcoord(coordinateName);
             var y = document.ggbApplet_$id.getYcoord(coordinateName);
-            coordinateMap_$id\[coordinateName + ".x"] = x;
-            coordinateMap_$id\[coordinateName + ".y"] = y;
+            document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_x"].value = x;
+            document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_y"].value = y;
         }
 // ]]>
 </script>
@@ -148,17 +148,36 @@
 sub set_coordinate {
    my ($id,$variable,$x,$y)=@_;
    return (<<ENDSETVARIABLE);
-coordinateMap_$id\['$variable.x'] = $x;
-coordinateMap_$id\['$variable.y'] = $y;
-document.ggbApplet_$id.evalCommand("$variable=("+coordinateMap_$id\["$variable.x"]+","+coordinateMap_$id\["$variable.y"]+")");
+document.ggbApplet_$id.evalCommand("$variable=($x,$y)");
 ENDSETVARIABLE
 }
 
 #
+# Input field name for a coordinate variable
+#
+
+sub field_name {
+    my ($id,$variable,$name)=@_;
+    return "HWVAL_$id\_$variable\_$name";
+}
+
+#
+# Generate an input field for a coordinate variable
+#
+
+sub generate_input_field {
+    my ($id,$variable,$x,$y)=@_;
+    $Apache::functionplotresponse::inputfields.=
+       "<input type='hidden' name='".&field_name($id,$variable,'x')."' value='$x' />\n".
+       "<input type='hidden' name='".&field_name($id,$variable,'y')."' value='$y' />\n";
+}
+
+#
 # Initialize a new coordinate variable at set a listener on it
 #
 sub new_coordinate {
     my ($id,$variable,$x,$y)=@_;
+    &generate_input_field($id,$variable,$x,$y);
     return &set_coordinate($id,$variable,$x,$y).&update_register($id,$variable);
 }
 
@@ -313,6 +332,7 @@
   undef %Apache::functionplotresponse::splineinity;
   undef %Apache::functionplotresponse::splinescalex;
   undef %Apache::functionplotresponse::splinescaley;
+  $Apache::functionplotresponse::inputfields='';
   $Apache::functionplotresponse::counter=0;
 # Internal ID to mark the applet and its coordinates
   my $internalid = $Apache::inputtags::part.'_'.&Apache::response::start_response($parstack,$safeeval);
@@ -356,6 +376,8 @@
      }
 # close the init script
      $result.=&end_init_script();
+# generate the input fields
+     $result.=$Apache::functionplotresponse::inputfields;
 # actually start the <applet>-tag
      $result.=&geogebra_startcode($internalid);
 # load the spline bytecode