How to approach building a Deltawerken application, Part 2
diego.lont at delware.nl
Mon Sep 17 07:53:40 UTC 2012
To set up user management, create an application specific user class. In AppName-Model, create a subclass of DEUser. See accessing the model for using users as model entrypoint.
In StoryBoard you can find the SBUser class. In order to be able to login, use a subclass of the DELoginForm. Override the "userClass" method, and the form is ready to use. It has some tags to allow you to customize the look and feel using css. In Storyboard this is used to allow you to register in addition to logging in.
EditForm and EditPanel
To let the user edit the model, use edit forms and edit panels. An EditForm is for editing a single object. Create an EditForm and set the "subject" to the object to edit. Note that the form needs to know whether it should create a new instance, or needs to make a (field)copy or not. The method to set a subject is "subject: aSubject isNew: aBoolean". The flag indicates if the object is new, and does not need copying or if it is an existing object and should be copied before editing.
The EditPanel is used when you need to edit multiple objects on the same page, and they either should be saved all together, or not saved at all (i.e. if validation of one of the objects fails). The interface of the EditPanel is very similar to EditForm, it has a "addSubject: aSubject isNew: aBoolean" method, that adds another EditComponent to the panel. You can also add EditComponents directly to the EditPanel.
StoryBoard only uses EditForms. The first EditForm you can find is in the SBRegisterUserForm. It is used to add new users, so the isNew flag is set to true. At this point the EditForm is a child of the SBRegisterUserForm, so the save and cancel action should be set. Alternative a EditForm can be shown modal, it returns nil on a cancel and the changed value on save.
subject: SBUser new isNew: true; " create a new user, and allow the edit form to change it "
title: 'Register user'; " title is optional and is shown as a heading "
propertySymbol: #initialEditFields; " normally password cannot be set when editing user, only initially, so a different field set is used "
saveAction: [ self save ]; " is called when the user presses save, and the user is valid "
cancelAction: [ self cancel ]; " is called when the user presses cancel "
To display collections reports are most useful. Reports are created by a builder. The builder has more or less the same options as a editForm. Reports should be refreshed when needed by setting the rows on rendering.
In StoryBoard the project overview makes use of a report for showing the projects. The builder is asked in the createProjectReport to create the appropriate report.
| builder |
builder := DEReportBuilder new
subject: SBProject; " use the description of SBProject to build the report "
propertySymbol: #reportColumns; " use the field set 'report column fields' to build the report "
builder addCustomColumn: self teamColumn.
^builder createReportFrom: self accessor: #showProject:
And the render method looks like this:
self projectReport rows: self projects. " we set this the rows here, to automatically update the content each time it is rendered. "
with: 'Current projects'.
canvas render: self projectReport.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the seaside