[Seaside] AddressBook demo

Tim Rowledge seaside@lists.squeakfoundation.org
Thu, 01 Aug 2002 20:59:56 -0700


This message is in MIME format which your mailer apparently does not support.
You either require a newer version of your software which supports MIME, or
a separate MIME decoding utility.  Alternatively, ask the sender of this
message to resend it in a different format.

--82992384--1013505755--1784529
Content-Type: text/plain; charset=us-ascii

Here's a little web addressbook I made today as a demo for somebody and
(slightly altered) as part of my test-taker stuff. Feel free to add it
to the release if you think it illustrates anything useful. Oh, it's for
0.93 since  haven't had time to move to 0.94 although it doesn't use any
explicit bindings so maybe it would just work?

tim
-- 
Tim Rowledge, tim@sumeru.stanford.edu, http://sumeru.stanford.edu/tim
Useful random insult:- Dropped his second stage too soon.

--82992384--1013505755--1784529
Content-Type: text/plain; charset=iso-8859-1; name="DemoAddressBook.1.cs"
Content-Disposition: attachment; filename="DemoAddressBook.1.cs"
Content-Transfer-Encoding: quoted-printable

'From Squeak 3.2 of 11 July 2002 [latest update: #4917] on 1 August 2002 =
at 5:53 pm'!=0D"Change Set:		DemoAddressBook=0DDate:			1 August 2002=0DAu=
thor:			tim@sumeru.stanford.edu=0D=0DA simple demo of address book functi=
onality. =0DHow to use it:-=0DNo entry is selected initially so click on =
one of the links, if any exist in the list of AllAddresses. The name etc =
for that entry will be displayed in the text fields.=0DYou can edit any o=
f the text fields. If you click the 'Change' button, the selected entry w=
ill be updated to those new values. If you click the 'Add' button a new e=
ntry with those values will be added. This is how you populate your addre=
ss book from scratch.=0D'Delete' will remove the selected entry.=0D=0DThe=
re is no persistence, security or any other advanced feature implemented =
in this trivial demo. "!=0D=0DIAComponent subclass: #OTAddressBookCompone=
nt=0D	instanceVariableNames: 'addresses currentEntry currentName currentA=
ddress currentPhone '=0D	classVariableNames: ''=0D	poolDictionaries: ''=0D=
	category: 'Seaside-Examples'!=0D=0D!OTAddressBookComponent commentStamp:=
 'tim 8/1/2002 17:41' prior: 0!=0DA simple web accessible address book. N=
o cleverness is implemented for persistence or objectifying the phone num=
bers etc, they're all just Strings. It's a demo, folks.=0D=0DEvaluate the=
 expression below to install it in the Seaside applications list:-=0D(IAA=
pplication named:'addressBook') mainClass: OTAddressBookComponent!=0D=0DO=
bject subclass: #OTAddressEntry=0D	instanceVariableNames: 'name address p=
hone net email '=0D	classVariableNames: ''=0D	poolDictionaries: ''=0D	cat=
egory: 'Seaside-Examples'!=0D=0D!OTAddressEntry commentStamp: 'tim 8/1/20=
02 17:51' prior: 0!=0DThis is a simple data holder for an address book. N=
othing clever needed, just instvars for some personal info.!=0D=0D=0D!OTA=
ddressBookComponent methodsFor: 'accessing' stamp: 'tim 8/1/2002 17:42'!=0D=
allAddresses=0D	"lazy initialization for the list of all the addresses"=0D=
	^addresses ifNil:[addresses _ SortedCollection sortBlock:[:a :b| a name =
< b name]]! !=0D=0D!OTAddressBookComponent methodsFor: 'accessing' stamp:=
 'tim 8/1/2002 17:43'!=0DclearCurrentTexts=0D	"empty all the text field c=
ontents, ready for getting up to date"=0D	currentName_ currentAddress_ cu=
rrentPhone_ nil! !=0D=0D!OTAddressBookComponent methodsFor: 'accessing' s=
tamp: 'tim 8/1/2002 17:43'!=0DcurrentAddress=0D	"if the currentAddress is=
n't setup, get the latest info from the current entry"=0D	^currentAddress=
 ifNil:[currentAddress _ self currentEntry address]! !=0D=0D!OTAddressBoo=
kComponent methodsFor: 'accessing' stamp: 'tim 8/1/2002 16:32'!=0Dcurrent=
Address: aString=0D	currentAddress_ aString! !=0D=0D!OTAddressBookCompone=
nt methodsFor: 'accessing' stamp: 'tim 8/1/2002 17:44'!=0DcurrentEntry=0D=
	"when the currentEntry is nil , stick a reasonable null entry in its pla=
ce"=0D	currentEntry ifNil:[currentEntry _ OTAddressEntry null].=0D	^curre=
ntEntry! !=0D=0D!OTAddressBookComponent methodsFor: 'accessing' stamp: 't=
im 8/1/2002 17:44'!=0DcurrentName=0D	"if the currentName isn't setup, get=
 the latest info from the current entry"=0D	^currentName ifNil:[currentNa=
me _ self currentEntry name]! !=0D=0D!OTAddressBookComponent methodsFor: =
'accessing' stamp: 'tim 8/1/2002 16:33'!=0DcurrentName: aString=0D	curren=
tName_ aString! !=0D=0D!OTAddressBookComponent methodsFor: 'accessing' st=
amp: 'tim 8/1/2002 17:44'!=0DcurrentPhone=0D	"if the currentPhone isn't s=
etup, get the latest info from the current entry"=0D	^currentPhone ifNil:=
[currentPhone _ self currentEntry phone]! !=0D=0D!OTAddressBookComponent =
methodsFor: 'accessing' stamp: 'tim 8/1/2002 16:33'!=0DcurrentPhone: aStr=
ing=0D	^currentPhone_ aString! !=0D=0D!OTAddressBookComponent methodsFor:=
 'accessing' stamp: 'tim 8/1/2002 17:45'!=0Dselect: anEntry =0D	"an entry=
 has been clicked in the main listing. If it is the same as the previous =
one, we've deslected it, so select a null. Otherwise, select the chosen e=
ntry"=0D	self clearCurrentTexts.=0D	currentEntry =3D anEntry=0D		ifTrue: =
[currentEntry _ nil]=0D		ifFalse: [currentEntry _ anEntry]! !=0D=0D!OTAdd=
ressBookComponent methodsFor: 'actions' stamp: 'tim 8/1/2002 17:46'!=0Dad=
dEntry=0D	"add a new entry with the contents of the text fields; one coul=
d plausibly check for a pre-existing entry with the same values here"=0D	=
addresses add: (currentEntry _ OTAddressEntry name: currentName address: =
currentAddress phone: currentPhone)! !=0D=0D!OTAddressBookComponent metho=
dsFor: 'actions' stamp: 'tim 8/1/2002 17:48'!=0DchangeEntry=0D	"change th=
e contents of the current entry to reflect the text fields. Note that thi=
s works perfectly well with a null entry that hasn't been added yet. Perh=
aps some extra checking would be appro=10priate her, though user testing =
should be done to determine the least surprising thing to do"=0D	currentE=
ntry name: currentName; address: currentAddress; phone: currentPhone! !=0D=
=0D!OTAddressBookComponent methodsFor: 'actions' stamp: 'tim 8/1/2002 17:=
49'!=0DdeleteEntry=0D	"remove the selected entry, if it exists. Do nothin=
g if there is no selection"=0D	addresses remove: currentEntry ifAbsent:[]=
! !=0D=0D!OTAddressBookComponent methodsFor: 'actions' stamp: 'tim 8/1/20=
02 17:50'!=0Dhtml=0D	"build the html for the webpage"=0D	^'<h3>Address Bo=
ok</h3>=0D<form sea:id=3D"fooble">=0D	<table>=0D		<tr>=0D			<th>Name<th>A=
ddress<th>Phone=0D		<tr>=0D			<td><input type=3D"text" sea:id=3D"currentN=
ame">=0D			<td><input type=3D"text" sea:id=3D"currentAddress">=0D			<td><=
input type=3D"text" sea:id=3D"currentPhone">=0D		<tr>=0D			<td><input typ=
e=3D"submit" sea:id=3D"addEntry" value=3D"Add As New Entry">=0D			<td><in=
put type=3D"submit" sea:id=3D"changeEntry" value=3D"Change This Entry ">=0D=
			<td><input type=3D"submit" sea:id=3D"deleteEntry" value=3D"Delete Sele=
cted Entry">=0D	</table>=0D</form>=0D<table width=3D"70%" border=3D1>=0D	=
<tr>=0D		<th>All Names<th>Addresses<th>Phone Numbers=0D	<tr sea:id=3D"add=
r/allAddresses">=0D		<td><a sea:id=3D"select:">[addr.name]</a>=0D		<td>[a=
ddr.address]=0D		<td>[addr.phone]=0D</table>'! !=0D=0D=0D!OTAddressEntry =
methodsFor: 'instance creation' stamp: 'tpr 7/31/2002 17:59'!=0Daddress=0D=
	^address! !=0D=0D!OTAddressEntry methodsFor: 'instance creation' stamp: =
'tpr 7/31/2002 18:08'!=0Daddress: aString=0D	address _ aString! !=0D=0D!O=
TAddressEntry methodsFor: 'instance creation' stamp: 'tpr 7/31/2002 17:59=
'!=0Dname=0D	^name! !=0D=0D!OTAddressEntry methodsFor: 'instance creation=
' stamp: 'tpr 7/31/2002 18:07'!=0Dname: aString=0D	name _aString! !=0D=0D=
!OTAddressEntry methodsFor: 'instance creation' stamp: 'tim 8/1/2002 16:1=
7'!=0Dphone=0D	^phone! !=0D=0D!OTAddressEntry methodsFor: 'instance creat=
ion' stamp: 'tim 8/1/2002 16:17'!=0Dphone: aString=0D	phone _ aString! !=0D=
=0D!OTAddressEntry methodsFor: 'instance creation' stamp: 'tim 8/1/2002 1=
7:52'!=0DsetNull=0D	"make  null entries so that nothing gets unexpected U=
ndefinedObject problems"=0D	name _ ''.=0D	address _ ''.=0D	phone _ ''.=0D=
	net _ ''.=0D	email _ ''! !=0D=0D=0D!OTAddressEntry class methodsFor: 'in=
stance creation' stamp: 'tim 8/1/2002 16:41'!=0Dname: nameString address:=
 addressString phone: phoneString=0D	^self new address: addressString; na=
me: nameString; phone: phoneString! !=0D=0D!OTAddressEntry class methodsF=
or: 'instance creation' stamp: 'tim 8/1/2002 17:51'!=0Dnull=0D	"create a =
suitable null address"=0D	^self new setNull! !=0D=0DOTAddressEntry class =
removeSelector: #name:address:!=0DOTAddressBookComponent removeSelector: =
#initialise!=0D
--82992384--1013505755--1784529--