Tidy up REST interface

- Ensure application/json where appropriate
 - Use jquery api rather than d3
This commit is contained in:
Nick O'Leary
2014-04-15 22:30:07 +01:00
parent d702caa5be
commit d00624f9e3
3 changed files with 53 additions and 62 deletions

View File

@@ -80,30 +80,35 @@ var RED = function() {
$("#btn-icn-deploy").addClass('spinner');
RED.view.dirty(false);
d3.xhr("flows").header("Content-type", "application/json")
.post(JSON.stringify(nns),function(err,resp) {
$("#btn-icn-deploy").removeClass('spinner');
$("#btn-icn-deploy").addClass('icon-upload');
if (resp && resp.status == 204) {
RED.notify("Successfully deployed","success");
RED.nodes.eachNode(function(node) {
if (node.changed) {
node.dirty = true;
node.changed = false;
}
});
// Once deployed, cannot undo back to a clean state
RED.history.markAllDirty();
RED.view.redraw();
} else {
RED.view.dirty(true);
if (resp) {
RED.notify("<strong>Error</strong>: "+resp,"error");
} else {
RED.notify("<strong>Error</strong>: no response from server","error");
}
console.log(err,resp);
$.ajax({
url:"flows",
type: "POST",
data: JSON.stringify(nns),
contentType: "application/json; charset=utf-8"
}).done(function(data,textStatus,xhr) {
RED.notify("Successfully deployed","success");
RED.nodes.eachNode(function(node) {
if (node.changed) {
node.dirty = true;
node.changed = false;
}
});
// Once deployed, cannot undo back to a clean state
RED.history.markAllDirty();
RED.view.redraw();
}).fail(function(xhr,textStatus,err) {
RED.view.dirty(true);
console.log(xhr);
console.log(textStatus);
console.log(err);
if (xhr.responseText) {
RED.notify("<strong>Error</strong>: "+xhr.responseText,"error");
} else {
RED.notify("<strong>Error</strong>: no response from server","error");
}
}).always(function() {
$("#btn-icn-deploy").removeClass('spinner');
$("#btn-icn-deploy").addClass('icon-upload');
});
}
}
@@ -150,7 +155,7 @@ var RED = function() {
}
function loadFlows() {
d3.json("flows",function(nodes) {
$.getJSON("flows",function(nodes) {
RED.nodes.import(nodes);
RED.view.dirty(false);
RED.view.redraw();