[Seaside] Is your code for your Seaside web-app using concise methods?

Rick Flower rickf at ca-flower.com
Wed Jan 24 04:33:12 UTC 2007

Ramon Leon wrote:
>> Anyway, I guess I'm just curious if my ST coding skills are 
>> leading me down the wrong direction (I'm used to writing C++ 
>> code for my day-job where it's not uncommon to find methods 
>> with 50-100 or more lines) and I should be going for more 
>> simplicity in how my methods & objects are laid out..
>> Comments?
> Any chance we take take one of them as an example, and see the code and make
> suggestions?
Sure.. I'll take a stab at posting some code that I can try to make 
sense of for you -- the code below is for a page that generates an 
offline (I'll have a different set for online orders that will work 
similar but different) order form entered by an administrator from a 
paper form given to them.. This form will eventually (I don't have some 
of the mechanics in place completely yet) add items to the database via 
Glorp but that part of the code isn't quite there yet...

Initially, we have the following which in turn renders other areas by 
calling methods later (below further) -- this code is using SeasideAsync 
as you'll notice near the bottom method (which is in a major state of 
flux & experimentation)..  Please take it easy on  my coding style -- 
this code is still being developed and is likely to have  some areas 
that could be simplified or whatever.

MSWLI_Admin_Organization>>renderAddPaperOrderOn: html
   | aDB org userList scripList |

   aDB        := self session db.
   org        := self session org.
   userList   := aDB readManyOf: MSADBUser  where: [:each | each org id 
= org id].
   scripList  := aDB readManyOf: MSADBScrip where: [:each | each org id 
= org id].

   html div class: 'fieldset_lookalike'; with:
      html break.
      self renderFamilyAndOrgDivs: html withOrg: org.
      html break.
      html form: [
         self renderUserSelectList:   html withUserList: userList.
         html div id: 'vendorListDropDown'; with:
            self renderScripSelectList: html withScripList: scripList.
         html div id: 'denominationListDropDown'; with:
            html text: '3) Select Scrip Denomination'. html break.
            (html select)
            list: #('Select a Vendor First' );
               callback: [self error: 'Should not come here'].
            html div id: 'cart-contents'; with: [ ].
         html break.
      html break. html break.
   html break

MSWLI_Admin_Organization>>renderFamilyAndOrgDivs: html withOrg: org

   html div style: 'border-bottom: solid 1px #555; height: 73px;'; with: [ 
      "Enclose both divs in an outer div to allow us to align the left & 
right inner divs   "
      html div id: 'familyname'; with: [
         html label style: 'font-weight: bold; height: 76px'; with: 
'Ship To: '. html break.
         html break; break; break.
      html div id: 'orgname'; with: [
         html label style: 'font-weight: bold; height: 76px'; with: 
'Ship From: '. html break.
         html label with: org orgName. html break.
         html label with: org address. html break.
         html label with: org location city, ', ', org location state, 
', ', org location zipcode.

MSWLI_Admin_Organization>>renderUserSelectList: html withUserList: 

   html div id: 'userListDropDown'; with: [
   html text: '1) Select Family for Order'. html break.
    (html select)
        list: aUserList;
        selected: aUserList first;
        labels: [:item |
           item familyId = 1
            ifTrue: [item nameLast]
            ifFalse: [item nameLast , ' (#' , item familyId asString , ')']
        callback: [self error: 'Should not come here'];
        liveCallback: [:item :h |
             h span id: 'familyname'; with: [
                h label style: 'font-weight: bold'; with: 'Ship Order 
To: '. h break.
                h label with: item nameLast,', ',item nameFirst. h break.
                h label with: item streetAddress. h break.
                h label with: item location city,', ',item location 
state,' ', item location zipcode.
           "(h span) id: 'familyname'; with: [ item nameLast  ]."

MSWLI_Admin_Organization>>renderScripSelectList: html withScripList: 
   | dummyDenom denomList blah |

   dummyDenom := Array withAll: #('select a Scrip Vendor first').
   blah := false.
   html text: '2) Select Scrip Vendor'. html break.
   (html select)
   list: aScripList;
      selected: aScripList first;
      labels: [:item |
         blah = false
            ifTrue: [ blah := true. 'Select a Vendor...']
            ifFalse: [item vendor name]
      callback: [self error: 'Should not come here'];
      liveCallback: [:item :h |
         (h span) id: 'denominationListDropDown'; with:
         [ "Once we get a vendor selected, let's fill in the div for the 
denomination by replacing it with another selector"
          denomList  := (item denominations reject: [:each | each 
denomination = 0]).
            h text: '3) Select Scrip Vendor first'. h break.
            (h select)
            list: denomList;
            selected: denomList first;
            labels: [:nitem | nitem denomination];
            liveCallback: [:nitem :h2 |


More information about the Seaside mailing list