Dashboard button with confirm

1,248 views
Skip to first unread message

Colin Law

unread,
Jan 12, 2018, 4:33:21 AM1/12/18
to node...@googlegroups.com
Is there a simple way of getting an Ok/Cancel confirm dialog upon clicking a dashboard button node?  I expected to find something searching here, the flows or google but have not come up with anything.

Colin

Nick O'Leary

unread,
Jan 12, 2018, 4:52:30 AM1/12/18
to Node-RED Mailing List
You can use a ui_notification node configured as an OK/Cancel Dialog.

Nick

On 12 January 2018 at 09:32, Colin Law <cla...@gmail.com> wrote:
Is there a simple way of getting an Ok/Cancel confirm dialog upon clicking a dashboard button node?  I expected to find something searching here, the flows or google but have not come up with anything.

Colin

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/CAL%3D0gLuD9ha9Bth5y1e6fDeNS_w_OWHHVkjU5rGsgBbJhETQgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Colin Law

unread,
Jan 12, 2018, 5:10:22 AM1/12/18
to node...@googlegroups.com
Brilliant, thanks NIck. Somehow I had missed the existence of that node.

Colin

Bart Butenaers

unread,
Jan 12, 2018, 7:27:35 AM1/12/18
to Node-RED
Hi Colin,

That is indeed a very useful node. You can also format the text in the dialog as HTML, which can be quite handy (e.g. to ask confirmation for multiple things)...

See https://github.com/node-red/node-red-dashboard/issues/253

Bart

Walter

unread,
Jan 12, 2018, 10:23:20 AM1/12/18
to Node-RED
Another way:

[{"id":"f1dd8826.255808","type":"function","z":"96082429.7476f8","name":"CountdownV4.1","func":"//-----------------------------------------------------------------\nvar tmrid = context.get('tmrid') || undefined;\nvar msgb = {};\nvar msga = {};\nvar state = 0;\n\nvar ap = JSON.parse(msg.topic);\nif (tmrid !== undefined)  {\n    clearTimeout(tmrid);\n    context.set('tmrid',undefined);\n    flow.set(ap.group,undefined);\n    msgb =  {\"payload\": {\"color\": ap.coloraction, \"label\": ap.labelabort.replace(\"@time@\",formatTime(state-1)) }}\n    \n    if (ap.abortaction.length > 0)\n        msga = {\"payload\": ap.abortaction, \"topic\": ap.topic};\n    else \n        msga = null;\n    state = 0;\n    setTimeout(timer,1000);\n}\nelse {\n    state = ap.intervall + 1; //init\n    tmrid = setInterval(timer,1000);\n    context.set('tmrid',tmrid);\n    flow.set(ap.group,tmrid);\n    msgb =  {\"payload\": {\"color\": ap.coloraction, \"label\": ap.labeltimer.replace(\"@time@\",formatTime(state-1)) }};\n    if (ap.action.length > 0)\n        msga = {\"payload\": ap.action, \"topic\": ap.topic};\n    else \n        msga = null;\n//    setTimeout(sendDelayed,535);\n}\n//return null;\nreturn [msgb,msga];\n\nfunction sendDelayed() {\n    node.send([msgb,msga]); \n}\n\nfunction timer() {\n    if (state > 0)  {\n        if (state == 1 && ap.labelaction !== undefined) \n            msgb =  {\"payload\": {\"color\": ap.coloraction, \"label\": ap.labelaction.replace(\"@time@\",formatTime(state-1)) }}\n        else\n            msgb =  {\"payload\": {\"color\": ap.coloraction, \"label\": ap.labeltimer.replace(\"@time@\",formatTime(state-1)) }}\n        msga = null;\n        state--;\n        if (flow.get(ap.group) != tmrid) {\n            clearTimeout(tmrid);\n            context.set('tmrid',undefined);\n            msgb =  {\"payload\": {\"color\": ap.colorend,\"label\": ap.labelend}};\n            msga = null;\n        }\n    } \n    else {                  \n        clearTimeout(tmrid);\n        context.set('tmrid',undefined);\n        flow.set(ap.group,undefined);\n        msgb =  {\"payload\": {\"color\": ap.colorend,\"label\": ap.labelend}};\n        if (ap.endaction.length > 0)\n            msga = {\"payload\": ap.endaction, \"topic\": ap.topic};\n        else \n            msga = null;\n        \n    }\n    node.send([msgb,msga]);\n}\n\nfunction formatTime(s){return(s-(s%=60))/60+(9<s?':':':0')+s}","outputs":"2","noerr":0,"x":659,"y":4043,"wires":[["34494d18.264072"],["609fec03.c698b4"]]},{"id":"34494d18.264072","type":"ui_button","z":"96082429.7476f8","name":"Unlock door","group":"519547e4.700b88","order":2,"width":"10","height":"4","passthru":false,"label":"{{msg.payload.label || \"Unlock door\"}} ","color":"","bgcolor":"","icon":"fa-unlock","payload":"unlock","payloadType":"str","topic":"{\"group\":\"lock\",\"intervall\": 5, \"labelend\":\"Unlock door\", \"labeltimer\":\"Really unlock? (@time@)\", \"labelabort\": \"Unlocking...\", \"labelaction\": \"Unlock door\", \"action\": \"\", \"coloraction\": \"Gold\", \"endaction\": \"\", \"colorend\": \"rgb(221, 221, 221)\", \"abortaction\": \"1\", \"topic\":\"hm/set/DoorLock/STATE\"}","x":659,"y":3988,"wires":[["f1dd8826.255808"]]},{"id":"609fec03.c698b4","type":"debug","z":"96082429.7476f8","name":"","active":true,"console":"false","complete":"true","x":881,"y":4045,"wires":[]},{"id":"519547e4.700b88","type":"ui_group","z":"","name":"Default","tab":"ea3bbdb9.e28e7","disp":true,"width":"12"},{"id":"ea3bbdb9.e28e7","type":"ui_tab","z":"","name":"Home","icon":"dashboard"}]

Colin Law

unread,
Jan 12, 2018, 11:43:44 AM1/12/18
to node...@googlegroups.com
Thanks Walter, though I think that is a little OTT for what I am need.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
Reply all
Reply to author
Forward
0 new messages