Building an Address Book > Creating the Application Functions > The cancelEditMode() Function

 

The cancelEditMode() Function

The cancelEditMode() function returns the address book to "browse mode" without saving any data from the "contact details" pane. Containing only two lines of code, cancelEditMode() performs the following tasks:

Enables the "address book" pane.

Disables the "contact details" pane.

Fills the "contact details" pane with the previously selected contact's information.

All of the work in cancelEditMode() is accomplished through calls to other functions. To switch back to "browse" mode, cancelEditMode() calls exitEditMode(). Then, to refresh the "contact details" pane, cancelEditMode() calls populateDetailsPane(). The call to populateDetailsPane() removes unwanted user changes from the "contact details" pane.

The complete listing for cancelEditMode() is shown below.

/*
 * Function: cancelEditMode()
 *   Desc: Returns the application to address book "browse
 *         mode" when the cancel button is pressed.
 *   Parameters: None.
 */

function cancelEditMode () 
{
  // Turn off text fields and enable
  // contactListBox and address book buttons.
  exitEditMode();

  // Put the last selected contact information
  // back into the contact details pane.
  populateDetailsPane();
}