diff --git a/lib/httpd.js b/lib/httpd.js index 3ff58cd..d87b9a2 100644 --- a/lib/httpd.js +++ b/lib/httpd.js @@ -261,7 +261,7 @@ module.exports.create = function (cli, engine/*, dnsd*/) { }); } else { engine.records.save(record, function (err, record) { - res.send({ success: true }); + res.send({ success: true, id: record.id }); }); } }); diff --git a/lib/public/js/app.js b/lib/public/js/app.js index 9efde37..1a49681 100644 --- a/lib/public/js/app.js +++ b/lib/public/js/app.js @@ -361,29 +361,35 @@ }); } - if (change) { - renderRecords(); - - return window.fetch( - '/api/records/' + record.id - , { method: 'POST' - , headers: new window.Headers({ - 'Authorization': 'Bearer ' + auth - , 'Content-Type': 'application/json;charset=UTF-8' - }) - , body: JSON.stringify(record) - } - ).then(function (resp) { - return resp.json().then(function (data) { - if (data.error) { - console.error(data); - window.alert(data.error.message); - return; - } - console.log('result:', data); - }); - }); + if (!change) { + return; } + + renderRecords(); + + return window.fetch( + '/api/records/' + record.id + , { method: 'POST' + , headers: new window.Headers({ + 'Authorization': 'Bearer ' + auth + , 'Content-Type': 'application/json;charset=UTF-8' + }) + , body: JSON.stringify(record) + } + ).then(function (resp) { + return resp.json().then(function (data) { + if (data.error) { + console.error(data); + window.alert(data.error.message); + return; + } + console.log('result:', data); + if (!record.id) { + record.id = data.id; + renderRecords(); + } + }); + }); }); $qs('select.js-record-form-type').value = '';