Facility Control

 View Only
  • 1.  Button style in "toggle buttons" widget

    Posted 01-07-2020 22:40
    Hello, Lets say,i have an parameter with 100 name/value pairs. I represent in with "toggle buttons" widget, i can set the colour of "toggle on" and " toggle off" states. The text on buttons is the "name" of each element ( name/value pair). What if i want to split this name to 2 lines(one word on top of button and other one on bottom)? What if i want to change colour of the text on individual button? Also, is there an method to rename single pair name without ogscript.replaceContraint ( which rebuilts whole parameter)? I want to create source/destination router control panel and i need to indicate which destination is in "lock" state. My comunication part of panel works good, i recieve those updates asynchronousy using listener, and i know to parse it. So, my idea was to add "locked" word to each dest name, in the second line of button. It will be perfect, if i could also paint that word ("locked") in red colour. But i didn't find any solution for that. Maybe i should create single "toggle" buttons for each source and dest, and then get all style control individually? Thanks a lot, Alex.


  • 2.  RE: Button style in "toggle buttons" widget

    Posted 01-08-2020 14:54

    Hi Alex

    You will need to replace the entire constraint each time but if you extract the code into a simple function to call, it should be relatively simple.

    Splitting into 2 lines has a shortcut in DashBoard - you can use "\n" wherever you want to split to appear.  This works for simple multi-line but more is involved if you want to change the color.

    If you want to change the color, you'll be best to take advantage of the button's ability to hold HTML inside of it - I have included an example panel that demonstrates this technique.

    <abs contexttype="opengear" keepalive="true">
    <meta>
    <params>
    <param access="1" constrainttype="INT_CHOICE" name="Toggle Button" oid="params.toggle" precision="0" type="INT16" value="0" widget="radio-toggle">
    <constraint key="0">One</constraint>
    <constraint key="1">Two</constraint>
    <constraint key="2">Three</constraint>
    <constraint key="3">Four</constraint>
    <constraint key="4">Five</constraint>
    <constraint key="5">Six</constraint>
    </param>
    <param access="1" constrainttype="INT_CHOICE" name="params.lock" oid="params.lock" precision="0" type="INT32_ARRAY" value="0;0;0;0;0;0" widget="checkbox">
    <constraint key="0">Unlocked</constraint>
    <constraint key="1">Locked</constraint>
    </param>
    </params>
    <api>function updateConstraint()
    {
    var names = ['One', 'Two', 'Three', 'Four', 'Five', 'Six'];
    var newConstraint = [];
    var locked = false;
    for (var i = 0; i &lt; names.length; i++)
    {
    locked = params.getValue('params.lock', i) == 1;
    newConstraint[i] = names[i];
    if (locked)
    {
    newConstraint[i] = '&lt;html&gt;&lt;center&gt;' + names[i] + '&lt;br/&gt;&lt;font color="#FF0000"&gt;LOCKED&lt;/font&gt;&lt;/center&gt;&lt;/html&gt;';
    }
    }

    params.replaceConstraint('params.toggle', params.createIntChoiceConstraint(newConstraint));
    }</api>
    </meta>
    <param expand="true" height="95" left="171" oid="params.toggle" showlabel="false" style="style:toggleButton;" top="93" width="577"/>
    <param expand="true" height="42" left="170" oid="params.lock" runtasksonload="true" top="235" width="573">
    <task tasktype="ogscript">updateConstraint();</task>
    </param>
    <label height="62" left="749" name="Lock" style="txt-align:west;" top="220" width="171"/>
    </abs>

     

    Cheers

    James


    #DashBoard


  • 3.  RE: Button style in "toggle buttons" widget

    Posted 01-08-2020 21:49

    Hello again James, and thanks for quick answer

    Its seems almost there, the only point: instead of manually create copy name array:

    var names = ['One', 'Two', 'Three', 'Four', 'Five', 'Six'];

    I need to fetch names from 'params.toggle' parameter - since the labels is dynamic and could be changed from time to time. So, i believe it have to be something like this:

    var names = [];
    var array = params.getAllValues ('params.toggle');
    for (var i = 0; i < array.length; i++){
    names[i] = params.getValueAsString('params.toggle',i)
    }

    But something wrong with that.

    params.getAllValues (that by the ogscript reference pdf should retrieve the entire array of values) returns only one string with the current selection value, neither params.getElementCount do the work (returns 1 always). The params.getValueAsString('params.toggle',index) also returns always only the chosen value. Maybe the parameter type should be changed to string array and constraint type to string key/value constraint (i will check it tomorrow, for today i'm done)? How to achieve this?

    Also, is it possible to set some variant of "read only"/inactive for single button in toggle buttons?

    Best regards, 

    Alex.

     


    #DashBoard


  • 4.  RE: Button style in "toggle buttons" widget

    Posted 01-08-2020 22:02

    Hi Alex

    getValueAsString() will only ever give you the value of the parameter in its String form. What you're looking to do is iterate over the list of all possible choices for the parameter - you want its Constraint.

    Here's an example of how to get the name of each choice:

    var oldConstraint = params.getConstraint('params.toggle');
    var choices = oldConstraint.getChoices();
    for (var i = 0; i < choices.length; i++)
    {
    ogscript.debug(choices[i].getName());
    }

    As for the read-only attribute - presently read/write applies to the entire parameter and you cannot turn individual choices off/on. You can use style information to make a choice appear as greyed-out and reject the change if someone attempts to set the value to the invalid option - that's about as close as you can get.

    Cheers

    James


    #DashBoard


  • 5.  RE: Button style in "toggle buttons" widget

    Posted 01-08-2020 22:16

    Ok, that's it! Thank you very much! 

    By the way, i just searched now ogscript reference pdf v8.7 with keyword "getChoices()" , with no result.. :(

    Again, lot of thanks. 

    Alex. 


    #DashBoard