Facility Control

 View Only
  • 1.  create a button that adds a task to another button

    Posted 01-22-2021 02:50

    Is there a way to make a button that adds/removes a task on another button?

    eg:

     

    Button 1 adds a specific task to button 2.

    Button 3 removes that same task from button 2.

     

    cheers

     

    james

     



  • 2.  RE: create a button that adds a task to another button

    Posted 01-22-2021 13:48

    There is no ogscript command to add/remove tasks specifically.

    There are 2 ways I can see to do something like this:

    1. I would just use a parameter to store whether the Button2 task should run or not.   Button1 sets that parameter to 1, button 3 sets that parameter to 0.   Button2 checks if the parameter is 1 before running anything.

    2. There is a "setXML" method that allows us to change the oglml of a particular element.  You would need to specify the entire button definition, but it should work.   Here is an example:

     

    <abs contexttype="opengear" id="_top" keepalive="false" style="">
    <button buttontype="push" height="68" left="470" name="Button1" top="105" width="179">
    <task tasktype="ogscript">var xml = '&lt;button buttontype="push" top="0" id="button2_id" left="0" name="Button2" bottom="0" right="0"&gt;';
    xml = xml + '&lt;task tasktype="ogscript"&gt;';
    xml = xml + ' ogscript.debug("I am button2, set by button1")';
    xml = xml + '&lt;/task&gt;';
    xml = xml + '&lt;/button&gt;';

    ogscript.setXML('button2_abs', xml);</task>
    </button>
    <abs height="81" id="button2_abs" left="219" top="277" width="190"/>
    <button buttontype="push" height="68" left="471" name="Button3" top="242" width="179">
    <task tasktype="ogscript">var xml = '&lt;button buttontype="push" top="0" id="button2_id" left="0" name="Button2" bottom="0" right="0"&gt;';
    xml = xml + '&lt;task tasktype="ogscript"&gt;';
    xml = xml + ' ogscript.debug("I am button2, set by button3")';
    xml = xml + '&lt;/task&gt;';
    xml = xml + '&lt;/button&gt;';

    ogscript.setXML('button2_abs', xml);</task>
    </button>
    </abs>

     

    Click on Button1 to make Button2 appear, then click on Button3 to change what it does.   You'll need to have the openGear Debug Information window open to see what the buttons do since they only do debug messages.

     

     


    #DashBoard


  • 3.  RE: create a button that adds a task to another button

    Posted 01-23-2021 00:53

    thanks Ben. Playing around with this now.


    #DashBoard


  • 4.  RE: create a button that adds a task to another button

    Posted 01-27-2021 21:54

    You could also put your script in a string array and use the JavaScript eval function:

     

    <abs contexttype="opengear" keepalive="true">
    <meta>
    <params>
    <param access="1" maxlength="0" name="Button Scripts" oid="button_scripts" precision="0" type="STRING_ARRAY" widget="default">
    <value>ogscript.debug("TEST 1");</value>
    </param>
    </params>
    </meta>
    <button buttontype="push" height="143" left="123" name="Run Scripts" top="109" width="240">
    <task tasktype="ogscript">var buttonScripts = params.getAllValues('button_scripts');
    for (var i = 0; i &lt; buttonScripts.length; i++)
    {
    eval(buttonScripts[i]);
    }</task>
    </button>
    <button buttontype="push" height="64" left="54" name="Add" top="327" width="188">
    <task tasktype="ogscript">var debugString = 'TEST ' + (params.getElementCount('button_scripts') + 1);
    params.setValue('button_scripts', params.getElementCount('button_scripts'), 'ogscript.debug("' + debugString + '");');</task>
    </button>
    <button buttontype="push" height="64" left="251" name="Remove First" top="327" width="188">
    <task tasktype="ogscript">if (params.getElementCount('button_scripts') &gt; 0)
    {
    params.getParam('button_scripts', 0).remove();
    }</task>
    </button>
    </abs>

    #DashBoard