[LON-CAPA-cvs] cvs: loncom /html/adm/helper newslot.helper

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 17 Oct 2005 21:19:30 -0000


albertel		Mon Oct 17 17:19:30 2005 EDT

  Modified files:              
    /loncom/html/adm/helper	newslot.helper 
  Log:
  - slot helper understands editing an existing slot
  
  
Index: loncom/html/adm/helper/newslot.helper
diff -u loncom/html/adm/helper/newslot.helper:1.4 loncom/html/adm/helper/newslot.helper:1.5
--- loncom/html/adm/helper/newslot.helper:1.4	Mon Oct 17 14:21:26 2005
+++ loncom/html/adm/helper/newslot.helper	Mon Oct 17 17:19:30 2005
@@ -1,5 +1,29 @@
 <helper title="Slot Creation" requiredpriv="mgq">
   <state name="START" title="Specify Required Attributes">
+    <exec>
+      if (!exists($helper->{'VARS'}{'name'}) ||
+	  $helper->{'VARS'}{'name'} !~ /\S/) {
+	  &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
+	  if (exists($env{'form.name'}) ||
+	      $env{'form.name'} =~ /\S/) {
+	      $helper->{'VARS'}{'name'}=$env{'form.name'};
+	  }
+      }
+      $helper->{DATA}{origslot} = sub {
+	  my ($which,$default)=@_;
+	  if (!exists($helper->{'VARS'}{'name'}) ||
+	      $helper->{'VARS'}{'name'} !~ /\S/) {
+	      return $default;
+	  }
+	  my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+	  my $cdom  = $env{'course.'.$env{'request.course.id'}.'.domain'};
+	  my $name=$helper->{'VARS'}{'name'};
+	  my %slot=&Apache::lonnet::get('slots', [$name], $cdom, $cnum);
+	  if (!ref($slot{$name})) { return $default; }
+	  if (!exists($slot{$name}{$which})) { return $default; }
+	  return $slot{$name}{$which};
+      }
+    </exec>
     <message nextstate="OPTIONAL">
       <message_text>
           Name: <br />&nbsp;&nbsp;&nbsp;
@@ -11,23 +35,34 @@
           if ($val=~/\s$/) { return 'Must not contain spaces'; }
           return undef;
       </validator>
+      <defaultvalue>
+        return $helper->{'VARS'}{'name'};
+      </defaultvalue>
     </string>
     <message>
       <message_text><br />Start time:<br />&nbsp;&nbsp;&nbsp;</message_text>
     </message>
-    <date variable="starttime" hoursminutes="1"></date>
+    <date variable="starttime" hoursminutes="1">
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('starttime');
+      </defaultvalue>
+    </date>
     <message>
       <message_text><br />End time:<br />&nbsp;&nbsp;&nbsp;</message_text>
     </message>
-    <date variable="endtime" hoursminutes="1"></date>
+    <date variable="endtime" hoursminutes="1">
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('endtime');
+      </defaultvalue>
+    </date>
     <message>
       <message_text><br />Type:</message_text>
     </message>
     <choices variable="type">
       <choice computer='preassigned'>Instructor asssignable.</choice>
-      <choice computer='student_schedulable'>Student selectable.</choice>
+      <choice computer='schedulable_student'>Student selectable.</choice>
       <defaultvalue>
-         return 'preassigned';
+        return &{$helper->{DATA}{origslot}}('type','preassigned');
       </defaultvalue>
     </choices>
   </state>
@@ -38,14 +73,20 @@
           <p>Description:<br />&nbsp;&nbsp;&nbsp;
       </message_text>
     </message>
-    <string variable="description" size="60"></string>
+    <string variable="description" size="60">
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('description');
+      </defaultvalue>
+    </string>
     <message>
       <message_text>
           </p><p>Time students can start reserving:<br />&nbsp;&nbsp;&nbsp;
       </message_text>
     </message>
     <date variable="startreserve" hoursminutes="1" anytime="1">
-	<defaultvalue>'anytime'</defaultvalue>
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('startreserve','anytime');
+      </defaultvalue>
     </date>
     <message>
       <message_text>
@@ -57,6 +98,9 @@
           if ($val ne '' && $val=~/\D/) { return 'Must be numeric.'; }
           return undef;
       </validator>
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('maxspace');
+      </defaultvalue>
     </string>
     <message>
       <message_text>
@@ -67,6 +111,9 @@
       <validator>
           return undef;
       </validator>
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('secret');
+      </defaultvalue>
     </string>
     <message>
       <message_text>
@@ -74,11 +121,21 @@
       </message_text>
     </message>
     <date variable="startunique" hoursminutes="1" anytime="1">
-	<defaultvalue>'anytime'</defaultvalue>
+      <defaultvalue>
+        my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
+        if ($default eq 'anytime') { return 'anytime' };
+        if (ref($default)) { return $default->[0]; }
+        return 'anytime';
+      </defaultvalue>
     </date>
     <message><message_text><br />&nbsp;&nbsp;&nbsp;End: </message_text></message>
     <date variable="endunique" hoursminutes="1" anytime="1">
-	<defaultvalue>'anytime'</defaultvalue>
+      <defaultvalue>
+        my $default=&{$helper->{DATA}{origslot}}('uniqueperiod','anytime');
+        if ($default eq 'anytime') { return 'anytime' };
+        if (ref($default)) { return $default->[1]; }
+        return 'anytime';
+      </defaultvalue>
     </date>
     <message>
       <message_text>
@@ -88,7 +145,11 @@
     <choices variable="restricttosymb">
       <choice nextstate="PROCTOR" computer='any'>usable for any resource.</choice>
       <choice nextstate="RESOURCESELECT" computer='resource'>restricted to a specific resource.</choice>
-      <defaultvalue>'any'</defaultvalue>
+      <defaultvalue>
+        my $default=&{$helper->{DATA}{origslot}}('symb');
+        if ($default) { return 'resource'; }
+        return 'any';
+      </defaultvalue>
     </choices>
     <message>
       <message_text> 
@@ -99,6 +160,9 @@
       <validator>
           return undef;
       </validator>
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('ip');
+      </defaultvalue>
     </string>
     <message> <message_text> </p> </message_text> </message>
   </state>
@@ -107,11 +171,23 @@
       <filterfunc>return $res->is_problem()</filterfunc>
       <valuefunc>return $res->symb()</valuefunc>
       <nextstate>PROCTOR</nextstate>
+      <defaultvalue>
+        return &{$helper->{DATA}{origslot}}('symb');
+      </defaultvalue>
     </resource>    
   </state>
   <state name="PROCTOR" title="Specify Proctors">
     <student variable="proctor" multichoice="1" coursepersonnel="1"
              nextstate="FINISH" activeonly="1" emptyallowed="1">
+      <defaultvalue>
+        my @defaults;
+        my $default=&{$helper->{DATA}{origslot}}('proctor');
+        if ($default) {
+	    $default=~ tr/@/:/;
+	    @defaults=(split(',',$default)); 
+	}
+        return @defaults;
+      </defaultvalue>
     </student>
   </state>
   <state name="FINISH" title="Creating/Modfying Slot">
@@ -149,7 +225,7 @@
         my $ret = &Apache::lonnet::cput('slots',
 					{$helper->{'VARS'}{'name'} => \%slot},
 					$cdom,$cname);
-        $result.="\n$ret ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
+        $result.="\n ".'Name: '.&HTML::Entities::encode($helper->{'VARS'}{'name'}).'</li>'.
     "\n".'<li> Starts: '.&Apache::lonlocal::locallocaltime($slot{'starttime'}).'</li>'.
                  "\n".'<li> Ends: '.&Apache::lonlocal::locallocaltime($slot{'endtime'}).'</li>'.
                  "\n".'<li> Type: '.$slot{'type'}.'</li>';