[LON-CAPA-cvs] cvs: loncom(version_2_10_X) /homework structuretags.pm

raeburn raeburn@source.lon-capa.org
Tue, 09 Nov 2010 17:52:13 -0000


raeburn		Tue Nov  9 17:52:13 2010 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom/homework	structuretags.pm 
  Log:
  - Backport 1.478.
  
  
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.465.2.5 loncom/homework/structuretags.pm:1.465.2.6
--- loncom/homework/structuretags.pm:1.465.2.5	Tue Sep 14 02:46:20 2010
+++ loncom/homework/structuretags.pm	Tue Nov  9 17:52:13 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.465.2.5 2010/09/14 02:46:20 raeburn Exp $
+# $Id: structuretags.pm,v 1.465.2.6 2010/11/09 17:52:13 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'})) {
@@ -281,6 +324,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();