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

albertel lon-capa-cvs-allow@mail.lon-capa.org
Mon, 23 Jul 2007 23:30:48 -0000


albertel		Mon Jul 23 19:30:48 2007 EDT

  Modified files:              
    /loncom/homework	lonhomework.pm structuretags.pm 
  Log:
  - add ability to apply style while editing in cstr
  
  
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.267 loncom/homework/lonhomework.pm:1.268
--- loncom/homework/lonhomework.pm:1.267	Fri Apr  6 20:12:42 2007
+++ loncom/homework/lonhomework.pm	Mon Jul 23 19:30:47 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.267 2007/04/07 00:12:42 albertel Exp $
+# $Id: lonhomework.pm,v 1.268 2007/07/23 23:30:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -901,6 +901,7 @@
     my @targets = @{$targets || [&get_target()]};
     &Apache::lonhomework::showhashsubset(\%env,'form.');
     &Apache::lonxml::debug("Running targets ".join(':',@targets));
+
     my $overall_result;
     foreach my $target (@targets) {
 	# FIXME need to do something intelligent when a problem goes
@@ -977,7 +978,9 @@
     my @allnames;
     &Apache::lonxml::debug("Looking for :$extension:");
     foreach my $file (</home/httpd/html/res/adm/includes/templates/*.$extension>) {
+	&Apache::lonxml::debug("Looking at $file");
 	my $name=&Apache::lonnet::metadata($file,'title');
+	&Apache::lonxml::debug("Got a name $name");
 	if ($namewanted && ($name eq $namewanted)) {
 	    $result=$file;
 	    last;
@@ -1047,6 +1050,24 @@
     return '';
 }
 
+sub update_construct_style {
+    if ($env{'request.state'} eq "construct"
+	&& $env{'form.problemmode'} eq &mt('View') 
+	&&  defined($env{'form.submitted'})
+	&& !defined($env{'form.resetdata'})
+	&& !defined($env{'form.newrandomization'})) {
+	if ((!$env{'form.style_file'} && $env{'construct.style'})
+	    ||$env{'form.clear_style_file'}) {
+	    &Apache::lonnet::delenv('construct\\.style');
+	} elsif ($env{'form.style_file'} 
+	    && $env{'construct.style'} ne $env{'form.style_file'}) {
+	    &Apache::lonnet::appenv('construct.style' => 
+				        $env{'form.style_file'});
+	}
+    }
+}
+
+
 sub handler {
     #my $t0 = [&gettimeofday()];
     my $request=$_[0];
@@ -1097,6 +1118,7 @@
 	    } elsif ($env{'form.problemmode'} eq &mt('Calculate answers')) {
 		&analyze($request,$file);
 	    } else {
+		&update_construct_style();
 		&renderpage($request,$file);
 	    }
 	} else {
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.383 loncom/homework/structuretags.pm:1.384
--- loncom/homework/structuretags.pm:1.383	Tue Jul 17 14:18:54 2007
+++ loncom/homework/structuretags.pm	Mon Jul 23 19:30:47 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.383 2007/07/17 18:18:54 albertel Exp $
+# $Id: structuretags.pm,v 1.384 2007/07/23 23:30:47 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -125,7 +125,7 @@
 
 	$extra_head .= &Apache::londefdef::generate_css_links();
 
-	if ($target eq 'edit') {
+	if ($env{'request.state'} eq 'construct') {
 	    $extra_head.=&Apache::edit::js_change_detection().
 		"<script type=\"text/javascript\">\n".
 		"if (typeof swmenu != 'undefined') {swmenu.currentURL=null;}\n".
@@ -309,16 +309,22 @@
               <input type="text" name="rndseed" size="10" value="'.
 	       $rndseed.'"
            onchange="javascript:document.lonhomework.changerandseed.click()" /></nobr>
-             <label><input type="checkbox" name="showallfoils" ';
+             <span class="LC_nobreak"><label><input type="checkbox" name="showallfoils" ';
     my $show_all_foils_text = 
 	($Apache::lonhomework::parsing_a_task) ?
 	&mt('&nbsp;Show&nbsp;All&nbsp;Instances')
 	: &mt('&nbsp;Show&nbsp;All&nbsp;Foils');
 
     if (defined($env{'form.showallfoils'})) { $result.='checked="on"'; }
-    $result.= ' />'.$show_all_foils_text.'</label>'.
+    $result.= ' />'.$show_all_foils_text.'</label></span>'.
 	&Apache::loncommon::help_open_topic('Problem_Editor_Testing_Area','Testing Problems').
 	'<hr />';
+    $result.=&mt('Apply style file').'
+<input type="text" name="style_file" value="'.&HTML::Entities::encode($env{'construct.style'},'"<>&').'" />
+ <a href="javascript:openbrowser(\'lonhomework\',\'style_file\',\'sty\')">'.&mt('Select').'</a>
+<input type="submit" name="clear_style_file" value="'.&mt('Clear').'" />
+<br />';
+
     if (!$Apache::lonhomework::parsing_a_task) {
 	$result.="
 <nobr>