home *** CD-ROM | disk | FTP | other *** search
/ Peanuts NeXT Software Archives / Peanuts-2.iso / Developer / webobjects / extensions / win-nt / WOPerl-lite-10e7.exe / Examples / WOPerl / TimeOff / Calendar.wo / Calendar.wos < prev    next >
Encoding:
Text File  |  1996-08-09  |  4.4 KB  |  135 lines

  1. /*
  2.  *   Calendar.wos
  3.  *   You may freely copy, distribute, and reuse the code in this example.
  4.  *   NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  5.  *   fitness for any particular use.
  6.  *
  7.  *     Written by Nico Popp and Eric Bailey
  8.  *
  9.  *   Calendar is a subcomponent (or child component) that's nested in the
  10.  *   component associated with the page Main. It messages the parent
  11.  *   component Main using a WOAction object callBack. 
  12.  * 
  13.  *   When the user clicks on a date in the Start Date or End Date
  14.  *   calendar, the Calendar's setSelectedDate method is triggered. This
  15.  *   sets the selectedDate variable to the date the user clicked on.
  16.  *   Since the selectedDate variable is tied to the startDate and
  17.  *   endDate variables in the parent's declarations file (Main.wod),
  18.  *   startDate and endDate are modified accordingly (depending, of
  19.  *   course, on whether the user clicked in the Start Date or the
  20.  *   End Date calendar). Next, the selectedDate method sends the WOAction
  21.  *   object callBack an invoke message. This invokes the mainPage method
  22.  *   in the parent's script Main.wos, which generates a new Main page
  23.  *   that includes the new startDate or endDate value.
  24.  *
  25.  */
  26.  
  27. id selectedDate;
  28. persistent id selectedMonth;
  29. persistent id selectedYear;
  30. action callBack;
  31.  
  32. id cell;
  33. id firstWeekDay;
  34. id lastDayOfMonth;
  35. id row, col;
  36.  
  37. - awake {
  38.     if (!selectedDate) 
  39.     selectedDate = [NSCalendarDate date];
  40.     if (!selectedMonth) 
  41.     selectedMonth = [selectedDate monthOfYear];
  42.     if (!selectedYear) 
  43.     selectedYear = [selectedDate yearOfCommonEra];
  44.     firstWeekDay = [self firstWeekDay];
  45.     lastDayOfMonth = [self lastDayOfMonth];
  46.     [self logWithFormat:@"FirstWeekDay:%@", firstWeekDay];
  47. }
  48.  
  49. - willPrepareForRequest:aRequest inContext:aContext {
  50.     cell = -1;
  51. }
  52.  
  53. - willGenerateResponse:aResponse inContext:aContext {
  54.     cell = -1;
  55. }
  56.  
  57. - firstDay {
  58.     return [NSCalendarDate dateWithYear:[selectedYear intValue] month:[selectedMonth intValue] day:1 hour:0 minute:0 second:0 timeZone:[NSTimeZone localTimeZone]];
  59. }
  60.  
  61. - selectedDay {
  62.     if (selectedDate)
  63.     return [[selectedDate dateWithCalendarFormat:@"%A, %B %d, %Y" timeZone:[NSTimeZone localTimeZone]] description];
  64.     else 
  65.     return @"No selection";
  66. }
  67.  
  68. - incrementYear {
  69.     selectedYear = [[[self firstDay] addYear:+1 month:0 day:0 hour:0 minute:0 second:0] yearOfCommonEra];
  70.     firstWeekDay =  [self firstWeekDay];
  71.     lastDayOfMonth =  [self lastDayOfMonth];
  72. }
  73.  
  74. - decrementYear {
  75.      selectedYear = [[[self firstDay] addYear:-1 month:0 day:0 hour:0 minute:0 second:0] yearOfCommonEra];
  76.     firstWeekDay =  [self firstWeekDay];
  77.     lastDayOfMonth =  [self lastDayOfMonth];
  78. }
  79.  
  80. - incrementMonth {
  81.     selectedMonth = [[[self firstDay] addYear:0 month:1 day:0 hour:0 minute:0 second:0] monthOfYear];
  82.     firstWeekDay = [self firstWeekDay];
  83.     lastDayOfMonth = [self lastDayOfMonth];
  84.     return nil;
  85. }
  86.  
  87. - decrementMonth {
  88.     selectedMonth = [[[self firstDay] addYear:0 month:-1 day:0 hour:0 minute:0 second:0] monthOfYear];
  89.     firstWeekDay =  [self firstWeekDay];
  90.     lastDayOfMonth =  [self lastDayOfMonth];
  91.     return nil;
  92. }
  93.  
  94. - formattedSelectedYear {
  95.     return [[[self firstDay] dateWithCalendarFormat:@"%Y" timeZone:[NSTimeZone localTimeZone]] description];
  96. }
  97.  
  98. - formattedSelectedMonth {
  99.     return [[[self firstDay] dateWithCalendarFormat:@"%B" timeZone:[NSTimeZone localTimeZone]] description];
  100. }
  101.  
  102. - firstWeekDay {    
  103.     return [[self firstDay] dayOfWeek];
  104. }
  105.  
  106. - lastDayOfMonth {
  107.     return [[[self firstDay] addYear:0 month:1 day:-1 hour:0 minute:0 second:0] dayOfMonth];
  108. }
  109.  
  110. - cellValue {
  111.     if ((cell >= firstWeekDay) && (cell < (lastDayOfMonth + firstWeekDay)))     
  112.     return (cell-firstWeekDay+1);
  113.     else 
  114.     return nil;
  115. }
  116.  
  117. - isSelectedCell {
  118.     cell++;
  119.     if ( ([selectedDate monthOfYear] == selectedMonth) && ((cell - firstWeekDay + 1) == [selectedDate dayOfMonth])) return YES;
  120.      return NO;
  121. }
  122.  
  123. - isUnselectedCell {
  124.     if ( ([selectedDate monthOfYear] == selectedMonth) && ((cell - firstWeekDay + 1) == [selectedDate dayOfMonth])) return NO;
  125.     else return YES;
  126. }
  127.  
  128. - setSelectedDate {
  129.     selectedDate = [NSCalendarDate dateWithYear:[selectedYear intValue] month:[selectedMonth intValue] day:([row intValue] * 7 + [col intValue] + 1  - [firstWeekDay intValue])  hour:0 minute:0 second:0 timeZone:[NSTimeZone localTimeZone]];
  130.     firstWeekDay = [self firstWeekDay];
  131.     lastDayOfMonth = [self lastDayOfMonth];
  132.     cell = 0;
  133.     return [callBack invoke];
  134. }
  135.