Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Open graphical representation when you click a Script for the server


  • Good morning gentlemen,
    please need to direct the user to a graphical representation after clicking on a graph created by the script for the server through onclick. Someone to help. Thank you.

    My code:

    var dpDao = new com.serotonin.mango.db.dao.PointValueDao();
    var dpVo = dpDao.getLatestPointValue('78');
    var s = "";
    
    if (dpVo.value=="true")
    
     s += "<img style='cursor:pointer;' src='graphics/Leds48/led48_green_1.png' onclick='mango.view.setPoint("+ point.id +", \""+ pointComponent.id +"\", \"false\");return false;'/>";
    
    else
    
    s += "<img style='cursor:pointer;' src='graphics/Leds48/led48_white_0.png' onclick='mango.view.setPoint("+ point.id +", \""+ pointComponent.id +"\", \"true\");return false;'/>";
    
    return s;
    

  • Hi Prayol,

    It's been quite a while since I wrote a server-side scripting component for the graphical views!

    You can add the point on the component through the dropdown. You cannot create a point value dao as you tried (the proper way would be com.serotonin.m2m2.Common.databaseProxy.newPointValueDao();), nor is there a method that takes a string ID like that. Instead, use the value that's already been added to the script context for the point added to the component, something like,

    if (value === true) //assuming it's a binary point
    
    return "<img style='cursor:pointer;' src='graphics/Leds48/led48_green_1.png' onclick='mango.view.setPoint("+ point.id +", "+ pointComponent.id +", false);return false;'/>";
    
    else
    
    return "<img style='cursor:pointer;' src='graphics/Leds48/led48_white_0.png' onclick='mango.view.setPoint("+ point.id +", "+ pointComponent.id +", true);return false;'/>";
    

    I didn't test the HTML, but using 'value' and adding the point to the compoent like so:

    0_1527695831189_serverSideScriptContextPoint.png


  • This post is deleted!

  • @phildunlap Hello phildunlap, thanks for the help.
    See, I use a variation of Mango here in Brazil called ScadaBR. As for DAO, it is working correctly in this variation. My problem is that I'm not sure how to insert the redirect after a click into the server script. I have to direct the user to this representation: views.shtm? ViewId = 8, how do I? I can not do it alone. Thank you


  • Have you tried a <script> tag that changes the window.location ?


  • @phildunlap said in Open graphical representation when you click a Script for the server:

    Have you tried a <script> tag that changes the window.location ?

    I tried this way: onclick = 'javascript: window.location.href =' http: // localhost: 8080 / ScadaBR / views.shtm? ViewId = 5 ";
    The problem, that is JavaScript is not my native language, so it is not a will and I do not know if it is correct what I did.


  • This was my test, worked to get my from the view page to the edit page.

    var s = "<button onclick=\"window.location.href = 'http://localhost:8080/view_edit.shtm?viewId=1';\">";
    if( value < 50 )
      return s+"<b>HELLO WORLD</b></button>";
    else
      return s+"<b>GOODBYE WORLD</b></button>";
    

  • @phildunlap said in Open graphical representation when you click a Script for the server:

    var s = "<button onclick="window.location.href = 'http://localhost:8080/view_edit.shtm?viewId=1';">";

    Thank you my friend. It worked! Now I'm just taking the button shape that was created around the chart to look perfect! It's possible ?


  • Certainly welcome (although consider using Mango :P). You can use a <div> tag, and a closing </div> instead of the <button></button>


  • @phildunlap
    Your help, I have already been very helpful. I do not want to be inopportune, but by putting it this way: (var s = "<div> <onclick = " window.location.href = 'http: // localhost: 8080 / ScadaBR / views.shtm? ViewId = 8' ; \ "> <\ div>";) - I lose the click and redirect function. thankful


  • var s = "<div onclick=\"window.location.href = 'http://localhost:8080/view_edit.shtm?viewId=1';\">";
    if( value < 50 )
      return s+"<b>HELLO WORLD</b></div>";
    else
      return s+"<b>GOODBYE WORLD</b></div>";
    

  • @phildunlap

    SHOW !!!! Thank you, Thank you, Thank you.