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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 27 May 2003 19:17:07 -0000


This is a MIME encoded message

--matthew1054063027
Content-Type: text/plain

matthew		Tue May 27 15:17:07 2003 EDT

  Modified files:              
    /loncom/interface/spreadsheet	lonspreadsheet.pm 
  Log:
  Moved load/save dialog generation to seperate subroutine.
  Reworked placement of UI elements.
  Added 'browse' link for  selection (part of Bug 657) of published
  spreadsheets.  These are not currently supported, but this is the first step.
  
  
--matthew1054063027
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20030527151707.txt"

Index: loncom/interface/spreadsheet/lonspreadsheet.pm
diff -u loncom/interface/spreadsheet/lonspreadsheet.pm:1.4 loncom/interface/spreadsheet/lonspreadsheet.pm:1.5
--- loncom/interface/spreadsheet/lonspreadsheet.pm:1.4	Fri May 23 15:36:04 2003
+++ loncom/interface/spreadsheet/lonspreadsheet.pm	Tue May 27 15:17:07 2003
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.4 2003/05/23 19:36:04 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.5 2003/05/27 19:17:07 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -58,6 +58,7 @@
 use Apache::studentcalc();
 use Apache::assesscalc();
 use Apache::Constants qw(:common :http);
+use Apache::lonmenu();
 use Apache::lonnet;
 use Apache::lonhtmlcommon;
 use HTML::Entities();
@@ -88,6 +89,94 @@
     return $selout.'</select>';
 }
 
+sub file_dialogs {
+    my ($spreadsheet) = @_;
+    my $bgcolor = "#FFFFFF";
+    my $sheettype = $spreadsheet->{'type'};
+    my $result = '';
+    ##
+    ## Deal with saving the spreadsheet
+    if (exists($ENV{'form.save'}) && 
+        exists($ENV{'form.savefilename'})) {
+        $spreadsheet->filename($ENV{'form.savefilename'});
+        my $save_status = $spreadsheet->save();
+        if ($save_status ne 'ok') {
+            $result .= "An error occurred while saving the spreadsheet".
+                "There error is:".$save_status;
+            return $result;
+        } else {
+            $result .= "Spreadsheet saved as ".$ENV{'form.savefilename'};
+        }
+    } elsif (exists($ENV{'form.newformula'}) && 
+             exists($ENV{'form.cell'})       && 
+             $ENV{'form.cell'} ne '' ) {
+        ##
+        ## Make any requested modifications to the spreadsheet
+        $spreadsheet->modify_cell($ENV{'form.cell'},
+                                  $ENV{'form.newformula'});
+        $spreadsheet->save_tmp();
+        # output that we are dealing with a temporary file
+        $result .=&hiddenfield('workcopy',$sheettype);
+        $result .='<pre>'.$ENV{'form.cell'}.' = '.
+                  $ENV{'form.newformula'}."</pre>\n";
+    }
+    ##
+    ## Editing code
+    $result .=&hiddenfield('cell','').
+              &hiddenfield('newformula','');
+    ##
+    ## Create the save and load dialogs
+    my $filename = $spreadsheet->filename();
+    $filename = '' if ($filename =~ /^default\.$sheettype/i);
+    $filename =~ s/_$sheettype$//;
+    my $save_dialog = '<nobr>'.
+        '<input type="submit" name="save" value="Save as" /> '.
+        '<input type="text" name="savefilename" size="30" value="'.
+        $filename.'" />'.
+        '</nobr>';
+    my $makedefault_dialog = '<input type="submit" name="makedefault" '.
+        'value="Make This Sheet the Default"/>';
+    #
+    my $link = '<a href="javascript:openbrowser'.
+        "('sheet','loadfilename','spreadsheet')\">Browse</a>";
+    my $load_dialog = <<END;
+<table bgcolor="$bgcolor">
+<tr><td><input type="submit" name="load" value="Load" /></td>
+    <td><nobr>
+        <input type="text" name="loadfilename" size="25" value="$filename" />
+        $link</nobr>
+    </td></tr>
+<tr><td>&nbsp;</td><td>
+    <select name="fileselect" onchange="document.sheet.loadfilename.value=document.sheet.fileselect.value" >
+    <option name="Default">Default</option>
+END
+    foreach my $sheetfilename ($spreadsheet->othersheets()) {
+        $sheetfilename =~ s/_$sheettype$//;
+        $load_dialog .= '    <option name="'.$sheetfilename.'"';
+        if ($filename eq $sheetfilename) {
+            $load_dialog .= ' selected';
+        }
+        $load_dialog .= '>'.$sheetfilename."</option>\n";
+    }
+    $load_dialog .= "</td><td>&nbsp;</td></tr>\n</table>\n";
+        #
+    $result .=<<END;
+<!-- load / save dialogs -->
+<table cellspacing="2">
+<tr>
+    <td>$load_dialog</td>
+    <td>
+        <table bgcolor="$bgcolor">
+        <tr><td>$save_dialog</td></tr>
+        <tr><td align="center">$makedefault_dialog</td></tr>
+        </table>
+    </td>
+</tr>
+</table>
+END
+    return $result;
+}
+
 sub handler {
     my $r=shift;
     #
@@ -155,6 +244,7 @@
                                                 $ENV{'request.course.id'});
     my $allowed_to_view =  &Apache::lonnet::allowed('vgr',
                                                 $ENV{'request.course.id'});
+
     #
     # Only those able to view others grades will be allowed to continue 
     # if they are not requesting their own.
@@ -175,10 +265,14 @@
     ##
     ## Spit out the javascript required for editing
     ##
-    if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
+    if ($allowed_to_edit) {
+        my $extra_javascript = 
+            &Apache::loncommon::browser_and_searcher_javascript();
         $r->print(<<ENDSCRIPT);
 <script language="JavaScript">
 
+    $extra_javascript
+
     var editwin;
 
     function celledit(cellname,cellformula) {
@@ -219,7 +313,8 @@
               '<form action="'.$r->uri.'" name="sheet" method="post">');
     $r->print(&hiddenfield('sname'  ,$ENV{'form.sname'}).
               &hiddenfield('sdomain',$ENV{'form.sdomain'}).
-              &hiddenfield('usymb'  ,$ENV{'form.usymb'}));
+              &hiddenfield('usymb'  ,$ENV{'form.usymb'}).
+              &Apache::lonmenu::regflush());
     $r->rflush();
     ##
     ## Determine the filename to use
@@ -250,87 +345,36 @@
         # error error - run in circles, scream and shout
         return;
     }
+    #
+    # Output selector
+    $r->print('<input type="submit" value="Update Display" /><br />');
     ##
     ## Editing/loading/saving
     if ($allowed_to_edit) {
-        ##
-        ## Deal with saving the spreadsheet
-        if (exists($ENV{'form.save'}) && 
-            exists($ENV{'form.savefilename'})) {
-            $spreadsheet->filename($ENV{'form.savefilename'});
-            my $save_status = $spreadsheet->save();
-            if ($save_status ne 'ok') {
-                $r->print("An error occurred while saving the spreadsheet".
-                          "There error is:".$save_status);
-            } else {
-                $r->print("Spreadsheet saved as ".$ENV{'form.savefilename'});
-            }
-        } elsif (exists($ENV{'form.newformula'}) && 
-                 exists($ENV{'form.cell'})       && 
-                 $ENV{'form.cell'} ne '' ) {
-            ##
-            ## Make any requested modifications to the spreadsheet
-            $spreadsheet->modify_cell($ENV{'form.cell'},
-                                      $ENV{'form.newformula'});
-            $spreadsheet->save_tmp();
-            # output that we are dealing with a temporary file
-            $r->print(&hiddenfield('workcopy',$sheettype));
-            $r->print('<pre>'.$ENV{'form.cell'}.' = '.
-                      $ENV{'form.newformula'}.'</pre>'."\n");
-        }
-        ##
-        ## Editing code
-        $r->print(&hiddenfield('cell','').
-                  &hiddenfield('newformula',''));
-        ##
-        ## Create the save and load dialogs
-        $filename = $spreadsheet->filename();
-        $filename = '' if ($filename =~ /^default\.$sheettype/i);
-        $filename =~ s/_$sheettype$//;
-        my $save_dialog = 
-            '<input type="submit" name="save" value="Save as ..." /> '.
-                '<input type="text" name="savefilename" size="30" value="'.
-                    $filename.'" />';
-        my $makedefault_dialog = 
-            '<input type="submit" name="makedefault" value="Make Default"/>';
-        #
-        my $load_dialog = 
-            '<input type="submit" name="load" value="Load ..." />'.
-                '<select name="loadfilename">'.
-                    '<option name="Default">Default</option>'."\n";
-        foreach my $sheetfilename ($spreadsheet->othersheets()) {
-            $sheetfilename =~ s/_$sheettype$//;
-            $load_dialog .= '<option name="'.$sheetfilename.'"';
-            if ($filename eq $sheetfilename) {
-                $load_dialog .= ' selected';
-            }
-            $load_dialog .= '>'.$sheetfilename."</option>\n";
-        }
-        #
-        $r->print(<<END);
-<!-- load / save dialogs -->
-<table cellspacing="3">
-<tr>
-<td>$load_dialog</td>
-<td>$save_dialog</td>
-<td>$makedefault_dialog</td>
-</tr>
-</table>
-END
+        $r->print('<table><tr><td>'.$spreadsheet->html_header().'</td>'.
+                  '<td valign="bottom">'.
+                  &file_dialogs($spreadsheet)."</td></tr></table>\n");
         $r->rflush();
+    } else {
+        $r->print('<table><tr><td>'.$spreadsheet->html_header().
+                  "</td></tr></table>\n");
     }
     #
-    # Output selector
-    $r->print($spreadsheet->html_header());
-    #
     # Keep track of the filename
     $r->print(&hiddenfield('filename',$filename));
     #
-    $r->print($spreadsheet->get_html_title());
-    if ($allowed_to_view || $allowed_to_edit) {
-        $r->print($spreadsheet->parent_link());
+    # Keep track of the number of times we have been called, sort of.
+    $r->print(&hiddenfield('not_first_run','whatever'));
+    #
+    if (exists($ENV{'form.not_first_run'}) || $sheettype ne 'classcalc') {
+        $r->print($spreadsheet->get_html_title());
+        if ($allowed_to_view || $allowed_to_edit) {
+            $r->print($spreadsheet->parent_link());
+        }
+        $spreadsheet->display($r);
+    } else {
+        $r->print("<h2>Make your selections and bonk the 'update display' button</h2>");
     }
-    $spreadsheet->display($r);
     $r->print('</form></body></html>');
     return OK;
 }

--matthew1054063027--