[LON-CAPA-cvs] cvs: rat / lonpage.pm loncom/homework inputtags.pm structuretags.pm
raeburn
raeburn at source.lon-capa.org
Sun Sep 14 11:21:47 EDT 2014
raeburn Sun Sep 14 15:21:47 2014 EDT
Modified files:
/loncom/homework structuretags.pm inputtags.pm
/rat lonpage.pm
Log:
- Bug 6740
- Eliminate multiple submit button clicks (work in progress).
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.519 loncom/homework/structuretags.pm:1.520
--- loncom/homework/structuretags.pm:1.519 Sun May 18 02:13:45 2014
+++ loncom/homework/structuretags.pm Sun Sep 14 15:21:43 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.519 2014/05/18 02:13:45 raeburn Exp $
+# $Id: structuretags.pm,v 1.520 2014/09/14 15:21:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -254,6 +254,32 @@
input_element.value = click;
img_element.src = '/adm/randomlabel.png?token='+token+'&clickdata='+click;
}
+
+var submithandled = 0;
+
+$(document).ready(function(){
+ $(document).delegate('form :submit', 'click', function( event ) {
+ if ( $( this ).hasClass( "LC_hwk_submit" ) ) {
+ var buttonId = this.id;
+ if (submithandled == 0) {
+ submithandled = 1;
+ $( "#msg_"+buttonId ).css({"display": "inline","background-color": "#87cefa",
+ "color": "black","padding": "2px"}) ;
+ $( ".LC_status_"+buttonId ).hide();
+ if (( $(this.form).id == "LC_page" ) && ($('input[name="all_submit"]').length )) {
+ if (( "#"+buttonId+"_pressed" ).length) {
+ $( "#"+buttonId+"_pressed" ).val( "1" );
+ }
+ }
+ $(this.form).submit();
+ $( this ).attr( "disabled", true);
+ event.preventDefault();
+ return true;
+ }
+ }
+ });
+});
+
// ]]>
</script>
JS
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.324 loncom/homework/inputtags.pm:1.325
--- loncom/homework/inputtags.pm:1.324 Thu Jun 19 19:37:35 2014
+++ loncom/homework/inputtags.pm Sun Sep 14 15:21:43 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.324 2014/06/19 19:37:35 raeburn Exp $
+# $Id: inputtags.pm,v 1.325 2014/09/14 15:21:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -997,7 +997,7 @@
}
sub decideoutput {
- my ($award,$awarded,$awardmsg,$solved,$previous,$target,$nocorrect)=@_;
+ my ($award,$awarded,$awardmsg,$solved,$previous,$target,$nocorrect,$tdclass)=@_;
my $message='';
my $button=0;
@@ -1573,7 +1573,7 @@
}
sub get_grade_messages {
- my ($id,$prefix,$target,$status,$nocorrect) = @_;
+ my ($id,$prefix,$target,$status,$nocorrect,$tdclass) = @_;
# nocorrect suppresses "Computer's answer now shown above"
my ($message,$latemessage,$trystr,$previousmsg);
my $showbutton = 1;
@@ -1588,13 +1588,13 @@
&Apache::lonxml::debug('Getting message');
($showbutton,my $css_class,$message,$previousmsg) =
&decideoutput($award,$awarded,$awardmsg,$solved,$previous,
- $target,(($status eq 'CAN_ANSWER') || $nocorrect));
+ $target,(($status eq 'CAN_ANSWER') || $nocorrect),$tdclass);
if ($target eq 'tex') {
$message='\vskip 2 mm '.$message.' ';
} else {
- $message="<td class=\"$css_class\">$message</td>";
+ $message="<td class=\"$tdclass $css_class\">$message</td>";
if ($previousmsg) {
- $previousmsg="<td class=\"LC_answer_previous\">$previousmsg</td>";
+ $previousmsg="<td class=\"$tdclass LC_answer_previous\">$previousmsg</td>";
}
}
}
@@ -1629,7 +1629,7 @@
$trial.="/".$Apache::inputtags::params{'maxtries'};
}
}
- $trystr = '<td><span class="LC_nobreak">'.&mt($tries_text.' [_1]',$trial).'</span></td>';
+ $trystr = '<td class="'.$tdclass.'"><span class="LC_nobreak">'.&mt($tries_text.' [_1]',$trial).'</span></td>';
}
}
@@ -1637,7 +1637,7 @@
#last submissions was after due date
$latemessage=&mt(' The last submission was after the Due Date ');;
if ($target eq 'web') {
- $latemessage='<td class="LC_answer_late">'.$latemessage.'</td>';
+ $latemessage='<td class="'.$tdclass.' LC_answer_late">'.$latemessage.'</td>';
}
}
return ($previousmsg,$latemessage,$message,$trystr,$showbutton);
@@ -1651,6 +1651,7 @@
my $trystr='';
my $button='';
my $previousmsg='';
+ my $tdclass='';
my $status = $Apache::inputtags::status['-1'];
&Apache::lonxml::debug("gradestatus has :$status:");
@@ -1667,21 +1668,29 @@
$showbutton = 0;
}
+ unless (($status eq 'SHOW_ANSWER') || ($status eq 'CANNOT_ANSWER')) {
+ if ($target ne 'tex') {
+ $tdclass = 'LC_status_submit_'.$id;
+ }
+ }
+
($previousmsg,$latemessage,$message,$trystr) =
&get_grade_messages($id,"resource.$id",$target,$status,
- $showbutton);
+ $showbutton,$tdclass);
if ($status eq 'CANNOT_ANSWER') {
$showbutton = 0;
}
if ( $status eq 'SHOW_ANSWER') {
undef($previousmsg);
}
- if ( $showbutton ) {
+ if ( $showbutton ) {
if ($target ne 'tex') {
$button =
'<input onmouseup="javascript:setSubmittedPart(\''.$id.'\');this.form.action+=\'#'.&escape($id).'\';"
- type="submit" name="submit_'.$id.'"
- value="'.&mt('Submit Answer').'" />';
+ type="submit" name="submit_'.$id.'" id="submit_'.$id.'" class="LC_hwk_submit"
+ value="'.&mt('Submit Answer').'" /> '.
+ '<div id="msg_submit_'.$id.'" style="display:none">'.
+ &mt('Processing your submission ...').'</div>';
}
}
@@ -1696,7 +1705,7 @@
$output =
'<table><tr><td>'.$button.'</td>'.$output;
if (!$no_previous) {
- $output.='<td>'.&previous_tries($id,$target).'</td>';
+ $output.='<td class="'.$tdclass.'">'.&previous_tries($id,$target).'</td>';
}
$output.= '</tr></table>';
return $output;
Index: rat/lonpage.pm
diff -u rat/lonpage.pm:1.104 rat/lonpage.pm:1.105
--- rat/lonpage.pm:1.104 Sat Mar 8 18:27:39 2014
+++ rat/lonpage.pm Sun Sep 14 15:21:47 2014
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Page Handler
#
-# $Id: lonpage.pm,v 1.104 2014/03/08 18:27:39 raeburn Exp $
+# $Id: lonpage.pm,v 1.105 2014/09/14 15:21:47 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -373,6 +373,10 @@
s/\<((?:input|select|button|textarea)[^\>]+)name\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 name="$prefix$2" $3\>/gsi;
$output=~
s/\<((?:input|select|button|textarea)[^\>]+)id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\>]*)\>/\<$1 id="$idprefix$2" $3\>/gsi;
+ $output=~
+ s/(\Q<div id="msg_\E)(\Qsubmit_\E)([^"]*)(\Q" style="display:none">\E)/<input type="hidden" name="$prefix$2$3_pressed" id="$idprefix$2$3_pressed" value="" \/>$1$idprefix$2$3$4/g;
+ $output=~
+ s/(\Q<td class="LC_status_\E)(\Qsubmit_\E)([^\"]*)(\s*[^\"]*"\>)/$1$idprefix$2$3$4/g;
if ($nuploads) {
$output=~
s/\<(input[^\>]+name=\"\Q$prefix\EHWFILE[^\>]+)\s*id\s*\=\s*[\'\"]*([^\'\"]+)[\'\"]*([^\)]*)\>/\<$1 id="$prefix$2" $3\>/gsi;
@@ -457,7 +461,7 @@
}
$fmtag .= ' action="'.
&Apache::lonenc::check_encrypt($requrl)
- .'">';
+ .'" id="LC_page">';
$r->print($fmtag);
}
} elsif (($target eq 'tex') || ($target eq 'tex_answer')) {
More information about the LON-CAPA-cvs
mailing list