This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Custom JavaScript examples
Добрый день.
Появилась задача. При присвоении объекту определенного значения нужно открыть план. Не могли бы вы мне с этим помочь? Как я понимаю слушатель должен быть привязан к объекту допустим 1/1/1 и
если объект изменил значение на 1, то showPlan(11);
если 2, то showPlan(12);
если 3, то showPlan(13);
Это как я понимаю решается через "case", я не знаю JS.
Кроме того мне это нужно не для vis, а для touch
Reply
Please post in English next time Smile
The task is to show a specific plan depending on a certain object value.
Code:
$(function(){
  if (typeof grp != 'undefined') {
    grp.listen('1/1/1', function(object, state) {
      var value = object.value;
      if (state == 'value') {
        if (value == 1) {
          showPlan(11);
        }
        else if (value == 2) {
          showPlan(12);
        }
        else if (value == 3) {
          showPlan(13);
        }
      }
    });
  }
});
Reply
(16.12.2016, 14:58)admin Wrote: Please post in English next time Smile
The task is to show a specific plan depending on a certain object value.
Code:
$(function(){
 if (typeof grp != 'undefined') {
   grp.listen('1/1/1', function(object, state) {
     var value = object.value;
     if (state == 'value') {
       if (value == 1) {
         showPlan(11);
       }
       else if (value == 2) {
         showPlan(12);
       }
       else if (value == 3) {
         showPlan(13);
       }
     }
   });
 }
});
Thank you very much. As it is applied to the "Touch"?
Reply
Yes, it will work in both visualizations
Reply
Is there any way to hide a object from visu when there´s no value? I´m monitoring a 4 byte float kW object, but there´s no point in having it show in visu when it´s 0.00 kW.
Reply
(24.12.2016, 00:08)FatMax Wrote: Is there any way to hide a object from visu when there´s no value? I´m monitoring a 4 byte float kW object, but there´s no point in having it show in visu when it´s 0.00 kW.

This script should work. You must add to this object in visualisation editor text "power" in Additional classes and change the value for nothing(now is '0 kWh', can be empty '''). You can also change the color of this text e.g. black when 0 and yellow when more than 0.
Code:
//Change text to nothing when 0,00 kWh
$(function(){
 function power_update(){
 // Set values
 var nothing = '0 kWh' // value for nothing
    
 power = parseFloat( $('.power').html() )
 if ( power == 0 || power == nothing ){
 $('.power').html(nothing);
 }
 }
 
 // Check for changes on value of item with power
 $(".power").bind("DOMSubtreeModified",function(){
   power_update();
 });
 
 // Initial execution
 power_update();
});
Reply
How open do not plan visualization, and widget. And its close at the end of time?
Reply
Hi everyone!
I will say Roman's quastion with another words:
is there way to make widget autoclosing function. He need 1 widget which can close itself after some time
Reply
Do somebody know how can I use in javascript:
- storage,
- trends?
Reply
Information about accessing to storage via javascript you can found here: http://forum.logicmachine.net/showthread.php?tid=85

Everything working great.
Reply
(19.01.2017, 11:30)Pawel Wrote: Information about accessing to storage via javascript you can found here: http://forum.logicmachine.net/showthread.php?tid=85

Everything working great.

Thanks Pawel, yes now I see that this is a solution but maybe do you know if there is some other way without creating a .lp file e.g. using lua in javascript? or exchanging some variables to this .lp?

And also can you describe the mechanism of .lp files? Because this is for me now a little abstraction. Are these scripts run residentlyin the background or only when there is some request from js or apps?
Reply
Hi Buuuudzik,

A .lp file is used for client side LUA scripting, the .lp file is executed once during page load, at that moment the LUA is executed and data is requested from server and the reply is transfered to client and you can use the reply as JSON object.

When you want new data you have to do a http (xhtml / ajax) request to the .lp file (even with arguments) to get new or other information from the server. This way you can do a normal storage.get / storage.set LUA command (basicly any LUA command available inside the LM) and transfer the reply to a JSON object to use on client side.

The content inside the .lp file is very flexible and when you master this you can build whatever you need.

So there is nothing running on de background, only on page load and when you do a xhtml / ajax request to the .lp file.

BR,

Erwin
Reply
I see that this is a very nice tool. I've prepared what I wanted, script which read trends and calculate the cost of outdoor heating for defined periods and this is exported as a JSON.
I see this is a very elastic tool but is there a possibility to send an ajax request with some variables.

E.g. in .lp file there is an universal function for cost calculation and in javascript there is a possibility to select for what number of days.
Reply
Hi Buuuudzik,

Yes you can send vars by the request by using xxx.xxx.xxx.xxx/yourfile.lp?argument1=yourfirstvalue&argument2=yoursecondvalue etcetera and than fetch them in your .lp file with:

Code:
require('apps')

argument1 = getvar('argument1')
argument2 = getvar('argument2')
 
or if your values need to be escaped use:

Code:
require('apps')
require('socket.url')

argument1 = socket.url.unescape(getvar('argument1'))
argument2 = socket.url.unescape(getvar('argument2'))

BR,

Erwin
Reply
Wink 
I didn't know about this so YES definitely this is an amazing tool! And of course thank you Erwin, you're traditionally a few(or much more) levels before me Smile  I only try to learn new things for having a good products for my clients Wink  Thanks


So this is right way for run the .lp file with some arguments from outside?
Code:
$.get( "/user/systemtime.lp?argument1=yourfirstvalue&argument2=yoursecondvalue", function( data ) {
Reply
Maybe somebody has some advice,

when I write custom javascripts and when I use jQuery to find objects everytime I has in the console a lot of founded objects and I think this is not caused by too wide filter but this is something else. It looks like the objects from scada-vis are also in trends and schedulers.

For examle this 2 scripts for find a object with class '.sekator' generates the same result in console.log() (see screenshot).

Script 1:
Code:
$(function(){
var sekator = $('#plan-1').find('.sekator')
console.log(sekator)
});

Script 2:
Code:
$(function(){
var sekator = $('.sekator')
console.log(sekator)
});

Is this result from console.log() is normal or can I something improve?

Attached Files Thumbnail(s)
   
Reply
Custom JS runs both visualizations, trends and schedulers. If you have some specific functions for visualization only, you can check the type like this:
Code:
$(function() {
  if (!$('body').hasClass('usermode')) {
    return;
  }

  // do something only in user visualization, not touch, trends, schedulers
});
Reply
Thanks admin for advice Smile

I've checked this on the other LM which I've cleaned to only 1 visupage and 1 trend and 2 schedulers and I see that javascripts are working then perfectly.

No such situation with searching something in other places. And also e.g this function is run only 1 time and I have in consol.log() only 1 result(but on my LM LB there is a lot of):
Code:
$(function(){
 var image12 = $(".image12");
 console.log(image12)
});
I've tried delete whole scripts from custom javascript from LM LB and start again but unfortunately this is not a solution.

But your advice Idea is the solution. It looks that loading is little shorter. Perfectly. Thanks Smile
Reply
Maybe somebody knows how can I edit the svg which is the background of a plan? I tried but I can't reach what is inside this svg, only source. It looks like this kind of images has some security or aren't editable.
Reply
SVG backgrounds are placed using <img> tag so you cannot access the SVG document via JS. You can create a layout and place your SVG as an image instead of background.
Reply


Forum Jump: