[Seaside] Refactoring menu bar code for Seaside App..
Rick Flower
rickf at ca-flower.com
Thu Aug 19 06:12:46 UTC 2010
Ok.. Just to followup.. I was able to create the attached code in case
anyone might
be able to make use of it.. I do not guarantee that it is bug free or
anything but it
does appear to work OK and is just an initial stab at an announcement
based
menu scheme that was written for Visualworks 7.7 and Seaside 3. The
general
paradigm with this example is that I've got 4 different user types :
1) Guest users (people just browsing)
2) Registered users (non-admins)
3) Organization admins
4) Site admins
Each one of these menus is derived from a Menu_Bar class which has
some of the
announcement plumbing in it. Each of the derived classes has a set of
callbacks --
one for each anchor that is selectable, an "isMenuValid" method to
indicate whether
this particular menu is applicable for the current situation (e.g.
don't display an admin
menu for a guest). I only have the guest menu enabled -- the others
are hard-coded
to not be viewable. Each time the user clicks on a link it sends a
#Announcement_MenuSelect to the UI_Menu class which squirrels away a
bunch
of info -- the code will then turn around and send another announcement
(#Announcement_SetMenuBody) to the MyApplicationRoot class which will
save the
new object as the "body" to be displayed. I'm sure there are many
other ways to
do this but this one works and is pretty clean I think -- no
references from one class
to another (e.g. no child/parent issues)..
Let me know if you notice any glaring issues with the code.. I might
extend it to
use jQuery and republish it if there's interest.. Unfortunately I can
only work on
this at night so it may take me a little bit of time..
-- Rick
-------------- next part --------------
A non-text attachment was scrubbed...
Name: BasicMenuAppUsingAnnouncements.st
Type: application/octet-stream
Size: 22438 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/seaside/attachments/20100818/04a77f78/BasicMenuAppUsingAnnouncements-0001.obj
-------------- next part --------------
On Aug 16, 2010, at 3:45 PM, Sean Allen wrote:
> On Mon, Aug 16, 2010 at 6:37 PM, Rick Flower <rickf at ca-flower.com>
> wrote:
>> On Mon, 16 Aug 2010 16:45:55 -0400, Sean Allen
>> <sean at monkeysnatchbanana.com> wrote:
>>> I would create actual menus for each type of menu so you can work
>>> with
>>> objects rather than a list of items and blocks.
>>> I find objects/components much easier to refactor, debug etc.
>>
>> So, create an object for each menu? My old code used something
>> similar with class side methods indicating whether the menu
>> was applicable for each type of user or not.. I'm just trying to
>> find a nice clean way to implement a lot of different menus.
>
> My first thought would be:
>
> A component for each type of menu. Then a general menu component that
> could double dispatch on the type of user to determine which menu
> component to use.
>
>>
>> By the way.. The method I referenced from the Seaside blog
>> tutorial earlier was (I believe) based on the material from
>> this post :
>> http://miguel.leugim.com.mx/index.php/2008/01/03/seaside-menus/
>>
>> I was perusing through the list archives and found an interesting
>> discussion back in 2008 regarding menu components and the use
>> of announcements.. I need to read up on them again as I'd really
>> like to better know what they're doing under the hood and to
>> possibly find a short example of their use with regards to a menu
>> system.. They're one of those scratch-my-head areas that I'm not
>> comfortable with yet..
>>
>
> Announcements are basically the observer pattern from GOF.
>
> +: loose coupling
> -: can be a nasty pain to debug
>
> You can google and find tons of pro and con on the observer pattern.
> That should give you plenty of info to evaluate the general
> publish/subscribe idea.
>
> I found that general idea to be very useful when I used to do C++ GUI
> development
> but haven't had any need for it when using Smalltalk. Then again, I've
> only been doing Smalltalk
> for 2 years.
More information about the seaside
mailing list