update annotations export dialog

This commit is contained in:
rolux 2014-09-18 17:24:58 +02:00
parent 32733bdefa
commit dd6ee74b71

View file

@ -34,6 +34,8 @@ pandora.ui.exportAnnotationsDialog = function(options) {
change: function() { change: function() {
updateStatus(); updateStatus();
that.enableButton('export'); that.enableButton('export');
!$link && addLink();
updateLink();
} }
}) })
.appendTo($content), .appendTo($content),
@ -44,25 +46,24 @@ pandora.ui.exportAnnotationsDialog = function(options) {
}) })
.appendTo($content), .appendTo($content),
$link,
that = Ox.Dialog({ that = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
id: 'dontExport', id: 'dontExport',
title: Ox._('Don\'t Export') title: Ox._('Don\'t Export')
}) })
.bindEvent({ .bindEvent({
click: function() { click: function() {
that.close(); that.close();
} }
}), }),
Ox.Button({ Ox.Button({
disabled: enabledLayers.length == 0, disabled: enabledLayers.length == 0,
id: 'export', id: 'export',
title: Ox._('Export') title: Ox._('Export')
}) })
.bindEvent({
click: exportAnnotations
})
], ],
closeButton: true, closeButton: true,
content: $content, content: $content,
@ -75,19 +76,38 @@ pandora.ui.exportAnnotationsDialog = function(options) {
updateStatus(); updateStatus();
function exportAnnotations() { if (enabledLayers.length) {
Ox.print( addLink();
Ox.formatSRT(annotations[$layerSelect.value()].map(function(annotation) { updateLink();
return { }
'in': annotation['in'],
out: annotation.out, function addLink() {
text: annotation.value var layer = $layerSelect.value();
.replace(/\n/g, ' ') $link = $('<a>').attr({
.replace(/\s+/g, ' ') target: '_blank'
.replace(/<br>/g, '\n') });
}; updateLink();
})) $(that.find('.OxButton')[3]).wrap($link);
); }
function updateLink() {
var layer = $layerSelect.value();
$link.attr({
download: options.title + ' - '
+ Ox.getObjectById(layers, layer).title + '.srt',
href: 'data:text/plain;base64,' + btoa(
Ox.formatSRT(annotations[layer].map(function(annotation) {
return {
'in': annotation['in'],
out: annotation.out,
text: annotation.value
.replace(/\n/g, ' ')
.replace(/\s+/g, ' ')
.replace(/<br>\s+?/g, '\n')
};
}))
)
})
} }
function updateStatus() { function updateStatus() {