WAStoreFillCart


Seaside-Examples-Store

Comment:

This component provides the main UI for browsing the store inventory and filling the cart.  The caller must provide a shopping cart instance with #cart:.  The component presents a navigation bar with options to browse and search on the left, and embeds a WACartView showing the cart contents on the right.  In the middle is initially embedded a WAStoreInfo.  Browsing and searching will replace this with a stock WABatchSelection component for listing items (see #displatItems:), or a WAStoreItemView for displaying individual items.  This answers back to the caller when the user chooses "checkout" from the nav bar.

Hierarchy:

ProtoObject
Object
WAPresenter
WAComponent
WAStoreFillCart

Summary:

instance variables:

cart cartView main

methods:

instance class
as yet unclassified no messages

Detail:

instance variables:

cart
cartView
main

instance methods:

as yet unclassified
browse

	self displayItems: self inventory allItems
cart: aCart

	cart _ aCart.
	cartView cart: aCart.
checkout

	self answer.
children

	^ Array with: cartView with: main
displayItem: anItem

	main call: (WAStoreItemView new item: anItem; cart: cart)
displayItems: aCollection

	| list |
	aCollection size = 1 ifTrue: [^ self displayItem: aCollection first].
	list _ WABatchSelection
			 items: aCollection
			 link: #title
			 text: #subtitle.
	[self displayItem: (main call: list)] repeat
	
initialize

	main _ WAStoreInfo new.
	cartView _ WAStoreCartView new
inventory

	^ WAStoreInventory default
renderContentOn: html

	html table: [
"		html tableRowWith: trail span: 3."
		html tableRow: [
			html cssId: 'nav'; tableData: [self renderNavBarOn: html].
			html cssId: 'main'; tableData: main.
			html cssId: 'side'; tableData: cartView.
		]
	]
renderNavBarOn: html

	html form: [
		html bold: 'Search:'.
		html space.
		html textInputWithValue: '' callback: [:v | self search: v].
	].
	html anchorWithAction: [self browse] text: 'Browse'.
	cart hasItems ifTrue: 
		[html break.
		html anchorWithAction: [self checkout] text: 'Checkout']
search: aString

	| results |
	results _ self inventory findItem: aString.
	results isEmpty
		ifTrue: [main inform: 'No items match ', aString printString]
		ifFalse: [self displayItems: results].
style

^ '
	#search {vertical-align: bottom}
	#main {width: 50%; padding: 10px}
	#side {vertical-align: top; }
	#cart {border-style: dashed; border-width: 1; padding: 5px}
	#nav {background-color: lightgrey; vertical-align: top; padding: 5px; border-width: 1; width: 15%; font-size: 12pt}
	#batch {font-size: 10pt}
'

class methods:

^top


- made by Dandelion -