add subtitle import dialog

This commit is contained in:
j 2012-02-15 00:18:08 +05:30
parent 9b21e867b2
commit 36572a048c
2 changed files with 99 additions and 6 deletions

View file

@ -3,8 +3,8 @@
pandora.ui.embedDialog = function(data) { pandora.ui.embedDialog = function(data) {
var content = Ox.Element().css({margin: '16px'}), var content = Ox.Element().css({margin: '16px'}),
height = 240, height = 360,
width = 320, width = 640,
that = Ox.Dialog({ that = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
@ -18,15 +18,15 @@ pandora.ui.embedDialog = function(data) {
], ],
closeButton: true, closeButton: true,
content: content, content: content,
height: Math.round((window.innerHeight - 24) * 0.75), height: height,
keys: { keys: {
'escape': 'close' 'escape': 'close'
}, },
maximizeButton: true, maximizeButton: true,
minHeight: 256, minHeight: height,
minWidth: 640, minWidth: width,
title: 'Embed Video', title: 'Embed Video',
width: Math.round(window.innerWidth * 0.75) width: width
}) })
.bindEvent({ .bindEvent({
close: function(data) { close: function(data) {

View file

@ -0,0 +1,93 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.importSubtitles = function(data) {
var content = Ox.Element().css({margin: '16px'}),
file,
height = 240,
width = 640,
that = Ox.Dialog({
buttons: [
Ox.Button({
id: 'close',
title: 'Close'
}).bindEvent({
click: function() {
that.close();
}
})
],
closeButton: true,
content: content,
keys: {
'escape': 'close'
},
maximizeButton: true,
height: height,
width: width,
title: 'Import Subtitles',
})
.bindEvent({
close: function(data) {
}
});
Ox.Select({
items: Ox.merge([{id: '', title: 'Select Layer'}], pandora.site.layers),
value: '',
})
.bindEvent({
change: function(data) {
var layer = data.value;
$('<input>')
.attr({
type: 'file'
})
.css({
padding: '8px'
})
.bind({
change: function(event) {
file = this.files[0];
var reader = new FileReader();
reader.onloadend = function(event) {
var srt = Ox.parseSRT(this.result),
total = srt.length;
function addAnnotation() {
if(srt.length>0) {
var data = srt.shift();
data.text = Ox.parseHTML(data.text);
content.html('Importing '+total+' <b>'+ layer +'</b>: <br>\n'
+ Ox.formatDuration(data['in'])
+ ' to ' + Ox.formatDuration(data.out) + '<br>\n'
+ data.text);
pandora.api.addAnnotation({
'in': data['in'],
out: data.out,
value: data.text,
item: pandora.user.ui.item,
layer: layer
}, function(result) {
if (result.status.code == 200) {
pandora.$ui.editor && pandora.$ui.editor.addAnnotation(layer, result.data);
addAnnotation();
} else {
content.html('Failed');
}
});
} else {
content.html('Done');
Ox.Request.clearCache();
//fixme, somehow reload timeline view here
}
}
addAnnotation();
};
reader.readAsText(file);
}
})
.appendTo(content);
}
})
.appendTo(content);
return that;
};