Page 1 of 1
.js Function user variables
Posted: Saturday 19 December 2020 9:59
by Enz0jacco
hey guys,
i've got the following situation:
I use two user variables which can only be either 'Open' or 'Closed'
I want the background color to change according this status.
I tried the following but my js knowledge is not very good:
Code: Select all
function getStatus_v18(block){
var idx = block.idx;
var device = block.device;
if(parseString(device['Data'])='Open'){
block.addClass='Klepopen';
}
else {
block.addClass='Klepdicht';
}
}
any ideas?
Re: .js Function user variables
Posted: Saturday 19 December 2020 10:11
by madpatrick
This is my setup.
in custom.js
Code: Select all
var trigger_207 = false; //Alarm modefunction getStatus_207(block)
function getStatus_207(block) {
var Data = block.device.Data;
var idx = block.idx;
var device = block.device;
if(device['Status']=='On') {
trigger_207 = true;
block.addClass = 'warning1'; // set the addClass parameter for block 207
}
else {
trigger_207 = false;
block.addClass = ''; // reset the addClass parameter for block
}
handleWarning();
}
in custom.css
Code: Select all
.warning1 {
background: rgba(255,0,0,0.6) !important;
background-clip: padding-box;
border: 3px solid white !important;
border-radius: 15px!important;
}
Re: .js Function user variables
Posted: Saturday 19 December 2020 12:39
by Lokonli
Enz0jacco wrote: ↑Saturday 19 December 2020 9:59
hey guys,
i've got the following situation:
I use two user variables which can only be either 'Open' or 'Closed'
I want the background color to change according this status.
I tried the following but my js knowledge is not very good:
Code: Select all
function getStatus_v18(block){
var idx = block.idx;
var device = block.device;
if(parseString(device['Data'])='Open'){
block.addClass='Klepopen';
}
else {
block.addClass='Klepdicht';
}
}
any ideas?
The if statement is wrong. Change it to:
Code: Select all
if(parseString(device['Data'])=='Open'){
(The single '=' is an assignment, for comparison use '==')
Re: .js Function user variables
Posted: Saturday 19 December 2020 13:35
by Enz0jacco
omg silly me, I could've known that.
unfortunately that was not the only problem.
I think maybe that var device and data is not correct but I'm not sure what it should be as it is a user variable.
Re: .js Function user variables
Posted: Saturday 19 December 2020 14:20
by Lokonli
O yes, indeed.
For variables it's device['Value'] instead of device['Data']
Re: .js Function user variables
Posted: Saturday 19 December 2020 14:29
by Enz0jacco
Ok did that and now I think there is something wrong with the getstatus part. I tried to put the v18 between quotes but that doesnt do the trick either.
Re: .js Function user variables
Posted: Saturday 19 December 2020 15:25
by Lokonli
And remove parseString...
Sent from my SM-A320FL using Tapatalk
Re: .js Function user variables
Posted: Saturday 19 December 2020 15:41
by Enz0jacco
ah makes sense ! its working perfectly thnx again!