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

@ -40,6 +40,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({
marginTop: '16px' marginTop: '16px'
@ -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(),
$link.attr({ format = $formatSelect.value(),
download: options.title + ' - ' items = annotations[layer].map(function(annotation) {
+ Ox.getObjectById(layers, layer).title + '.srt', var text = format == 'json'
href: 'data:text/plain;base64,' + btoa( ? annotation.value
Ox.formatSRT(annotations[layer].map(function(annotation) { : annotation.value
.replace(/\n/g, ' ')
.replace(/\s+/g, ' ')
.replace(/<br>\s+?/g, '\n');
return { return {
'in': annotation['in'], 'in': annotation['in'],
out: annotation.out, out: annotation.out,
text: annotation.value text: text
.replace(/\n/g, ' ')
.replace(/\s+/g, ' ')
.replace(/<br>\s+?/g, '\n')
}; };
})) });
$link.attr({
download: options.title + ' - '
+ Ox.getObjectById(layers, layer).title + '.' + format,
href: 'data:text/plain;base64,' + btoa(
format == 'json'
? JSON.stringify(items, null, ' ')
: Ox.formatSRT(items)
) )
}) });
} }
function updateStatus() { function updateStatus() {