gpt4 book ai didi

javascript - 如何使用提交按钮(onclick)在javaScript(服务器端)上创建消息框

转载 作者:行者123 更新时间:2023-12-02 18:32:26 26 4
gpt4 key购买 nike

这是我编写的示例脚本。

任务:- 如果用户尚未在系统上注册为成员(member),则创建弹出消息以显示用户。

-用户必须在注释 View “按姓名列出的员工信息”中输入姓名

-如果用户在 View 中拥有姓名,它将向审阅者写入一条消息,以告知审阅者他们的请求。

-如果用户在“按姓名的员工信息” View 中没有姓名,则会弹出一条消息告诉用户该怎么做。

// address book
var db:NotesDatabase = session.getDatabase("websvr/pcs", "names", false);
var vw2:NotesView = db.getView("($VIMPeople)");
var dc2:NotesDocumentCollection = vw2.getAllDocumentsByKey(document1.getItemValue("Name"),true);
var doc2:NotesDocument=dc2.getFirstDocument();

while (doc2!=null){
sname=doc2.getItemValueString('LastName')
doc2=dc2.getNextDocument();
}
// end of address book


//current database
var vw:NotesView = database.getView("Staff Information By Name");
var doc:NotesDocument = vw.getDocumentByKey(sname, true);


//check whether have setting on reviewer for current user else will be hard code to specific person
if (doc!=null)
{
revname=doc.getItemValueString("Reviewer")
rev=doc.getItemValueString("ReviewerEmail");

//set Email
var maildoc:NotesDocument=database.createDocument();
var body=maildoc.createMIMEEntity();
var stream=session.createStream();
var content="Dear "+revname+",<br></br>"+

"Please click <a href='http://"+applicationScope.hostname+"/"+(applicationScope.dbfilepath).replace(/(\\)/g, "/")+"/"+
"RequisitionForm.xsp?databaseName="+applicationScope.serverCN+"!!"+
applicationScope.dbfilepath+"&documentId="+
document1.getDocument().getUniversalID()+
"&action=editDocument'>here</a> to view it if you are in a web browser (eg: Internet Explorer, Mozilla Firefox, Google Chrome etc.)"+
"<br /><br /><b>OR</b><br /><br />"+
"<a href='"+document1.getDocument().getNotesURL()+"'>here</a> if you are in the Notes Client. Thank you.";

stream.writeText(content);
body.setContentFromText(stream, "text/html; charset=iso-8859-1", 0);
maildoc.replaceItemValue('Subject', 'Kindly review this '+document1.getItemValueString('Item')+' request by '+document1.getItemValueString('Name')+" on "+I18n.toString(@Today(), 'dd/MM/yyyy'));
maildoc.send(rev);

document1.replaceItemValue("TotalCost",document1.getValue("Cost")*document1.getValue("Qty"));
document1.replaceItemValue("Status","Pending");
document1.save();
context.redirectToPage("/MyRequisition.xsp");
}
else
{
a = 'alert("You do not have access right, please contact admin to register!")' ;
view.postScript(a);
break;
}

在其他页面上运行的示例脚本:

a = 'alert("The applicant details must be unique!")' ;
b = 'alert("Applicant Details inserted!")' ;

var vw:NotesView = database.getView("Staff information by Name");

var doc:NotesDocument = vw.getDocumentByKey(getComponent("Name").getValue(), true);

if (doc!=null){
view.postScript(a);
break;
}
else
{

var newDoc = database.createDocument();
newDoc.appendItemValue("Form", "Staff Form");
newDoc.appendItemValue("Name", getComponent("Name").getValue());
newDoc.appendItemValue("Designation", getComponent("Designation").getValue());
newDoc.appendItemValue("Department", getComponent("Department").getValue());
newDoc.appendItemValue("Reviewer", getComponent("Reviewer").getValue());
newDoc.appendItemValue("Email", getComponent("Email").getValue());
newDoc.appendItemValue("ReviewerEmail", getComponent("ReviewerEmail").getValue());
newDoc.save();
getComponent("Name").setValue("");
getComponent("Designation").setValue("");
getComponent("Department").setValue("");
getComponent("Reviewer").setValue("");
getComponent("Email").setValue("");
getComponent("ReviewerEmail").setValue("");
view.postScript(b);
}

最佳答案

postScript() 仅适用于部分刷新。如果您的代码在事件处理程序中以完全刷新模式运行,则您的 postScript 语句将无效。

替代解决方案是使用输出脚本 (xp:scriptBlock) 组件,如下所示:

var message = "#{requestScope.message}";
if (message) {
alert(message);
}

在您的 SSJS 中只需设置您的消息:

requestScope.message = condition ? "True!" : "False!";

http://publib.boulder.ibm.com/infocenter/domhelp/v8r0/index.jsp?topic=%2Fcom.ibm.designer.domino.ui.doc%2Fwpd_controls_cref_scriptblock.html

关于javascript - 如何使用提交按钮(onclick)在javaScript(服务器端)上创建消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17671180/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com