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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 15 Jan 2008 03:09:10 -0000


This is a MIME encoded message

--raeburn1200366550
Content-Type: text/plain

raeburn		Mon Jan 14 22:09:10 2008 EDT

  Modified files:              
    /loncom/homework	structuretags.pm lonhomework.pm edit.pm 
  Log:
  Bug 5579. Form elements named problemmode were moved in structuretags.pm rev 1.408.  The result was that a button click of 'Calculate Answers' resulted in @{$env{'form.problemmode'}} in which the last array item was 'View' not 'Calculate Answers'.
  
  Eliminate the dependency on form element ordering by setting the value of problemmode on a buttonclick via javascript:setmode().         
  
  
--raeburn1200366550
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080114220910.txt"

Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.415 loncom/homework/structuretags.pm:1.416
--- loncom/homework/structuretags.pm:1.415	Mon Jan 14 09:32:14 2008
+++ loncom/homework/structuretags.pm	Mon Jan 14 22:09:09 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.415 2008/01/14 14:32:14 raeburn Exp $
+# $Id: structuretags.pm,v 1.416 2008/01/15 03:09:09 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -94,6 +94,7 @@
 
 sub homework_js {
     return &Apache::loncommon::resize_textarea_js().
+           &setmode_javascript().
 	<<'JS';
 <script type="text/javascript">
 function setSubmittedPart (part) {
@@ -113,10 +114,22 @@
     input_element.value = click;
     img_element.src = '/adm/randomlabel.png?token='+token+'&clickdata='+click;
 }
+
 </script>
 JS
 }
 
+sub setmode_javascript {
+    return <<"ENDSCRIPT";
+<script type="text/javascript">
+function setmode(form,probmode) {
+    form.problemmode.value = probmode;
+    form.submit();
+}
+</script>
+ENDSCRIPT
+}
+
 sub page_start {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
 	$extra_head)=@_;
@@ -307,14 +320,15 @@
 '.&mt('Problem Editing').&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').'
 </div>
 <div class="LC_edit_problem_discards">
-       <input type="hidden" name="problemmode" value="'.&mt('Edit').'" />
-       <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
-       <input '.&Apache::edit::submit_ask_anyway().' type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />
+       <input type="hidden" name="problemmode" value="edit" />
+       <input type="button" name="submitmode" accesskey="d" value="'.&mt('Discard Edits and View').'" '.
+       ' onclick="javscript:setmode(this.form,'."'discard.'".')"  />
+       <input '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'editxml'".')').' type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" />
        <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
 </div>
 <div class="LC_edit_problem_saves">
-       <input type="submit" name="submit" accesskey="s" value="'.&mt('Save and Edit').'" />
-       <input type="submit" name="submit" accesskey="v" value="'.&mt('Save and View').'" />
+       <input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save and Edit').'" />
+       <input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />
   </div>
 <hr class="LC_edit_problem_divide" />
 '.&Apache::lonxml::message_location().'
@@ -328,13 +342,14 @@
 <div class="LC_edit_problem_footer">
   <hr class="LC_edit_problem_divide" />
   <div class="LC_edit_problem_discards">
-     <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
-     <input '.&Apache::edit::submit_ask_anyway().' type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />
+     <input type="button" name="submitmode" accesskey="d" value="'.&mt('Discard Edits and View').'" '.
+     'onclick=javascript:setmode(this.form,'."'discard'".')" />
+     <input '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'editxml'".')').' type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" />
      <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
   </div>
   <div class="LC_edit_problem_saves">
-    <input type="submit" name="submit" value="'.&mt('Save and Edit').'" />
-    <input type="submit" name="submit" value="'.&mt('Save and View').'" />
+    <input type="submit" name="submitbutton" value="'.&mt('Save and Edit').'" />
+    <input type="submit" name="submitbutton" value="'.&mt('Save and View').'" />
   </div>
   <hr class="LC_edit_problem_divide" />
 </div>
@@ -461,8 +476,9 @@
 	if (!$numtoanalyze) { $numtoanalyze=20; }
 	$result .= '<span class="LC_nobreak">'.
 	    &mt('[_1] for [_2] versions.',
-		'<input type="submit" name="problemmode" value='.&mt('"Calculate answers').'" />',
-		'<input type="text" name="numtoanalyze" value="'.
+		'<input type="button" name="submitmode" value="'.&mt('Calculate answers').'" '.
+                'onclick="javascript:setmode(this.form,'."'calcanswers'".')" />
+		<input type="text" name="numtoanalyze" value="'.
 		$numtoanalyze.'" size="5" />').
 		&Apache::loncommon::help_open_topic("Analyze_Problem",'',undef,undef,300).
 		'</span>';
@@ -472,9 +488,11 @@
     $result.='
    </div>
    <div class="LC_edit_problem_header_edit_row">';
-    $result.='<input type="hidden" name="problemmode" value="'.&mt('View').'" />';
-    $result .= '<input type="submit" name="problemmode" accesskey="e" value="'.&mt('Edit').'" />';
-    $result .= '<input type="submit" name="problemmode" accesskey="x" value="'.&mt('EditXML').'" />';
+    $result.='<input type="hidden" name="problemmode" value="view" />';
+    $result .= '<input type="button" name="submitmode" accesskey="e" value="'.&mt('Edit').'" '.
+               'onclick="javascript:setmode(this.form,'."'edit'".')" />';
+    $result .= '<input type="button" name="submitmode" accesskey="x" value="'.&mt('EditXML').'" '.
+               'onclick="javascript:setmode(this.form,'."'editxml'".')" />';
     $result.='
    </div>
    '.&Apache::lonxml::message_location().'
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.288 loncom/homework/lonhomework.pm:1.289
--- loncom/homework/lonhomework.pm:1.288	Mon Jan 14 09:32:14 2008
+++ loncom/homework/lonhomework.pm	Mon Jan 14 22:09:09 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.288 2008/01/14 14:32:14 raeburn Exp $
+# $Id: lonhomework.pm,v 1.289 2008/01/15 03:09:09 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -137,8 +137,8 @@
 	    if ($env{'form.problemstate'} eq 'WEB_GRADE') {
 		#$env{'form.webgrade'} = 'yes';
 		return ('grade','webgrade','answer');
-	    } elsif ( $env{'form.problemmode'} eq &mt('View') ||
-		 $env{'form.problemmode'} eq &mt('Discard Edits and View')) {
+	    } elsif (($env{'form.problemmode'} eq 'view') ||
+		     ($env{'form.problemmode'} eq 'discard')) {
 		if ( defined($env{'form.submitted'}) &&
 		     (!defined($env{'form.resetdata'})) &&
 		     (!defined($env{'form.newrandomization'}))) {
@@ -146,10 +146,9 @@
 		} else {
 		    return ('web','answer');
 		}
-	    } elsif ( $env{'form.problemmode'} eq &mt('Edit') ||
-		      $env{'form.problemmode'} eq 'Edit') {
+	    } elsif ($env{'form.problemmode'} eq 'edit') {
 		if ( $env{'form.submitted'} eq 'edit' ) {
-		    if ( $env{'form.submit'} eq &mt('Save and View') ) {
+		    if ( $env{'form.submitbutton'} eq &mt('Save and View') ) {
 			return ('modified','web','answer');
 		    } else {
 			return ('modified','no_output_web','edit');
@@ -744,20 +743,25 @@
 
 sub analyze_header {
     my ($request) = @_;
+    my $js = &Apache::structuretags::setmode_javascript();
     my $result =
-	&Apache::loncommon::start_page('Analyzing a problem',undef);
+	&Apache::loncommon::start_page('Analyzing a problem',$js);
 
     $result .= 
 	&Apache::lonxml::message_location().'
             <form name="lonhomework" method="POST" action="'.
 	    &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
+            '<input type="hidden" name="problemmode" value="'.
+            $env{'form.problemmode'}.'" />'.
 	    &Apache::structuretags::remember_problem_state().'
             <div class="LC_edit_problem_analyze_header">
-            <input type="submit" name="problemmode" value="'.&mt("EditXML").'" />
-            <input type="submit" name="problemmode" value="'.&mt('Edit').'" />
+            <input type="button" name="submitmode" value="'.&mt("EditXML").'" '.
+            'onclick="javascript:setmode(this.form,'."'editxml'".')" />
+            <input type="button" name="submitmode" value="'.&mt('Edit').'" '.
+            'onclick="javascript:setmode(this.form,'."'edit'".')" />
             <hr class="LC_edit_problem_divide" />
-
-            <input type="submit" name="submit" value="'.&mt("View").'" />
+            <input type="button" name="submitmode" value="'.&mt("View").'" '.
+            'onclick="javascript:setmode(this.form,'."'view'".')" />
             <hr class="LC_edit_problem_divide" />
             </div>
             </form>';
@@ -920,9 +924,9 @@
 	if (!$error) { $problem=&Apache::lonnet::getfile($file); }
     }
     &Apache::lonhomework::showhashsubset(\%env,'^form');
-    if ( $env{'form.submit'} eq &mt('Save and View') ) {
+    if ( $env{'form.submitbutton'} eq &mt('Save and View') ) {
 	&Apache::lonhomework::showhashsubset(\%env,'^form');
-	$env{'form.problemmode'}='View';
+	$env{'form.problemmode'}='view';
 	&renderpage($request,$file);
     } else {
 	my ($rows,$cols) = &Apache::edit::textarea_sizes(\$problem);
@@ -937,7 +941,8 @@
 	if ($rows < 20) { $rows = 20; }
 	my $js =
 	    &Apache::edit::js_change_detection(). 
-	    &Apache::loncommon::resize_textarea_js();
+	    &Apache::loncommon::resize_textarea_js().
+            &Apache::structuretags::setmode_javascript();
 	my $only_body =  ($env{'environment.remote'} eq 'off')? 0 : 1;
 	my $start_page = 
 	    &Apache::loncommon::start_page(&mt("EditXML [_1]",$file),$js,
@@ -947,7 +952,6 @@
 						'onresize' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
 						'onload'   => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
 				    }});
-
 	$result.=$start_page.
 	    &renderpage($request,$file,['no_output_web'],1).
             '<form '.&Apache::edit::form_change_detection().' name="lonhomework" method="POST" action="'.
@@ -961,14 +965,15 @@
                 </td></tr>
               </table>
               <div class="LC_edit_problem_discards">
-                <input type="hidden" name="problemmode" value="'.&mt('EditXML').'" />
-                <input type="submit" name="problemmode" accesskey="d" value="'.&mt('Discard Edits and View').'" />
-                <input type="submit" '.&Apache::edit::submit_ask_anyway().'name="problemmode" accesskey="e" value="'.&mt('Edit').'" />
+                <input type="hidden" name="problemmode" value="editxml" />
+                <input type="button" name="submitmode" accesskey="d" value="'.&mt('Discard Edits and View').'" '.
+                'onclick="javascript:setmode(this.form,'."'discard'".')" />
+                <input type="button" '.&Apache::edit::submit_ask_anyway('setmode(this.form,'."'edit'".')').'name="submitmode" accesskey="e" value="'.&mt('Edit').'" />
                 <input type="submit" name="Undo" accesskey="u" value="'.&mt('undo').'" />
               </div>
               <div class="LC_edit_problem_saves">
-                <input type="submit" name="submit" accesskey="s" value="'.&mt('Save').'" />
-                <input type="submit" name="submit" accesskey="v" value="'.&mt('Save and View').'" />
+                <input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'"  />
+                <input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />
               </div>
               <hr class="LC_edit_problem_divide" />
 	      '.&Apache::lonxml::message_location().'
@@ -1169,7 +1174,7 @@
 
 sub update_construct_style {
     if ($env{'request.state'} eq "construct"
-	&& $env{'form.problemmode'} eq &mt('View') 
+	&& $env{'form.problemmode'} eq 'view' 
 	&&  defined($env{'form.submitted'})
 	&& !defined($env{'form.resetdata'})
 	&& !defined($env{'form.newrandomization'})) {
@@ -1192,13 +1197,6 @@
     $Apache::lonxml::debug=$env{'user.debug'};
     $env{'request.uri'}=$request->uri;
     &setuppermissions();
-    # some times multiple problemmodes are submitted, need to select
-    # the last one
-    if ( defined($env{'form.problemmode'}) && ref($env{'form.problemmode'}) ) {
-	my $mode=$env{'form.problemmode'}->[-1];
-	undef $env{'form.problemmode'};
-	$env{'form.problemmode'}=$mode;
-    }
 
     my $file=&Apache::lonnet::filelocation("",$request->uri);
 
@@ -1227,12 +1225,11 @@
 						    ['problemmode']);
 	    if (!(defined $env{'form.problemmode'})) {
 		#first visit to problem in construction space
-		$env{'form.problemmode'}='View';
+		$env{'form.problemmode'}= 'view';
 		&renderpage($request,$file);
-	    } elsif ($env{'form.problemmode'} eq &mt('EditXML') ||
-		     $env{'form.problemmode'} eq 'EditXML') {
+	    } elsif ($env{'form.problemmode'} eq 'editxml') {
 		&editxmlmode($request,$file);
-	    } elsif ($env{'form.problemmode'} eq &mt('Calculate answers')) {
+	    } elsif ($env{'form.problemmode'} eq 'calcanswers') {
 		&analyze($request,$file);
 	    } else {
 		&update_construct_style();
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.112 loncom/homework/edit.pm:1.113
--- loncom/homework/edit.pm:1.112	Tue Oct  2 20:24:48 2007
+++ loncom/homework/edit.pm	Mon Jan 14 22:09:09 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.112 2007/10/03 00:24:48 albertel Exp $
+# $Id: edit.pm,v 1.113 2008/01/15 03:09:09 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -577,7 +577,8 @@
 }
 
 sub submit_ask_anyway {
-    return ' onclick="still_ask=true;" ';
+    my ($extra_action) = @_;
+    return ' onclick="still_ask=true;'.$extra_action.'" ';
 }
 
 sub textarea_sizes {

--raeburn1200366550--