Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_toast.js 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module.exports = function(RED) {
  2. var ui = require('../ui')(RED);
  3. function ToastNode(config) {
  4. RED.nodes.createNode(this, config);
  5. if (config.hasOwnProperty("displayTime") && (config.displayTime.length > 0)) {
  6. try { this.displayTime = parseFloat(config.displayTime) * 1000; }
  7. catch(e) { this.displayTime = 3000; }
  8. }
  9. this.position = config.position || "top right";
  10. this.highlight = config.highlight;
  11. this.ok = config.ok;
  12. this.cancel = config.cancel;
  13. this.className = config.className;
  14. this.topic = config.topic;
  15. if (config.sendall === undefined) { this.sendall = true; }
  16. else { this.sendall = config.sendall; }
  17. this.raw = config.raw || false;
  18. var node = this;
  19. // var noscript = function (content) {
  20. // if (typeof content === "object") { return null; }
  21. // content = '' + content;
  22. // content = content.replace(/<.*cript.*/ig, '');
  23. // content = content.replace(/.on\w+=.*".*"/g, '');
  24. // content = content.replace(/.on\w+=.*\'.*\'/g, '');
  25. // return content;
  26. // }
  27. var done = ui.add({
  28. node: node,
  29. control: {},
  30. storeFrontEndInputAsState: false,
  31. forwardInputMessages: false,
  32. beforeSend: function (msg) {
  33. var m = msg.payload.msg;
  34. m.topic = node.topic || m.topic;
  35. return m;
  36. }
  37. });
  38. node.on('input', function(msg) {
  39. if (node.sendall === true) { delete msg.socketid; }
  40. var dt = node.displayTime || msg.timeout * 1000 || 3000;
  41. if (dt <= 0) { dt = 1; }
  42. //msg.payload = noscript(msg.payload);
  43. ui.emitSocket('show-toast', {
  44. title: node.topic || msg.topic,
  45. toastClass: node.className || msg.className,
  46. message: msg.payload,
  47. highlight: node.highlight || msg.highlight,
  48. displayTime: dt,
  49. position: node.position,
  50. id: node.id,
  51. dialog: (node.position === "dialog" || node.position === "prompt") || false,
  52. prompt: (node.position === "prompt") || false,
  53. ok: node.ok,
  54. cancel: node.cancel,
  55. socketid: msg.socketid,
  56. raw: node.raw,
  57. msg: msg
  58. });
  59. });
  60. node.on("close", done);
  61. }
  62. RED.nodes.registerType("ui_toast", ToastNode);
  63. };