Standard dialogs

David Shaffer
Shaffer Consulting

Introduction

Seaside includes several useful modal dialogs which can be invoked via convience methods in WAComponent (an ancestor class of your compontents or tasks). These convenience methods include: The classes used to build these dialogs can be extended to create custom dialogs as well. Here will will show how to use and extend these dialogs.

Presenting an informational dialog to the user

The method WAComponent>>inform: displays an modal informational dialog (using call:) . For example, the Smalltalk code:
eraseAllData
	self inform: 'All of your data was erased.'
displays the dialog:

Obtaining confirmation from the user

The Smalltalk code:
clearCart
	(self confirm: 'Are you sure you want to clear your shopping cart?') 
		ifTrue: [self cart clear]
prompts the user with a Yes/No dialog and if they answer yes clears their shopping cart. Here's what the dialog looks like:

Asking the user for text input

We can obtain simple textual input from the user via:
readAge
    ^(self request: 'Please enter your age') asNumber
which displays the following dialog:

There are several variants of the request: method. Look through them by browsing WAComponent. If you want the user to enter a multi-line note (using an HTML textarea rather than an input of type text) you can use the WANoteDialog:
readAppointmentDescription
    | d |
    d := WANoteDialog new.
    d addMessage: 'Enter the appointment description'.
    ^self call: d
addMessage: simple adds a message decorator to the dialog (see Decorations for details). The resulting dialog looks like this:

Building your own simple dialogs

It is straightforward to build your own simple customized dialogs. In some cases the stock dialogs can be configured to meet your needs. Otherwise you might choose to create your own components. The class WAFormDialog and its several abstract subclasses provide useful base classes for dialogs.

WAFormDialog

WAFormDialog has support for adding forms, buttons, rendering validation errors, and a hook for subclasses to plug in their rendering code. It doesn't add too much functionality to WAComponent so the decision to subclass it or do everything yourself isn't one which will have a big impact on your application. Normally you would subclass WAFormDialog and override one or more of the following methods: Browsing subclasses of WAFormDialog will provide you with plenty of examples. Here's a simple common dialog which displays three buttons "save", "don't save", "cancel"
WAFormDialog subclass: #QuitWithoutSavingDialog
	instanceVariableNames: ''
	classVariableNames: ''
	poolDictionaries: ''
	category: 'SCSeasideTutorial'

buttons
	^#(save dontSave cancel)

cancel
	self answer: #cancel

dontSave
	self answer: #dontSave

save
	self answer: #save
Notice that I don't even need to override renderDialogOn:. Normally the developer will want to display a message along with these buttons but that can be accomplished with a message decorator. Here's a sample method to use this dialog:
quitPressedWithoutSaving
    | d result |
    d := QuitWithoutSavingDialog new.
    d addMessage: 'You pressed "quit" without saving your document.  What do you want to do?'.
    result := self call: d.
    result = #save ifTrue: [self saveDocument].
    result = #quit ifTrue: [self quit]
which displays

WALabelledFormDialog

TBD

WAEditDialog

TBD