ST 4U 123: Reusing the Post Editor
Today's Smalltalk 4 You continues the VA Smalltalk Seaside tutorial by reusing the post tool to edit existing posts. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:
If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.
You can also watch it on YouTube:
In this section we'll reuse the posting tool we've already built to edit existing posts.
First, we'll modify the #renderPostOn: method in BlogListView - we want an edit link to appear for logged in users:
renderPost: post on: html html div class: 'post'; with: [html strong: [html text: post title]. html break. self session currentUser ifNotNil: [self renderEditLinkOn: html for: post. html break]. html html: post content; break; text: 'Posted on: ', post timestamp printString; break]
We check the session, and if there's a logged in user, we drop in an edit link. Next, we need that #renderEditLinkOn:for: method in BlogListView:
renderEditLinkOn: html for: post html anchor callback: [self openEditorOn: post]; with: 'Edit'
That creates our link - we still need to write the code for using the link:
openEditorOn: post | editor | editor := BlogPostView new. editor post: post. (self show: editor) onAnswer: [:ans | ans ifTrue: [BlogStorage default updatePost: editor post]]
Here we again see the #show:OnAnswer: control flow in VA Seaside use - but we are using the answer. recall that the post editor answers true or false - we use that in this code to determine whether or not to save the post. Since the view used in #show:onAnswer: is done at the end of that, we revert back to the main view in either case. Finally, the #updatePost: method in BlogStorage is a placeholder - in this example, all storage is in memory only:
updatePost: aPost "no op, since it's all in memory" ^self
That's it - we are now reusing the post tool for editing.
That about wraps it up for today - next time, we'll get into the posting tool itself. To see that in action, let's login:
Note the new Edit link - try going through the blogView link - you won't see it:
Follow the edit link for one of the posts - you'll see something like this:
Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.
Technorati Tags: va smalltalk, seaside, tutorial
Enclosures:
[st4u123-iPhone.m4v ( Size: 5792419 )]