added service for new note

This commit is contained in:
Thomas Hervey
2018-07-20 22:19:57 -04:00
parent bf9b19359a
commit 1d61355d08
2 changed files with 39 additions and 2 deletions

View File

@@ -861,7 +861,43 @@ export default {
// Create a note
// POST /api/0.6/notes?params
postNoteCreate: function(note, callback) {
// todo
if (!this.authenticated()) {
return callback({ message: 'Not Authenticated', status: -3 }, note);
}
if (_noteCache.inflightPost[note.id]) {
return callback({ message: 'Note update already inflight', status: -2 }, note);
}
if (!note.loc[0] || !note.loc[1] || !note.newComment) return; // location & description required
var path = '/api/0.6/notes?' +
'lat=' + note.loc[1] +
'&lon=' + note.loc[0] +
'&' + utilQsString({ text: note.newComment });
_noteCache.inflightPost[note.id] = oauth.xhr(
{ method: 'POST', path: path },
wrapcb(this, done, _connectionID)
);
function done(err, xml) {
delete _noteCache.inflightPost[note.id];
if (err) { return callback(err); }
// we get the updated note back, remove from caches and reparse..
var item = encodeNoteRtree(note);
_noteCache.rtree.remove(item, function isEql(a, b) { return a.data.id === b.data.id; });
delete _noteCache.note[note.id];
var options = { skipSeen: false };
return parseXML(xml, function(err, results) {
if (err) {
return callback(err);
} else {
return callback(undefined, results[0]);
}
}, options);
}
},
@@ -884,6 +920,7 @@ export default {
action = 'reopen';
} else {
action = 'comment';
if (!note.newComment) return; // when commenting, comment required
}
var path = '/api/0.6/notes/' + note.id + '/' + action;

View File

@@ -322,7 +322,7 @@ export function uiNoteEditor(context) {
this.blur(); // avoid keeping focus on the button - #4641
var osm = services.osm;
if (osm) {
osm.postNoteAdd(d, d.status, function(err, note) {
osm.postNoteCreate(d, function(err, note) {
dispatch.call('change', note);
});
}