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 / DodgeLite / Main.wo / Main.pl-pl < prev    next >
Encoding:
Text File  |  1996-08-09  |  2.9 KB  |  103 lines

  1. # $Id: Main.pl-pl,v 1.1 1996/07/26 05:17:03 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. # Written by Jean-Marie Hullot
  10. #
  11. # The WebScript file for the Main component displays car information such
  12. # as price range, model name, and car types to allow the user to build
  13. # selection criteria.
  14.  
  15. package WO::DodgeLite::Main;
  16. use WOPerl;
  17.  
  18. @IVARS=qw(models model selectedModels
  19.       prices price selectedPrices
  20.       types type selectedTypes
  21.       sortBys sortBy selectedSortOrder);
  22.  
  23. # Initialize variables 
  24. sub awakeX
  25. {
  26.   my $self=shift;
  27.   print "Main awake (object types)...\n";
  28.   $self->{'models'} = pl($WOApp->modelsDict->allValues);
  29.   $self->{'types'}=pl($WOApp->typesDict->allValues);
  30.   $self->{'prices'} = [8000, 10000, 12000, 14000, 16000,
  31.         18000, 20000, 25000, 30000, 50000, 90000];
  32.   $self->{'sortBys'} = ["Price", "Type", "Model"];
  33.   return;
  34. }
  35.  
  36. # This version of awake relies on fact that $WOApp is implemented in WOPerl
  37. # and that it keeps its ivars as Perl data types...
  38. sub awake
  39. {
  40.   my $self=shift;
  41.   print "Main awake (perl types)...\n";
  42.  
  43.   my $href=pl($WOApp)->modelsDict;
  44.   my @mvalues=values(%$href);
  45.   $self->{'models'} = \@mvalues;
  46.  
  47.   $href=pl($WOApp)->typesDict;
  48.   my @tvalues=values(%$href);
  49.   $self->{'types'}= \@tvalues;
  50.  
  51.   $self->{'prices'} = [8000, 10000, 12000, 14000, 16000,
  52.         18000, 20000, 25000, 30000, 50000, 90000];
  53.   $self->{'sortBys'} = ["Price", "Type", "Model"];
  54.   return;
  55. }
  56.  
  57.  
  58. # Formatter for price browser 
  59. sub priceFormat {
  60.   my $self=shift;
  61.   return "\$ $self->{'price'}";
  62. }
  63.  
  64. sub displayCars
  65. {
  66.   my $self=shift;
  67.   # Create the second page that will display all the cars matching 
  68.   # the client's criteria
  69.   my $selectedCarsPage = $WOApp->pageWithName("SelectedCars");
  70.   my $x;
  71.   $x=$self->{'selectedModels'};
  72.   if ($#$x<0) {
  73.     $self->{'selectedModels'} = $self->{'models'}; 
  74.   }
  75.   $x=$self->{'selectedTypes'};
  76.   if ($#$x<0) {
  77.     $self->{'selectedTypes'} = $self->{'types'}; 
  78.   }
  79.   $x=$self->{'selectedPrices'};
  80.   if ($#$x<0) {
  81.     $self->{'selectedPrices'} = $self->{'prices'}; 
  82.   }
  83.   $x=$self->{'selectedSortOrder'};
  84.   if (!$x)  {
  85.     $self->{'selectedSortOrder'} = "Price";
  86.   }
  87.  
  88.   # Set the selection parameters expressed by the client
  89.   # (car models, type, price range, ordering).
  90.   # Notice that all these selections (selectedModels, selectedTypes,...)
  91.   # are automatically filled by the declarations. (See Main.wod.)
  92.   $selectedCarsPage->setModels($self->{'selectedModels'});
  93.   $selectedCarsPage->setTypes($self->{'selectedTypes'});
  94.   $selectedCarsPage->setPrices($self->{'selectedPrices'});
  95.   $selectedCarsPage->setSortOrder($self->{'selectedSortOrder'});
  96.   $selectedCarsPage->fetchSelectedCars(); 
  97.  
  98.   return $selectedCarsPage;
  99. }
  100.  
  101. 'WO::DodgeLite::Main';
  102. # EOF
  103.