[LON-CAPA-cvs] cvs: rat / lonratedt.pm lonratsrv.pm

www lon-capa-cvs@mail.lon-capa.org
Sat, 31 Aug 2002 00:42:31 -0000


www		Fri Aug 30 20:42:31 2002 EDT

  Modified files:              
    /rat	lonratedt.pm lonratsrv.pm 
  Log:
  Fixes "View" Bug
  Provides temporary file/save mechanism (both edt and srv needed)
  
  
Index: rat/lonratedt.pm
diff -u rat/lonratedt.pm:1.33 rat/lonratedt.pm:1.34
--- rat/lonratedt.pm:1.33	Mon Aug 26 08:38:40 2002
+++ rat/lonratedt.pm	Fri Aug 30 20:42:30 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Edit Handler for RAT Maps
 #
-# $Id: lonratedt.pm,v 1.33 2002/08/26 12:38:40 www Exp $
+# $Id: lonratedt.pm,v 1.34 2002/08/31 00:42:30 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -37,6 +37,8 @@
 use Apache::lonnet;
 use Apache::lonratsrv;
 use Apache::lonsequence;
+use Apache::loncommon;
+use File::Copy;
 
 use vars qw(@order @resources);
 
@@ -328,7 +330,11 @@
 # ------------------------------------------------------------------- Store map
 
 sub storemap {
-    my $fn=shift;
+    my $realfn=shift;
+    my $fn=$realfn.'.tmp';
+    unless (-e $fn) {
+	copy($realfn,$fn);
+    }
     &startfinish();
     my $output='graphdef<:>no';
     my $k=1;
@@ -462,7 +468,22 @@
 sub smpedt {
    my ($r,$url,$errtext)=@_;
    my $buttons=&buttons(2);
-
+   my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
+   my $targetmsg='';
+   if ($ENV{'form.save'}) {
+       $targetmsg='<b>Saving ...</b><br>';
+       copy($tmpfn,&Apache::lonnet::filelocation('',$url));
+       unlink($tmpfn);
+   }
+   if ($ENV{'form.revert'}) {
+       $targetmsg='<b>Reverting ...</b><br>';
+       unlink($tmpfn);
+   }
+   if (-e $tmpfn) {
+      $targetmsg=
+        '<b><font color="red">You are working with an unsaved version of your map.</font></b><br>';
+      my ($errtext,$fatal)=&mapread($tmpfn,'');
+   }
 # ---------------------------------------------------------- Process form input
 
    my @importselect=();
@@ -654,6 +675,8 @@
 # ------------------------------------------------------------ Assemble windows
    
    my $idx=-1;
+   $importdetail='&'.$importdetail;
+   $importdetail=~s/^\&+/\&/;
    my $importwindow=
        '<option value="-1"> ---- Import and Paste Area ---- </option>'.
      join("\n",map {
@@ -682,6 +705,7 @@
 
 # ----------------------------------------------------- Start simple RAT screen
    my $editscript=&editscript('simple');
+   my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
    $r->print(<<ENDSMPHEAD);
 <html>
 <head>
@@ -699,17 +723,17 @@
 
    function viewtarget() {
        openview((document.forms.simpleedit.targetdetail.value.split('&'))
-                [document.forms.simpleedit.target.selectedIndex+1]);
+                [document.forms.simpleedit.target.selectedIndex]);
    }
 
    function viewimport() {
        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
-                [document.forms.simpleedit.importsel.selectedIndex+1]);
+                [document.forms.simpleedit.importsel.selectedIndex]);
    }
 
 </script>
 </head>                 
-<body bgcolor='#FFFFFF'>
+$bodytag
 $buttons
 <font color=red>$errtext</font>
 <h1>$url</h1>
@@ -739,7 +763,10 @@
 <input type=button onClick=
 "javascript:impfortarget.value=1;groupimport();" value="Group Import">
 after selected
-<hr><input type=button onClick="javascript:viewtarget()" value="View">
+<hr>$targetmsg
+<input type=submit name="revert" value="Revert to Last Saved">
+<input type=submit name="save" value="Save">
+<input type=button onClick="javascript:viewtarget()" value="View">
 </td></tr>
 
 <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
@@ -786,11 +813,14 @@
 
 sub viewmap {
     my ($r,$url,$adv,$errtext)=@_;
-    $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
+    $r->print('<html>'.
+     &Apache::loncommon::bodytag('Edit Content of a Map').
+     &buttons($adv));
     if ($errtext) {
 	$r->print($errtext.'<hr>');
     }
     my $idx=0;
+    $r->print('<h1>'.$url.'</h1>');
     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
 	if (defined($_)) {
             $idx++;
Index: rat/lonratsrv.pm
diff -u rat/lonratsrv.pm:1.21 rat/lonratsrv.pm:1.22
--- rat/lonratsrv.pm:1.21	Mon Aug 19 17:15:08 2002
+++ rat/lonratsrv.pm	Fri Aug 30 20:42:30 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Server for RAT Maps
 #
-# $Id: lonratsrv.pm,v 1.21 2002/08/19 21:15:08 www Exp $
+# $Id: lonratsrv.pm,v 1.22 2002/08/31 00:42:30 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -205,8 +205,8 @@
     my ($fn,$errtext)=@_;
     my %alltypes;
     my %allvalues;
-    if (($fn=~/\.sequence$/) ||
-        ($fn=~/\.page$/)) {
+    if (($fn=~/\.sequence(\.tmp)*$/) ||
+        ($fn=~/\.page(\.tmp)*$/)) {
 
 # ------------------------------------------------------------- Deal with input
         my @tags=split(/<&>/,$ENV{'form.output'});