• Recent
    • Tags
    • Popular
    • Register
    • Login

    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 Mango 5 Documentation Website

    Graphic View - Image Clicking

    Wishlist
    6
    19
    16.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cyberoblivion
      last edited by

      Here is a simple solution to this...
      This isnt how I ended up implementing it but I'm sure most people won't want to modify the DB so you could do it this way very easily.

      First in the javascript tag on the views.jsp page you can add

       var TOGGLE = 0;
              var SET_TRUE = 1;
              var SET_FALSE = 2;
              var buttonType=TOGGLE;
              
              function getCurrentValue(divId){
                  var theDiv = $(divId);
                  var temp = null;
                  var inputElems = theDiv.getElementsByTagName("input");
                  for (var i=0; i<inputElems.length; i++) {
                      if (inputElems*.id.startsWith("txtChange")) {
                          temp = inputElems*.value;
                      }
                  }
                  return temp;
              }
              function buttonController(pointId, pointType, setable, pointViewId){
                  var divId = "c"+pointViewId+"Change";            
                  if(pointType==1 && setable){
                      if (buttonType==TOGGLE) {
                          mango.view.setPoint(pointId, pointViewId, getCurrentValue(divId)>0?0:1);
                      } else if (buttonType==SET_TRUE) {
                          mango.view.setPoint(pointId, pointViewId, 1);
                      } else if (buttonType==SET_FALSE) {
                          mango.view.setPoint(pointId, pointViewId, 0);
                      }
                  }
              }
      

      then in the div with ```
      id="c${pv.id}"

      add a onmousedown event handler like this
      
      

      onmousedown="buttonController(${pv.dataPoint.id},${pv.dataPoint.pointLocator.dataTypeId},${pv.dataPoint.pointLocator.settable},${pv.id});"

      
      
      Thats it.. you can now click on the image to change its value! :-)
      you can set the mode in the javascript to toggle, set true, set false, of course you which ever way you choose it will act the same for all...
      The script also only allow action on binary type datapoints.
      
      Maybe its usefull for someone who knows.. :-D
      
      
      1 Reply Last reply Reply Quote 0
      • M
        mlohbihler
        last edited by

        Nice work. Coming in 1.6.0 there will be an alternate solution as well. The point and pointView objects have been added to the server-side script graphic renderer, which will provide you with the context you need to call the set point function. There is a bunch of quote escaping to do to turn the server-side script into a client-side script, but i made a binary point toggle-able with the following:

        var result = "";
        result += "&lt;span onclick='mango.view.setPoint("+ point.id+", "+ pointView.id +", \""+ !value +"\")'&gt;";
        
        if (value)
            result += "i'm ON. click me";
        else
            result += "i'm OFF. click me";
        
        result += "&lt;/span&gt;";
        return result;
        
        

        Best regards,
        Matthew

        1 Reply Last reply Reply Quote 0
        • M
          mlohbihler
          last edited by

          Oh, note that this script doesn't work in view editing mode. You need to save the view and test the script in read-only mode.

          Best regards,
          Matthew

          1 Reply Last reply Reply Quote 0
          • M
            mjbcomputers
            last edited by

            For some reason MANGO did not like the "pointView.id"... What I did to get it to work was to manually place in the number based upon the graphic views url "http://localhost:8080/mango/views.shtm?viewId=2" so I placed a 2.

            var result = "";
            result += "<span onclick='mango.view.setPoint("+ point.id+", "+ 2 +", ""+ !value +"")'>";

            if (value)
            result += "i'm ON. click me";
            else
            result += "i'm OFF. click me";

            result += "</span>";
            return result;

            1 Reply Last reply Reply Quote 0
            • M
              mlohbihler
              last edited by

              The dangers of trusting dated information...

              I don't recall what version it was, but somewhere the var was changed from pointView to pointComponent.

              Best regards,
              Matthew

              1 Reply Last reply Reply Quote 0
              • M
                mjbcomputers
                last edited by

                Thanks for the info! I'll change my code!

                1 Reply Last reply Reply Quote 0
                • J
                  Jokke
                  last edited by

                  Hello

                  The code for clicking the text works nicely. I am more intrested to have image(button/checkbox/light bulb) which can be clicked to togle the value. with such the usability would be better. Is there any new methods for this? How is the "have drinks" in mango example implemeted?

                  The code posted by cyberoblivion seems intresting. Can you please explain some details. Where is the codes to "in div" and the onmousebutton event handler to be put?

                  thanks
                  Jokke

                  1 Reply Last reply Reply Quote 0
                  • M
                    mlohbihler
                    last edited by

                    Hi Jokke,

                    The "have a drink" control in the sample remote view is coded as follows:

                    var s = &quot;&quot;;
                    if (value)
                        s += &quot;&lt;img style='cursor:pointer;' src='graphics/Drinks/drink.png' onclick='mango.view.setPoint(&quot;+ point.id +&quot;, \&quot;&quot;+ pointComponent.id +&quot;\&quot;, \&quot;false\&quot;);return false;'/&gt&quot;;
                    else
                        s += &quot;&lt;img src='graphics/Drinks/drink_empty.png'/&gt&quot;;
                    return s;
                    

                    The backing point has a change detector that triggers an event handler after 30 seconds.

                    If you're more interested in the flashing light toggle, the code for that is:

                    var s = &quot;&quot;;
                    s += &quot;Or, use these scripted controls to turn the light &quot;;
                    s += &quot;&lt;a href='#' onclick='mango.view.setPoint(&quot;+ point.id +&quot;, \&quot;&quot;+ pointComponent.id +&quot;\&quot;, \&quot;false\&quot;);return false;'&gt&quot;;
                    s += value ? &quot;Off&quot; : &quot;&lt;b&gt;Off&lt;/b&gt&quot;;
                    s += &quot;&lt;/a&gt, &quot;;
                    s += &quot;&lt;a href='#' onclick='mango.view.setPoint(&quot;+ point.id +&quot;, \&quot;&quot;+ pointComponent.id +&quot;\&quot;, \&quot;true\&quot;);return false;'&gt&quot;;
                    s += value ? &quot;&lt;b&gt;On&lt;/b&gt&quot; : &quot;On&quot;;
                    s += &quot;&lt;/a&gt, or to &quot;;
                    s += &quot;&lt;a href='#' onclick='mango.view.setPoint(&quot;+ point.id +&quot;, \&quot;&quot;+ pointComponent.id +&quot;\&quot;, \&quot;&quot;+ !value +&quot;\&quot;);return false;'&gt;Toggle&lt;/a&gt&quot;;
                    s += &quot; its state.&quot;;
                    return s;
                    
                    

                    Best regards,
                    Matthew

                    1 Reply Last reply Reply Quote 0
                    • J
                      Jokke
                      last edited by

                      Excelent, thanks for the hints. Now I got the image click working. Your example was also simple enough for other js noobs like me :D .

                      -Jokke

                      1 Reply Last reply Reply Quote 0
                      • D
                        diegoferreira
                        last edited by

                        Hello,

                        Great topic, but let´s say I wanna alter other datapoint values not related to this server side script.

                        I tried something like:

                        s += "<a href='#' onclick='mango.view.setPoint("+ "\"DP_900421\"" +", \""+ pointComponent.id +"\", \"false\");return false;'>"
                        

                        And it returns me simple error message box, with no info, and no JS error.

                        What should be the proper way to set other datapoint values?

                        Thanks,

                        1 Reply Last reply Reply Quote 0
                        • D
                          diegoferreira
                          last edited by

                          Something I tried too:

                          var s = "";
                          var dpVO = new com.serotonin.mango.db.dao.DataPointDao();
                           if (value){
                               s += "<img style='cursor:pointer;' src='graphics/U27-12/Button/bt_On.jpg' onclick='mango.view.setPoint(" + dpVO.getDataPoint("DP_403189").getId() +", \""+ pointComponent.id +"\", \"false\");return false;'/>";
                          } else {
                               s += "<img style='cursor:pointer;' src='graphics/U27-12/Button/bt_Off.jpg' onclick='mango.view.setPoint("+ dpVO.getDataPoint("DP_403189").getId() +", \""+ pointComponent.id +"\", \"true\");return true;'/>";
                          }
                           return s;
                          

                          I set an "input" data point as my reference datapoint, and this is my attempt to configure or set an "output" datapoint by server side script.

                          1 Reply Last reply Reply Quote 0
                          • M
                            mlohbihler
                            last edited by

                            Setting of points not added to the view is not allowed because it could violate permissions.

                            Best regards,
                            Matthew

                            1 Reply Last reply Reply Quote 0
                            • D
                              diegoferreira
                              last edited by

                              That is true, but even if add the "output" datapoint beside my server side script I the error persists.

                              The question rests... no way to do this?

                              1 Reply Last reply Reply Quote 0
                              • M
                                mlohbihler
                                last edited by

                                Well, i spoke a bit generally there. Setting of points not in a view is a potential violation of permissions, and pretty much for this reason there is no support in view components for what you are trying to do (i.e. use the XID to reference a point to set, or for any other reason for that matter).

                                Can you not just use a script component for the point in question? Otherwise, what you can do is create a point change detector on the scripts point that triggers set point handler(s) that sets another point(s).

                                Best regards,
                                Matthew

                                1 Reply Last reply Reply Quote 0
                                • D
                                  diegoferreira
                                  last edited by

                                  Thanks, I´ll try this approach!

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post