IBM®
Skip to main content
    Country/region select      Terms of use
 
 
   
     Home      Products      Services & solutions      Support & downloads      My account     
 
developerWorks
AIX and UNIX
Information Mgmt
Lotus
New to Lotus
Products
How to buy
Downloads
Live demos
Technical library
Training
Support
Forums & community
Events
Rational
Tivoli
WebSphere
Java™ technology
Linux
Open source
SOA and Web services
Web development
XML
My developerWorks
About dW
Submit content
Feedback



developerWorks  >  Lotus  >  Technical Library
developerWorks



Tips from LDD
Making Web applications act like Notes applications

Tip submitted by
Dean Menzel


Level: Intermediate
Works with: Notes/Domino
Updated: 08/01/2002

Related link:
More Tips from LDD


Make your Web applications behave like your Notes applications! Use the JavaScript onDblClick and onKeyPress events to edit a document when it is double-clicked and to close a document when the Escape key is pressed. To do this, we'll add code to the HTML Body Attributes and HTML Head Content objects. Then we'll create four hidden Computed-for-Display text fields on the form to process the code.

Note: The following code works only in Microsoft Internet Explorer 5.5 and later. Make sure that URLs in your application use the Domino URL command syntax format. For example, a document in read mode in the Web browser must have the ?OpenDocument URL command in the URL.

In Domino Designer, open a form in your Web application, and then select the HTML Body Attributes in the Objects window. Copy and paste the following code:

"onKeyPress=\"pageOnKeyPress()\" onDblClick=\"pageOnDblClick()\"

The onKeyPress and onDblClick events appear in the opening <BODY> tag, so if you double-click anywhere in the document, the document opens in edit mode. When you press the Escape key while in edit mode, a message prompts you to save the document.

In the HTML Head Content, copy and paste the following code:

pathparts:=@Explode(@Middle(path_info;0;"?");"/");
ViewPath:=@Implode(@Subset(pathparts;@Elements(pathparts)-1);"/") + "?openview";

"<SCRIPT>" +
    "function pageOnKeyPress(){" +
      @If(!allowedToEdit;"return";"")+
      "/* ESC key pressed */ " +
      "if(event.keyCode==27){" +
      @If(@IsDocBeingEdited;
        "if(confirm(\"Do you wish to save?\"))document.forms[0].submit();else return;";
        "var thisRef=location.href.toLowerCase();"+
        "if(thisRef.indexOf(\"openview\")==-1)location.href='/"+ViewPath+"'"
        ) +
      "}" +
      "}" +
    "function pageOnDblClick(){" +
      "location.href='"+@Middle(path_info;0;"?")+"?"+@ReplaceSubstring(@LowerCase(query_string);"opendocument";"editdocument")+"';" + "}" +

"</SCRIPT>"

The JavaScript for the onKeyPress and onDblClick events is dynamically calculated using formula language. The pageOnKeyPress() function is dynamically calculated depending on whether the page is in read or edit mode. If you are in read mode, pressing the Escape key sends you back to the original view. If you are in edit mode, you are prompted to save the document.

After you add the code to the HTML Head Content and HTML Body Attributes, you need to create several fields on the form to process the code.

The first two fields are path_info and query_string. These fields are used to determine the correct Domino URL command syntax and URLs for the Web browser. Create two hidden Computed-for-Display text fields on your form and name them path_info and query_string, respectively. List the field names in the Programmer's pane as the values of the fields.

Create a third hidden Computed-for-Display field on the form called $$Return. Copy and paste the following code into the Programmer's pane as the field's value:

thisDBFilePath:=@ReplaceSubstring(@Subset(@DbName;-1);"\\";"/");

@If(@Contains(@LowerCase(query_string);"savedocument");
    "["+path_info+"?"+@ReplaceSubstring(@LowerCase(query_string);"savedocument";"opendocument")+"]";
    "["+thisDBFilePath+"/default/"+@Text(@DocumentUniqueID)+"?opendocument]")

Add the fourth, and last, hidden Computed-for-Display text field to the form; call it allowedToEdit. Then in the Programmer's pane, add an @True formula for the field value. The allowedToEdit field determines if the user has the double-click event available to open the document in edit mode. The formula for allowedToEdit evaluates to either @True or @False and can be calculated from any ACL security model.

For experienced Notes client users, these modifications to your Web applications make using the Web much more palatable than always having to find and click a button to perform an action.


SUBMIT YOUR TIPS!
We encourage you to send us your tips (You can also click the "Would you like to submit a tip?" graphic below.) Your tips can be anything you've discovered about any Lotus product. The most important thing is that your tip be interesting, useful, or handy. And be sure to include complete information about how your tip works. For ideas, take a look at our tip archives. If we publish your tip, we'll send you the IBM Redbooks Lotus Collection on CD.






Would you like to submit a tip?
    About IBM Privacy Contact