Dashboard: New Version of OK/cancel with input message node - helper subflow

My original post is closed so here you have a new one:

image

I updated my OK/Cancel helper subflow. Perhaps it could be useful for others. It now handle the socketid of the desired dashboard and work with OK/cancel with input too

It is important that you pass the socketid with your message msg.socketid to avoid the dialog poping up on all open dashboards. If you like to have it open on all screens delete msg.socketid before. BTW you can use the OK/Cancel subfow now for imputs too. Due to the nature of the message node you then have to enter the cancel condition instead of the OK condition because the payload contains then either the entered value or (in most cases) "cancel" ("Abbruch" if you work on a German UI). I left the OK condition in for compatibility reasons.

Hope this helps.

[{"id":"fd36bbc4.fe50d8","type":"subflow","name":"OK/Cancel helper","info":"# OK/Cancel dialog helper\n\n## description\n\nThis is a little helper to make OK/Cancel dialogs easy to implement inside a data stream\n\n## how it works\n\nIf a message arrives at the **imput** a message dialog box is triggered. The original Message is cloned into `msg.dialogHelperOrgMsg`. If the dialog sends `msg.payload` with the **passPayload** the original message is released on the second output.\n\nIf you use the message node \"with input\" enter your cancel payload instead pass payload as `msg.payload` will include the entered text.\n\nmake shure you pass `msg.socketid`of the session you like the dialog to be displayed.\n\n## configuration\n\n- **Title** ***optional** a string displayed on the title of the dialog\n- **Message** message to be displayed\n- **passPayload** the `msg.payload` expected on the imput to release to original message.\n- **cancelPayload** if this subflow is used for text imput dialogs enter your cancel payload instead pass payload als `msg.payload` will include the ented text.","category":"","in":[{"x":37,"y":85,"wires":[{"id":"6a44f1d4.72a75"}]}],"out":[{"x":343,"y":85,"wires":[{"id":"6a44f1d4.72a75","port":1}]},{"x":343,"y":136,"wires":[{"id":"6a44f1d4.72a75","port":2}]}],"env":[{"name":"title","type":"str","value":"Please Confirm","ui":{"icon":"font-awesome/fa-comment","label":{"en-US":"Title"},"type":"input","opts":{"types":["str","env"]}}},{"name":"message","type":"str","value":"should the message pass on?","ui":{"icon":"font-awesome/fa-comment-o","label":{"en-US":"Message"},"type":"input","opts":{"types":["str","env"]}}},{"name":"passPayload","type":"str","value":"OK","ui":{"icon":"font-awesome/fa-check-square-o","type":"input","opts":{"types":["str","env"]}}},{"name":"cancelPayload","type":"str","value":"Cancel"}],"color":"#3FADB5","icon":"font-awesome/fa-comments-o","status":{"x":343,"y":34,"wires":[{"id":"6a44f1d4.72a75","port":0}]}},{"id":"6a44f1d4.72a75","type":"function","z":"fd36bbc4.fe50d8","name":"confirm","func":"var status={fill:\"\",shape:\"dot\",text:\"\"};\nif (msg!==undefined && !msg.hasOwnProperty(\"dialogHelperOrgMsg\")) { // no message in queue\n    var dialogMsg={\n        topic:env.get('title'),\n        payload:env.get('message'),\n        socketid:msg.socketid,\n        dialogHelperOrgMsg:RED.util.cloneMessage(msg)\n    };\n    status={fill:\"yellow\",shape:\"dot\",text:\"waiting for response\"};\n    return [{payload:status},dialogMsg,null];\n} else {\n    var cancelPayload=env.get('cancelPayload').toLowerCase();\n    var passPayload=env.get('passPayload').toLowerCase();\n    if (passPayload!=='') {\n        if (msg.payload.toLowerCase()===passPayload) {\n            status={fill:\"green\",shape:\"dot\",text:\"message passed\"};\n            return [{payload:status},null,msg.dialogHelperOrgMsg];\n        } else {\n            status={fill:\"blue\",shape:\"dot\",text:msg.payload+\"==(!\"+passPayload+\") message droped\"};\n            return [{payload:status},null,null];\n        }\n    } else if (cancelPayload!=='') {\n        if (msg.payload.toLowerCase()!==cancelPayload) {\n            status={fill:\"green\",shape:\"dot\",text:\"message passed\"};\n            msg.dialogHelperOrgMsg.payload.input=msg.payload; // add input to msg.payload\n            return [{payload:status},null,msg.dialogHelperOrgMsg];\n        } else {\n            status={fill:\"blue\",shape:\"dot\",text:msg.payload+\"==(\"+cancelPayload+\") message droped\"};\n            return [{payload:status},null,null];\n        }        \n    } else {\n        status={fill:\"red\",shape:\"dot\",text:\"pass or cancel payload undefined\"};\n        return [{payload:status},null,null];\n    }\n}","outputs":3,"noerr":0,"x":196,"y":85,"wires":[[],[],[]],"info":"# OK/Cancel dialog helper function\n\n## description\n\nThis is a little helper to make OK/Cancel dialogs easy to implement inside a data stream\n\n## how it works\n\nIf a message arrives at the **imput** a message dialog box is triggered. The original Message is cloned into `msg.dialogHelperOrgMsg`. If the dialog sends `msg.payload` with the **passPayload** the original message is released on the second output.\n\n## envioment variables\n\n- **title** ***optional** a string displayed on the title of the dialog\n- **message** message to be displayed\n- **passPayload** the `msg.payload` expected on the imput to release to original message."},{"id":"22cd7020.bc418","type":"subflow:fd36bbc4.fe50d8","z":"ff359c1a.20955","name":"new Program?","env":[{"name":"title","value":"create new program","type":"str"},{"name":"message","value":"Name","type":"str"},{"name":"passPayload","value":"","type":"str"}],"x":1168,"y":612,"wires":[["d859babc.c28248"],["ae255bf0.36dbf8"]]}]

As always: Feedback welcome!

This topic was automatically closed after 60 days. New replies are no longer allowed.