(function () { /** * replace module name with a custom name for the local-script. * * All local-script should be attached to the "custom.ls" package. * If more than one script is required for an application, a common root package * should be created (e.g. "custom.ls.customerName.*"). */ var MODULE_NAME = "OpenGuardStatus", ENABLE_LOGGING = false, RECORD_LOG = false, logger = shmi.requires("visuals.tools.logging").createLogger(MODULE_NAME, ENABLE_LOGGING, RECORD_LOG), fLog = logger.fLog, log = logger.log, module = shmi.pkg( MODULE_NAME ); // MODULE CODE - START /* private variables */ /* private functions */ /** * Implements local-script run function. * * This function will be called each time a local-script will be enabled. * * @param {LocalScript} self instance reference of local-script control */ module.run = function (self) { //Place your Code here // CONFIG const nameOfItem1 = 'virtual:testInt', nameOfItem2 = 'virtual:testInt2', dialogName = 'dialogbox_GuardStatus'; var testInt = 0, testInt2 = 0; // CONFIG END // Variables let dialogbox = null, subscriptionToken1 = null, subscriptionToken2 = null; // Create UI Action instance const core = shmi.visuals.core, parameters = [ { "name": "dialog", "params": [ "."+dialogName, "show" ] } ]; const action = new core.UiAction(parameters); // Get item manager handle const im = shmi.visuals.session.ItemManager; const myItemHandler1 = im.getItemHandler(); const myItemHandler2 = im.getItemHandler(); myItemHandler1.setValue = function (value1) { console.log("The value of the virtual:testInt has been set to " + value1); testInt = value1; if (testInt == 1 && testInt2 == 0) { console.log("Executing action"); action.execute(); } }; myItemHandler2.setValue = function (value2) { console.log("The value of the virtual:testInt2 has been set to " + value2); testInt2 = value2; if (testInt == 1 && testInt2 == 0) { console.log("Executing action"); action.execute(); } }; // Wait until the dialog has been initialized shmi.onReady( { controls: { dialogbox: "."+dialogName } }, function (resolved) { // Subscribe to the item and bind the item handler subscriptionToken1 = im.subscribeItem(nameOfItem1, myItemHandler1); subscriptionToken2 = im.subscribeItem(nameOfItem2, myItemHandler2); } ); /* called when this local-script is disabled */ self.onDisable = function () { self.run = false; /* from original .onDisable function of LocalScript control */ // Unlisten when no longer req'd (e.g. in handlers) - don't leave this out! if (subscriptionToken1) { subscriptionToken1.unlisten(); subscriptionToken1 = null; } // Unlisten when no longer req'd (e.g. in handlers) - don't leave this out! if (subscriptionToken2) { subscriptionToken2.unlisten(); subscriptionToken2 = null; } }; }; // MODULE CODE - END fLog("module loaded"); })();