[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet Spreadsheet.pm studentcalc.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 26 Aug 2005 20:46:49 -0000


albertel		Fri Aug 26 16:46:49 2005 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm studentcalc.pm 
  Log:
  - fixes bug #4296 spreadsheet can't be edited
  
  
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.53 loncom/interface/spreadsheet/Spreadsheet.pm:1.54
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.53	Wed Aug 24 14:14:47 2005
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Fri Aug 26 16:46:46 2005
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.53 2005/08/24 18:14:47 albertel Exp $
+# $Id: Spreadsheet.pm,v 1.54 2005/08/26 20:46:46 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -968,25 +968,32 @@
         $self->{'formulas'} = $formulas;
         $self->{'rows'} = [];
         $self->{'template_cells'} = [];
+	$self->{'loaded'} = 1;
         return;
     } else {
-	if (!$self->{'loaded'}) {
-	    $self->{'loaded'}=1;
-	    # Load in the spreadsheet definition
-	    if (exists($env{'form.workcopy'}) && 
-		$self->{'type'} eq $env{'form.workcopy'}) {
-		$self->load_tmp();
-	    } else {
-		$self->load();
-	    }
-	}
+	$self->check_formulas_loaded();
         return %{$self->{'formulas'}};
     }
 }
 
+sub check_formulas_loaded {
+    my $self=shift;
+    if (!$self->{'loaded'}) {
+	$self->{'loaded'}=1;
+	# Load in the spreadsheet definition
+	if (exists($env{'form.workcopy'}) && 
+	    $self->{'type'} eq $env{'form.workcopy'}) {
+	    $self->load_tmp();
+	} else {
+	    $self->load();
+	}
+    }
+}
+
 sub set_formula {
     my $self = shift;
     my ($cell,$formula) = @_;
+    $self->check_formulas_loaded();
     $self->{'formulas'}->{$cell}=$formula;
     return;
 }
@@ -996,7 +1003,7 @@
 ##
 sub formulas_keys {
     my $self = shift;
-    my @keys = keys(%{$self->{'formulas'}});
+    $self->check_formulas_loaded();
     return keys(%{$self->{'formulas'}});
 }
 
@@ -1007,6 +1014,7 @@
 sub formula {
     my $self = shift;
     my $cell = shift;
+    $self->check_formulas_loaded();
     if (defined($cell) && exists($self->{'formulas'}->{$cell})) {
         return $self->{'formulas'}->{$cell};
     }
@@ -1085,6 +1093,7 @@
     my $self = shift;
     $self->{'rows'}=[];
     $self->{'template_cells'}=[];
+    $self->check_formulas_loaded();
     while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
         push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0);
         push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);
@@ -1525,6 +1534,7 @@
     ## Will be rendered for the user
     ## But not on this day
     my $Str = '<spreadsheet type="'.$self->{'type'}.'">'."\n";
+    $self->check_formulas_loaded();
     while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
         if ($cell =~ /^template_(\w+)/) {
             my $col = $1;
@@ -1674,6 +1684,7 @@
 
 sub set_row_sources {
     my $self = shift;
+    $self->check_formulas_loaded();
     while (my ($cell,$value) = each(%{$self->{'formulas'}})) {
         next if ($cell !~ /^A(\d+)/ || $1 < 1);
         my $row = $1;
@@ -1684,6 +1695,7 @@
 
 sub set_row_numbers {
     my $self = shift;
+    $self->check_formulas_loaded();
     while (my ($cell,$value) = each(%{$self->{'formulas'}})) {
 	next if ($cell !~ /^A(\d+)$/);
         next if (! defined($value));
Index: loncom/interface/spreadsheet/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.34 loncom/interface/spreadsheet/studentcalc.pm:1.35
--- loncom/interface/spreadsheet/studentcalc.pm:1.34	Fri Aug  5 16:06:22 2005
+++ loncom/interface/spreadsheet/studentcalc.pm	Fri Aug 26 16:46:46 2005
@@ -1,5 +1,5 @@
 #
-# $Id: studentcalc.pm,v 1.34 2005/08/05 20:06:22 albertel Exp $
+# $Id: studentcalc.pm,v 1.35 2005/08/26 20:46:46 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -585,6 +585,7 @@
 
 sub set_row_sources {
     my $self = shift;
+    $self->check_formulas_loaded();
     while (my ($cell,$value) = each(%{$self->{'formulas'}})) {
         next if ($cell !~ /^A(\d+)$/ || $1 < 1);
         my $row = $1;
@@ -597,6 +598,7 @@
 
 sub set_row_numbers {
     my $self = shift;
+    $self->check_formulas_loaded();
     while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
         next if ($cell !~ /^A(\d+)/);
         my $row = $1;