home *** CD-ROM | disk | FTP | other *** search
- # $Id: Main.pl,v 1.1 1996/07/26 05:18:55 pedja Exp $
- # Main.pl: converted from the original Main.wos
- # The original file contains the following notice:
- #
- # 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.
- #
- # The TimeOff application lets a user submit a vacation request. This
- # request consists of a vacation start date, an end date, and the
- # user's login and password. The TimeOff application uses a subcomponent,
- # Calendar, that messages the parent component (Main) using a WOAction
- # object. This works as follows:
- #
- # 1. The parent page (Main) references the child component in its
- # declarations file (Main.wod):
- #
- # START:Calendar {
- # selectedDate = startDate;
- # callBack = mainPage;
- # };
- #
- # END:Calendar {
- # selectedDate = endDate;
- # callBack = mainPage;
- # };
- #
- # The callback attributes specified in the declaration take as their
- # values methods that are triggered when the child component sends the
- # callBack object an invoke message. Through this mechanism the child
- # component is able to message the parent.
- #
- # 2. The child component's script (Calendar.wos) uses the action
- # keyword to declare that the callBack specified in the parent's
- # declarations file is a WOAction object:
- #
- # action callBack;
- #
- # 3. The child component's script (Calendar.wos) sends the WOAction
- # object callBack an invoke message in its setSelectedDate method,
- # which tells callBack to invoke its associated method, mainPage.
- #
- # The Main.wos script processes the information the user enters into
- # the Calendar and text fields: the vacation start and end dates, the
- # login, and the password. If any of these items is missing or if the
- # information is logically inconsistent (for example, if the vacation
- # end date precedes the vacation start date), this script returns the
- # Error page stating the error.
-
- package WO::TimeOff::Main;
- use WOPerl;
-
- @IVARS=qw(name password);
- @PERSISTENT=qw(startDate endDate);
- # NOTE: startDate and endDate ivars are NSObjects (NSDate)
-
- sub mainPage {
- return $_[0];
- }
-
- sub recordTimeOff {
- my($self)=shift;
- my($errorPage,$message);
-
- if (nil($self->{'startDate'})) {
- $errorPage = $WOApp->pageWithName("Error");
- $errorPage->setErrorMessage(
- "You need to pick a start date for your vacation request.");
- return $errorPage;
- }
-
- if (nil($self->{'endDate'})) {
- $errorPage = $WOApp->pageWithName("Error");
- $errorPage->setErrorMessage(
- "You need to pick an end date for your vacation request.");
- return $errorPage;
- }
-
- if ($self->{'startDate'}->compare($self->{'endDate'})>=0) {
- $errorPage = $WOApp->pageWithName("Error");
- $message = "Your vacation start date ("
- . $self->{'startDate'}->dateWithCalendarFormatTimeZone(
- "%A, %B %d, %Y",NSTimeZone->localTimeZone)->description
- . ") is after your vacation end date ("
- . $self->{'endDate'}->dateWithCalendarFormatTimeZone(
- "%A, %B %d, %Y",NSTimeZone->localTimeZone)->description
- . ")";
- $errorPage->setErrorMessage($message);
- return $errorPage;
- }
-
- if (!$self->{'name'} || !$self->{'password'}) {
- $errorPage = $WOApp->pageWithName("Error");
- $errorPage->setErrorMessage("You forgot to enter your login information!");
- return $errorPage;
- }
- return $WOApp->pageWithName("Thanks");
- }
-
- sub willGenerateResponseInContext {
- print "Generating response: page Main\n";
- return(nil);
- }
-
- 'WO::TimeOff::Main';
- # EOF
-