Table of Contents
Previous Section
The Registration application includes the scripts Application.wos, Main.wos, and Registrants.wos. The contents of these scripts are listed below.
The application script Application.wos creates a RegistrationManager object manager that's used by the Main.wos and Registrants.wos component scripts to register new users and return a list of all registrants.
id manager;
- awake
{
manager = [RegistrationManager manager];
}
The Main.wos script includes methods for registering a new user, clearing the forms on the page, and returning a page that lists all of the people who have registered.
id newPerson;
id message;
- awake
{
if (!newPerson) {
newPerson = [NSMutableDictionary dictionary];
}
message = @"";
}
/*
* Ask the RegistrationManager manager object to write the user's data
* to a file. Set the value of the message string based on the results
* of the attempted registration.
*/
- register
{
// Set message from the validation dictionary.
id aPerson, results;
aPerson = [Person personWithDictionary:newPerson];
results = [[WOApp manager] registerPerson:aPerson];
if ([[results objectForKey:@"isValid"] isEqual:@"No"])
message = [results objectForKey:@"failureReason"];
else
message = @"You have been successfully registered.";
}
/*
* Clear all of the forms on the page.
*/
- clear
{
[newPerson setObject:@"" forKey:@"name"];
[newPerson setObject:@"" forKey:@"email"];
[newPerson setObject:@"" forKey:@"address"];
message = @"";
}
/*
* Return a page listing all of the people who have registered.
*/
- showRegistrants
{
id registrants = [WOApp pageWithName:@"Registrants"];
return registrants;
}
The Registrants.wos script accesses the list of all registered people through the application's manager object. The Registrants component uses a WORepetitionElement (declared in Registrants.wod, not shown) to iterate over all of the names in the list. The anItem variable maps to a declaration in Registrants.wod that defines a single element in the WORepetition.
id anItem;
id myNamesArray;
- awake
{
myNamesArray = [[WOApp manager] registrants];
}