This is the tip we all were waiting for. This LotusScript agent represents AddressBook on the Web. It has been tested with Microsoft Internet Explorer 5.5 and Mozilla Firefox 1.0.x.
Please note that DBPath is a Computed For Display field on the form from where you wish to call the Web Address Book. The formula for DBPath field is
@ReplaceSubstring
(@Subset(@DbName;-1);"\\";"/")
Also, please note that screenWidth and screenHeight are variables to be defined in the JavaScript header section, as written below:
(Note: screenWidth and screenHeight are used in openAddressDialogbox().)
var screenWidth = screen.width;
var screenHeight = screen.height;
Here's the code for the AddressBook:
Javascript:
-------------
how to call:
openAddressDialogbox
(document.forms[0].fieldName)
function openAddressDialogbox(element) {
window.nameElement = element ;
var popUpWidth = 342;
var popUpHeight = 400;
var popUpLeft = parseInt
((screenWidth - popUpWidth)/2);
var popUpTop = parseInt
((screenHeight - popUpHeight)/2);
var strNewWin = '/' +
document.forms[0].DbPath.value
+ '/agtWebNAB?OpenAgent&default='
+ escape(element.value);
//alert(strNewWin);
var newWin = window.open( strNewWin , 'newWin',
'toolbar=no,location=no,directories=no,
status=yes,resizable=no,scrollbars=
no,menubar=no,top='+popUpTop
+',left='+popUpLeft+',width='+
popUpWidth+',height='+popUpHeight );
}
LotusScript:
--------------
Agent: agtWebNAB
Run on: None
Manually from Actions Menu
Sub Initialize
On Error Goto errorHandler
' start printing the HTML
Print | <HTML><HEAD>
<TITLE>Address Book</TITLE>
<META HTTP-EQUIV="Pragma"
CONTENT="no-cache">|
' print the styles to be used
Print |
<STYLE TYPE=text/css>
BODY { font-family: verdana,arial,
helvetica; font-size:
8pt; margin: 4 ; background: #EFEFEF; }
INPUT, SELECT { font-family:
verdana,arial,helvetica;
font-size: 8pt; border-style: solid;
border-color: #000000; border-width: 1; }
TABLE { border-width: 0; }
TD { background: #FFFFFF;
color: #000000; font-family:
verdana,arial,helvetica; font-size:
8pt; font-weight: normal;
text-align: left ; vertical-align: top ;
padding: 2; border-width: 0; }
.BLUE { background: #C0E1FF;
border-style: solid;
border-color: #4181C0; border-width: 1; }
.GREY { background: #EFEFEF;
border-style: solid;
border-color: #808080; border-width: 1; }
.LIST { width: 322 ; }
.ODD { background: #FFFFFF;}
.EVEN { background: #C0E1FF;}
.GROUP { background-color: #F1F1B4;
border:
2 solid #808080 }
.BUTTONB { background: #C0E1FF;
border-style:
solid; border-color: #4181C0; border-width: 1;
cursor: hand ; }
.BUTTONG { background: #D0D0D0;
border-style:
solid; border-color: #000000; border-width:
1; cursor: hand ; }
</STYLE>
|
' print disable right click JavaScript Code
Print |
<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
function press(e)
{
if ((ns4 && (e.which == 3 || e.which == 2)) ||
(ie4 && (event.button == 2 || event.button == 3)))
{
self.status = "Page design in hidden";
return false;
}
return true;
}
for (var i=0; i<document.images.length; i++)
document.images[i].onmousedown=press;
for (var i=0; i<document.links.length; i++)
document.links[i].onmousedown=press;
document.onmousedown=press;
if (ns4) window.captureEvents
(Event.MOUSEDOWN);
window.onmousedown=press;
-->
</SCRIPT>
|
' print the JavaScript functions called in the buttons
Print |<SCRIPT LANGUAGE=JavaScript>
<!--
function openAddressBook() {
var selindex=document.forms[0]
.AddressBookList.options.selectedIndex ;
var curAddressBook = document.forms[0]
.AddressBookList.options[document.forms[0]
.AddressBookList.selectedIndex].value;
//alert(document.forms[0].hAgentContext.value +
'&default=' + document.forms[0].Selection.value +
'&addressBook=' + curAddressBook);
document.form1.action =
document.forms[0].hAgentContext.value
+ '&default=' + document.forms[0].Selection.value +
'&addressBook=' + curAddressBook;
document.form1.submit();
}
function popName() {
var selindex=document.forms[0]
.AddressList.options.selectedIndex ;
document.forms[0].Selection.value =
document.forms[0].AddressList.options[selindex].value;
//document.forms[0].AddressList.options.selectedIndex = -1;
}
function clickFirst(i) {
//alert(document.forms[0].hAgentContext.value +
'&act=first&start=' + i + '&default=' + document.forms[0]
.Selection.value);
document.form1.action =
document.forms[0].hAgentContext.value
+ '&act=first&start=' + i + '&default=' +
document.forms[0].Selection.value ;
document.form1.submit();
}
function clickPrev(i) {
//alert(document.forms[0].hAgentContext.value +
'&act=prev&start=' +
i + '&default=' + document.forms[0].Selection.value);
document.form1.action =
document.forms[0].hAgentContext.value +
'&act=prev&start=' + i + '&default='
+ document.forms[0].Selection.value ;
document.form1.submit();
}
function clickSearch(i) {
//alert(document.forms[0].hAgentContext.value
+ '&act=search&start=' + i
+ '&query=' + document.forms[0].SearchString.value
+ '&default=' +
document.forms[0].Selection.value);
document.form1.action =
document.forms[0].hAgentContext.value +
'&act=search&start=' + i + '&query=' +
document.forms[0]
.SearchString.value + '&default=' +
document.forms[0].Selection.value ;
document.form1.submit();
}
function clickNext(i) {
//alert(document.forms[0].hAgentContext.value
+ '&act=next&start='
+ i + '&default=' + document.forms[0].Selection.value);
document.form1.action =
document.forms[0].hAgentContext.value
+ '&act=next&start=' + i + '&default=' +
document.forms[0].Selection.value ;
document.form1.submit();
}
function clickLast(i) {
//alert(document.forms[0].hAgentContext.value
+ '&act=last&start='
+ i + '&default=' +
document.forms[0].Selection.value);
document.form1.action =
document.forms[0].hAgentContext.value
+ '&act=last&start=' + i + '&default=' +
document.forms[0].Selection.value ;
document.form1.submit();
}
// -->
</SCRIPT>
</HEAD> |
' code to populate options starts
Dim session As NotesSession
Dim db As NotesDatabase
Dim ndb As NotesDatabase
Dim books As Variant
Dim selectedBook As String
Dim docContext As NotesDocument
Dim vw As NotesView
Dim nav As NotesViewNavigator
Dim entry As NotesViewEntry
Set session = New NotesSession
Set docContext = session.DocumentContext
books = session.AddressBooks
Dim h_QueryString_Decoded As String
h_QueryString_Decoded =
Cstr(docContext.Query_String_Decoded(0))
Dim strNdbServer As String
strNdbServer =
extractParameter(h_QueryString_Decoded,"addressBook")
' start printing the BODY
Print "<BODY OnContextMenu='return false'>"
Print "<FORM Name='form1' method='POST' action=''>"
Print "<TABLE CELLSPACING=3 CELLPADDING=0>"
Print |
<TR VALIGN=top><
TD CLASS=BLUE WIDTH=322><DIV
ALIGN=left><B>Look in Address Book(s)
</B></DIV></TD></TR>
<TR VALIGN=top>
<TD CLASS=GREY WIDTH=322>
<SELECT NAME=AddressBookList SIZE=1
CLASS=LIST ONCHANGE=openAddressBook()>
|
Forall b In books
If b.IsPublicAddressBook Or b.isPrivateAddressBook
Then
Call b.Open("","")
If Ucase(strNdbServer) = Ucase(b.Server) Then
Print "<OPTION CLASS='ODD' SELECTED VALUE='"
& b.Server & "' TITLE='" & b.Server & "'>"
& b.Title & "</OPTION>"
Else
Print "<OPTION CLASS='ODD' VALUE='" & b.Server
& "' TITLE='" & b.Server & "'>" & b.Title & "</OPTION>"
End If
End If
End Forall
Print |
</SELECT>
</TD>
</TR>
|
Set db = session.CurrentDatabase
'Print "<script language=JavaScript>alert('strNdbServer =
" & strNdbServer & "');</script>"
Dim namServer As NotesName
If strNdbServer = "" Then
' get names.nsf database on current server
Set ndb = session.getDatabase("","names")
Else
'' get names.nsf database on selected server
Set ndb = session.getDatabase(strNdbServer,"names")
End If
Set namServer = New NotesName(ndb.Server)
'Continue Printing
Print "<TR VALIGN=top><TD CLASS=BLUE
WIDTH=322><DIV ALIGN=center><B>Names
on " & namServer.Common
& "</B></DIV></TD></TR>"
Print "<TR VALIGN=top><TD CLASS=GREY
WIDTH=322><DIV ALIGN=center>"
If Not ndb.IsOpen Then
Call ndb.Open("","names")
End If
' get the People view and create a ViewNavigator
object for navigating the entries in the view
Set vw = ndb.getView("$VIMPeopleAndGroups")
Set nav = vw.createViewNav()
' get the first document in view
Set entry = nav.getFirstDocument()
' initialize variables required later on
Dim pos As Integer
Dim maxCount As Integer
Dim l_first As String
Dim l_prev As String
Dim l_next As String
Dim l_last As String
Dim l_search As String
' variable for maximum names to be
shown as options in the SELECT tag
maxCount = 200
' variable for the actions passed in the URL
l_first = "first"
l_prev = "prev"
l_next = "next"
l_last = "last"
l_search = "search"
Dim defaultSelection As String
Dim startParameter As String
Dim start As Integer
Dim action As String
' gets the default value for selection passed in the URL
defaultSelection =
extractParameter(h_QueryString_Decoded,"default")
' gets the start parameter passed in the URL
startParameter =
extractParameter(h_QueryString_Decoded,"start")
start = 1
If Isnull(startParameter) Or startParameter="" Then
start = 1
pos = 1
Else
start = startParameter
pos = start
End If
' Gets the button clicked on the window
action = extractParameter
(h_QueryString_Decoded,"act")
If Isnull(action) Then
' Keep the entry as first document
Elseif action=l_first Then
' Keep the entry as first document
Elseif action=l_prev Then
pos = start - maxCount
If pos<1 Then
pos=1
End If
Set entry = nav.getNth(pos)
If entry Is Nothing Then
Set entry = nav.getFirstDocument()
End If
Elseif action=l_search Then
Set entry = vw.getEntryByKey(extractParameter
(h_QueryString_Decoded,"query"), False)
If entry Is Nothing Then
pos = start
Else
pos = entry.getPosition(".")
End If
Set entry = nav.getNth(pos)
Elseif action=l_next Then
pos = start + maxCount
Set entry = nav.getNth(pos)
If entry Is Nothing Then
Set entry = nav.getLastDocument()
pos = entry.getPosition(".")
End If
Elseif action=l_last Then
Set entry = nav.getLastDocument()
pos = entry.getPosition(".")
pos = pos - maxCount + 1
If pos < 1 Then
pos = 1
End If
Set entry = nav.getNth(pos)
Else
' Keep the entry as first document
End If
Dim varTemp As Variant
varTemp = Evaluate
(|@Left("| & h_QueryString_Decoded
& |";"OpenAgent") + "?OpenAgent"|)
' print the navigation buttons
Print "<INPUT TYPE=hidden NAME='hAgentContext'
VALUE='" & varTemp(0) & "'>"
Print |<INPUT TYPE=button VALUE=First
CLASS='BUTTONB' onClick=clickFirst(| & pos & |)
onmouseover="this.className='BUTTONG'"
onmouseout="this.className='BUTTONB'" >|
Print |<INPUT TYPE=button VALUE=Prev
CLASS='BUTTONB' onClick=clickPrev(| & pos & |)
onmouseover="this.className='BUTTONG'"
onmouseout="this.className='BUTTONB'" >|
Print |<INPUT NAME=SearchString VALUE='' SIZE=12
MAXLENGTH=10 TITLE=
"Type search query and click 'Go' button">|
Print |<INPUT TYPE=button VALUE=
Go CLASS='BUTTONB'
STYLE='width:30' onClick=clickSearch(| & pos & |)
onmouseover="this.className='BUTTONG'"
onmouseout="this.className='BUTTONB'" >|
Print |<INPUT TYPE=button
VALUE=Next CLASS='BUTTONB'
onClick=clickNext(| & pos & |)
onmouseover="this.className='BUTTONG'"
onmouseout="this.className='BUTTONB'" >|
Print |<INPUT TYPE=button VALUE=Last
CLASS='BUTTONB' onClick=clickLast(| & pos & |)
onmouseover="this.className='BUTTONG'"
onmouseout="this.className='BUTTONB'" >|
Print "</DIV></TD></TR>"
Print "<TR VALIGN=top><TD
CLASS=GREY WIDTH=300><SELECT
NAME=AddressList SIZE=15 CLASS=LIST
onClick=popName() onChange=popName()>"
Dim count As Integer
' initializes the counter
count = 0
' iterate through the view entries till end of
view or maximum count in the options list is reached
Dim eType As String
Dim vFieldName As String
Dim person As NotesName
While (Not entry Is Nothing And (count<maxCount))
eType = entry.document.getItemValue("Type")(0)
If eType = "Person" Then
vFieldName = "FullName"
Else
vFieldName = "ListName"
End If
' creates a Name object for getting
username in abbreviated format
Set person = session.CreateName
(entry.document.getItemValue(vFieldName)(0))
If eType = "Person" Then
If count Mod 2 = 0 Then
Print "<OPTION CLASS='EVEN' VALUE='"
& person.Common & "' TITLE='"
& person.Abbreviated & "'>"
& person.Common & "</OPTION>"
Else
Print "<OPTION CLASS='ODD' VALUE='"
& person.Common & "' TITLE='"
& person.Abbreviated & "'>"
& person.Common & "</OPTION>"
End If
Else
Print "<OPTION CLASS='GROUP' VALUE='"
& person.Common & "' TITLE='" & person.Abbreviated
& "'>[ " & person.Common & " ]</OPTION>"
End If
count = count + 1
' get the next view entry
Set entry = nav.getNextDocument(entry)
Wend
Print "</SELECT></TD></TR>"
Print "<TR VALIGN=top><TD CLASS=BLUE
WIDTH=322><B>></B> "
Print "<INPUT NAME=Selection VALUE='"
& defaultSelection & "' size=45 READONLY
STYLE='background: #C0E1FF;
border-width: 0;'></TD></TR>"
Print "<TR VALIGN=middle><TD
CLASS=GREY WIDTH=322><DIV ALIGN=center>"
Print |<INPUT TYPE=button VALUE='OK'
CLASS='BUTTONB' STYLE='width: 50'
onClick='window.opener.nameElement.value =
document.forms[0].Selection.value ; window.close()'
onmouseover="this.className='BUTTONG'"
onmouseout="this.className='BUTTONB'" >|
Print |<INPUT TYPE=button VALUE='Cancel'
CLASS='BUTTONB' STYLE='width: 50' onClick='self.close()'
onmouseover="this.className='BUTTONG'"
onmouseout="this.className='BUTTONB'" ></DIV>|
Print "</TD></TR>"
Print |
<TR VALIGN=middle>
<TD CLASS=GROUP WIDTH=322>*Entries in this
color are <b>GROUPS</b> enclosed by [ ]
</TD>
</TR>
|
Print "</TABLE>"
' finish off the code
' end of the HTML
Print "</FORM></BODY></HTML>"
Exit Sub
errorHandler:
Msgbox "[Humana Testing] : Error in " & "agtWebNAB"
& " at line number " & Erl
Msgbox "[Humana Testing] :
Error Number is " & Err
Msgbox "[Humana Testing] :
Error Description is " & Error End Sub
Public Function ExtractParameter ( QueryString As String,
ParameterName As String) As String
On Error Goto errorHandler
ParameterName = ParameterName & "="
Dim startPosition, endPosition,
queryStringLength, parameterLength As Integer
Dim parameterValue As String
queryStringLength = Len ( QueryString )
parameterLength = Len ( ParameterName )
startPosition = Instr ( 1, QueryString,
ParameterName, 5 )
If startPosition = 0 Then
parameterValue = ""
Else
startPosition = startPosition + parameterLength
endPosition= Instr ( startPosition, QueryString, "&" )
If ( endPosition = 0 ) Then
endPosition = queryStringLength + 1
parameterLength = endPosition - startPosition
parameterValue = Mid
( QueryString, startPosition,parameterLength )
Elseif ( endPosition <> 0 ) Then
parameterLength = endPosition - startPosition
parameterValue = Mid
( QueryString, startPosition,parameterLength )
End If
End If
ExtractParameter = parameterValue
Exit Function
Msgbox "[Humana Testing] : Error in "
& "ExtractParameter
errorHandler:()" & " at line number " & Erl
Msgbox "[Humana Testing] :
Error Number is " & Err
Msgbox "[Humana Testing] :
Error Description is " & Error
End Function
MEMBER FEEDBACK TO THIS TIP
Excellent tip !!! I've been in need of this tip for a long time. This works beautifully on the web and the feature of selecting names from multiple address books is remarkable. The only thing missing is the ability to select multiple names from address book and I'd love it if you would add that code too. Thanks again !!!
John D.
******************************************
I am missing a description of the "how" and "where" of this tip. Should the shown code be put into the personal address book to enhance its look and/or performance on the Web? I made a few small developments with the V5 and V6.5 Domino Designer, but I am
not a great developer.
Frank B.
******************************************
This code can be applied to any database. If you put it in names.nsf, it works best because you can reference Domino Addressbook directly from within any database. Your code also would be central to all databases.
This code gives you an address book that is superior to the one you get after looking into the mail template in R5. However, there are techniques there to show an iNotes addressbook prompt. The code given is an agent that should be implemented within the database you prefer.
The JavaScript code should be placed in the JSHeader section of the form. Call your JavaScript from a button or link.
Sunilkumar Vishwakarma, tip author
******************************************
In the agent, for the <select> tag, use the MULTIPLE attribute to allow it to select more than one name. You'll also want to update the agent agtWebNAB for the following JavaScript function:
function popName() {
selected = new Array();
var objNAB = document.forms[0].AddressList;
for(var i=0;i<objNAB.options.length;i++){
if(objNAB.options[i].selected)
selected.push(objNAB.options[i].value)
}
var names = selected.join(",");
var selindex=document.forms[0].
AddressList.options.selectedIndex ;
//document.forms[0].Selection.value =
document.forms[0].AddressList.options
[selindex].value;
//document.forms[0].AddressList.options.
selectedIndex = -1;
document.forms[0].Selection.value = names;
}
This should take care of multiple selections in the pop-up window.
Sunilkumar Vishwakarma, tip author
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip exchange by member Sunilkumar Vishwakarma. Please let others know how useful it is via the rating scale below. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.