[LON-CAPA-cvs] cvs: loncom /homework edit.pm lonhomework.pm structuretags.pm
www
www@source.lon-capa.org
Sun, 06 Feb 2011 18:43:11 -0000
This is a MIME encoded message
--www1297017791
Content-Type: text/plain
www Sun Feb 6 18:43:11 2011 EDT
Modified files:
/loncom/homework edit.pm lonhomework.pm structuretags.pm
Log:
Bug #6425: make is so that pressing "Return" does not trigger an "Undo"
Also, try to disentangle the historically grown logic of this: form.problemmode now governs all behavior.
--www1297017791
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20110206184311.txt"
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.133 loncom/homework/edit.pm:1.134
--- loncom/homework/edit.pm:1.133 Sat Nov 13 03:22:58 2010
+++ loncom/homework/edit.pm Sun Feb 6 18:43:10 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# edit mode helpers
#
-# $Id: edit.pm,v 1.133 2010/11/13 03:22:58 www Exp $
+# $Id: edit.pm,v 1.134 2011/02/06 18:43:10 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -741,6 +741,12 @@
return ' onclick="still_ask=true;'.$extra_action.'" ';
}
+sub submit_dont_ask {
+ my ($extra_action) = @_;
+ return ' onclick="is_submit=true;'.$extra_action.'" ';
+}
+
+
sub textarea_sizes {
my ($data)=@_;
my $count=0;
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.322 loncom/homework/lonhomework.pm:1.323
--- loncom/homework/lonhomework.pm:1.322 Mon Nov 1 16:19:49 2010
+++ loncom/homework/lonhomework.pm Sun Feb 6 18:43:10 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Homework handler
#
-# $Id: lonhomework.pm,v 1.322 2010/11/01 16:19:49 raeburn Exp $
+# $Id: lonhomework.pm,v 1.323 2011/02/06 18:43:10 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -129,43 +129,44 @@
return ('web');
}
} elsif ($env{'request.state'} eq "construct") {
+#
+# We are in construction space, editing and testing problems
+#
if ( defined($env{'form.grade_target'}) ) {
return ($env{'form.grade_target'});
}
if ( defined($env{'form.preview'})) {
if ( defined($env{'form.submitted'})) {
+#
+# We are doing a problem preview
+#
return ('grade', 'web');
} else {
return ('web');
}
} else {
if ($env{'form.problemstate'} eq 'WEB_GRADE') {
- #$env{'form.webgrade'} = 'yes';
return ('grade','webgrade','answer');
- } elsif (($env{'form.problemmode'} eq 'view') ||
- ($env{'form.problemmode'} eq 'discard')) {
- if ( defined($env{'form.submitted'}) &&
- (!defined($env{'form.resetdata'})) &&
- (!defined($env{'form.newrandomization'}))) {
- return ('grade', 'web','answer');
- } else {
- return ('web','answer');
- }
- } elsif ($env{'form.problemmode'} eq 'edit') {
- if ( $env{'form.submitted'} eq 'edit' ) {
- if ( $env{'form.submitbutton'} eq &mt('Save and View') ) {
- return ('modified','web','answer');
- } else {
- return ('modified','no_output_web','edit');
- }
- } else {
- return ('no_output_web','edit');
- }
+ } elsif ($env{'form.problemmode'} eq 'saveview') {
+ return ('modified','web','answer');
+ } elsif ($env{'form.problemmode'} eq 'discard') {
+ return ('web','answer');
+ } elsif (($env{'form.problemmode'} eq 'saveedit') ||
+ ($env{'form.problemmode'} eq 'undo')) {
+ return ('modified','no_output_web','edit');
+ } elsif ($env{'form.problemmode'} eq 'edit') {
+ return ('no_output_web','edit');
} else {
return ('web');
}
- }
+ }
+#
+# End of Construction Space
+#
}
+#
+# Huh? We are nowhere, so do nothing.
+#
return ();
}
@@ -628,11 +629,12 @@
sub handle_save_or_undo {
my ($request,$problem,$result) = @_;
+
my $file = &Apache::lonnet::filelocation("",$request->uri);
my $filebak =$file.".bak";
my $filetmp =$file.".tmp";
my $error=0;
- if ($env{'form.Undo'} eq &mt('undo')) {
+ if (($env{'form.problemmode'} eq 'undo') || ($env{'form.problemmode'} eq 'undoxml')) {
my $error=0;
if (!&File::Copy::copy($file,$filetmp)) { $error=1; }
if ((!$error) && (!&File::Copy::copy($filebak,$file))) { $error=1; }
@@ -655,6 +657,7 @@
}
} else {
&Apache::lonnet::correct_line_ends($result);
+
my $fs=Apache::File->new(">$filebak");
if (defined($fs)) {
print $fs $$problem;
@@ -898,13 +901,16 @@
$problem='';
}
- if (defined($env{'form.editxmltext'}) || defined($env{'form.Undo'})) {
+
+ if (($env{'form.problemmode'} eq 'saveeditxml') ||
+ ($env{'form.problemmode'} eq 'saveviewxml') ||
+ ($env{'form.problemmode'} eq 'undoxml')) {
my $error=&handle_save_or_undo($request,\$problem,
\$env{'form.editxmltext'});
if (!$error) { $problem=&Apache::lonnet::getfile($file); }
}
&Apache::lonhomework::showhashsubset(\%env,'^form');
- if ( $env{'form.submitbutton'} eq &mt('Save and View') ) {
+ if ($env{'form.problemmode'} eq 'saveviewxml') {
&Apache::lonhomework::showhashsubset(\%env,'^form');
$env{'form.problemmode'}='view';
&renderpage($request,$file);
@@ -918,8 +924,6 @@
&Apache::loncommon::resize_textarea_js().
&Apache::structuretags::setmode_javascript().
&Apache::lonhtmlcommon::dragmath_js("EditMathPopup");
- my $dragmath_button =
- &Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1);
# Breadcrumbs
my $brcrum = [{'href' => &Apache::loncommon::authorspace(),
@@ -934,9 +938,9 @@
'add_entries' => {
'onresize' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
'onload' => q[resize_textarea('LC_editxmltext','LC_aftertextarea')],
- },
+ },
'bread_crumbs' => $brcrum,
-});
+ });
$result=$start_page
.&Apache::loncommon::head_subbox(
@@ -951,25 +955,13 @@
</td><td align="right">
'.&Apache::loncommon::helpLatexCheatsheet('Problem_LON-CAPA_Functions','Script Functions').'
</td></tr>
- </table>
- <div class="LC_edit_problem_discards">
- <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').'" />
- '.$dragmath_button.'
- </div>
- <div class="LC_edit_problem_saves">
- <input type="submit" name="submitbutton" accesskey="s" value="'.&mt('Save').'" />
- <input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />
- </div>
- <hr style="clear:both;" />
- '.&Apache::lonxml::message_location().'
- </div>
- ' . '
- <textarea '.&Apache::edit::element_change_detection().
+ </table>';
+
+ $result.='<input type="hidden" name="problemmode" value="saveedit" />'.
+ &Apache::structuretags::problem_edit_buttons('editxml');
+
+ $result.='<hr style="clear:both;" />'.&Apache::lonxml::message_location().'</div>'.
+ '<textarea '.&Apache::edit::element_change_detection().
' rows="'.$rows.'" cols="'.$cols.'" style="width:100%" '.
' name="editxmltext" id="LC_editxmltext">'.
&HTML::Entities::encode($problem,'<>&"').'</textarea>
@@ -1246,7 +1238,10 @@
#first visit to problem in construction space
$env{'form.problemmode'}= 'view';
&renderpage($request,$file);
- } elsif ($env{'form.problemmode'} eq 'editxml') {
+ } elsif (($env{'form.problemmode'} eq 'editxml') ||
+ ($env{'form.problemmode'} eq 'saveeditxml') ||
+ ($env{'form.problemmode'} eq 'saveviewxml') ||
+ ($env{'form.problemmode'} eq 'undoxml')) {
&editxmlmode($request,$file);
} elsif ($env{'form.problemmode'} eq 'calcanswers') {
&analyze($request,$file);
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.486 loncom/homework/structuretags.pm:1.487
--- loncom/homework/structuretags.pm:1.486 Tue Jan 18 21:45:32 2011
+++ loncom/homework/structuretags.pm Sun Feb 6 18:43:10 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.486 2011/01/18 21:45:32 www Exp $
+# $Id: structuretags.pm,v 1.487 2011/02/06 18:43:10 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -464,27 +464,48 @@
<input type="hidden" name="problemstatus" value="'.$env{'form.problemstatus'}.'" />';
}
+sub problem_edit_action_button {
+ my ($name,$action,$accesskey,$text,$flag)=@_;
+ my $actionscript="setmode(this.form,'$action')";
+ return "\n<input type='button' name='$name' accesskey='$accesskey' value='".&mt($text)."'".
+ ($flag?&Apache::edit::submit_ask_anyway($actionscript):&Apache::edit::submit_dont_ask($actionscript))." />";
+}
+
sub problem_edit_buttons {
- return '
-<div class="LC_edit_problem_discards">
- <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="submitbutton" accesskey="s" value="'.&mt('Save and Edit').'" />
- <input type="submit" name="submitbutton" accesskey="v" value="'.&mt('Save and View').'" />
-</div>';
+ my ($mode)=@_;
+# Buttons that do not save
+ my $result='<div class="LC_edit_problem_discards">'.
+ &problem_edit_action_button('subdiscview','discard','d','Discard Edits and View',1);
+ if ($mode eq 'editxml') {
+ $result.=&problem_edit_action_button('subedit','edit','e','Edit',1);
+ $result.=&problem_edit_action_button('subundo','undoxml','u','Undo',1);
+ $result.=&Apache::lonhtmlcommon::dragmath_button("LC_editxmltext",1);
+ } else {
+ $result.=&problem_edit_action_button('subeditxml','editxml','x','EditXML',1);
+ $result.=&problem_edit_action_button('subundo','undo','u','Undo',1);
+ }
+ $result.="\n</div>";
+# Buttons that save
+ $result.='<div class="LC_edit_problem_saves">';
+ if ($mode eq 'editxml') {
+ $result.=&problem_edit_action_button('subsaveedit','saveeditxml','s','Save and EditXML');
+ $result.=&problem_edit_action_button('subsaveview','saveviewxml','v','Save and View');
+ } else {
+ $result.=&problem_edit_action_button('subsaveedit','saveedit','s','Save and Edit');
+ $result.=&problem_edit_action_button('subsaveview','saveview','v','Save and View');
+ }
+ $result.="\n</div>\n";
+ return $result;
}
sub problem_edit_header {
- return '<input type="hidden" name="submitted" value="edit" /><input type="hidden" name="problemmode" value="edit" />'.
- &Apache::structuretags::remember_problem_state().'
+ return '<input type="hidden" name="submitted" value="edit" />'.
+ &remember_problem_state('edit').'
<div class="LC_edit_problem_header">
<div class="LC_edit_problem_header_title">
'.&mt('Problem Editing').&Apache::loncommon::help_open_menu('Problem Editing','Problem_Editor_XML_Index',5,'Authoring').'
</div>'.
+'<input type="hidden" name="problemmode" value="saveedit" />'.
&problem_edit_buttons().'
<hr style="clear:both;" />
'.&Apache::lonxml::message_location().'
--www1297017791--