From 656c803720c74af51345d71f7cc9f196d2c52f12 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 29 Jan 2018 11:35:34 -0700 Subject: [PATCH] add new record --- lib/httpd.js | 2 +- lib/public/js/app.js | 50 +++++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 23 deletions(-) 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 = '';