I have a repeat control that contains a button that will process documents that a user selects. My first use case is for deletions. I detect whether or not the user selects at least one document and post an error message if they do not, using view.postScript.
I want to add a confirmation dialog box, confirming that the user wants to take the action on the documents (like delete them) but cannot find a way to do it.
Ideally I want to do this all in my current SSJS.
My code is below, with a stub in for where I want to ask the user for confirmation.
Any help would be greatly appreciated.
//Did the user select a document
var hasSelected:Boolean = false;
for (var id in SelectedDocs.getSelectedIDs()) {
hasSelected = true;
break
}
//If false then set a warning
if (hasSelected == false)
{
x="alert('Error\\n\\nPlease select one or more documents to delete.\\n\\n');";
view.postScript(x)
return
}
//If true then ask confirmation
if (hasSelected == true)
{
}
var rspView:NotesView = database.getView("(dbAllRpPCTasks)")
for (var id in SelectedDocs.getSelectedIDs()) {
//Get each selected doc
var doc:NotesDocument = database.getDocumentByID(id);
//Get child docs and delete them
var key:String = doc.getItemValueString("ID");
var dc:NotesDocumentCollection = rspView.getAllDocumentsByKey(key);
if (dc.getCount() != 0)
{dc.removeAll(true);}
//Delete the selected doc
doc.remove(true)
doc.recycle();
SelectedDocs.setSelectedState(id,false);
}
Thanks for all the suggestions. I am responding to Frank's answer. Trying to write CSJS that will determine if the user selected docs and then proceed or not.
In the on click event of my button in the CSJS I have the following:
var dtList = document.getElementsByName("#{id:dataView1.getSelectedIds()}");
confirm("What is the length?" + dtList.length);
confirm("Can I get an item?" + dtList.item(0));
It returns a length of zero and the item is undefined.