其余代码之前的SSJS确认对话框在XPage中的按钮后面运行

时间:2016-05-10 14:23:28

标签: dialog xpages

我想在继续之前做出确认。我的意思是,在用户做出决定之前,其他代码不应运行(是/否)。如果用户按下“是”按钮,则应创建新文档。如果用户选择“否”则不会发生任何事情。 在此代码中会出现一个确认对话框,询问“您确定要创建新文档”。我的问题是 已创建新文档如果用户选择“是或否”。这个代码在Dialog中不关心答案?然后运行整个代码,出现该对话框。我想我会想念一些事情:(

var dateOther = docOther.getFirstItem("TarihBitis").getDateTimeValue();
if (dateOther==null)
{  
    var dlgA = getComponent("dialogTarifeConfirm");
    dlgA.show();
    //Creating New Doc...
    var docNew = database.createDocument();
    docNew.appendItemValue("Subject", requestScope.subject);
    docNew.appendItemValue("fieldName1", viewScope.fieldName1);
    docNew.appendItemValue("fieldName2", viewScope.fieldName2);
    docNew.save();
}

任何建议表示赞赏。 问候 Cumhur Ata

更新1:请在对话框代码不关心答案后找到我混合的位置两个文件都已创建,然后屏幕上会出现对话框。我想我错过了一些我不知道的事情。

try 
{
    //Sync backend document with changes made in the frontend document
    var doc:NotesDocument = document1.getDocument(true);
    var today:NotesDateTime = session.createDateTime(@Now());
    var bugun:java.util.Date = new java.util.Date();
    var dateFormat = new java.text.SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
    cn = sessionScope.commonUserName;

    //getCurrnetUserName as String
    var user:String=session.getEffectiveUserName();

    var tKey = doc.getItemValueString("ParentUNID");
    var ParaBirimi = document1.getItemValueString("ParaBirimi");
    var tarifeView:NotesView = database.getView("(viewStandartTarifelerKontrol)");
    var vec:NotesViewEntryCollection = tarifeView.getAllEntriesByKey(ParaBirimi);
    var docBuUNID = document1.getDocument().getUniversalID();
    if(document1.isNewNote())
    {
        if (vec.getCount() > 0) 
        {
            var entry1:NotesViewEntry = vec.getFirstEntry();
            while (entry1!= null) 
            {
                var tarifeDoc:NotesDocument = entry1.getDocument();
                var tarifeUNID  = tarifeDoc.getUniversalID();
                var ParentUNID = tarifeDoc.getItemValueString("ParentUNID");
                if (docBuUNID!=tarifeUNID)
                {       
                    var tarifeDocBasDate:NotesDateTime = tarifeDoc.getItemValueDateTimeArray("startDate").elementAt(0);
                    var docBuBasDate:NotesDateTime = doc.getItemValueDateTimeArray("startDate").elementAt(0);
                    var days:int = tarifeDocBasDate.timeDifferenceDouble(docBuBasDate) / 86400; 

                    diff = docBuBasDate.timeDifference(tarifeDocBasDate)/86400;
                    var a = tarifeDoc.getFirstItem("endDate").getDateTimeValue();
                    if (a==null)
                    {  
                        if(diff>0)
                        {
                            var a = getComponent("dialogConfirm1");
                            a.show();
                            //If the user say YES FORMA document will be created.
                            var docNew = database.createDocument();
                            docNew.appendItemValue("Subject", viewScope.subject);
                            docNew.appendItemValue("Form","FormA");

                            //If the user say NO FORMB document will be created.
                            var docNew = database.createDocument();
                            docNew.appendItemValue("Subject", viewScope.subject);
                            docNew.appendItemValue("Form","FormB");
                            docNew.save();
                        }
                    }

                }
                var tmpentry = vec.getNextEntry();
                entry1.recycle();
                entry1 = tmpentry;
            }
        }
    }
}
catch(e) 
{
    print(e);
}

2 个答案:

答案 0 :(得分:2)

1。创建一个用于打开对话框的按钮:

<xp:button id="btnDialogTarifeConfirm" value="Create New Document">
    <xp:eventHandler event="onclick" submit="true" execMode="partial" execId="btnDialogTarifeConfirm">
        <xp:this.action><![CDATA[#{javascript:var dialogTarifeConfirm:com.ibm.xsp.extlib.component.dialog.UIDialog = getComponent("dialogTarifeConfirm");
            dialogTarifeConfirm.show();}]]></xp:this.action>
    </xp:eventHandler>
</xp:button>

2。在对话框按钮btnCreateNewDocument后面放置代码:

<xe:dialog id="dialogTarifeConfirm" title="Create New Document">
    ...
    <xp:div styleClass="lotusDialogFooter">
        <xp:button id="btnCreateNewDocument" value="YES (Create New Document)">
            <xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="lotusForm"
                    execMode="partial" execId="btnCreateNewDocument">
                    <xp:this.action><![CDATA[#{javascript://Creating New Doc...
    var docNew = database.createDocument();
    docNew.appendItemValue("Subject", requestScope.subject);
    docNew.appendItemValue("fieldName1", viewScope.fieldName1);
    docNew.appendItemValue("fieldName2", viewScope.fieldName2);
    docNew.save();}]]></xp:this.action>
                </xp:eventHandler>
        </xp:button>
        <xp:link escape="true" text="No" themeId="Link.Action"
            onclick="XSP.closeDialog('#{id:dialogTarifeConfirm}')">
        </xp:link>
    </xp:div>
</xe:dialog>

我希望这会有所帮助

答案 1 :(得分:1)

你能否使用“this.message”?

使用它删除文档的一个简单示例可能是:

<xp:button value="Delete" id="button3"
                                        styleClass="btn btn-danger btn-block btn-xs">
                                        <xp:eventHandler event="onclick" submit="true"
                                            refreshMode="complete">
                                            <xp:this.action>

                                                <xp:actionGroup>

                                                    <xp:confirm>
                                                        <xp:this.message><![CDATA[#{javascript:"Are you sure you want to delete this document?"}]]></xp:this.message>
                                                    </xp:confirm>
                                                    <xp:actionGroup>
                                                        <xp:this.condition><![CDATA[#{javascript:var id = rowData.getUniversalID();
    var doc:NotesDocument = database.getDocumentByUNID(id);
    doc.remove(true);}]]></xp:this.condition>
                                                    </xp:actionGroup>

                                                </xp:actionGroup>
                                            </xp:this.action>
                                        </xp:eventHandler>
                                    </xp:button>