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