0
Answered

Trigger a script from a button press

Iain Brew 5 years ago updated by bradren007 5 years ago 5

I am working on a small project where by depending on the value of a server tag/feedback, when a button is pressed it will show a particular popup. 

IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice("F10A-SERVER-01"), function(name,value)
{
   IR.Log("Name = " + name + ", Value = " + value);    //For Debug Only
   if(name == "LAB1-SIM" && value == 1)
      {
      IR.ShowPopup("LabLink_Receive_Lab1");
      }
   else if(name == "LAB1-SIM" && value == 0)
      {    
      IR.ShowPopup("LabLink_NoAccess");
      }        
}); 
};  

In this example, there is a tag on my server called 'LAB1-SIM.' When a particular button is pressed (lets call it 'load' for now) it should load either the 'LabLink_Receive_Lab1' or 'LabLink_NoAccess' popup depending on the value of the tag (0 or 1).

The trouble I have is tying this script to a button press. The script should only be executed when the button is pressed, not at project startup or if the tag value changes. Any help would be greatly appreciated!

GOOD, I'M SATISFIED
Satisfaction mark by Iain Brew 5 years ago

Thank you for this! I changed the code to request the status from the Server Feedback and will test tomorrow when I get to our labs. This is to allow our users to 'enable' or 'disable' the ability for other control panels in other labs to access video controls. If enabled, a user in another lab can then see a popup allowing them to route video content to a local projector. If disabled, they will see a popup advising they need to ask permission from the other lab. 

Hello.

Do you have any more questions?

+1

Thank you for your help. The code works really well - it's a great snippet to build other ideas now:

IR.AddListener(IR.EVENT_ITEM_PRESS, IR.GetPopup("LabLink_Sources").GetItem("Receive_Lab1"), function()
{
var status = IR.GetVariable("Drivers.F10A-SERVER-01.LAB1-SIM");

if (status == 0)
{
IR.HideAllPopups("");
IR.ShowPopup("LabLink_Sources");
IR.ShowPopup("LabLink_NoAccess");
IR.Log("0");
}
if (status == 1)
{
IR.HideAllPopups("");
IR.ShowPopup("LabLink_Sources");
IR.ShowPopup("LabLink_Receive_Lab1");
IR.Log("1");
status = 0;

}
});