2014-09-18 10:40:41 +00:00
|
|
|
'use strict';
|
|
|
|
|
2014-09-18 14:44:57 +00:00
|
|
|
pandora.ui.exportAnnotationsDialog = function(options) {
|
|
|
|
|
|
|
|
var annotations = pandora.$ui.editor.getCurrentAnnotations(),
|
|
|
|
|
|
|
|
layers = pandora.site.layers.map(function(layer) {
|
|
|
|
return {
|
|
|
|
disabled: annotations[layer.id].length == 0,
|
|
|
|
id: layer.id,
|
|
|
|
title: layer.title
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
enabledLayers = layers.filter(function(layer) {
|
|
|
|
return layer.disabled == false;
|
|
|
|
}),
|
|
|
|
|
|
|
|
layer = (enabledLayers.length ? enabledLayers : layers)[0].id,
|
|
|
|
|
|
|
|
$content = Ox.Element().css({margin: '16px'}),
|
|
|
|
|
|
|
|
$layerSelect = Ox.Select({
|
|
|
|
items: layers,
|
|
|
|
label: Ox._('Layer'),
|
|
|
|
labelWidth: 128,
|
|
|
|
value: layer,
|
|
|
|
width: 384
|
|
|
|
})
|
|
|
|
.css({
|
|
|
|
marginTop: '16px'
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
change: function() {
|
|
|
|
updateStatus();
|
|
|
|
that.enableButton('export');
|
2014-09-18 15:24:58 +00:00
|
|
|
!$link && addLink();
|
|
|
|
updateLink();
|
2014-09-18 14:44:57 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.appendTo($content),
|
2014-09-18 17:54:37 +00:00
|
|
|
|
|
|
|
$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),
|
2014-09-18 14:44:57 +00:00
|
|
|
|
|
|
|
$status = Ox.$('<div>')
|
|
|
|
.css({
|
|
|
|
marginTop: '16px'
|
|
|
|
})
|
|
|
|
.appendTo($content),
|
|
|
|
|
2014-09-18 15:24:58 +00:00
|
|
|
$link,
|
|
|
|
|
2014-09-18 14:44:57 +00:00
|
|
|
that = Ox.Dialog({
|
|
|
|
buttons: [
|
|
|
|
Ox.Button({
|
2014-09-18 15:24:58 +00:00
|
|
|
id: 'dontExport',
|
|
|
|
title: Ox._('Don\'t Export')
|
|
|
|
})
|
|
|
|
.bindEvent({
|
|
|
|
click: function() {
|
|
|
|
that.close();
|
|
|
|
}
|
|
|
|
}),
|
2014-09-18 14:44:57 +00:00
|
|
|
Ox.Button({
|
2014-09-18 15:24:58 +00:00
|
|
|
disabled: enabledLayers.length == 0,
|
|
|
|
id: 'export',
|
|
|
|
title: Ox._('Export')
|
|
|
|
})
|
2014-09-18 14:44:57 +00:00
|
|
|
],
|
|
|
|
closeButton: true,
|
|
|
|
content: $content,
|
|
|
|
fixedSize: true,
|
2014-09-18 17:54:37 +00:00
|
|
|
height: 112,
|
2014-09-18 14:44:57 +00:00
|
|
|
removeOnClose: true,
|
|
|
|
title: Ox._('Export Annotations'),
|
|
|
|
width: 416
|
|
|
|
});
|
|
|
|
|
|
|
|
updateStatus();
|
|
|
|
|
2014-09-18 17:54:37 +00:00
|
|
|
enabledLayers.length && addLink();
|
2014-09-18 15:24:58 +00:00
|
|
|
|
|
|
|
function addLink() {
|
2014-09-18 17:54:37 +00:00
|
|
|
var $button = $(Ox.last(that.find('.OxButton')))
|
2014-09-18 15:24:58 +00:00
|
|
|
updateLink();
|
2014-09-18 17:54:37 +00:00
|
|
|
$button.wrap($('<a>'));
|
|
|
|
// On wrap, a reference to the link would *not* be the link in the DOM
|
|
|
|
$link = $($button.parent());
|
2014-09-18 15:24:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateLink() {
|
2014-09-18 17:54:37 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
});
|
2014-09-18 15:24:58 +00:00
|
|
|
$link.attr({
|
|
|
|
download: options.title + ' - '
|
2014-09-18 17:54:37 +00:00
|
|
|
+ Ox.getObjectById(layers, layer).title + '.' + format,
|
2014-09-18 15:24:58 +00:00
|
|
|
href: 'data:text/plain;base64,' + btoa(
|
2014-09-18 17:54:37 +00:00
|
|
|
format == 'json'
|
|
|
|
? JSON.stringify(items, null, ' ')
|
|
|
|
: Ox.formatSRT(items)
|
2014-09-18 15:24:58 +00:00
|
|
|
)
|
2014-09-18 17:54:37 +00:00
|
|
|
});
|
2014-09-18 14:44:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateStatus() {
|
|
|
|
$status.html(Ox._('All {0} currently shown will be exported.', [
|
|
|
|
Ox.getObjectById(layers, $layerSelect.value()).title.toLowerCase()
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return that;
|
2014-09-18 10:40:41 +00:00
|
|
|
|
|
|
|
};
|