Editing fields in a Lotus Notes view with Ajax
Create another column and set the value as follows: Now we have to write the JavaScript function "inLineEdit." This function creates a text area object, sets the value and replaces the text. It also sets "global editing variables" editing and "XMLHttpRequest." Editing variable is used to ensure that only one field is edited at a time. "XMLHttpRequestObject" is a JavaScript object which allows interaction with the Lotus Domino server. It ensures that when clicking on any of the field values, a text area object appears. The above function creates the "XMLHttpRequest" object and calls an agent called "UpdateViaAjax" by passing the field name, text area content and unique document ID. This function just replaces the text area with the text node. Now we have to write the real agent that updates the content. The agent is simple -- it returns the reference of the Lotus Notes document using a universal ID and updates the field with the content of the text area.
" "width="200" onClick="inLineEdit
('"+@Text(@DocumentUniqueID)+"', 'name')"
>"+name+""
"width="200" onClick="inLineEdit
('"+@Text(@DocumentUniqueID)+"',
'designation')">"+designation+"
Name
Designation
var editing=false;
var xmlHttpRequest;
function inLineEdit(documentId, fieldName){
if (editing) return;
var obj = window.event.srcElement;
while(obj.tagName!="TD")
obj=obj.parentNode;
var x = obj.innerHTML
var y = document.createElement('TEXTAREA');
y.setAttribute("DOCUMENTID", documentId);
y.setAttribute("FIELD", fieldName);
y.setAttribute("id", "AJAX");
y.onkeypress=processKeyEvent;
y.value=x;
while (obj.hasChildNodes())
{
obj.removeChild(obj.firstChild);
}
obj.appendChild(y);
y.focus();
editing=true;
}
function processKeyEvent(){
if(window.event.keyCode==13){
if(window.XMLHttpRequest){
xmlHttpRequest=new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlHttpRequest=
new ActiveXObject("Microsoft.XMLHTTP");
}
var url=location.href;
if(url.toUpperCase().indexOf(".NSF")!=-1)
url=url.substring(0, url.toUpperCase().
indexOf(".NSF")+4);
else if(url.toUpperCase().
indexOf(".NTF")!=-1)
url=url.substring(0,
url.toUpperCase().indexOf(".NTF")+4);
var y = document.getElementById("AJAX");
var id=y.getAttribute("DOCUMENTID");
var value=y.innerHTML;
var fieldName=y.getAttribute("FIELD");
url=url+"/(UpdateViaAjax)?OpenAgent&id="
+id+"&value="+value+"&field="+fieldName+"";
xmlHttpRequest.open("GET", url, true);
xmlHttpRequest.onreadystatechange=callback;
xmlHttpRequest.send(null);
}
}
function callback(){
if(xmlHttpRequest.readyState==4){
var y = document.getElementById("AJAX");
var result=y.innerHTML;
var newElement=document.
createTextNode(result);
var parent=y.parentNode;
while(parent.tagName!="TD")
parent=parent.parentNode;
while (parent.hasChildNodes())
{
parent.removeChild(parent.firstChild);
}
parent.appendChild(newElement);
editing=false;
}
}
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim query As String
Dim id As String
Dim fieldValue As String
Dim fieldName As String
Dim colDoc As NotesDocument
Set db=session.CurrentDatabase
Set doc=session.DocumentContext
query= doc.Query_String_Decoded(0)
query=Strright(query, "&id=")
id=Left(query, Instr(query, "&value=")-1)
query=Strright(query, "&value=")
fieldValue=Left(query, Instr(query, "&field=")-1)
query=Strright(query, "&field=")
fieldName=query
Set colDoc=db.GetDocumentByUNID(id)
If Not colDoc Is Nothing Then
Call colDoc.ReplaceItemValue(fieldName,
fieldValue)
Call colDoc.Save(False, False)
End If
2 則留言:
這位同學
你貼這個有何用意ㄋㄟ?
實在不懂....
同學,
因為這個部落格也提供相關的 IT 資訊跟消息,所以今天 Po 一份有關 Lotus Notes 的技術文件囉 ~~
張貼留言