mirror of
https://github.com/bckelley/cgm-remote-monitor.git
synced 2026-08-24 03:14:12 -05:00
treatments edit/save needed changes, XMLHttp -> $.ajax
This commit is contained in:
@@ -57,7 +57,7 @@ function configure (app, wares, ctx) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.json(created);
|
||||
console.log('Treatment saved');
|
||||
console.log('Treatment saved', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3657,6 +3657,9 @@ function init() {
|
||||
,'This is only a rough estimation that can be very inaccurate and does not replace actual blood testing. The formula used is taken from: Nathan, David M., et al. "Translating the A1C assay into estimated average glucose values." <i>Diabetes care</i> 31.8 (2008): 1473-1478.' : {
|
||||
cs: 'Toto je pouze hrubý odhad, který může být velmi nepřesný a nenahrazuje měření z krve. Vzorec je převzatý z: Nathan, David M., et al. "Translating the A1C assay into estimated average glucose values." <i>Diabetes care</i> 31.8 (2008): 1473-1478.'
|
||||
}
|
||||
,'Saving record failed' : {
|
||||
cs: 'Uložení záznamu selhalo'
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -102,16 +102,18 @@ treatments.report = function report_treatments(datastorage, daystoshow, options)
|
||||
}
|
||||
|
||||
function deleteTreatmentRecord(_id) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('DELETE', '/api/v1/treatments/'+_id, true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||
xhr.setRequestHeader('api-secret', client.hashauth.hash());
|
||||
xhr.onload = function () {
|
||||
if (xhr.statusText!=='OK') {
|
||||
alert(translate('Deleting record failed'));
|
||||
$.ajax({
|
||||
method: 'DELETE'
|
||||
, url: '/api/v1/treatments/' + _id
|
||||
, headers: {
|
||||
'api-secret': client.hashauth.hash()
|
||||
}
|
||||
};
|
||||
xhr.send(null);
|
||||
}).done(function treatmentDeleted (response) {
|
||||
console.info('treatment deleted', response);
|
||||
}).fail(function treatmentDeleteFail (response) {
|
||||
console.info('treatment delete failed', response);
|
||||
alert(translate('Deleting record failed') + '. ' + translate('Status') + ': ' + response.status);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -139,8 +141,10 @@ treatments.report = function report_treatments(datastorage, daystoshow, options)
|
||||
data.insulin = $('#rped_insulinGiven').val();
|
||||
data.notes = $('#rped_adnotes').val();
|
||||
data.enteredBy = $('#rped_enteredBy').val();
|
||||
data.created_at = client.utils.mergeInputTime($('#rped_eventTimeValue').val(), $('#rped_eventDateValue').val());
|
||||
data.eventTime = new Date(client.utils.mergeInputTime($('#rped_eventTimeValue').val(), $('#rped_eventDateValue').val())).toISOString();
|
||||
data.units = options.units;
|
||||
delete data.mills;
|
||||
delete data.created_at;
|
||||
$( this ).dialog('close');
|
||||
saveTreatmentRecord(data);
|
||||
delete datastorage[day];
|
||||
@@ -183,18 +187,20 @@ treatments.report = function report_treatments(datastorage, daystoshow, options)
|
||||
return false;
|
||||
}
|
||||
|
||||
var dataJson = JSON.stringify(data, null, ' ');
|
||||
$.ajax({
|
||||
method: 'PUT'
|
||||
, url: '/api/v1/treatments/'
|
||||
, headers: {
|
||||
'api-secret': client.hashauth.hash()
|
||||
}
|
||||
, data: data
|
||||
}).done(function treatmentSaved (response) {
|
||||
console.info('treatment saved', response);
|
||||
}).fail(function treatmentSaveFail (response) {
|
||||
console.info('treatment save failed', response);
|
||||
alert(translate('Saving record failed') + '. ' + translate('Status') + ': ' + response.status);
|
||||
});
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('PUT', '/api/v1/treatments/', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||
xhr.setRequestHeader('api-secret', client.hashauth.hash());
|
||||
xhr.onload = function () {
|
||||
if (xhr.statusText!=='OK') {
|
||||
alert(translate('Saving record failed'));
|
||||
}
|
||||
};
|
||||
xhr.send(dataJson);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -43,12 +43,17 @@ function storage (env, ctx) {
|
||||
}
|
||||
|
||||
function remove (_id, fn) {
|
||||
return api( ).remove({ '_id': new ObjectID(_id) }, fn);
|
||||
api( ).remove({ '_id': new ObjectID(_id) }, fn);
|
||||
|
||||
ctx.bus.emit('data-received');
|
||||
}
|
||||
|
||||
function save (obj, fn) {
|
||||
obj._id = new ObjectID(obj._id);
|
||||
prepareData(obj);
|
||||
api().save(obj, fn);
|
||||
|
||||
ctx.bus.emit('data-received');
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +89,7 @@ function prepareData(obj) {
|
||||
}
|
||||
|
||||
obj.created_at = results.created_at.toISOString();
|
||||
if (obj.preBolus !== 0 && obj.carbs) {
|
||||
if (obj.preBolus && obj.preBolus !== 0 && obj.carbs) {
|
||||
results.preBolusCarbs = obj.carbs;
|
||||
delete obj.carbs;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// TODO:
|
||||
// - bypass nightmode in reports
|
||||
// - make axis on daytoday better working with thresholds
|
||||
// - get rid of /static/report/js/time.js
|
||||
// - load css dynamic + optimize
|
||||
// - add tests
|
||||
// - XMLHttpRequest - > $.ajax in treatments.js
|
||||
// - on save/delete treatment ctx.bus.emit('data-received'); is not enough. we must add something like 'data-updated'
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
Reference in New Issue
Block a user