0
votes

I am struggling with the following.

On my XPage I have a viewpanel component, but it is not bound to a notesview datasource, but to a hashmap stored in viewScope. Reasons for this is beyond scope of my question.

Since the lines in my view are not actually linked to the documents I cannot use the standard checkboxes and the related getSelectedDocIds. I do however want a way to remove the selected documents. I have a column with checkboxes containing the unid of the corresponding row.

So long story short. I have an array of unids and want to perform an action that does the following:

  • Display a dijit.Dialog asking for confirmation
  • If OK clicked call a function that does the following:
    • Remove the documents based on the unids
    • Refresh the viewpanel

I am thinking of the following 2 solutions, but in doubt what would be best (maybe a third, even simpler solution?)

  1. Have the OK button of the dojo dialog call a function that does an XmlHttpRequest to an XAgent or plain old LS agent

  2. Have the OK button trigger an eventhandler that runs on the server as described by JeremyHodge here. But how would I pass the unids as parameter and refresh the view afterwards?

Thanks!

3

3 Answers

1
votes

Cant you just make use of the extension library dialog with the dialog button control. In this button control you can then

A third option would be to add a column to your datatable/view which contains checkboxes. On the onchange event of these boxes you add an eventhander which adds the value to a viewScope variable.

A button on the bottom (or top.) of the page you add the code you need to remove the selected items from the hashmap, delete the documents associate with the selected id's. this button can be a ordinary button with a partial refresh on the viewpanel. When you run into the bug that you cant use buttons in a dialog please use the extension library dialog control because this fixes that issue for you.

If the current user does not have the correct access level to delete documents you could use the sessionAsSigner global (assuming the signer of the design element has the correct access levels).

This way you dont need to go call an xAgent by xmlthttprequest and can stay with the default xpage methodology.

I hope this helps in some way

1
votes

I would second @jjbsomhorst in the use of the extension library for the dialog box - if you use one at all. Usually users don't read dialog boxes. So the approach would be add the column with the checkboxes, but don't bother with an event handler, but bind them ALL with their value to ONE scopeVariable. On submission that variable will then hold an array with the selected UNID. Then render a page that lists these documents and have a confirm button. While the new page affords a server round-trip the likelihood, that users actually pay attention is way higher. What you can do:

Have the normal page that renders the dialog with editable checkboxes and when the user clicks "Delete" you set something like viewScope.confirmDeleteMode=true; and use that as condition for the checkboxes and make them read-only AND set the class of the selected rows to "morituri" which in your CSS would have something like .morituri { color: white; background-color : red; font-weight: bold } and a new button "Confirm Delete" (and hide the Delete button).

This way you only have one page to deal with.

1
votes

I went for option 2, which has the possibility to provide the partial refresh id. I passed the unids as a submitvalue like:

function doRemove(unids){

     XSP.executeOnServer(ISP.UI.removeEventID, ISP.UI.removeRefreshID, {

        params: {
            '$$xspsubmitvalue': unids
        },
        onComplete : function() {
            //alert('test')
        }
    });

}

The ISP.UI.removeEventID performs the following code:

var unids = context.getSubmittedValue();
removeDocuments(unids); //SSJS function performing the actual delete
viewScope.reload = 'reload' //triggers the hashmap to be rebuild based on new documentcollection