Facility Control

 View Only
  • 1.  OnChange Handles in Widget

    Posted 11-30-2023 12:07

    Hi, 

    I am trying to build a widget that reacts when a parameter on it's device Data Source changes. I have built a simple panel that functions, but when converting it to a widget I am unsure where to put the object ID of the device, and not sure where to put ogscript handles tag. Especially as I also want to pull from the parameter which is an array, but that parameter be selectable on a per widget basis

    Is this possible or will I need to create a different trigger for events?

    Cheers,

    Dan



    ------------------------------
    Dan West
    ------------------------------


  • 2.  RE: OnChange Handles in Widget

    Posted 12-04-2023 09:19

    Hi Dan,

    I think this is possible. Below is a similar panel in which the widget selection changes as per the selected parameter and vice-versa. 

    In the panel below, we make use of the "onchange" and "onload" handlers. Here, in the first ogscript block, upon loading or changing,  we check the value of "Selection_OID" which is the parameter with the text input and set this value to the Selectable so that whenever we change the value of the Selection_OID, we automatically update the selected constraint. Similarly in the next ogscript block, when we change the selected constraint, we update the Selection_OID accordingly so that both the parameters have the same value. 

    In your case, you can use a similar ogscript onload and onchange handler which updates the widget parameters as per the Device's data sources.

    <abs contexttype="opengear" style="">
       <meta>
          <params>
             <param access="1" constraint="0.0;100.0;0.0;100.0;1" constrainttype="INT_STEP_RANGE" name="Selection" oid="Selection" precision="0" type="INT32" value="10" widget="spinner"/>
          </params>
       </meta>
       <widgets>
          <widgetdescriptor id="com.rossvideo.sel.sample">
             <config>
                <params>
                   <param access="1" maxlength="0" name="Selection OID" oid="Selection_OID" type="STRING" value="" widget="text"/>
                </params>
             </config>
             <oglml>
                <abs>
                   <meta>
                      <params>
                         <param access="1" constrainttype="INT_CHOICE" name="Selectable" oid="Selectable" precision="0" type="INT32" value="-1" widget="radio-toggle">
                            <constraint key="0"/>
                            <constraint key="1"/>
                            <constraint key="2"/>
                            <constraint key="3"/>
                            <constraint key="4"/>
                            <constraint key="5"/>
                            <constraint key="6"/>
                            <constraint key="7"/>
                            <constraint key="8"/>
                            <constraint key="9"/>
                            <constraint key="10"/>
                         </param>
                      </params>
                      <ogscript handles="onchange,onload" oid="%value[Selection_OID][0]%" skip="%eval[params.getValue('Selection_OID', 0) == '' ? 'true' : ' false']%">var selectionOID = params.getValue('Selection_OID', 0);
          if (selectionOID != null)
          {
             var selectionValue = params.getValue(selectionOID, 0);
             if (selectionValue != null &amp;&amp; selectionValue != params.getValue('Selectable', 0))
             {
                params.setValue('Selectable', 0, selectionValue);
             }
          }</ogscript>
                      <ogscript handles="onchange" oid="Selectable" skip="%eval[params.getValue('Selection_OID', 0) == '' ? 'true' : ' false']%">var selectionOID = params.getValue('Selection_OID', 0);
          if (selectionOID != null)
          {
             var selectionValue = params.getValue(selectionOID, 0);
             if (selectionValue != null &amp;&amp; selectionValue != params.getValue('Selectable', 0))
             {
                params.setValue(selectionOID, 0, params.getValue('Selectable', 0));
             }
          }</ogscript>
                   </meta>
                   <flow bottom="0" horizontalfill="true" left="0" right="0" top="0" verticalfill="true">
                      <param expand="true" height="100" oid="Selectable" style="style:toggleButton" width="100"/>
                   </flow>
                </abs>
             </oglml>
          </widgetdescriptor>
       </widgets>
       <param expand="true" height="106" left="4" oid="Selection" top="4" width="124"/>
       <widget height="349" left="16" top="126" widgetid="com.rossvideo.sel.sample" width="425">
          <config>
             <params>
                <param oid="Selection_OID" value="Selection"/>
             </params>
          </config>
       </widget>
    </abs>
    

    I hope this helps! If it doesn't, feel free to reach out and attach the panel if possible.

    Best Regards,



    ------------------------------
    Altaz Daruwala
    Ross Video
    ------------------------------