From 4689d56955b9b2f6305e3efa47dc9ceed5d991a4 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sun, 23 Apr 2017 23:20:50 +0100 Subject: [PATCH] Allow a node to decide for itself if its button should be enabled or not This means: 1. an Inject node that has only been moved can still inject 2. the Debug node is now marked as changed when its button is clicked which, without this fix, then prevented the button from being clicked to toggle its state again --- editor/js/ui/view.js | 28 +++++++++++++++++++--------- nodes/core/core/20-inject.html | 13 ++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/editor/js/ui/view.js b/editor/js/ui/view.js index bd1b9a5d0..b67a91d0a 100644 --- a/editor/js/ui/view.js +++ b/editor/js/ui/view.js @@ -1680,8 +1680,20 @@ RED.view = (function() { d3.event.stopPropagation(); } + function isButtonEnabled(d) { + var buttonEnabled = true; + if (d._def.button.hasOwnProperty('enabled')) { + if (typeof d._def.button.enabled === "function") { + buttonEnabled = d._def.button.enabled.call(d); + } else { + buttonEnabled = d._def.button.enabled; + } + } + return buttonEnabled; + } + function nodeButtonClicked(d) { - if (!activeSubflow && !d.changed) { + if (!activeSubflow) { if (d._def.button.toggle) { d[d._def.button.toggle] = !d[d._def.button.toggle]; d.dirty = true; @@ -1696,8 +1708,6 @@ RED.view = (function() { if (d.dirty) { redraw(); } - } else if (d.changed) { - RED.notify(RED._("notification.warning", {message:RED._("notification.warnings.undeployedChanges")}),"warning"); } else { RED.notify(RED._("notification.warning", {message:RED._("notification.warnings.nodeActionDisabled")}),"warning"); } @@ -1890,10 +1900,10 @@ RED.view = (function() { .attr("height",node_height-12) .attr("fill",function(d) { return d._def.color;}) .attr("cursor","pointer") - .on("mousedown",function(d) {if (!lasso && !d.changed) {focusView();d3.select(this).attr("fill-opacity",0.2);d3.event.preventDefault(); d3.event.stopPropagation();}}) - .on("mouseup",function(d) {if (!lasso && !d.changed) { d3.select(this).attr("fill-opacity",0.4);d3.event.preventDefault();d3.event.stopPropagation();}}) - .on("mouseover",function(d) {if (!lasso && !d.changed) { d3.select(this).attr("fill-opacity",0.4);}}) - .on("mouseout",function(d) {if (!lasso && !d.changed) { + .on("mousedown",function(d) {if (!lasso && isButtonEnabled(d)) {focusView();d3.select(this).attr("fill-opacity",0.2);d3.event.preventDefault(); d3.event.stopPropagation();}}) + .on("mouseup",function(d) {if (!lasso && isButtonEnabled(d)) { d3.select(this).attr("fill-opacity",0.4);d3.event.preventDefault();d3.event.stopPropagation();}}) + .on("mouseover",function(d) {if (!lasso && isButtonEnabled(d)) { d3.select(this).attr("fill-opacity",0.4);}}) + .on("mouseout",function(d) {if (!lasso && isButtonEnabled(d)) { var op = 1; if (d._def.button.toggle) { op = d[d._def.button.toggle]?1:0.2; @@ -2177,10 +2187,10 @@ RED.view = (function() { thisNode.selectAll(".node_icon_shade_border").attr("d",function(d){ return "M "+(("right" == d._def.align) ?0:30)+" 1 l 0 "+(d.h-2)}); thisNode.selectAll(".node_button").attr("opacity",function(d) { - return (activeSubflow||d.changed)?0.4:1 + return (activeSubflow||!isButtonEnabled(d))?0.4:1 }); thisNode.selectAll(".node_button_button").attr("cursor",function(d) { - return (activeSubflow||d.changed)?"":"pointer"; + return (activeSubflow||!isButtonEnabled(d))?"":"pointer"; }); thisNode.selectAll(".node_right_button").attr("transform",function(d){ var x = d.w-6; diff --git a/nodes/core/core/20-inject.html b/nodes/core/core/20-inject.html index a883daf01..0151e08aa 100644 --- a/nodes/core/core/20-inject.html +++ b/nodes/core/core/20-inject.html @@ -510,8 +510,19 @@ If you want every 20 minutes from now - use the "interval" option.

$("#node-input-crontab").val(crontab); }, button: { + enabled: function() { + return !this.changed + }, onclick: function() { - var label = (this.name||this.payload).replace(/&/g,"&").replace(//g,">"); + if (this.changed) { + return RED.notify(RED._("notification.warning", {message:RED._("notification.warnings.undeployedChanges")}),"warning"); + } + var label = (this.name||this.payload); + if (label.length > 30) { + label = label.substring(0,50)+"..."; + } + label = label.replace(/&/g,"&").replace(//g,">"); + if (this.payloadType === "date") { label = this._("inject.timestamp"); } if (this.payloadType === "none") { label = this._("inject.blank"); } var node = this;