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_date_picker.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. module.exports = function(RED) {
  2. var ui = require('../ui')(RED);
  3. function DatePickerNode(config) {
  4. RED.nodes.createNode(this, config);
  5. var node = this;
  6. var group = RED.nodes.getNode(config.group);
  7. if (!group) { return; }
  8. var tab = RED.nodes.getNode(group.config.tab);
  9. if (!tab) { return; }
  10. node.on("input", function(msg) {
  11. node.topi = msg.topic;
  12. });
  13. var done = ui.add({
  14. node: node,
  15. tab: tab,
  16. group: group,
  17. forwardInputMessages: config.passthru,
  18. emitOnlyNewValues: false,
  19. control: {
  20. type: 'date-picker',
  21. label: config.label,
  22. order: config.order,
  23. ddd : new Date().setUTCHours(0,0,0,0),
  24. width: config.width || group.config.width || 6,
  25. height: config.height || 1,
  26. className: config.className || '',
  27. },
  28. convert: function (p,o,m) {
  29. var d = new Date(m.payload);
  30. this.control.ddd = d;
  31. return m.payload;
  32. },
  33. beforeEmit: function (msg, value) {
  34. if (value === undefined) { return; }
  35. value = new Date(value);
  36. return { msg:msg, value:value };
  37. },
  38. convertBack: function (value) {
  39. var d = new Date(value).valueOf();
  40. return d;
  41. },
  42. beforeSend: function (msg) {
  43. var t = RED.util.evaluateNodeProperty(config.topic,config.topicType || "str",node,msg) || node.topi;
  44. if (t) { msg.topic = t; }
  45. }
  46. });
  47. node.on("close", done);
  48. }
  49. RED.nodes.registerType("ui_date_picker", DatePickerNode);
  50. };