NY_00001_YesNoPlugIn

This is a simple dialog offering "YES" and "NO" buttons in response to a question. The dialog can also be closed using the "Escape" key or the close button in the upper right corner.

The dialog is located in a separate plugin.

Of course, one might question whether such a small dialog justifies creating its own microservice. However, the dialog can be used by many programs in this form. While its handling is slightly more complex than that of a local dialog, it shares the same mechanics as all the other dialogs presented here. This makes its use straightforward and consistently uniform after a short period.

Usage

Creation

The call requires the microservice ID.

private static final IId MICRO_SERVICE_YES_NO = CIdFactory.fromObject("NY_WebDialogYesNo_00001");

The message to be displayed is required for this dialog. Alternatively, other parameters can also be specified. These are saved in the properties provided. When the dialog is closed, these are included in the response.

The session token received at login is also required.

An ID of an HTML element in which the dialog is embedded must also be specified. This is usually a div element.

private void openDialogYesNo(final byte[] aSessionToken,
                             @NotNull final String aDivElementId,
                             @NotNull final String aMessage) throws CException
{
    final CStringProperties params = new CStringProperties();
    params.put("message",
               aMessage);
    mWebDialogApi.showWebDialog(MICRO_SERVICE_YES_NO,
                                aSessionToken,
                                aDivElementId,
                                params);
}

The dialog can be terminated programmatically by sending a CRecordWebDismissDialog message.

Dialog terminates notification

// constructor:
addMessageHandler(CRecordWebNotifyDialogDismissed.ID,
                  this::asyncWebDialogFinished);
private boolean asyncWebDialogFinished(@NotNull final CEnvelope aEnvelope,
                                       @NotNull final CRecord aRecord) throws CException
{
    if (aEnvelope.isAnswer())
    {
        return false;
    }
    else
    {
        final int reason = CRecordWebNotifyDialogDismissed.getReason(aRecord,
                                                                     -1);
        if (reason == CWebDialogApi.REASON_SUCCESS)
        {
            final IId microserviceId = CRecordWebNotifyDialogDismissed.getMicroserviceId(aRecord,
                                                                                         null);
            // Check whether this is our dialog
            if (MICRO_SERVICE_YES_NO.equals(microserviceId))
            {
                // The returned properties contain the results as well as the properties provided.
                final CStringProperties results = CRecordWebNotifyDialogDismissed.getResults(aRecord,
                                                                                         new CStringProperties());
                final String yesOrNo = results.get("result");
                if ("yes".equals(yesOrNo))
                {
                    // ...
                }
            }
        }
        else if (reason == CWebDialogApi.REASON_ERROR)
        {
            // ...
        }
        else if (reason == CWebDialogApi.REASON_CANCELED_BY_USER)
        {
            // ...
        }
        else if (reason == CWebDialogApi.REASON_CANCELED_BY_OWNER)
        {
            // ...
        }
        aEnvelope.setResultSuccess();
        return true;
    }
}