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

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 31 Mar 2005 21:24:29 -0000


albertel		Thu Mar 31 16:24:29 2005 EDT

  Modified files:              
    /loncom/homework	essayresponse.pm inputtags.pm bridgetask.pm 
  Log:
  - some cleanups/improvments to the file submission layout
  - modularize the file submission code
  - allow a user to submit a portfolio file
  
  
Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.59 loncom/homework/essayresponse.pm:1.60
--- loncom/homework/essayresponse.pm:1.59	Thu Feb 10 17:43:15 2005
+++ loncom/homework/essayresponse.pm	Thu Mar 31 16:24:29 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.59 2005/02/10 22:43:15 banghart Exp $
+# $Id: essayresponse.pm,v 1.60 2005/03/31 21:24:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -48,7 +48,6 @@
 	my $coll= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.collaborators"},'<>&"');
 	my $uploadedfiletypes= &Apache::lonnet::EXT("resource.$part".'_'."$id.uploadedfiletypes");
         $uploadedfiletypes=~s/[^\w\,]//g;
-	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
 	$result='<br /><table border="1">';
 	$result.='<tr><td>'.
 	    '<input type="radio" name="HWDRAFT'.$part.'_'.$id.'" value="yes" checked="checked" /> '.
@@ -64,32 +63,8 @@
 	    $result .= &check_collaborators($ncol,$coll) if ($coll =~ /\w+/);
 	    $result .='</td></tr>';
 	}
-        if ($uploadedfiletypes) {
-	    $result.='<tr><td>'.&mt('Submit a file: (only one file can be uploaded)').
-		' <br /><input type="file" size="50" name="HWFILE'.
-		$part.'_'.$id.'" /><br />'.
-		&mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />'.
-                '<strong>OR:</strong><br /><a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&amp;fieldname=HWPORT'.$part.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>Select Portfolio Files</a>'.
-                '<br />'.
-                '<input type="text" size="50" name="HWPORT'.$part.'_'.$id.'" value="" />'.
-		'<br />';
-	    if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
-	        $result.="Portfolio files previously selected: <strong>".&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"})."</strong><br />";
-	    }
-
-            if ($uploadedfile) {
-	       my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
-	       push (@Apache::lonxml::extlinks,$url);
-	       &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
-	       my $curfile='<a href="'.$url.
-		   '"><img src="/adm/lonIcons/unknown.gif" border=0" /> '.
-		   $uploadedfile.'</a>';
-	       $result.=&mt('Currently submitted: <tt>[_1]</tt>',$curfile);
-           } else {
-              $result.=&mt('(Hand in a file you have prepared on your computer)');
-           }
-           $result.='</td></tr>'; 
-        }
+	$result.=&Apache::inputtags::file_selector($part,$id,
+						   $uploadedfiletypes,'both');
         $result.='</table>';
     }
     return $result;
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.159 loncom/homework/inputtags.pm:1.160
--- loncom/homework/inputtags.pm:1.159	Tue Mar 15 11:50:19 2005
+++ loncom/homework/inputtags.pm	Thu Mar 31 16:24:29 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.159 2005/03/15 16:50:19 albertel Exp $
+# $Id: inputtags.pm,v 1.160 2005/03/31 21:24:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -294,6 +294,62 @@
     return "";
 }
 
+# $part -> partid
+# $id -> responseid
+# $uploadefiletypes -> comma seperated list of extensions allowed or * for any
+# $which -> 'uploadedonly'  -> only newly uploaded files
+#           'portfolioonly' -> only allow files from portfolio
+#           'both' -> allow files from either location
+# returns a table row <tr> 
+sub file_selector {
+    my ($part,$id,$uploadedfiletypes,$which)=@_;
+    if (!$uploadedfiletypes) { return ''; }
+    my $result;
+    
+    $result.='<tr><td>'.
+	&mt('Allowed filetypes: <b>[_1]</b>',$uploadedfiletypes).'<br />';
+    if ($which eq 'uploadonly' || $which eq 'both') { 
+	$result.=&mt('Submit a file: (only one file can be uploaded)').
+	    ' <br /><input type="file" size="50" name="HWFILE'.
+	    $part.'_'.$id.'" /><br />';
+	my $uploadedfile= &HTML::Entities::encode($Apache::lonhomework::history{"resource.$part.$id.uploadedfile"},'<>&"');
+
+	if ($uploadedfile) {
+	    my $url=$Apache::lonhomework::history{"resource.$part.$id.uploadedurl"};
+	    push (@Apache::lonxml::extlinks,$url);
+	    &Apache::lonnet::allowuploaded('/adm/essayresponse',$url);
+	    my $icon=&Apache::loncommon::icon($url);
+	    my $curfile='<a href="'.$url.'"><img src="'.$icon.
+		'" border="0" />'.$uploadedfile.'</a>';
+	    $result.=&mt('Currently submitted: <tt>[_1]</tt>',$curfile);
+	} else {
+	    #$result.=&mt('(Hand in a file you have prepared on your computer)');
+	}
+    }
+    if ( $which eq 'both') { 
+	$result.='<br />'.'<strong>'.&mt('OR:').'</strong><br />';
+    }
+    if ($which eq 'portfolioonly' || $which eq 'both') { 
+	$result.='<a href='."'".'javascript:void(window.open("/adm/portfolio?mode=selectfile&amp;fieldname=HWPORT'.$part.'_'.$id.'","cat","height=600,width=800,scrollbars=1,resizable=1,menubar=2,location=1"))'."'".'>'.
+	    &mt('Select Portfolio Files').'</a><br />'.
+	    '<input type="text" size="50" name="HWPORT'.$part.'_'.$id.'" value="" />'.
+	    '<br />';
+	if ($Apache::lonhomework::history{"resource.$part.$id.portfiles"}=~/[^\s]/){
+	    my $filelist;
+	    foreach my $file (split(',',&Apache::lonnet::unescape($Apache::lonhomework::history{"resource.$part.$id.portfiles"}))) {
+		my (undef,undef,$domain,$user)=&Apache::lonxml::whichuser();
+		my $url="/uploaded/$domain/$user/portfolio$file";
+		my $icon=&Apache::loncommon::icon($url);
+		$filelist.='<a href="'.$url.'"><img src="'.$icon.
+		    '" border="0" />'.$file.'</a>';
+	    }
+	    $result.=&mt("Portfolio files previously selected: <strong>[_1]</strong>",$filelist);
+	}
+    }
+    $result.='</td></tr>'; 
+    return $result;
+}
+
 sub checkstatus {
     my ($value,$awardref,$msgref)=@_;
     for (my $i=0;$i<=$#$awardref;$i++) {
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.7 loncom/homework/bridgetask.pm:1.8
--- loncom/homework/bridgetask.pm:1.7	Thu Mar 31 11:05:13 2005
+++ loncom/homework/bridgetask.pm	Thu Mar 31 16:24:29 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: bridgetask.pm,v 1.7 2005/03/31 16:05:13 albertel Exp $
+# $Id: bridgetask.pm,v 1.8 2005/03/31 21:24:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,6 +61,14 @@
     return 0;
 }
 
+sub add_previous_version_button {
+    my $result;
+    $result.=' Show a previously done version: <select name="previousversion">
+<option>Pick one</option>
+</select>';
+    return $result;
+}
+
 sub start_Task {
     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
 
@@ -73,6 +81,9 @@
     my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
 	&Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
 
+    if ($target eq 'web') {
+	$body_tag_start.=&add_previous_version_button();
+    }
     if ($target eq 'web' || $target eq 'grade' || $target eq 'answer' ||
 	$target eq 'tex') {
 	($status,$accessmsg,$slot) = 
@@ -153,6 +164,10 @@
 	    ($target eq 'answer') || ($target eq 'tex')
 	   ) {
 	    if ($target eq 'web') {
+		$result.='<table border="1">'.
+		    &Apache::inputtags::file_selector("bridge","task","*",
+						      'portfolioonly').
+						      "</table>";
 		$result.=&Apache::lonxml::xmlend().'</html>';
 	    }
 	}