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

raeburn raeburn@source.lon-capa.org
Wed, 03 Nov 2010 17:06:28 -0000


raeburn		Wed Nov  3 17:06:28 2010 EDT

  Modified files:              
    /loncom/homework	structuretags.pm inputtags.pm 
  Log:
  - BridgeTask (for .task files):
    Javascript pop-up confirm if "Submit Answer" is pressed when previously 
    submitted files have been marked for deletion.
  - Display of submitted files for essayresponse and BT includes warning
    about consequences of file deletion.  
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.477 loncom/homework/structuretags.pm:1.478
--- loncom/homework/structuretags.pm:1.477	Thu Oct 28 00:27:56 2010
+++ loncom/homework/structuretags.pm	Wed Nov  3 17:06:28 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.477 2010/10/28 00:27:56 www Exp $
+# $Id: structuretags.pm,v 1.478 2010/11/03 17:06:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -161,6 +161,45 @@
 ENDSCRIPT
 }
 
+sub file_delchk_js {
+    my $delfilewarn = &mt('You have indicated you wish to delete some files previously included for submission.').'\\n'.
+                          &mt('Deleted files will not be graded.').' '.
+                          &mt('Submit Answer?');
+    return <<"ENDSCRIPT";
+<script type="text/javascript">
+function file_deletion_check(formname) {
+    var str = new RegExp("^HWFILE.+_delete\$");
+    var delfilecount = 0;
+    var elemnum = formname.elements.length;
+    if (elemnum == 0) {
+        return true;
+    }
+    for (i=0; i<formname.elements.length; i++) {
+        var id = formname.elements[i].id;
+        if (id != '') {
+            if (str.test(id)) {
+                if (formname.elements[i].type == 'checkbox') {
+                    if (formname.elements[i].checked) {
+                        delfilecount ++;
+                    }
+                }
+            }
+        }
+    }
+    if (delfilecount > 0) {
+        if (confirm("$delfilewarn")) {
+            return true;
+        } else {
+            return false;
+        }
+    } else {
+        return true;
+    }
+}
+</script>
+ENDSCRIPT
+}
+
 sub page_start {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$name,
 	$extra_head)=@_;
@@ -185,6 +224,10 @@
                               );
         $extra_head .= &Apache::lonhtmlcommon::htmlareaselectactive(\%textarea_args);
     }
+    my $is_task = ($env{'request.uri'} =~ /\.task$/);
+    if ($is_task) {
+        $extra_head .= &file_delchk_js();
+    }
 
     my %body_args;
     if (defined($found{'html'})) {
@@ -277,6 +320,9 @@
 	if ($target eq 'edit') {
 	    $form_tag_start.=&Apache::edit::form_change_detection();
 	}
+        if ($is_task) {
+            $form_tag_start .= ' onsubmit="return file_deletion_check(this);"';
+        }
 	$form_tag_start.='>'."\n";
 
 	my $symb=&Apache::lonnet::symbread();
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.272 loncom/homework/inputtags.pm:1.273
--- loncom/homework/inputtags.pm:1.272	Sun Oct 31 12:33:02 2010
+++ loncom/homework/inputtags.pm	Wed Nov  3 17:06:28 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.272 2010/10/31 12:33:02 www Exp $
+# $Id: inputtags.pm,v 1.273 2010/11/03 17:06:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -576,6 +576,7 @@
     }
     foreach my $name (sort(keys(%okfiles))) {
         if (ref($okfiles{$name}) eq 'ARRAY') {
+            my $num = 0;
             foreach my $url (@{$okfiles{$name}}) {
                 if (ref($rows{$url}) eq 'HASH') {
                     my $link = $rows{$url}{link};
@@ -592,7 +593,8 @@
                         if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
                             $result .=
                                  '<td valign="bottom"><input type="checkbox" name="HWFILE'.$jspart.'_'.$id.'_delete"'.
-                                 ' value="'.$portfile.'" /></td>'."\n";
+                                 ' value="'.$portfile.'" id="HWFILE'.$jspart.'_'.$id.'_'.$num.'_delete" /></td>'."\n";
+                            $num ++;
                         }
                         my $showname = $rows{$url}{path}.$name;
                         if ($legacy{$url}) {
@@ -610,7 +612,9 @@
         }
     }
     if ($header_shown) {
-        $result .= &Apache::loncommon::end_data_table();
+        $result .= &Apache::loncommon::end_data_table().
+                   '<br /><span class="LC_warning">'.
+                   &mt('Items checked for deletion will not be included amongst the files evaluated when your submission is graded.').'</span>';
     }
     if (@bad_file_list) {
         my $bad_files = '<span class="LC_filename">'.