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

matthew lon-capa-cvs@mail.lon-capa.org
Tue, 12 Nov 2002 20:14:51 -0000


matthew		Tue Nov 12 15:14:51 2002 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Multi-line cell contents edit window.
  
  
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.137 loncom/interface/lonspreadsheet.pm:1.138
--- loncom/interface/lonspreadsheet.pm:1.137	Fri Nov  8 15:18:29 2002
+++ loncom/interface/lonspreadsheet.pm	Tue Nov 12 15:14:51 2002
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.137 2002/11/08 20:18:29 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.138 2002/11/12 20:14:51 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1190,6 +1190,7 @@
     if ($value =~ /^\s*$/ ) {
         $value = '<font color="'.$bgcolor.'">#</font>';
     }
+    $formula =~ s/\n/\\n/gs;
     $result .= '<a href="javascript:celledit(\''.
         $name.'\',\''.$formula.'\');">'.$value.'</a>';
     return $result;
@@ -2828,17 +2829,45 @@
     # Header....
     #
     $r->print('<html><head><title>LON-CAPA Spreadsheet</title>');
+    my $nothing = "''";
+    if ($ENV{'browser.type'} eq 'explorer') {
+        $nothing = "'javascript:void(0);'";
+    }
+
     if ($ENV{'request.role'} !~ /^st\./) {
         $r->print(<<ENDSCRIPT);
 <script language="JavaScript">
 
-    function celledit(cn,cf) {
-        var cnf=prompt(cn,cf);
-        if (cnf!=null) {
-            document.sheet.unewfield.value=cn;
-            document.sheet.unewformula.value=cnf;
-            document.sheet.submit();
+    var editwin;
+
+    function celledit(cellname,cellformula) {
+        var edit_text = '';
+        edit_text +='<html><head><title>Cell Edit Window</title></head><body>';
+        edit_text += '<form name="editwinform">';
+        edit_text += '<center><h3>Cell '+cellname+'</h3>';
+        edit_text += '<textarea name="newformula" cols="40" rows="6"';
+        edit_text += ' wrap="off" >'+cellformula+'</textarea>';
+        edit_text += '</br>';
+        edit_text += '<input type="button" name="accept" value="Accept"';
+        edit_text += ' onClick=\\\'javascript:';
+        edit_text += 'opener.document.sheet.unewfield.value=';
+        edit_text +=     '"'+cellname+'";';
+        edit_text += 'opener.document.sheet.unewformula.value=';
+        edit_text +=     'document.editwinform.newformula.value;';
+        edit_text += 'opener.document.sheet.submit();';
+        edit_text += 'self.close()\\\' />';
+        edit_text += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+        edit_text += '<input type="button" name="abort" ';
+        edit_text +=     'value="Discard Changes"';
+        edit_text += ' onClick="javascript:self.close()" />';
+        edit_text += '</center></body></html>';
+
+        if (editwin != null && !(editwin.closed) ) {
+            editwin.close();
         }
+
+        editwin = window.open($nothing,'CellEditWin','height=200,width=350,scrollbars=no,resizeable=yes,alwaysRaised=yes,dependent=yes',true);
+        editwin.document.write(edit_text);
     }
 
     function changesheet(cn) {
@@ -2857,7 +2886,7 @@
 ENDSCRIPT
     }
     $r->print('</head>'.&Apache::loncommon::bodytag('Grades Spreadsheet').
-              '<form action="'.$r->uri.'" name=sheet method=post>');
+              '<form action="'.$r->uri.'" name="sheet" method="post">');
     $r->print(&hiddenfield('uname',$ENV{'form.uname'}).
               &hiddenfield('udom',$ENV{'form.udom'}).
               &hiddenfield('usymb',$ENV{'form.usymb'}).