17.7. Implementation and Testing

The first thing you need to take care of is restricting access to the write view. If you go to the write view without being logged in there will be no user id for the currentUser and the submitPost function will give you a null reference in error when trying to retrieve the userId to set it as the authorId for the PostVO. To restrict access to the write view, edit the writeButton in the ApplicationControlBar in the MainView component to match the following:

<mx:LinkButton label="Write" id="writeButton"
visible="{(this.model.currentUser == null)
? false:(this.model.currentUser.accessLevel == 100)}" click="new
ChangeMainViewEvent(ChangeMainViewEvent.WRITE_VIEW).dispatch();"/>

Here the visible property is tied to the value of a ternary expression that checks to see if there is a current user. Simply checking to see if accessLevel equals 100 will not work and will cause the button to be shown until a user logs in and there is a value for the accessLevel property, so you first have to determine whether the currentUser property is null. If there is no user, the button is hidden. If there is a user, the access level is checked and the button is displayed if the access level is 100 (indicating that the user is an author).

Now edit the writeView HBox, adding the PostEditor view below the label:

<mx:HBox id="writeView"> <mx:Label styleName="viewHeader" text="Write"/> <views:PostEditor width="100%" postSubmitted="{this.model.postSubmissionStatus}"/> </mx:HBox> ...

Get Professional Cairngorm™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.