Add toggle button support to core, tidying up debug node

This commit is contained in:
Nicholas O'Leary
2013-10-28 16:45:31 +00:00
parent 87fdc74ed0
commit 948cbc537e
3 changed files with 60 additions and 35 deletions

View File

@@ -59,16 +59,10 @@
icon: "debug.png",
align: "right",
button: {
color: function() {
return (typeof this.active === 'undefined') ? ("#87a980" ) : (this.active ? "#87a980" : "#b9b9b9");
},
wide: function() {
return (typeof this.active === 'undefined') ? 100 : (this.active ? 100 : 110);
},
toggle: "active",
onclick: function() {
var label = this.name||"debug";
var node = this;
d3.xhr("debug/"+this.id).post(function(err,resp) {
d3.xhr("debug/"+this.id+"/"+(this.active?"enable":"disable")).post(function(err,resp) {
if (err) {
if (err.status == 404) {
RED.notify("<strong>Error</strong>: debug node not deployed","error");
@@ -79,14 +73,8 @@
}
} else if (resp.status == 200) {
RED.notify("Successfully activated: "+label,"success");
node.active = true;
node.dirty = true;
RED.view.redraw();
} else if (resp.status == 201) {
RED.notify("Successfully deactivated: "+label,"success");
node.active = false;
node.dirty = true;
RED.view.redraw();
} else {
RED.notify("<strong>Error</strong>: unexpected response: ("+resp.status+") "+resp.response,"error");
}

View File

@@ -100,16 +100,19 @@ DebugNode.logHandler.on("log",function(msg) {
});
RED.nodes.addLogHandler(DebugNode.logHandler);
RED.app.post("/debug/:id", function(req,res) {
RED.app.post("/debug/:id/:state", function(req,res) {
var node = RED.nodes.getNode(req.params.id);
var state = req.params.state;
if (node != null) {
if (node.active) {
node.active = false;
if (state === "enable") {
node.active = true;
res.send(201);
} else {
node.active = true;
} else if (state === "disable") {
node.active = false;
res.send(200);
}
} else {
res.send(404);
}
} else {
res.send(404);
}