Project A: Build an Event Calendar

Project A Build an Event Calendar

Difficulty Level:

Easy

Completion Time:

1 to 2 hours

Project Materials:

1 Form, 6 Fields, 1 View, 2 Action Buttons

Languages Used:

LotusScript and Formula

Recurring Events:

Yes, "Single Document" Approach

Possible Usages:

Conference room reservations, equipment rentals, vacation planner

 

Create the Database

Let's start building the calendar application by launching the Lotus Domino Designer client and creating a blank database. When the Designer client is running, select the File > Database > New menu options. Specify Meeting Calendar as the application title and MtgCalendar.nsf as the file name. Be sure to select -Blank- as the template type (see Figure 8.3).

Figure 8.3. New database dialog

Tip

It's a good idea to remove all spaces from the File Name field. Spaces can cause problems when working with web applications. For example, replace Meeting Calendar.nsf with MtgCalendar.nsf.

 

Create the Appointment Form

The appointment form captures the event start and end dates, total number of recurring appointment days, author, subject, and details. The number of appointment days will be automatically computed based on the start and end dates. Most of the work associated with calendar applications resides in the appointment form, including management of recurrent events.

To create a form, click the New Form button or select the Create > Design > Form... menu options. After the form has been created, add a descriptive text title such as Appointment at the top of the form and the following field descriptions down the left side of the form.

  • Start Date:
  • End Date:
  • Total Days:
  • Person:
  • Subject:
  • Details:

Your form should now look similar to Figure 8.4.

Figure 8.4. Appointment form with field titles

 

Define the Fields

Next, add the fields beside each field title as specified in the following table. To create a field, select the Create > Field menu options (see Figure 8.5). Be sure to set the data type, formula, and other properties in the properties dialog window for each field. The field name, type, and style will be defined in the properties dialog.

Figure 8.5. Field property dialog

By default, the properties dialog window will be displayed when the first field is created. Select Edit > Properties if the properties dialog window is not visible.

The field Formula will be placed in the Value or Default Value section of the Programmer's pane, located in the lower section of the Designer client. Select View > Programmer's Pane if the pane is not visible. Figure 8.6 shows the Programmer's pane for the StartDate field.

Figure 8.6. Default value formula for StartDate field

Field Name

Type

Formula

Remarks

StartDate

Date/Time, Editable

DEFAULT StartDate:=
@If(@IsNewDoc; @Today;
@Return(StartDate));
 StartDate
 

In tab 1 of the properties dialog, set the Style to Calendar/Time control.

EndDate

Date/Time, Editable

 

In tab 1 of the properties dialog, set the Style to Calendar/Time control.

TotalDays

Number, Computed

@If(StartDate = ""; 0;
EndDate = ""; 0;
@BusinessDays(
StartDate; EndDate));
 

This formula will automatically compute the total number of days associated with the calendar event based on the start and end dates.

Person

Names, Computed when Composed

@UserName;
 

This formula will automatically compute the author's name.

Subject

Text, Editable

   

Body

Rich Text, Editable

   

Your calendar appointment form should now look like Figure 8.7.

Figure 8.7. Appointment form with fields added

 

Set the Form Objects and Properties

The Window Title displays in a tab at the top of the Lotus Notes client whenever a document is opened. The title helps make the application more user-friendly and can be set to any arbitrary value or text string. However, because the display space on the tab is limited, you should limit the text value. To set the window title, locate the Window Title section and add the following in the Programmer's pane (see Figure 8.8):

"Appointment"

Figure 8.8. Window Title for Appointment form

 

QuerySave Event

The QuerySave event will be used to refresh the current document any time the document is saved. This will ensure that the most current data is displayed to the user any time the form is saved (e.g., when the user selects the File > Save menu options). Add the following to the QuerySave event located in the Objects section of the Programmer's pane.

Sub Querysave(Source As Notesuidocument, Continue As Variant)
 Source.Refresh
End Sub

 

Form Property

Finally, select the Design > Form Properties menu options. This will display the properties dialog window for the form. On tab 1, check the Automatically refresh fields setting in the Options section (see Figure 8.9). This option will refresh computed fields as you change the data on the appointment form. For example, when the start and end dates are changed, the total number of days value will automatically update.

Figure 8.9. Form database dialog

To complete the form, specify Appointment | Appt in the Name field of the form properties dialog. The vertical bar indicates the alias name for the form. This completes the setup of the appointment form. Save and close the form.

Tip

Always provide a form name and alias name. All code should then refer to the alias name. This provides greater flexibility to change the form name without impacting existing code and/or view formulas.

 

Create the Calendar View

The majority of the project is now complete. The only step remaining is the creation of the calendar view used to display the appointments. Whenever a database is created, a default viewcalled "(untitled)"is automatically generated. Select Views in the Design pane and double-click on it to open in edit mode.

The next step is to define the properties for the view. Select the Design > View Properties menu options. Set the name to Calendar and alias name to Cal. Change the view Style from Standard Outline to Calendar. This setting changes the appearance of the view from the traditional look to a graphical calendar display. After you change the view, the Domino Designer client will display a warning message similar to Figure 8.10.

Figure 8.10. Warning message when selecting calendar view

Click Yes to continue.

Note

The calendar graphical display only appears in the Lotus Notes client and is not what you will see in the Designer client as the view is being developed.

 

Define the Columns

For this project, the view will include three columns. As mentioned in the architecture section, the first two columns are required for the calendar views. These columns will be hidden. The third column will display information associated with the appointment.

Column 1

Column 1 is a hidden column and must contain the start date/time value sorted in ascending order. To set the properties for this column, click on the column header and select the Design > Column Properties menu options.

In tab 1, set the Title to Date. In tab 2, set the Sort type to Ascending and select Show multiple values as separate entries. This is the option used to show one document across multiple calendar dates. Now switch to tab 6 and select the Hide column checkbox (see Figure 8.11).

Figure 8.11. Hide column on tab 6 of the view property dialog

Note

Column titles are not displayed in the calendar view. However, providing a column header name will help you and other developers understand the view design and column content.

With the column properties defined, next set the column value. In the Programmer's pane, change the display type from Simple Function to Formula and set the column formula to the following:

REM "Column1 contains the list of start dates";
REM "as defined in the appointment form";
DateList := @Explode(@TextToTime(@Text(StartDate)
+ "-" + @Text(EndDate)));
@TextToTime(DateList)

 

Column 2

The second column must contain the duration in order for the calendar to display correctly. This column will also be hidden. Select the Create > Append New Column menu options to add the new column. Select the Design > Column Properties menu options to display the column properties dialog window. In tab 1, set the Title to Duration. Then switch to tab 6 and select the Hide column checkbox.

With the column properties defined, next set the column value. For this project, the duration will be set to zero. In the Programmer's pane, change the display type from Simple Function to Formula and set the column formula to the following:

REM "Column2 contains the duration for the appointment";
REM "Set this column to zero, unless you set a start and";
REM "stop time for each appointment";
0

 

Column 3

The third column simply displays a text value for the calendar event. For this project, the appointment subject will be displayed on the calendar view. Alternatively, this column could contain the person, person and subject, or some other combination of document fields and text. This is the value that will be shown on the actual calendar view.

Select the Create > Append New Column menu options to add the new column. In the Programmer's pane, change the display type from Simple Function to Field and set the column formula to the following:

Subject

Tip

You may want to set the background color for the column to enhance the application usability. This will highlight the entry and help users locate calendar events on the view. To set the background color, select the third tab in the View properties dialog. The Background setting is located in the Entry section.

 

Set the View Objects and Properties

This project includes three methods for creating new appointmentsthe menu bar, an action button, and clickable calendar events. This will allow users to select the Create > Appointment menu options, click the New Appointment button (described later in this section), or double-click on a calendar date.

The RegionDoubleClick event allows users to double-click on a calendar date and automatically launch the new appointment form. When the form is displayed, the start date is populated with the date selected on the calendar.

This event also contains a data validation check to see if the selected date is before the current date. If the date is in the past, the user receives the prompt, "Date in past. Do you want to continue?" If the user selects Yes, the answer variable is set to 6 (which is a default value automatically set by the Lotus Notes application).

To configure this functionality, locate the RegionDoubleClick event in the Objects section of the Programmer's pane and then add the following LotusScript code. This code will create a new appointment if the date is today, in the future, or if the user answered Yes to create the record in the past. This routine is only executed if the user double-clicks on a calendar date.

Sub Regiondoubleclick(Source As Notesuiview)

 Dim doc As NotesDocument
 Dim workspace As New NotesUIWorkspace
 Dim uidoc As NotesUIDocument
 Dim view As NotesView
 Dim dateTime As New NotesDateTime("")
 Dim answer As Integer

 ' Display warning if selected date is in the past.
 Call dateTime.SetNow
 If Source.CalendarDateTime < dateTime.LSLocalTime Then
 answer%=Msgbox("Date in past. Do you want to continue?", _
 292, "Continue?")
 End If

 ' Create the appointment if date is in the past and user
 ' clicked, YES or create the appointment if date is in
 ' the future.
 If (answer% = 6) Or _
 (Source.CalendarDateTime >= Cdat (dateTime.DateOnly)) Then
 Set view = Source.View
 Set uidoc = workspace.ComposeDocument ("", "", "Appt")
 Set doc = uidoc.Document
 doc.StartDate = Source.CalendarDateTime
 End If

End Sub

Tip

This code can be added to the RegionDoubleClick event for any calendar view. This code checks to see if the date is in the past and prompts the user if they want to continue. To incorporate this feature into an existing database application, simply change Appt to the appropriate form name and add the code. This will make the application more user-friendly and enhance general usability.

 

Create Action Buttons for the View

Two action buttons will be created for the view. One button will be used to create new appointments. The other button will jump the calendar view to the current date.

To create the first button, select the Create > Action > Action menu options and name the button New Appointment. Close the properties dialog and add the following to the Programmer's pane.

@Command([Compose];"":"Appt")

To create the second button, select the Create > Action > Action menu options and name the button Today. Close the properties dialog and add the following to the Programmer's pane.

@Command([CalendarGoTo];@Date(@Now))

Tip

Optionally, you can add an icon to the action button. To add an icon, click on the action button and select the Design > Action Properties menu options. Then select an icon in the lower section of the properties dialog window.

Save and close the view. Congratulations, you have completed the project! If would you like to further customize the application, refer to Chapters 13 through 17 for additional enhancements. When you open the Lotus Notes client, your project should look similar to Figure 8.12.

Figure 8.12. Completed project



Project B Build a Conference Room Reservation System

An Introduction to the Lotus Domino Tool Suite

Getting Started with Designer

Navigating the Domino Designer Workspace

Domino Design Elements

An Introduction to Formula Language

An Introduction to LotusScript

Fundamentals of a Notes Application

Calendar Applications

Collaborative Applications

Reference Library Applications

Workflow Applications

Web Applications

Design Enhancements Using LotusScript

Design Enhancements Using Formula Language

View Enhancements

Sample Agents

Miscellaneous Enhancements and Tips for Domino Databases

Data Management

Security

Application Deployment and Maintenance

Troubleshooting

Appendix A. Online Project Files and Sample Applications

Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?



Lotus Notes Developer's Toolbox(c) Tips for Rapid and Successful Deployment
Lotus Notes Developers Toolbox: Tips for Rapid and Successful Deployment
ISBN: 0132214482
EAN: 2147483647
Year: N/A
Pages: 293
Authors: Mark Elliott

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net