如何在 Web 浏览器 (HTML) 中显示对话框列表,以便用户可以 select Lotus Notes 通讯簿中的信息
How can I display dialog list in web browser (HTML) so that user can select information from Address Book in Lotus Notes
在此之前我问了一个问题here如何通过网络浏览器显示地址簿。然后,我找到了一个Agent,可以运行 找到Address Book 中的所有信息。但我现在的问题是,我不知道如何显示对话框列表以便用户可以选择任何信息。
我的代理如下:
books = s.AddressBooks
foundflag = False
ForAll b In books
If b.FileName="names.nsf" Then
Call b.Open( "", "" )
Set view = b.GetView( "People" )
Call view.Refresh
foundflag = True
Exit ForAll
End If
End ForAll
If Not foundflag Then
returnVal = "NSF file not found."
GoTo endp
End If
count = 0
Set tmpdoc = view.GetFirstDocument
Do While Not tmpdoc Is Nothing
If tmpdoc.MailFile(0) <> "" _
And tmpdoc.MailAddress(0) = "" _
And tmpdoc.InternetAddress(0)<>"" Then
count = count + 1
tmpstr = tmpdoc.LastName(0)
If tmpstr="" Then tmpstr = tmpdoc.FirstName(0)
tmplist(count) = tmpstr & "|@|" & tmpdoc.InternetAddress(0)
End If
Set tmpdoc = view.GetNextDocument(tmpdoc)
Loop
If count=0 Then
returnVal = "No employee were found"
GoTo endp
End If
我的 jQuery 可以调用此代理,但我不知道如何在 HTML 中显示列表。我的 jQuery 如下:
$.post("http://server/pcspec.nsf/jsonEmpList?OpenAgent",
function(data, status) {
var arr = JSON.parse(data);
if (arr.status == "success") {
$(arr.items).each(function(i, item) {
$("#PUserID").append('<option value="' + item.mail + '">' + item.name + ' (' + item.mail + ')</option>');
});
} else {
alert(arr.message);
}
})
.fail(function(xhr, status, error) {
console.log("ERROR - " + xhr + " - " + status + " - " + error);
})
所以我的问题是,如何在网络浏览器中提示对话框列表供用户进行选择。任何帮助将不胜感激。谢谢!
如果您问 "How do I get information back from an agent to jQuery",答案就是 PRINT 语句。我在使用地址簿时遇到错误,所以我硬编码了 public 地址簿的名称。但是这个片段将 return 一个 JSON 对象。当然,您需要声明适当的变量并相应地设置服务器名称。
Set db = s.getDatabase("server/document","names.nsf",False)
If db Is nothing Then
print "ERROR: Names.nsf not found</br>"
exit sub
End If
Set view=db.getView("People")
Set tmpdoc = view.GetFirstDocument
Do While Not tmpdoc Is Nothing
If tmpdoc.MailFile(0) <> "" _
And tmpdoc.MailAddress(0) = "" _
And tmpdoc.InternetAddress(0)<>"" Then
tmpStr = ToJSON(tmpdoc)
Print tmpStr + "<br />"
End If
Set tmpdoc = view.GetNextDocument(tmpdoc)
Loop
结果:
{"value": "CN=John Doe/O=ACME", "text": "john.doe@acme.com"}
{"value": "CN=Jane Smith/O=ACME", "text": "jane.smith@acme.com"}
今晚早些时候我正在做类似的事情。但我的方法有些不同。在我的例子中,我在下拉字段中使用插件 Select2,用户可以从列表中选择一个人。
// Initialize Select2 dropdown
$('[data-dropdown="names"]').select2({
allowClear: true,
theme: 'bootstrap',
width: '100%',
minimumResultsForSearch: 20,
minimumInputLength: 3,
delay: 450,
ajax: {
url: "/agents/getContactList.json?OpenAgent",
dataType: "json",
data: function(params) {
var query = {
term: params.term
};
return query;
}
}
});
<div class="form-group">
<label for="selectContact">Contact Name</label>
<select id="selectContact" class="form-control input-sm dominoDropdown" data-placeholder="">
<option value=""></option>
</select>
</div>
Select2 下拉列表是通过 Ajax 调用 Lotusscript 代理来填充的,returns 所有名称都部分匹配下拉列表中输入的内容。您当然也可以预先加载所有数据,但根据 NAB 中文档的数量,速度可能会很慢。
下面是 Lotusscript 代理的代码。它使用我自己的 类 进行 URL 查询字符串解析和 JSON 生成,但在 Domino 10 中你有 类 内置。通过删除我正在使用的一些额外选项,我在一定程度上简化了代码。
Option Public
Option Declare
Use "Class.JSON"
Use "Class.URL"
Sub Initialize
'--- Local Notes classes used in agent
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesViewEntryCollection
Dim view As NotesView
Dim columns As Variant
Dim column As NotesViewColumn
Dim entry As NotesViewEntry
'--- Custom classes
Dim json As JSONData
Dim url As New URLData()
'--- Local variables
Dim jsontxt As String
Dim i As Integer
Dim value As String
Dim filtervalue As String
Dim id As String
Dim options As String
Dim lookupview As String
Dim query As String
'*** Get document
Set db = session.CurrentDatabase
lookupview = "(lookup_Contacts)"
Set view = db.GetView(lookupview)
If view Is Nothing Then
MsgBox "Contact view not found"
Exit Sub
End If
Call view.Refresh()
jsontxt = "[ "
'*** Get all entries in view
Set col = view.AllEntries()
'*** Reduce the collection using a full-text search
query = |[LastName] CONTAINS *| & url.GetValue("term") & |* OR [FirstName] CONTAINS *| & url.GetValue("term") & |*|
Call col.FTSearch(query,0)
If col Is Nothing Then
MsgBox "col is nothing!"
Exit Sub
End If
'*** Loop through view entries and build the JSON to return
Set entry = col.GetFirstEntry()
Do Until entry Is Nothing
value = CStr(entry.ColumnValues(3)) ' Name to display
If InStr(LCase(value),LCase(filtervalue))>0 Then
id = CStr(entry.ColumnValues(2)) ' UNID
Set json = New JSONdata()
Call json.NoStatus()
Call json.SetValue("id", id)
Call json.SetValue("text", value)
jsontxt = jsontxt + json.GetJSON() + ","
End If
Set entry = col.GetNextEntry(entry)
Loop
'*** Remove trailing comma
If Len(jsontxt)>4 Then
jsontxt = Left$(jsontxt, Len(jsontxt)-1)
End If
jsontxt = jsontxt + " ]"
'*** MIME Header to tell browser what kind of data we will return (Javascript).
'*** See http://www.rfc-editor.org/rfc/rfc4329.txt
Print "content-type: application/javascript; charset=utf-8"
Print |{ "results": |+jsontxt+| }|
End Sub
这是最终结果:
2019-09-03 更新:代理查找所用视图的屏幕截图
祝你好运!
在此之前我问了一个问题here如何通过网络浏览器显示地址簿。然后,我找到了一个Agent,可以运行 找到Address Book 中的所有信息。但我现在的问题是,我不知道如何显示对话框列表以便用户可以选择任何信息。
我的代理如下:
books = s.AddressBooks
foundflag = False
ForAll b In books
If b.FileName="names.nsf" Then
Call b.Open( "", "" )
Set view = b.GetView( "People" )
Call view.Refresh
foundflag = True
Exit ForAll
End If
End ForAll
If Not foundflag Then
returnVal = "NSF file not found."
GoTo endp
End If
count = 0
Set tmpdoc = view.GetFirstDocument
Do While Not tmpdoc Is Nothing
If tmpdoc.MailFile(0) <> "" _
And tmpdoc.MailAddress(0) = "" _
And tmpdoc.InternetAddress(0)<>"" Then
count = count + 1
tmpstr = tmpdoc.LastName(0)
If tmpstr="" Then tmpstr = tmpdoc.FirstName(0)
tmplist(count) = tmpstr & "|@|" & tmpdoc.InternetAddress(0)
End If
Set tmpdoc = view.GetNextDocument(tmpdoc)
Loop
If count=0 Then
returnVal = "No employee were found"
GoTo endp
End If
我的 jQuery 可以调用此代理,但我不知道如何在 HTML 中显示列表。我的 jQuery 如下:
$.post("http://server/pcspec.nsf/jsonEmpList?OpenAgent",
function(data, status) {
var arr = JSON.parse(data);
if (arr.status == "success") {
$(arr.items).each(function(i, item) {
$("#PUserID").append('<option value="' + item.mail + '">' + item.name + ' (' + item.mail + ')</option>');
});
} else {
alert(arr.message);
}
})
.fail(function(xhr, status, error) {
console.log("ERROR - " + xhr + " - " + status + " - " + error);
})
所以我的问题是,如何在网络浏览器中提示对话框列表供用户进行选择。任何帮助将不胜感激。谢谢!
如果您问 "How do I get information back from an agent to jQuery",答案就是 PRINT 语句。我在使用地址簿时遇到错误,所以我硬编码了 public 地址簿的名称。但是这个片段将 return 一个 JSON 对象。当然,您需要声明适当的变量并相应地设置服务器名称。
Set db = s.getDatabase("server/document","names.nsf",False)
If db Is nothing Then
print "ERROR: Names.nsf not found</br>"
exit sub
End If
Set view=db.getView("People")
Set tmpdoc = view.GetFirstDocument
Do While Not tmpdoc Is Nothing
If tmpdoc.MailFile(0) <> "" _
And tmpdoc.MailAddress(0) = "" _
And tmpdoc.InternetAddress(0)<>"" Then
tmpStr = ToJSON(tmpdoc)
Print tmpStr + "<br />"
End If
Set tmpdoc = view.GetNextDocument(tmpdoc)
Loop
结果:
{"value": "CN=John Doe/O=ACME", "text": "john.doe@acme.com"}
{"value": "CN=Jane Smith/O=ACME", "text": "jane.smith@acme.com"}
今晚早些时候我正在做类似的事情。但我的方法有些不同。在我的例子中,我在下拉字段中使用插件 Select2,用户可以从列表中选择一个人。
// Initialize Select2 dropdown
$('[data-dropdown="names"]').select2({
allowClear: true,
theme: 'bootstrap',
width: '100%',
minimumResultsForSearch: 20,
minimumInputLength: 3,
delay: 450,
ajax: {
url: "/agents/getContactList.json?OpenAgent",
dataType: "json",
data: function(params) {
var query = {
term: params.term
};
return query;
}
}
});
<div class="form-group">
<label for="selectContact">Contact Name</label>
<select id="selectContact" class="form-control input-sm dominoDropdown" data-placeholder="">
<option value=""></option>
</select>
</div>
Select2 下拉列表是通过 Ajax 调用 Lotusscript 代理来填充的,returns 所有名称都部分匹配下拉列表中输入的内容。您当然也可以预先加载所有数据,但根据 NAB 中文档的数量,速度可能会很慢。
下面是 Lotusscript 代理的代码。它使用我自己的 类 进行 URL 查询字符串解析和 JSON 生成,但在 Domino 10 中你有 类 内置。通过删除我正在使用的一些额外选项,我在一定程度上简化了代码。
Option Public
Option Declare
Use "Class.JSON"
Use "Class.URL"
Sub Initialize
'--- Local Notes classes used in agent
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesViewEntryCollection
Dim view As NotesView
Dim columns As Variant
Dim column As NotesViewColumn
Dim entry As NotesViewEntry
'--- Custom classes
Dim json As JSONData
Dim url As New URLData()
'--- Local variables
Dim jsontxt As String
Dim i As Integer
Dim value As String
Dim filtervalue As String
Dim id As String
Dim options As String
Dim lookupview As String
Dim query As String
'*** Get document
Set db = session.CurrentDatabase
lookupview = "(lookup_Contacts)"
Set view = db.GetView(lookupview)
If view Is Nothing Then
MsgBox "Contact view not found"
Exit Sub
End If
Call view.Refresh()
jsontxt = "[ "
'*** Get all entries in view
Set col = view.AllEntries()
'*** Reduce the collection using a full-text search
query = |[LastName] CONTAINS *| & url.GetValue("term") & |* OR [FirstName] CONTAINS *| & url.GetValue("term") & |*|
Call col.FTSearch(query,0)
If col Is Nothing Then
MsgBox "col is nothing!"
Exit Sub
End If
'*** Loop through view entries and build the JSON to return
Set entry = col.GetFirstEntry()
Do Until entry Is Nothing
value = CStr(entry.ColumnValues(3)) ' Name to display
If InStr(LCase(value),LCase(filtervalue))>0 Then
id = CStr(entry.ColumnValues(2)) ' UNID
Set json = New JSONdata()
Call json.NoStatus()
Call json.SetValue("id", id)
Call json.SetValue("text", value)
jsontxt = jsontxt + json.GetJSON() + ","
End If
Set entry = col.GetNextEntry(entry)
Loop
'*** Remove trailing comma
If Len(jsontxt)>4 Then
jsontxt = Left$(jsontxt, Len(jsontxt)-1)
End If
jsontxt = jsontxt + " ]"
'*** MIME Header to tell browser what kind of data we will return (Javascript).
'*** See http://www.rfc-editor.org/rfc/rfc4329.txt
Print "content-type: application/javascript; charset=utf-8"
Print |{ "results": |+jsontxt+| }|
End Sub
这是最终结果:
2019-09-03 更新:代理查找所用视图的屏幕截图
祝你好运!