home *** CD-ROM | disk | FTP | other *** search
- /*
- * Calendar.wos
- * You may freely copy, distribute, and reuse the code in this example.
- * NeXT disclaims any warranty of any kind, expressed or implied, as to its
- * fitness for any particular use.
- *
- * Written by Nico Popp and Eric Bailey
- *
- * Calendar is a subcomponent (or child component) that's nested in the
- * component associated with the page Main. It messages the parent
- * component Main using a WOAction object callBack.
- *
- * When the user clicks on a date in the Start Date or End Date
- * calendar, the Calendar's setSelectedDate method is triggered. This
- * sets the selectedDate variable to the date the user clicked on.
- * Since the selectedDate variable is tied to the startDate and
- * endDate variables in the parent's declarations file (Main.wod),
- * startDate and endDate are modified accordingly (depending, of
- * course, on whether the user clicked in the Start Date or the
- * End Date calendar). Next, the selectedDate method sends the WOAction
- * object callBack an invoke message. This invokes the mainPage method
- * in the parent's script Main.wos, which generates a new Main page
- * that includes the new startDate or endDate value.
- *
- */
-
- id selectedDate;
- persistent id selectedMonth;
- persistent id selectedYear;
- action callBack;
-
- id cell;
- id firstWeekDay;
- id lastDayOfMonth;
- id row, col;
-
- - awake {
- if (!selectedDate)
- selectedDate = [NSCalendarDate date];
- if (!selectedMonth)
- selectedMonth = [selectedDate monthOfYear];
- if (!selectedYear)
- selectedYear = [selectedDate yearOfCommonEra];
- firstWeekDay = [self firstWeekDay];
- lastDayOfMonth = [self lastDayOfMonth];
- [self logWithFormat:@"FirstWeekDay:%@", firstWeekDay];
- }
-
- - willPrepareForRequest:aRequest inContext:aContext {
- cell = -1;
- }
-
- - willGenerateResponse:aResponse inContext:aContext {
- cell = -1;
- }
-
- - firstDay {
- return [NSCalendarDate dateWithYear:[selectedYear intValue] month:[selectedMonth intValue] day:1 hour:0 minute:0 second:0 timeZone:[NSTimeZone localTimeZone]];
- }
-
- - selectedDay {
- if (selectedDate)
- return [[selectedDate dateWithCalendarFormat:@"%A, %B %d, %Y" timeZone:[NSTimeZone localTimeZone]] description];
- else
- return @"No selection";
- }
-
- - incrementYear {
- selectedYear = [[[self firstDay] addYear:+1 month:0 day:0 hour:0 minute:0 second:0] yearOfCommonEra];
- firstWeekDay = [self firstWeekDay];
- lastDayOfMonth = [self lastDayOfMonth];
- }
-
- - decrementYear {
- selectedYear = [[[self firstDay] addYear:-1 month:0 day:0 hour:0 minute:0 second:0] yearOfCommonEra];
- firstWeekDay = [self firstWeekDay];
- lastDayOfMonth = [self lastDayOfMonth];
- }
-
- - incrementMonth {
- selectedMonth = [[[self firstDay] addYear:0 month:1 day:0 hour:0 minute:0 second:0] monthOfYear];
- firstWeekDay = [self firstWeekDay];
- lastDayOfMonth = [self lastDayOfMonth];
- return nil;
- }
-
- - decrementMonth {
- selectedMonth = [[[self firstDay] addYear:0 month:-1 day:0 hour:0 minute:0 second:0] monthOfYear];
- firstWeekDay = [self firstWeekDay];
- lastDayOfMonth = [self lastDayOfMonth];
- return nil;
- }
-
- - formattedSelectedYear {
- return [[[self firstDay] dateWithCalendarFormat:@"%Y" timeZone:[NSTimeZone localTimeZone]] description];
- }
-
- - formattedSelectedMonth {
- return [[[self firstDay] dateWithCalendarFormat:@"%B" timeZone:[NSTimeZone localTimeZone]] description];
- }
-
- - firstWeekDay {
- return [[self firstDay] dayOfWeek];
- }
-
- - lastDayOfMonth {
- return [[[self firstDay] addYear:0 month:1 day:-1 hour:0 minute:0 second:0] dayOfMonth];
- }
-
- - cellValue {
- if ((cell >= firstWeekDay) && (cell < (lastDayOfMonth + firstWeekDay)))
- return (cell-firstWeekDay+1);
- else
- return nil;
- }
-
- - isSelectedCell {
- cell++;
- if ( ([selectedDate monthOfYear] == selectedMonth) && ((cell - firstWeekDay + 1) == [selectedDate dayOfMonth])) return YES;
- return NO;
- }
-
- - isUnselectedCell {
- if ( ([selectedDate monthOfYear] == selectedMonth) && ((cell - firstWeekDay + 1) == [selectedDate dayOfMonth])) return NO;
- else return YES;
- }
-
- - setSelectedDate {
- 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]];
- firstWeekDay = [self firstWeekDay];
- lastDayOfMonth = [self lastDayOfMonth];
- cell = 0;
- return [callBack invoke];
- }
-