[Seaside] New VW port

Avi Bryant avi@beta4.com
Sun, 2 Jun 2002 12:08:44 -0700 (PDT)

On 2 Jun 2002, Cees de Groot wrote:

> I've published a new VW port. It seems to work (again :-)), although some
> sample applications still fail - the issue of course is to determine
> whether they fail due to Squeak compatibility issues in the apps
> themselves or whether the port of Seaside is broken.

Cool, I'll check it out.

Since the port is based on my 0.94 snapshot, that means that the VW port
is currently more recent than the Squeak version (anyone who's interested
can access the same snapshot at
http://beta4.com/seaside/downloads/seaside-snapshot.cs, however)

> OBTW: what's the easiest way to generate big, complex, tables? I have a table
> with price information that's editable. It's a 3D thing: I have subscription
> periods, customer types, and two prices (setup and period). So the table looks
> like:
>             Normal         Affiliate     Partner
>          setup  period   setup period  setup period
> 12m      10.00   5.00    10.00 4.50    10.00 4.00
> 24m      10.00   9.50    10.00 9.00    10.00 8.50
> 36m       5.00  14.00     5.00 13.00    5.00 12.00
> <empty row so that people can just fill in the blanks to add a row>
> I want the rows to have alternating colors, and the customer types as well
> (and where they cross, a blend of both). All the prices (but not the periods)
> are editable text fields. Naturally, I want to separate the structure from the
> looks (alternating stuff) as much as possible.

Well, it's hard to say exactly without knowing what your data structures
are.  The best way of doing things tends to be to construct a structure
for display purposes that matches the structure of your table - so,
assuming you have some price object already that relates customer type,
period, and setup, you want to arrange something like

  with: '12m' -> (Dictionary
                     with: 'Normal' -> normal12mPrice
                     with: 'Affiliate' -> affiliate12mPrice
                     with: ...)
  with: '24m' -> ...

Or better yet, construct it based on a particular ordering #(Normal
Affiliate Partner) of customer types, so that it's maybe

  with: '12m' -> (Array with: normal12mPrice with: affiliate12mPrice with: ...)
  with: '24m' -> ...

(these are just to illustrate the structure, obviously, not how you would
construct them in real life).

Anyway, once you have, say, a method called #rows that returns that
(you'll want better names, but I'm not clear on what the 12m/24m/...
represent), building the table is very straightforward.  Something like:

<tr><td colspan="2" sea:id:="type/customerTypes">[type]</td></tr>
<tr sea:id="row/rows">
  <td sea:id="rowHead">[row.key]</td>
  <repeat sea:id="price/row.value">
     <td sea:id="setupCell"><input sea:id:="price.setup"></td>
     <td sea:id="priceCell">[price.period]</td>
<tr>... similar stuff for form to add row </tr>

Then you have to deal with the background colors.  Note that I've given
ids to the three kinds of cells; this means you can bind to them or (in
the version you've ported) give them display events.  So, you can do
something like

  (template elementNamed: 'setupCell')
    onDisplay: [:cell | cell attributeAt: #bgcolor put: self cellColor].

  |currentRow currentColumn|
  currentRow := locals at: #row.
  currentColumn := locals at: #price.
  ^ self cellColorForRow: row column: price

Of course, you may want to use the #class attribute instead of #bgcolor
directly, and then have some CSS somewhere, but whatever - the structure
is the same.

And that should be it.  Make sense, seem reasonable?

Although actually, you probably want to make sure that what's entered
into the price input is treated as numeric, so in addHandlers, you'll also
want a line like

(template elementNamed: 'price.setup') inputConversion: #asNumber.

And in fact since these are prices, you would also want some kind of
output conversion/formatting, that produced a string with exactly two
decimal places - and I haven't added support for that yet in that
particular snapshot, but it's easy to do.