Help understanding Scripting in HTML Viewer Widget?

I’m not sure if it is possible. I set up the Tutorial in a theoretical way, but it isn’t really working yet. For example, with the iChangeColor(elem,prop,color) function, I set the Invoke Action Parameter as follows:

iChangeColor([:elem], [:prop], [:color])

However, my Rule only shows a setting value for [:color], so I guess I have the Action Parameter set incorrectly, or it only accepts a single [:setting] value. And I can’t get that (1 setting) to work either. Maybe my function is borked. Still playing with it.

I had colors changing, did submit no problem, changed form values, did click methods… it was all working… then I split the Script into several Functions… now I’m not sure any of it works…

I am tyoing with it as well… I actually put that on hold and I am toying with passing values from TimeTrex into command values of SambaPOS.

1 Like

@emre, does the Action Parameter not accept quoted values? I can’t get it to pass the value to the function. Neither of these work:

iChangeColor('#FFFF00')
iChangeColor('Yellow')

Only this works (no quotes):

iChangeColor(Yellow)

And what about default values for a function in the Script, like this…

function iChangeColor(icolor='#000000') {
     document.body.style.backgroundColor=icolor;
}

The only time I’ve been successful at iChangeColor() is when I set the value directly in the script, or use a quote-less value passed in:

function iChangeColor(icolor) {
     document.body.style.backgroundColor='#FF0000';
}

I just successfully made the folowing behavior… I added a button called Clock Out on the same screen as my TimeTrex HTml viewer… when pressed it invoked the Clock out portion of TimeTrex which caused timetrex to record the punch and then send another value back to SambaPOS telling Samba to logout… lol it worked great… Not sure I would use that but it worked!

The really cool thing is… i was able to record a punch inside timetrex WITHOUT all the fancy API calls and .bat stuff I was using. Now thats not to say I would still need that stuff for automation at Login etc… because this only works with HTML widget on screen.

So right now its neat that I got it to work but its not really that functional of a feature because I could just press logout from Timetrex without having to use the extra step of clicking a samba button. This does tell me I can do some cool things that would definitely be functional though.

That unlocks protection against ghosts amulet + 100 experience.

Have fun :ghost:

1 Like

If you include quotes that will be a value with quotes. Just like a quote in a word. This is not a JS parsing. We only need a function name and parameters. It could be iChangeColor,blue or something else. I’ve just formatted it like F(x) to make it look like a function.

OK that’s not so important. Doesn’t it work when you do not include quotes?

@emre, Excluding quotes, this works:

iChangeColor(Yellow)

This does not:

iChangeColor(#FFFF00)

This also does not work:

// script with default value for icolor
function iChangeColor(icolor='#FF0000') {
    document.body.style.backgroundColor=icolor;
}

Subsequently, call the function via HTML Invoke Action:

iChangeColor(Yellow)

That is to say, as soon as I define a default value for the parameter in the function, no value is successfully passed through, quoted or not.

I’ve improved it a bit. I hope it works better on next update.

1 Like

I’ve just added {:SETTING} tag support for scripts.

Thanks for that @emre.

I realize this is a bit of a side-feature that isn’t necessarily that important, but if Javascript Injection and Function Invocation works as we expect it to, the possibilities are tremendous.

However, if we need to change the way we know to code in Javascript, it becomes cumbersome and unnatural. I hope you can appreciate that.

LOL I should admit that was a silly feature.

I was planning using eval function to execute an anonymous function as parameter. So we may not need to inject script for simple tasks and I thought that might be useful there but it won’t :slight_smile: I’m rolling it back.

Whoah, what do you mean? I hope you don’t mean what I think you mean, because…

Are you saying eval() is just as good or better and that you’ll switch to that? I hope so, because I don’t want to see this power disappear. Not just @Jesse is giddy about the possibilities, so am I… as are others I’m sure.

No I won’t switch to that. We’ll have injection…

For next version I thought we may configure invoke script parameter as

eval(document.body.style.backgroundColor='#F0000')

that won’t need script injection.

I also thought we may configure it as

eval(document.body.style.backgroundColor={:COLOR})

That was the reason of {:SETTING} support but it is useless as we won’t need to configure it as a script and just pass it as a rule parameter. So I meant to roll back setting support.

sorry if it was confusing :slight_smile: I’ve even didn’t tested if it is possible or not. I was both implementing scripts and entity logs together.

Yahoo! Can’t wait for that!

Back on topic for this thread then…

I set the Action Parameter to Invoke this function as such

iChangeColor([:elem], [:prop], [:color])

I thought my Rule might give me access to all those settings. However, my Rule only shows a setting value for [:color]… so does it only accept a single [:setting] value right now? Can this be examined and expanded?

If those are settings you should type it as iChangeColor({:elem}, {:prop}, {:color})

Really? Since when?

Read this :slight_smile:

1 Like

LOL, funny guy - you know I wrote that. :wink:

Ok, maybe I’m using the wrong terminology. I don’t want to access settings; I want to “prompt” for input to the Action within the Rule, so as far as I know, the syntax is:

 [:HeyIamAnActionSoGiveMeAvalueFromTheRuleToPutInHere]
1 Like

Yes we call that a Variable. I’ll check why it does not support multiple variables.

1 Like

This works now:

iChangeColor(#FFFF00)

This still does not work:

// script with default value for icolor
function iChangeColor(icolor=#FF0000) {
    document.body.style.backgroundColor=icolor;
}

Instead, I have to do an explicit check within the function; this works:

function iChangeColor(icolor) {
    if (icolor==undefined) {
        icolor='#FF0000';
    }
    document.body.style.backgroundColor=icolor;
}

Multiple variables are now presented to the Rule:

iChangeColor([:elem],[:prop],[:color])

However, if I do not specify a value for the first 2 variables, then the last variable (color) remains undefined, so my function uses a default (red):

function iChangeColor(ielem,iprop,icolor) {
    if (ielem==undefined) {
        ielem='body';
    }
    if (iprop==undefined) {
        iprop='backgroundColor';
    }
    if (icolor==undefined) {
        icolor='#FF0000';
    }
    document.body.style.backgroundColor=icolor;
}

Workaround: supply values for everything (this works):

Good improvements, thanks @emre!

1 Like