Configuring Siebel Open UI > Example of Customizing Siebel Open UI > Process of Customizing the Presentation Model >
Attaching an Event Handler to a Presentation Model
This task is a step in Process of Customizing the Presentation Model. At this point in this example, you have set up and customized the presentation model to choose records to delete, to delete them, and then to move them to the recycle bin. In this topic, you modify the presentation model to allow the user to click an item in the carousel, and then click the plus sign (+) to restore the record. Figure 24 illustrates the code you use to attach an event handler to a presentation model. Each number in this figure identifies the corresponding step number in the numbered task list that this book includes immediately after this figure.
Figure 24. Attaching an Event Handler to a Presentation Model
|
To attach an event handler to a presentation model
- In the recyclebinpmodel.js file, add the method that handles the event:
function OnClickRestore(index){
The name of an event handler typically starts with the following prefix:
On
Siebel Open UI calls this method when the user clicks the plus sign (+).
- Bind the OnClickRestore method to the RESTORE custom event:
this.AttachEventHandler("RESTORE", OnClickRestore);
This code adds the RESTORE custom event. The physical renderer sends this event to the presentation model, and then this presentation model runs OnClickRestore. The AttachEventHandler method sets up a dependency injection, so you add it in the Init method. For more information, see AttachEventHandler Method and About Dependency Injection.
- Identify the method that Siebel Open UI uses when a user creates a record.
Examine the Flow That Creates New Records in List Applets, Calling the Siebel Server. Note that Siebel Open UI uses the NewRecord method, and then uses the WriteRecord method as an input argument for the InvokeMethod method when it runs InvokeMethod in the presentation model. For more information, see NewRecord Method.
- Determine how Siebel Open UI stores the field values of a new record that a user creates.
Examine Flow That Handles Focus Changes in List Applets. This flow describes the process that occurs between the initial NewRecord call and the WriteRecord call when Siebel Open UI creates a record in the client. It stores the field values in the client while the user enters these values and navigates from one field to another field. For more information, see WriteRecord Method.
Siebel Open UI can do the following to create a record that it restores through the OnClickRestore event handler:
- Run the InvokeMethod method for the NewRecord.
- Store values that the user enters in each field, and use values from the records that Siebel Open UI stores in the recycle bin.
- Run the InvokeMethod method for WriteRecord with the client already configured to include the field values for the record.
- Make sure Siebel Open UI can use the NewRecord method in the applet:
if(this.ExecuteMethod("CanInvokeMethod", "NewRecord")){
If Siebel Open UI cannot run the NewRecord method, then it exits this conditional statement.
- Add the property that Siebel Open UI uses to store the index that identifies the record it must restore:
this.AddProperty("restorationIndex", -1);
The physical renderer must specify the record to restore. To do this, it uses the DeletionCompletedSet property to get the restorationIndex of this record from the client and store it. It then sends this index to the presentation model as part of a request to restore the record. The restorationIndex is an index that resides in the DeletionCompletedSet property of the record.
Siebel Open UI sends this value from the recycle bin record that the user chooses to restore. The OnClickRestore method receives this property, and then Siebel Open UI stores this value in the restorationIndex property of the presentation model.
- Configure the OnClickRestore method:
this.SetProperty("inRestoration", true); this.SetProperty("restorationIndex", index); this.ExecuteMethod("InvokeMethod", "NewRecord", null, false); this.ExecuteMethod("InvokeMethod", "WriteRecord", null, false);
where:
- NewRecord and WriteRecord are input arguments to the InvokeMethod method. In Step 3 you determined that Siebel Open UI uses the NewRecord method or the WriteRecord method as an input argument for the InvokeMethod, so you specify these methods in this code.
Siebel Open UI stores the field values of a record in the WriteRecord request before it sends this request to the Siebel Server. It stores these values differently depending on whether it creates a record from the recycle bin or whether the user creates a new record. The physical user interface layer does not store these values if the user attempts to restore a record from the recycle bin. It stores these values only if the user creates a new record. You write this customization in the next topic in this example, Customizing Methods in the Presentation Model to Store Field Values.
This customization runs only while WriteRecord is running to restore a record from the recycle bin. It does not run when the user creates a new record and Siebel Open UI calls WriteRecord. When you start this restoration logic in the OnClickRestore method, you set a presentation model property that serves as a flag that indicates that a recycle bin restoration is in progress. An explicit AddProperty call does not exist for this property, so Siebel Open UI creates this property only if the user uses the recycle bin.
- Save the recyclebinpmodel.js file.
|