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 / Main.wo / Main.pl < prev    next >
Encoding:
Perl Script  |  1996-08-09  |  3.6 KB  |  107 lines

  1. # $Id: Main.pl,v 1.1 1996/07/26 05:18:55 pedja Exp $
  2. # Main.pl: converted from the original Main.wos
  3. # The original file contains the following notice:
  4. #
  5. #   You may freely copy, distribute, and reuse the code in this example.
  6. #   NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  7. #   fitness for any particular use.
  8. #
  9. #   The TimeOff application lets a user submit a vacation request. This
  10. #   request consists of a vacation start date, an end date, and the
  11. #   user's login and password. The TimeOff application uses a subcomponent,
  12. #   Calendar, that messages the parent component (Main) using a WOAction
  13. #   object. This works as follows:
  14. #   
  15. #   1. The parent page (Main) references the child component in its
  16. #      declarations file (Main.wod):
  17. #
  18. #      START:Calendar {
  19. #      selectedDate = startDate;
  20. #      callBack = mainPage;
  21. #      };
  22. #
  23. #      END:Calendar {
  24. #      selectedDate = endDate;
  25. #      callBack = mainPage;
  26. #      };
  27. #
  28. #   The callback attributes specified in the declaration take as their
  29. #   values methods that are triggered when the child component sends the
  30. #   callBack object an invoke message. Through this mechanism the child 
  31. #   component is able to message the parent.
  32. #
  33. #   2. The child component's script (Calendar.wos) uses the action
  34. #      keyword to declare that the callBack specified in the parent's
  35. #      declarations file is a WOAction object:
  36. #      
  37. #      action callBack;
  38. #
  39. #   3. The child component's script (Calendar.wos) sends the WOAction
  40. #      object callBack an invoke message in its setSelectedDate method, 
  41. #      which tells callBack to invoke its associated method, mainPage.
  42. #   The Main.wos script processes the information the user enters into 
  43. #   the Calendar and text fields: the vacation start and end dates, the 
  44. #   login, and the password. If any of these items is missing or if the 
  45. #   information is logically inconsistent (for example, if the vacation
  46. #   end date precedes the vacation start date), this script returns the 
  47. #   Error page stating the error.
  48.  
  49. package WO::TimeOff::Main;
  50. use WOPerl;
  51.  
  52. @IVARS=qw(name password);
  53. @PERSISTENT=qw(startDate endDate);
  54. # NOTE: startDate and endDate ivars are NSObjects (NSDate)
  55.  
  56. sub mainPage {
  57.   return $_[0];
  58. }
  59.  
  60. sub recordTimeOff {
  61.   my($self)=shift;
  62.   my($errorPage,$message);
  63.     
  64.   if (nil($self->{'startDate'})) {
  65.     $errorPage = $WOApp->pageWithName("Error");
  66.     $errorPage->setErrorMessage(
  67.         "You need to pick a start date for your vacation request.");
  68.     return $errorPage;
  69.   }
  70.     
  71.   if (nil($self->{'endDate'})) {
  72.     $errorPage = $WOApp->pageWithName("Error");
  73.     $errorPage->setErrorMessage(
  74.         "You need to pick an end date for your vacation request.");
  75.     return $errorPage;
  76.   }
  77.     
  78.   if ($self->{'startDate'}->compare($self->{'endDate'})>=0) {
  79.     $errorPage = $WOApp->pageWithName("Error");
  80.     $message = "Your vacation start date ("
  81.       . $self->{'startDate'}->dateWithCalendarFormatTimeZone(
  82.        "%A, %B %d, %Y",NSTimeZone->localTimeZone)->description
  83.       . ") is after your vacation end date ("
  84.       . $self->{'endDate'}->dateWithCalendarFormatTimeZone(
  85.        "%A, %B %d, %Y",NSTimeZone->localTimeZone)->description
  86.       . ")";
  87.     $errorPage->setErrorMessage($message);
  88.     return $errorPage;
  89.   }
  90.  
  91.   if (!$self->{'name'} || !$self->{'password'}) {
  92.     $errorPage = $WOApp->pageWithName("Error");
  93.     $errorPage->setErrorMessage("You forgot to enter your login information!");
  94.     return $errorPage;
  95.   }        
  96.   return $WOApp->pageWithName("Thanks");
  97. }
  98.  
  99. sub willGenerateResponseInContext {
  100.   print "Generating response: page Main\n";
  101.   return(nil);
  102. }
  103.  
  104. 'WO::TimeOff::Main';
  105. # EOF
  106.