queue [add|edit]Annotation calls

addAnnotation was called multiple times creating multiple annotations
editAnnotation calls might overwrite later calls depending on response
time.
This commit is contained in:
j 2020-09-22 12:49:20 +02:00
parent 5bbb6ca195
commit 2dfe0f3ff2

View file

@ -205,9 +205,9 @@ pandora.ui.editor = function(data) {
}).open(); }).open();
}, },
editannotation: function(data) { editannotation: function(data) {
Ox.Log('', 'editAnnotation', data); Ox.Log('', 'editAnnotation', data.id, data);
function callback(result) { function callback(result) {
Ox.Log('', 'editAnnotation result', result); Ox.Log('', 'editAnnotation result', result.data.id, result);
if (!Ox.isEmpty(result.data)) { if (!Ox.isEmpty(result.data)) {
result.data.date = Ox.formatDate( result.data.date = Ox.formatDate(
result.data.modified.slice(0, 10), '%B %e, %Y' result.data.modified.slice(0, 10), '%B %e, %Y'
@ -222,21 +222,56 @@ pandora.ui.editor = function(data) {
pandora.UI.set('videoPoints.' + ui.item + '.annotation', result.data.id.split('/')[1] || ''); pandora.UI.set('videoPoints.' + ui.item + '.annotation', result.data.id.split('/')[1] || '');
Ox.Request.clearCache(); Ox.Request.clearCache();
}; };
var edit = {
'in': data['in'],
out: data.out,
value: data.value
}
if (data.id[0] == '_') { if (data.id[0] == '_') {
pandora.api.addAnnotation({ edit.item = ui.item;
'in': data['in'], edit.layer = data.layer;
item: ui.item,
layer: data.layer, if (queue[data.id]) {
out: data.out, queue[data.id].push(edit);
value: data.value } else {
}, callback); queue[data.id] = [];
pandora.api.addAnnotation(edit, function(result) {
callback(result);
var id = data.id,
pending = queue[id];
delete queue[id];
pending.length && Ox.serialForEach(pending, function(edit, index, array, callback) {
edit.id = id
Ox.Log('', 'process pending editAnnotation request', id, edit);
pandora.api.editAnnotation(edit, function(result) {
callback();
})
}, function() {
Ox.Request.clearCache();
});
});
}
} else { } else {
pandora.api.editAnnotation({ edit.id = data.id;
id: data.id, if (queue[data.id]) {
'in': data['in'], queue[data.id].push(edit);
out: data.out, } else {
value: data.value queue[data.id] = [];
}, callback); pandora.api.editAnnotation(edit, function(result) {
callback(result);
var pending = queue[edit.id];
delete queue[edit.id];
pending.length && Ox.serialForEach(pending, function(edit, index, array, cb) {
Ox.Log('', 'process pending editAnnotation request', edit.id, edit);
pandora.api.editAnnotation(edit, function(result) {
callback(result);
cb();
})
}, function() {
Ox.Request.clearCache();
});
});
}
} }
}, },
embedselection: function() { embedselection: function() {
@ -387,7 +422,8 @@ pandora.ui.editor = function(data) {
pandora_videotimeline: function(data) { pandora_videotimeline: function(data) {
that.options({timeline: data.value}); that.options({timeline: data.value});
} }
}); }),
queue = [];
pandora._dontSelectResult = false; pandora._dontSelectResult = false;