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

www lon-capa-cvs@mail.lon-capa.org
Wed, 03 Sep 2003 01:53:46 -0000


www		Tue Sep  2 21:53:46 2003 EDT

  Modified files:              
    /loncom/interface	lonannounce.pm lonhtmlcommon.pm 
  Log:
  Use calendar function to more intuitively pick dates.
  
  
Index: loncom/interface/lonannounce.pm
diff -u loncom/interface/lonannounce.pm:1.18 loncom/interface/lonannounce.pm:1.19
--- loncom/interface/lonannounce.pm:1.18	Tue Sep  2 17:15:59 2003
+++ loncom/interface/lonannounce.pm	Tue Sep  2 21:53:46 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Announce
 #
-# $Id: lonannounce.pm,v 1.18 2003/09/02 21:15:59 www Exp $
+# $Id: lonannounce.pm,v 1.19 2003/09/03 01:53:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -86,7 +86,8 @@
 		', '.localtime($start).' - '.localtime($end).': '.$msg;
             if ($courseid eq $ENV{'request.course.id'}) {
               if ((&Apache::lonnet::allowed('srm',$ENV{'request.course.id'}))
-               && (!$showedcheck{$start.'_'.$end})) {
+               && (!$showedcheck{$start.'_'.$end})
+	       && ($ENV{'form.pickdate'} ne 'yes')) {
                $output.='<input type="checkbox" name="remove_'.$start.'_'.
 		   $end.'">';
                $showedcheck{$start.'_'.$end}=1;
@@ -102,7 +103,7 @@
 	((($day eq $todayhash{'day'}) &&
           ($month eq $todayhash{'month'}) &&
           ($year eq $todayhash{'year'}))?' bgcolor="#FFFF00"':'').
-           '><b>'.$day.'</b><br>'.$output.'</td>';
+           '>'.&tfont('<b>'.&picklink($day,$day,$month,$year).'</b><br>'.$output).'</td>';
 }
 
 sub plaincell {
@@ -171,6 +172,43 @@
    }
 }
 
+sub tfont {
+    my $text=shift;
+    if ($ENV{'form.pickdate'} eq 'yes') {
+	return '<font size="1">'.$text.'</font>';
+    } else {
+	return $text;
+    }
+}
+
+sub picklink {
+    my ($text,$day,$month,$year)=@_;
+    if ($ENV{'form.pickdate'} eq 'yes') {
+	return '<a href="javascript:dialin('.$day.','.$month.','.$year.')">'.
+	    $text.'</a>';
+    } else {
+	return $text;
+    }
+}
+
+sub dialscript {
+    return (<<ENDDIA);
+<script language="Javascript">
+function dialin(day,month,year) {
+	opener.document.$ENV{'form.formname'}.$ENV{'form.element'}\_year.value=year;
+    var slct=opener.document.$ENV{'form.formname'}.$ENV{'form.element'}\_month;
+    var i;
+    for (i=0;i<slct.length;i++) {
+        if (slct.options[i].value==month) { slct.selectedIndex=i; }
+    }
+    opener.document.$ENV{'form.formname'}.$ENV{'form.element'}\_day.value=day;
+    opener.$ENV{'form.element'}\_checkday();
+    self.close();
+}
+</script>
+ENDDIA
+}
+
 sub handler {
     my $r = shift;
     $r->content_type('text/html');
@@ -185,7 +223,7 @@
     undef %showedcheck;
 # ---------------------------------------------------------- Get month and year
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
-                                            ['month','year','pickdate']);
+                             ['month','year','pickdate','formname','element']);
 # --------------------------------------------------- Decide what month to show
     my $year=$todayhash{'year'};
     if ($ENV{'form.year'}) { $year=$ENV{'form.year'}; }
@@ -194,7 +232,8 @@
 
 # ---------------------------------------------- See if we are in pickdate mode
     my $pickdatemode=($ENV{'form.pickdate'} eq 'yes');
-
+    my $pickinfo='&pickdate=yes&formname='.$ENV{'form.formname'}.
+	'&element='.$ENV{'form.element'};
 # --------------------------------------------- Find out first day of the month
 
     my %firstday=&Apache::loncommon::timehash(
@@ -226,6 +265,7 @@
     if ($pickdatemode) {
 # no big header in pickdate mode
 	$r->print(&Apache::loncommon::bodytag("Pick a Date",'','',1).
+		  &dialscript().
 		  '<font size="1">');
     } else {
        $r->print(&Apache::loncommon::bodytag("Announcements and Calendar"));
@@ -339,14 +379,27 @@
     }
     $r->print(
  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
- ($pickdatemode?'&pickdate=yes':'').'">Previous Month</a> '.
+ ($pickdatemode?$pickinfo:'').'">Previous Month</a> '.
  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
- ($pickdatemode?'&pickdate=yes':'').'">Next Month</a>'.
+ ($pickdatemode?$pickinfo:'').'">Next Month</a>'.
  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
  '&year='.$todayhash{'year'}.
- ($pickdatemode?'&pickdate=yes':'').'">Current Month</a><p>'.
-        '<table border="2" cols="7" rows="5"><tr><th>Sun</th><th>Mon</th>'.
-        '<th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>');
+ ($pickdatemode?$pickinfo:'').'">Current Month</a><p>'.
+        '<table border="2" cols="7" rows="5"><tr><th>'.
+&tfont('Sun')
+.'</th><th>'.
+&tfont('Mon')
+.'</th><th>'.
+&tfont('Tue')
+.'</th><th>'.
+&tfont('Wed')
+.'</th><th>'.
+&tfont('Thu')
+.'</th><th>'.
+&tfont('Fri')
+.'</th><th>'.
+&tfont('Sat')
+.'</th></tr>');
 
     my $tk=&Apache::loncommon::maketime(%firstday);
     my $outp;
@@ -379,12 +432,12 @@
     if ($allowed) { $r->print('<input type="button" onClick="removesub()" value="Remove Checked Entries"></form>'); }
     $r->print('<p>'.
  '<a href="/adm/announcements?month='.$pm.'&year='.$py.
- ($pickdatemode?'&pickdate=yes':'').'">Previous Month</a> '.
+ ($pickdatemode?$pickinfo:'').'">Previous Month</a> '.
  '<a href="/adm/announcements?month='.$fm.'&year='.$fy.
- ($pickdatemode?'&pickdate=yes':'').'">Next Month</a>'.
+ ($pickdatemode?$pickinfo:'').'">Next Month</a>'.
  '&nbsp;&nbsp;&nbsp;<a href="/adm/announcements?month='.$todayhash{'month'}.
  '&year='.$todayhash{'year'}.
- ($pickdatemode?'&pickdate=yes':'').'">Current Month</a></p>'.
+ ($pickdatemode?$pickinfo:'').'">Current Month</a></p>'.
  ($pickdatemode?'</font>':'').
  '</body></html>');
     return OK;
Index: loncom/interface/lonhtmlcommon.pm
diff -u loncom/interface/lonhtmlcommon.pm:1.28 loncom/interface/lonhtmlcommon.pm:1.29
--- loncom/interface/lonhtmlcommon.pm:1.28	Fri Jul 25 15:56:37 2003
+++ loncom/interface/lonhtmlcommon.pm	Tue Sep  2 21:53:46 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common html routines
 #
-# $Id: lonhtmlcommon.pm,v 1.28 2003/07/25 19:56:37 matthew Exp $
+# $Id: lonhtmlcommon.pm,v 1.29 2003/09/03 01:53:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -181,6 +181,16 @@
             document.$formname.$dname\_day.value = 30;
         }
     }
+
+    function $dname\_opencalendar() {
+       var calwin=window.open(
+"/adm/announcements?pickdate=yes&formname=$formname&element=$dname&month="+
+document.$formname.$dname\_month.value+"&year="+
+document.$formname.$dname\_year.value,
+             "LONCAPAcal",
+              "height=350,width=350,scrollbars=yes,resizable=yes,menubar=no");
+
+    }
 </script>
 ENDJS
     $result .= "  <nobr><select name=\"$dname\_month\" ".$special.' '.
@@ -223,7 +233,7 @@
         "value=\"$min\" size=\"3\" /> m\n";
     $result .= "  <input type=\"text\" name=\"$dname\_second\" ".$special.' '.
         "value=\"$sec\" size=\"3\" /> s\n";
-    $result .= "</nobr>\n<!-- end $dname date setting form -->\n";
+    $result .= "<a href=\"javascript:$dname\_opencalendar()\">Select Date</a></nobr>\n<!-- end $dname date setting form -->\n";
     return $result;
 }