Facility Control

 View Only
  • 1.  Get Element Name or OID?

    Posted 04-05-2018 08:14

    So, I kinda got a workaround for the populate X-number of buttons that I asked for in this post:
    https://discussions.rossvideo.com/forum/default-forum-gc1/dashboard-gc43/15654-create-buttons-from-list-array-of-parameters

    Though now I have about 36 buttons, that all needs basically the same task function.
    So, instead of writing this down 36 times (copy/paste of course), I was going to make my own custom function for this and just add this (also makes it WAY easier to do any changes to this function).

    BUT!
    For this to work, I need to be able to grab either the NAME or the ID of the button that is pressed. Seeing as they are all different "values", but the function and result remains the "same" based on the value of that specific button. I've been looking through the documentation, and all I can find are functions that require the OID in order to retrieve the information I need.
    I was kinda hoping for a similar thing of:

    getElementID(this);

    or something similar.
    Anyone? :)



  • 2.  RE: Get Element Name or OID?

    Posted 04-05-2018 16:01

    You're almost certainly better off using a parameter with an array of toggle buttons to show a choice parameter here. When the choice is changed, you can read the new value and run your task.

    <abs contexttype="opengear" id="_top" style="">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="Choices" oid="params.choices" precision="0" type="INT16" value="-1" widget="radio-toggle">
                <constraint key="0">Choice 1</constraint>
                <constraint key="1">Choice 2</constraint>
                <constraint key="2">Choice 3</constraint>
                <constraint key="3">Choice 4</constraint>
                <constraint key="4">Choice 5</constraint>
                <constraint key="5">Choice 6</constraint>
             </param>
             <param access="1" maxlength="0" name="Selected" oid="params.selected" stateless="true" type="STRING" value="Nothing" widget="default"/>
          </params>
       </meta>
       <param expand="true" height="131" left="29" oid="params.choices" style="style:toggleButton;" top="23" width="711">
          <task tasktype="ogscript">if (this.getValue() &gt;= 0)
    {
       params.setValue('params.selected', 0, "You selected " + this.getValueAsString());
       this.setValue(-1);
    }
    </task>
       </param>
       <param expand="true" height="84" left="49" oid="params.selected" top="185" widget="100" width="354"/>
    </abs>

    #DashBoard


  • 3.  RE: Get Element Name or OID?

    Posted 04-06-2018 07:38

    While I normally would completly agree with you, I need to be able to pick 3 options from the same list.
    I'll add the working version of what I ended up with here, and if you're able to make a better working version, then by ALL means. The one I made is definetly made by touch-and-go...

    Clarification: The "jsonport" isnt needed for this part, and the maximum number of players that can be shown in this version is 12. So if you wanna add more players to the parameters that make up the table of players (wich will be populated by REST calls and JSON) remember that it will not show more than 12.

    Click "populate" and the grid will be updated. This will of course be a function that is called upon whenever the roster in the table is updated when I get to the full version.

    <abs contexttype="opengear" gridsize="20" id="_top" jsonport="5566" scroll="horizontal">
       <meta>
          <style id="greyBtn" name="greyBtn" value="bg#4C4C4C;"/>
          <style id="blueBtn" name="blueBtn" value="bg#0034FD;"/>
          <style id="redBtn" name="redBtn" value="bg#C70000;"/>
          <params>
             <param access="1" maxlength="0" name="Navn" oid="0x2" precision="0" type="STRING_ARRAY" value="Ola;Per;Pål;Johnny;Mons;Morten" widget="text">
                <value>Ola</value>
                <value>Per</value>
                <value>Pål</value>
                <value>Johnny</value>
                <value>Mons</value>
                <value>Morten</value>
             </param>
             <param access="1" constrainttype="INT_NULL" name="Num" oid="0x3" precision="0" type="INT16_ARRAY" value="2;8;65;22;35;82;98" widget="default"/>
             <param access="1" constrainttype="INT_CHOICE" name="Table" oid="0x4" precision="0" type="INT16" value="4" widget="default">
                <constraint key="3">#</constraint>
                <constraint key="2">Name</constraint>
             </param>
             <param access="1" maxlength="0" name="goal_by" oid="goal_by" type="STRING" value="8" widget="text-display"/>
             <param access="1" maxlength="0" name="ass_by1" oid="ass_by1" type="STRING" value="65" widget="text-display"/>
             <param access="1" maxlength="0" name="ass_by2" oid="ass_by2" type="STRING" value="98" widget="text-display"/>
          </params>
       </meta>
       <param expand="true" height="40" left="240" oid="Number" top="380" width="80"/>
       <param evenstyle="f:bg#E2E2E2;" expand="true" height="120" left="240" oid="0x4" scrolling="true" showlabel="false" top="40" widget="table" width="240"/>
       <abs height="260" id="h_frame" left="100" style="bg#BFBFBF;bdr#535353;bdr:thick;" top="200" width="340">
          <button buttontype="push" height="60" id="btn0" left="20" name="btn0" top="20" width="60">
             <task tasktype="ogscript">var i = 0;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn1" left="100" name="btn1" top="20" width="60">
             <task tasktype="ogscript">var i = 1;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn2" left="180" name="btn2" top="20" width="60">
             <task tasktype="ogscript">var i = 2;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn3" left="260" name="btn3" top="20" width="60">
             <task tasktype="ogscript">var i = 3;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn4" left="20" name="btn4" top="100" width="60">
             <task tasktype="ogscript">var i = 4;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn5" left="100" name="btn5" top="100" width="60">
             <task tasktype="ogscript">var i = 5;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn6" left="180" name="btn6" top="100" width="60">
             <task tasktype="ogscript">var i = 6;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn7" left="260" name="btn7" top="100" width="60">
             <task tasktype="ogscript">var i = 7;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn8" left="20" name="btn8" top="180" width="60">
             <task tasktype="ogscript">var i = 8;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn9" left="100" name="btn9" top="180" width="60">
             <task tasktype="ogscript">var i = 9;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn10" left="180" name="btn10" top="180" width="60">
             <task tasktype="ogscript">var i = 10;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
          <button buttontype="push" height="60" id="btn11" left="260" name="btn11" top="180" width="60">
             <task tasktype="ogscript">var i = 11;
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }</task>
          </button>
       </abs>
       <button buttontype="push" height="120" left="60" name="Populate" top="40" width="160">
          <task tasktype="ogscript">var i = 0;
    var tot  = params.getElementCount(0x3);
    var x = 16;
    
    while (i &lt; x) {
       var spiller = params.getValue(0x3, i);
       var btn = 'btn'+i;
       ogscript.rename(btn, spiller);
       if (spiller == 0) {
          ogscript.hide(btn);
       } else {
          ogscript.reveal(btn);
       }
       //ogscript.setSize('h_frame', 340, h);
       i++;
    }
    
    var h = (80 * Math.ceil(tot / 4))+20;
    ogscript.setSize('h_frame', 340, h);
    
    params.setValue('goal_by', 0, '');
    params.setValue('ass_by2', 0, '');
    params.setValue('ass_by1', 0, '');</task>
       </button>
       <param expand="true" height="40" left="220" oid="goal_by" style="txt-align:center;size:Big;" top="480" width="60">
          <task tasktype="ogscript">var goalby = params.getValue('goal_by', 0);
    
    if (goalby == '') {
       ogscript.hide('confirm');
    } else {
       ogscript.reveal('confirm');
    }</task>
       </param>
       <param expand="true" height="40" left="220" oid="ass_by1" style="txt-align:center;size:Big;" top="540" width="60"/>
       <param expand="true" height="40" left="220" oid="ass_by2" style="txt-align:center;size:Big;" top="600" width="60"/>
       <label height="40" left="120" name="Goal by: " style="txt-align:east;size:Big;" top="480" width="100"/>
       <label height="40" left="120" name="Assist 1: " style="txt-align:east;size:Big;" top="540" width="100"/>
       <label height="40" left="120" name="Assist 2: " style="txt-align:east;size:Big;" top="600" width="100"/>
       <button buttontype="push" height="80" id="confirm" left="320" name="Confirm" top="520" width="120">
          <task tasktype="ogscript">var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    var assist = '';
    var msg = '';
    
    if (assby1 != '') {
       assist = assby1;
       if (assby2 != '') {
          assist = assist + ' and ' + assby2;
       }
    }
    
    if (goalby == '') {
       ogscript.debug('No one scored?');
    } else {
       msg = 'CONFIRMED: Goal by: ' + goalby;
       if (assist != '') {
          msg = msg + ' Assist by: ' + assist;
          ogscript.debug(msg);
       } else {
          ogscript.debug(msg);
       }
    }</task>
       </button>
    </abs>

    So, as you can see... If there is a "GET NAME" function out there somewhere, I'd really like it...


    #DashBoard


  • 4.  RE: Get Element Name or OID?

    Posted 04-07-2018 13:52

    Hi,

    to avoid the copy/paste code in all buttons you can put your user function in a tag

    see modified code :

    <abs contexttype="opengear" gridsize="20" id="_top" jsonport="5566" scroll="horizontal">
       <meta>
          <style id="greyBtn" name="greyBtn" value="bg#4C4C4C;"/>
          <style id="blueBtn" name="blueBtn" value="bg#0034FD;"/>
          <style id="redBtn" name="redBtn" value="bg#C70000;"/>
          <params>
             <param access="1" maxlength="0" name="Navn" oid="0x2" precision="0" type="STRING_ARRAY" value="Ola;Per;Pål;Johnny;Mons;Morten" widget="text">
                <value>Ola</value>
                <value>Per</value>
                <value>Pål</value>
                <value>Johnny</value>
                <value>Mons</value>
                <value>Morten</value>
             </param>
             <param access="1" constrainttype="INT_NULL" name="Num" oid="0x3" precision="0" type="INT16_ARRAY" value="2;8;65;22;35;82;98" widget="default"/>
             <param access="1" constrainttype="INT_CHOICE" name="Table" oid="0x4" precision="0" type="INT16" value="5" widget="default">
                <constraint key="3">#</constraint>
                <constraint key="2">Name</constraint>
             </param>
             <param access="1" maxlength="0" name="goal_by" oid="goal_by" type="STRING" value="" widget="text-display"/>
             <param access="1" maxlength="0" name="ass_by1" oid="ass_by1" type="STRING" value="" widget="text-display"/>
             <param access="1" maxlength="0" name="ass_by2" oid="ass_by2" type="STRING" value="" widget="text-display"/>
          </params>
          <api> function myCommonFunction(i)
    {
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }
    }
    </api>
       </meta>
       <param expand="true" height="40" left="240" oid="Number" top="380" width="80"/>
       <param evenstyle="f:bg#E2E2E2;" expand="true" height="120" left="240" oid="0x4" scrolling="true" showlabel="false" top="40" widget="table" width="240"/>
       <abs height="260" id="h_frame" left="100" style="bg#BFBFBF;bdr#535353;bdr:thick;" top="200" width="340">
          <button buttontype="push" height="60" id="btn0" left="20" name="btn0" top="20" width="60">
             <task tasktype="ogscript"> myCommonFunction('0');</task>
          </button>
          <button buttontype="push" height="60" id="btn1" left="100" name="btn1" top="20" width="60">
             <task tasktype="ogscript"> myCommonFunction('1');</task>
          </button>
          <button buttontype="push" height="60" id="btn2" left="180" name="btn2" top="20" width="60">
             <task tasktype="ogscript"> myCommonFunction('2');</task>
          </button>
          <button buttontype="push" height="60" id="btn3" left="260" name="btn3" top="20" width="60">
             <task tasktype="ogscript"> myCommonFunction('3');</task>
          </button>
          <button buttontype="push" height="60" id="btn4" left="20" name="btn4" top="100" width="60">
             <task tasktype="ogscript"> myCommonFunction('4');</task>
          </button>
          <button buttontype="push" height="60" id="btn5" left="100" name="btn5" top="100" width="60">
             <task tasktype="ogscript"> myCommonFunction('5');</task>
          </button>
          <button buttontype="push" height="60" id="btn6" left="180" name="btn6" top="100" width="60">
             <task tasktype="ogscript"> myCommonFunction('6');</task>
          </button>
          <button buttontype="push" height="60" id="btn7" left="260" name="btn7" top="100" width="60">
             <task tasktype="ogscript"> myCommonFunction('7');</task>
          </button>
          <button buttontype="push" height="60" id="btn8" left="20" name="btn8" top="180" width="60">
             <task tasktype="ogscript"> myCommonFunction('8');</task>
          </button>
          <button buttontype="push" height="60" id="btn9" left="100" name="btn9" top="180" width="60">
             <task tasktype="ogscript"> myCommonFunction('9');</task>
          </button>
          <button buttontype="push" height="60" id="btn10" left="180" name="btn10" top="180" width="60">
             <task tasktype="ogscript"> myCommonFunction('10');</task>
          </button>
          <button buttontype="push" height="60" id="btn11" left="260" name="btn11" top="180" width="60">
             <task tasktype="ogscript"> myCommonFunction('11');</task>
          </button>
       </abs>
       <button buttontype="push" height="120" left="60" name="Populate" top="40" width="160">
          <task tasktype="ogscript">var i = 0;
    var tot  = params.getElementCount(0x3);
    var x = 16;
    
    while (i &lt; x) {
       var spiller = params.getValue(0x3, i);
       var btn = 'btn'+i;
       ogscript.rename(btn, spiller);
       if (spiller == 0) {
          ogscript.hide(btn);
       } else {
          ogscript.reveal(btn);
       }
       //ogscript.setSize('h_frame', 340, h);
       i++;
    }
    
    var h = (80 * Math.ceil(tot / 4))+20;
    ogscript.setSize('h_frame', 340, h);
    
    params.setValue('goal_by', 0, '');
    params.setValue('ass_by2', 0, '');
    params.setValue('ass_by1', 0, '');</task>
       </button>
       <param expand="true" height="40" left="220" oid="goal_by" style="txt-align:center;size:Big;" top="480" width="60">
          <task tasktype="ogscript">var goalby = params.getValue('goal_by', 0);
    
    if (goalby == '') {
       ogscript.hide('confirm');
    } else {
       ogscript.reveal('confirm');
    }</task>
       </param>
       <param expand="true" height="40" left="220" oid="ass_by1" style="txt-align:center;size:Big;" top="540" width="60"/>
       <param expand="true" height="40" left="220" oid="ass_by2" style="txt-align:center;size:Big;" top="600" width="60"/>
       <label height="40" left="120" name="Goal by: " style="txt-align:east;size:Big;" top="480" width="100"/>
       <label height="40" left="120" name="Assist 1: " style="txt-align:east;size:Big;" top="540" width="100"/>
       <label height="40" left="120" name="Assist 2: " style="txt-align:east;size:Big;" top="600" width="100"/>
       <button buttontype="push" height="80" id="confirm" left="320" name="Confirm" top="520" width="120">
          <task tasktype="ogscript">var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    var assist = '';
    var msg = '';
    
    if (assby1 != '') {
       assist = assby1;
       if (assby2 != '') {
          assist = assist + ' and ' + assby2;
       }
    }
    
    if (goalby == '') {
       ogscript.debug('No one scored?');
    } else {
       msg = 'CONFIRMED: Goal by: ' + goalby;
       if (assist != '') {
          msg = msg + ' Assist by: ' + assist;
          ogscript.debug(msg);
       } else {
          ogscript.debug(msg);
       }
    }</task>
       </button>
    
    </abs>

    #DashBoard


  • 5.  RE: Get Element Name or OID?

    Posted 04-08-2018 22:10
    Why of course!
    And then pass the jersey number through the function as a variable of course!

    It was a long day with alot of head scratching...
    It would still be great to be able to create the buttons dynamically, and also be able to get the name of the button, as then nothing would really be hardcoded. But it will make do for now!

    Thanks for the tip! Even though it was staring me in the face all along...
    #DashBoard


  • 6.  RE: Get Element Name or OID?

    Posted 04-09-2018 10:03

    yes , you were almost there !

    ogscript.setXML can be used to dynamically generates UI : it replaces the contents of an element with a string of XML code.

    see test code with element named dynamicContent:

    <?xml version="1.0" encoding="UTF-8"?><abs contexttype="opengear" gridsize="20" id="_top" jsonport="5566" scroll="horizontal">
       <meta>
          <style id="greyBtn" name="greyBtn" value="bg#4C4C4C;"/>
          <style id="blueBtn" name="blueBtn" value="bg#0034FD;"/>
          <style id="redBtn" name="redBtn" value="bg#C70000;"/>
          <params>
             <param access="1" maxlength="0" name="Navn" oid="0x2" precision="0" type="STRING_ARRAY" value="Ola;Per;Pål;Johnny;Mons;Morten" widget="text">
                <value>Ola</value>
                <value>Per</value>
                <value>Pål</value>
                <value>Johnny</value>
                <value>Mons</value>
                <value>Morten</value>
             </param>
             <param access="1" constrainttype="INT_NULL" name="Num" oid="0x3" precision="0" type="INT16_ARRAY" value="2;8;65;22;35;82;98" widget="default"/>
             <param access="1" constrainttype="INT_CHOICE" name="Table" oid="0x4" precision="0" type="INT16" value="5" widget="default">
                <constraint key="3">#</constraint>
                <constraint key="2">Name</constraint>
             </param>
             <param access="1" maxlength="0" name="goal_by" oid="goal_by" type="STRING" value="" widget="text-display"/>
             <param access="1" maxlength="0" name="ass_by1" oid="ass_by1" type="STRING" value="" widget="text-display"/>
             <param access="1" maxlength="0" name="ass_by2" oid="ass_by2" type="STRING" value="" widget="text-display"/>
          </params>
          <api> function myCommonFunction(i)
    {
    
    var btn = 'btn'+i;
    var num = Math.trunc(params.getValue(0x3, i)).toString();
    ogscript.debug(num);
    var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    
    if (goalby == num || assby1 == num || assby2 == num) {
       ogscript.setStyle(btn, 'style:greyBtn');
       if (goalby == num) {
          params.setValue('goal_by', 0, '');
       } else if (assby1 == num) {
          params.setValue('ass_by1', 0, '');
          if (assby2 != '') {
             params.setValue('ass_by1', 0, assby2);
             params.setValue('ass_by2', 0, '');
          }
       } else if (assby2 == num) {
          params.setValue('ass_by2', 0, '');
       }
    } else if (goalby == '') {
        ogscript.setStyle(btn, 'style:redBtn');
        params.setValue('goal_by', 0, num);
    } else if (assby1 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by1', 0, num);
    } else if (assby2 == '') {
        ogscript.setStyle(btn, 'style:blueBtn');
        params.setValue('ass_by2', 0, num);
    } else {
       ogscript.debug ('NOT A VALID INPUT!');
    }
    }
    </api>
       </meta>
       <param expand="true" height="40" left="240" oid="Number" top="380" width="80"/>
       <param evenstyle="f:bg#E2E2E2;" expand="true" height="120" left="240" oid="0x4" scrolling="true" showlabel="false" top="40" widget="table" width="240"/>
       <abs height="260" id="h_frame" left="100" style="bg#BFBFBF;bdr#535353;bdr:thick;" top="200" width="340">
        <abs id="dynamicContent">
        </abs>
       </abs>
       <button buttontype="push" height="120" left="60" name="Populate" top="40" width="160">
          <task tasktype="ogscript"/>
          <task tasktype="ogscript">var i = 0;
    var tot  = params.getElementCount(0x3);
    var x = 16;
    var str = '';
    var posX = 0;
    var posY = 0;
    
    while (i &lt; tot) {
       var spiller = params.getValue(0x3, i);
       
       posX = 20 + 80*(i % 4);
       posY = 20 + 80*Math.floor(i / 4);
       str = str + '&lt;button buttontype="push" height="60" id="btn' + i + '" left="' + posX + '" name="' + spiller + '" top="' + posY + '" width="60"&gt;' + '&lt;task tasktype="ogscript"&gt; myCommonFunction(' + i + ');&lt;/task&gt;' + '&lt;/button&gt;';
    
       i++;
    }
    
    
    ogscript.setXml('dynamicContent', str);
    
    params.setValue('goal_by', 0, '');
    params.setValue('ass_by2', 0, '');
    params.setValue('ass_by1', 0, '');</task>
       </button>
       <param expand="true" height="40" left="220" oid="goal_by" style="txt-align:center;size:Big;" top="480" width="60">
          <task tasktype="ogscript">var goalby = params.getValue('goal_by', 0);
    
    if (goalby == '') {
       ogscript.hide('confirm');
    } else {
       ogscript.reveal('confirm');
    }</task>
       </param>
       <param expand="true" height="40" left="220" oid="ass_by1" style="txt-align:center;size:Big;" top="540" width="60"/>
       <param expand="true" height="40" left="220" oid="ass_by2" style="txt-align:center;size:Big;" top="600" width="60"/>
       <label height="40" left="120" name="Goal by: " style="txt-align:east;size:Big;" top="480" width="100"/>
       <label height="40" left="120" name="Assist 1: " style="txt-align:east;size:Big;" top="540" width="100"/>
       <label height="40" left="120" name="Assist 2: " style="txt-align:east;size:Big;" top="600" width="100"/>
       <button buttontype="push" height="80" id="confirm" left="320" name="Confirm" top="520" width="120">
          <task tasktype="ogscript">var goalby = params.getValue('goal_by', 0);
    var assby1 = params.getValue('ass_by1', 0);
    var assby2 = params.getValue('ass_by2', 0);
    var assist = '';
    var msg = '';
    
    if (assby1 != '') {
       assist = assby1;
       if (assby2 != '') {
          assist = assist + ' and ' + assby2;
       }
    }
    
    if (goalby == '') {
       ogscript.debug('No one scored?');
    } else {
       msg = 'CONFIRMED: Goal by: ' + goalby;
       if (assist != '') {
          msg = msg + ' Assist by: ' + assist;
          ogscript.debug(msg);
       } else {
          ogscript.debug(msg);
       }
    }</task>
       </button>
    
    </abs>

    #DashBoard


  • 7.  RE: Get Element Name or OID?

    Posted 04-10-2018 07:38
    See NOW you're talking! SWEET!!!

    I didnt know about the ogscript.setXML part to generate content!
    This basically solves the "getName" need as well, seeing as the id variable to send with the button is defined while the button is generated!
    AWESOME!

    This is great... From having 1247 lines of code (32 players) down to 133 lines of code to do the SAME thing! WOOOO!!! (getting way too exited over this...)
    "‹Thanks for some great input there @amignon !

    Now to code the part that gets the players stats from a database through REST API, though I'm pretty sure I got that one covered.
    Call on the "populate" part whenever I successfully pull data from the database, be able to pick teams, update the rosters and stats based on that, and voila!

    This part here wich we just created will be a on a separate "CONSUMER"-panel in the final version of course, where someone pushing either "GOAL" og "PENALTY" will make this screen we just created (or something similar) appear and let the people that gets the info from the ref. press the jerseys involed, and set this info back up to the "PROVIDER"-panel.

    PERFECT!
    "‹Thanks again @amignon !
    #DashBoard