Logic Machine Forum
JavaScript Functions Integration - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: JavaScript Functions Integration (/showthread.php?tid=5273)



JavaScript Functions Integration - Fahd - 27.02.2024

Hey everyone,

I'm currently employing two JavaScript functions to showcase alarms on the SCADA page.
They're functioning well individually. However, when one function triggers an alarm and then the other one does too, it seems like only the most recent alarm stays visible.
I don't know how to merge both functions to ensure all alarms display properly.

Any help?

Thanks in advance !

Code:
$(function() {
  if (typeof grp != 'object') {
    return;
  }

  function updat() {
    var text = [];
    var currentDate = new Date().toLocaleString();
    var alarmsExiste = true;

    $.each(grp.tag('ahu'), function(id, object) {
      if (object.value === false) {
        text.push('<span class="blink">'+  object.name + " is Offline" + '</span>');
        alarmsExiste = true;
      }
    });

   if (alarmsExiste) {
      $('.alarm').css({
        'white-space': 'pre',
        'position': 'relative',
        'left': '25px',
        'top': '40px'
       
      }).html(text.join('<br>'));
    }
  }

  grp.taglisten('ahu', updat, true);
});

Code:
$(function() {
  if (typeof grp != 'object') {
    return;
  }

  function update() {
    var text = [];
    var currentDate = new Date().toLocaleString();
    var alarmsExist = true;

    $.each(grp.tag('alarm'), function(id, object) {
      if (object.value) {
        text.push('<span class="blink">'+  object.name + '</span>');
        alarmsExist = true;
      }
    });
    if (alarmsExist) {
    $('.alarm').css('white-space', 'pre').html(text.join('<br>'));
  } }
   

  grp.taglisten('alarm', update, true);
});



RE: JavaScript Functions Integration - admin - 28.02.2024

You can combine both functions together if you want a single list of alerts. Otherwise you need to use different elements/selectors where alerts are placed.