0
Answered

Trigger popups on tag value changing

Iain Brew 7 years ago in Tips and Tricks updated 7 years ago 13

I have been teaching myself building server projects using tags and having a good time. I want to step up to the next level and achieve the following:


If a server tag (example) has a particular value written to it (either a text string or number), I want to then trigger a popup to open or close. i.e.


If server tag "example" = x

then

open/close popup/page "name_of_popup"


I have looked more into the Javascript thing (i.e. using a tag like a feedback channel) but I am a bit stuck with this element. An advice would be appreciated! The rationale behind this is for multi-control panel projects. If i shut down the system on one control, I want the other controls to also show the 'shut down' screen.


GOOD, I'M SATISFIED

Thanks for the great help as always :)

Satisfaction mark by Iain Brew 7 years ago
Answered

hello.

Open Popup function here http://dev.iridiummobile.net/GUI_API/en#IR.ShowPopup

Close popup function here http://dev.iridiummobile.net/GUI_API/en#IR.HidePopup


In panel project, you should use EVENT_TAG_CHANGE event for AddListener http://dev.iridiummobile.net/Drivers_API/en#IR.EVENT_TAG_CHANGE 

. in this event you should write script like this

if (name == example)

{

  if (value == "open popup")

  {

      IR.OpenPopup("popup name")

  }

  if (value == "close popup")

  {

      IR.HidePopup("popup name")

  }


}

I have tried this but I think I have made mistakes - I am not terribly fluent in Javascript:


Server = F10A_Server

Tag = SIM_PBTrigger

Value to activate = 1

Page to open = Navigation


-----------


IR.AddListener(IR.EVENT_TAG_CHANGE, IR.GetDevice("F10A_Server")),
{
   IR.GetVariable("Drivers.F10A_Server.SIM_PBTrigger"), function(value);
      {
      IR.Log(value);
      }
   {     
   if(IR.Log("value") == 1),
   IR.GetPage("Navigation");
   }
}


Hello Iain. Try this.


-----------


IR.AddListener(IR.EVENT_TAG_CHANGE,IR.GetDeveice("F10A_Server"),function(name,value){

 if(name == "SIM_PBTrigger" && value == 1)

     IR.ShowPage("Navigation");

}

Thanks Francesco - I have tried your code but didn't have luck in having it show a page - perhaps my syntax is wrong?


EVENT_TAG_CHANGE work only with native driver.

If you use a custom driver, the event not trigger.


Also, have you any message on log window?

The Driver I'm looking too at the moment is a built-in iRidium Server drive (named F10A_Server in this project). I will check the log and post below:

Which log window should I be looking for exactly? I am testing this by logging into the server and sending a trigger value (in this case 1) however the device does not respond.

Thanks - will check it out now!

In addition, if I want to trigger more than one thing, what would be the correct syntax? I have used an 'else if' statement to create various states, however can only trigger one action - I want to for example, show a page AND a popup depending on a value:


IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice("F10A_Server"), function(name,value)
{
   IR.Log("Name = " + name + ", Value = " + value);    //For Debug Only
   if(name == "SIM_OTTrigger" && value == 0)
      IR.ShowPage("System_Start");
   else if(name == "SIM_OTTrigger" && value == 1)
      IR.ShowPage("Navigation");
      IR.ShowPopup("Inputs");



});                                                                            

+1

Check the { and }


IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice("F10A_Server"), function(name,value) {

   IR.Log("Name = " + name + ", Value = " + value);    //For Debug Only

   if(name == "SIM_OTTrigger" && value == 0) {

      IR.ShowPage("System_Start");

   } else if(name == "SIM_OTTrigger" && value == 1) {

      IR.ShowPage("Navigation");

      IR.ShowPopup("Inputs");

   }

});

Solved - once again thank you. I am still a bit of a novice when it comes to Javascript, so still getting to grips with the syntax. Appreciate your assistance!


Yay! Problem solved:


IR.AddListener(IR.EVENT_TAG_CHANGE , IR.GetDevice("F10A_Server"), function(name,value)
{
   IR.Log("Name = " + name + ", Value = " + value);    //For Debug Only
   if(name == "SIM_OTTrigger" && value == 1)
      IR.ShowPage("System_Start");
});