aboutsummaryrefslogtreecommitdiff
path: root/pharo-mooc/contact-book/src/ContactBook/WAContactBook.class.st
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-11-21 22:26:28 +0100
committerEugen Wissner <belka@caraus.de>2025-11-21 22:26:28 +0100
commit8568518b57dba05500b63a4e471f8fa65883d10a (patch)
tree59681b400bccd6fd1299b3c22443c2ddf6f1b378 /pharo-mooc/contact-book/src/ContactBook/WAContactBook.class.st
parentc03c9f8b886c0e8eca5a701c0ca941e05e0b6285 (diff)
downloadbook-exercises-8568518b57dba05500b63a4e471f8fa65883d10a.tar.gz
Add pharo contact book
Diffstat (limited to 'pharo-mooc/contact-book/src/ContactBook/WAContactBook.class.st')
-rw-r--r--pharo-mooc/contact-book/src/ContactBook/WAContactBook.class.st116
1 files changed, 116 insertions, 0 deletions
diff --git a/pharo-mooc/contact-book/src/ContactBook/WAContactBook.class.st b/pharo-mooc/contact-book/src/ContactBook/WAContactBook.class.st
new file mode 100644
index 0000000..209cbe0
--- /dev/null
+++ b/pharo-mooc/contact-book/src/ContactBook/WAContactBook.class.st
@@ -0,0 +1,116 @@
+Class {
+ #name : 'WAContactBook',
+ #superclass : 'SBSRootComponent',
+ #instVars : [
+ 'contactBook'
+ ],
+ #category : 'ContactBook',
+ #package : 'ContactBook'
+}
+
+{ #category : 'initialization' }
+WAContactBook class >> initialize [
+ (WAAdmin register: self asApplicationAt: 'contacts')
+ addLibrary: JQDeploymentLibrary;
+ addLibrary: SBSDeploymentLibrary
+]
+
+{ #category : 'rendering' }
+WAContactBook >> addContact [
+ (self call: WAContact new)
+ ifNotNil: [ :contact | contactBook addContact: contact ]
+]
+
+{ #category : 'accessing' }
+WAContactBook >> contactBook [
+ ^ contactBook ifNil: [ contactBook := ContactBook createDefault ]
+]
+
+{ #category : 'accessing' }
+WAContactBook >> contacts [
+ ^ self contactBook contacts
+]
+
+{ #category : 'iterating' }
+WAContactBook >> contactsDo: aBlock [
+ self contacts do: aBlock
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderButtonsForContact: aContact on: html [
+ html buttonGroup: [
+ self
+ renderEditButtonForContact: aContact on: html;
+ renderRemoveButtonForContact: aContact on: html ]
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderContact: aContact on: html [
+ html tableRow: [
+ html
+ tableData: aContact fullname;
+ tableData: aContact email;
+ tableData: [ self renderPhotoOf: aContact on: html ];
+ tableData: [ self renderButtonsForContact: aContact on: html ] ]
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderContactsOn: html [
+ html table: [
+ html tableHead: [
+ html
+ tableHeading: 'Name';
+ tableHeading: 'Email';
+ tableHeading: 'Photo' ].
+ self contactsDo: [ :contact | self renderContact: contact on: html ] ]
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderContentOn: html [
+ "Main entry point of the view. Render both a title and the list of contacts."
+
+ html
+ container: [
+ html heading
+ level: 1;
+ with: 'My Contact Book'.
+ html form: [
+ self renderContactsOn: html.
+ self renderGlobalButtonsOn: html ] ]
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderEditButtonForContact: aContact on: html [
+ html outlineButton
+ beSuccess;
+ callback: [ self call: (WAContact editContact: aContact) ];
+ with: 'Edit'
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderGlobalButtonsOn: html [
+ html buttonGroup: [
+ html outlineButton
+ beSuccess;
+ callback: [ self addContact ];
+ with: 'New contact' ]
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderPhotoOf: aContact on: html [
+ html image url: aContact gravatarUrl
+]
+
+{ #category : 'rendering' }
+WAContactBook >> renderRemoveButtonForContact: aContact on: html [
+ html outlineButton
+ beDanger;
+ callback: [ self contactBook removeContact: aContact ];
+ with: 'Remove'
+]
+
+{ #category : 'updating' }
+WAContactBook >> updateRoot: anHtmlRoot [
+ super updateRoot: anHtmlRoot.
+ anHtmlRoot title: 'Contact Book'
+]