Tools for EventScripter

System function: confirm()

Description

confirm(string message) : bool

Shows a dialog with confirm and abort buttons. Returns true on confirm, otherwise false.

Example

// Trigger Required: "Interval"
// Options recommended: 3000ms, synchronous

require(JD_HOME + "/eventscripter/system/confirm.js");

var ret = confirm("Confirm?");
alert(ret);

Sourcecode

JD_HOME/eventscripter/system/confirm.js
/*jslint browser, long */
/*global getEnvironment, callSync, JD_HOME, alert */
function confirm(message) {
    "use strict";

    message = message.replace("\r", "\\r");
    message = message.replace("\n", "\\n");
    var env = getEnvironment();
    switch (env.getOSFamily()) {
    case "WINDOWS":
        return !(!callSync(JD_HOME + "/eventscripter/system/bin/confirm.bat", "JD2 - EventScripter", message));
    default:
        alert("Soryy, your OS is yet not supported for confirm()");
    }
}
JD_HOME/eventscripter/system/bin/confirm.bin
@echo off
SETLOCAL EnableDelayedExpansion

SET _title=%~1
SET _text=%~2

set _text=%_text:\r="&vbCr&"%
set _text=%_text:\n="&vbLf&"%

:uniqueTempVbs
set "vbsFileName=%TEMP%\~%RANDOM%.vbs"
if exist "%vbsFileName%" goto :uniqueTempVbs

ECHO Wscript.Echo MsgBox("!_text!",1,"!_title!")>%vbsFileName%
FOR /f "delims=/" %%G IN ('cscript //nologo %vbsFileName%') DO set _input=%%G
DEL %vbsFileName%

if "%_input%" EQU "1" (
    ECHO 1
)

ENDLOCAL