openmedialibrary/static/js/removeAnnotations.js

48 lines
1.5 KiB
JavaScript

'use strict';
oml.ui.removeAnnotationsDialog = function() {
var ui = oml.user.ui,
annotations = oml.$ui.viewer.getAnnotations().filter(function(a) {
return a.user == oml.user.id
}),
annotationsName = Ox._(annotations.length == 1 ? 'Annotation' : 'Annotations'),
theseAnnotationsName = annotations.length == 1
? Ox._('this annotation')
: Ox._('these {0} annotations', [Ox.formatNumber(annotations.length)]),
that = oml.ui.confirmDialog({
buttons: [
Ox.Button({
style: 'squared',
title: Ox._('No, Keep {0}', [annotationsName])
}),
Ox.Button({
style: 'squared',
title: Ox._('Yes, Delete {0}', [annotationsName])
})
],
content: Ox._(
'Are you sure that you want to permanently delete {0}?',
[theseAnnotationsName]
),
title: Ox._('Delete {0}', [annotationsName])
}, function() {
Ox.serialForEach(annotations, function(a, index, annotations, next) {
oml.api.removeAnnotation({
item: ui.item,
annotation: a.id
}, function(result) {
next()
})
}, function() {
Ox.Request.clearCache();
oml.$ui.viewer.renderAnnotations(true);
})
});
return that;
};