annotation import: allow for JSON

This commit is contained in:
rolux 2014-09-19 10:14:40 +02:00
parent 9f3badf1c6
commit 0448fca803

View file

@ -39,8 +39,26 @@ pandora.ui.importAnnotationsDialog = 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: updateFileInput
})
.appendTo($content),
$fileInput = Ox.FileInput({ $fileInput = Ox.FileInput({
label: Ox._('SRT File'), label: Ox._('File'),
labelWidth: 128, labelWidth: 128,
maxFiles: 1, maxFiles: 1,
width: 384 width: 384
@ -50,7 +68,7 @@ pandora.ui.importAnnotationsDialog = function(options) {
}) })
.bindEvent({ .bindEvent({
change: function(data) { change: function(data) {
status.empty(); $status.empty();
that[ that[
data.value.length ? 'enableButton' : 'disableButton' data.value.length ? 'enableButton' : 'disableButton'
]('import'); ]('import');
@ -86,7 +104,7 @@ pandora.ui.importAnnotationsDialog = function(options) {
closeButton: true, closeButton: true,
content: $content, content: $content,
fixedSize: true, fixedSize: true,
height: 144, height: 176,
keys: { keys: {
escape: 'dontImport' escape: 'dontImport'
}, },
@ -96,6 +114,7 @@ pandora.ui.importAnnotationsDialog = function(options) {
}); });
updateLanguageSelect(); updateLanguageSelect();
updateFileInput();
function disableButtons() { function disableButtons() {
that.disableButtons(); that.disableButtons();
@ -112,6 +131,7 @@ pandora.ui.importAnnotationsDialog = function(options) {
var annotations = [], var annotations = [],
language = $languageSelect.value(), language = $languageSelect.value(),
layer = $layerSelect.value(), layer = $layerSelect.value(),
format = $formatSelect.value(),
file = $fileInput.value()[0], file = $fileInput.value()[0],
reader = new FileReader(); reader = new FileReader();
@ -119,7 +139,9 @@ pandora.ui.importAnnotationsDialog = function(options) {
reader.onloadend = function(e) { reader.onloadend = function(e) {
if (this.result) { if (this.result) {
annotations = parseSRT(this.result); annotations = format == 'json'
? JSON.parse(this.result)
: parseSRT(this.result);
} }
if (annotations.length) { if (annotations.length) {
$status.html(Ox._( $status.html(Ox._(
@ -128,10 +150,12 @@ pandora.ui.importAnnotationsDialog = function(options) {
[annotations.length] [annotations.length]
)); ));
annotations = annotations.map(function(annotation) { annotations = annotations.map(function(annotation) {
var value = Ox.sanitizeHTML(annotation.text) var value = Ox.sanitizeHTML(annotation.text);
.replace(/<br[ /]*?>\n/g, '\n') if (format == 'srt') {
value = value.replace(/<br[ /]*?>\n/g, '\n')
.replace(/\n\n/g, '<br>\n') .replace(/\n\n/g, '<br>\n')
.replace(/\n/g, '<br>\n'); .replace(/\n/g, '<br>\n');
}
if (language != pandora.site.language) { if (language != pandora.site.language) {
value = '<span lang="' + language + '">' value = '<span lang="' + language + '">'
+ value + '</span>'; + value + '</span>';
@ -185,6 +209,12 @@ pandora.ui.importAnnotationsDialog = function(options) {
}); });
} }
function updateFileInput() {
$fileInput.options({
label: $formatSelect.value().toUpperCase() + ' File'
});
}
function updateLanguageSelect() { function updateLanguageSelect() {
var layerType = Ox.getObjectById( var layerType = Ox.getObjectById(
pandora.site.layers, $layerSelect.value() pandora.site.layers, $layerSelect.value()