allow for JSON export of annotations

This commit is contained in:
rolux 2014-09-18 19:54:37 +02:00
parent 3a00f73b9d
commit 9f3badf1c6

View File

@ -39,6 +39,26 @@ pandora.ui.exportAnnotationsDialog = function(options) {
} }
}) })
.appendTo($content), .appendTo($content),
$formatSelect = Ox.Select({
items: [
{id: 'json', title: 'JSON'},
{id: 'srt', title: 'SRT'}
],
label: Ox._('Format'),
labelWidth: 128,
value: 'json',
width: 384
})
.css({
marginTop: '16px'
})
.bindEvent({
change: function() {
$link && updateLink();
}
})
.appendTo($content),
$status = Ox.$('<div>') $status = Ox.$('<div>')
.css({ .css({
@ -68,7 +88,7 @@ pandora.ui.exportAnnotationsDialog = function(options) {
closeButton: true, closeButton: true,
content: $content, content: $content,
fixedSize: true, fixedSize: true,
height: 80, height: 112,
removeOnClose: true, removeOnClose: true,
title: Ox._('Export Annotations'), title: Ox._('Export Annotations'),
width: 416 width: 416
@ -76,38 +96,41 @@ pandora.ui.exportAnnotationsDialog = function(options) {
updateStatus(); updateStatus();
if (enabledLayers.length) { enabledLayers.length && addLink();
addLink();
updateLink();
}
function addLink() { function addLink() {
var layer = $layerSelect.value(); var $button = $(Ox.last(that.find('.OxButton')))
$link = $('<a>').attr({
target: '_blank'
});
updateLink(); updateLink();
$(that.find('.OxButton')[3]).wrap($link); $button.wrap($('<a>'));
// On wrap, a reference to the link would *not* be the link in the DOM
$link = $($button.parent());
} }
function updateLink() { function updateLink() {
var layer = $layerSelect.value(); var layer = $layerSelect.value(),
format = $formatSelect.value(),
items = annotations[layer].map(function(annotation) {
var text = format == 'json'
? annotation.value
: annotation.value
.replace(/\n/g, ' ')
.replace(/\s+/g, ' ')
.replace(/<br>\s+?/g, '\n');
return {
'in': annotation['in'],
out: annotation.out,
text: text
};
});
$link.attr({ $link.attr({
download: options.title + ' - ' download: options.title + ' - '
+ Ox.getObjectById(layers, layer).title + '.srt', + Ox.getObjectById(layers, layer).title + '.' + format,
href: 'data:text/plain;base64,' + btoa( href: 'data:text/plain;base64,' + btoa(
Ox.formatSRT(annotations[layer].map(function(annotation) { format == 'json'
return { ? JSON.stringify(items, null, ' ')
'in': annotation['in'], : Ox.formatSRT(items)
out: annotation.out,
text: annotation.value
.replace(/\n/g, ' ')
.replace(/\s+/g, ' ')
.replace(/<br>\s+?/g, '\n')
};
}))
) )
}) });
} }
function updateStatus() { function updateStatus() {