update import video dialog

This commit is contained in:
rlx 2016-08-09 15:29:35 +02:00
parent 3b4da19bd2
commit 50af217a68

View file

@ -2,36 +2,56 @@
pandora.ui.importMediaDialog = function(options) { pandora.ui.importMediaDialog = function(options) {
var help = Ox._('Enter a URL from an external site (like YouTube or Vimeo).'), var help = Ox._('You can import videos from external sites, like YouTube or Vimeo.'),
$content = Ox.Element().css({margin: '16px'}), $content = Ox.Element().css({margin: '16px'}),
$input = Ox.Input({
label: Ox._('URL'),
labelWidth: 128,
width: 384
})
.bindEvent({
change: submitURL
}),
$button = Ox.Button({ $button = Ox.Button({
overlap: 'left',
title: Ox._('Preview'), title: Ox._('Preview'),
width: 128 width: 128
}) })
.css({
marginLeft: '-20px',
paddingLeft: '20px',
position: 'absolute',
right: '16px',
top: '16px'
})
.bindEvent({ .bindEvent({
click: submitURL click: submitURL
}), })
.appendTo($content),
$form = Ox.FormElementGroup({ $input = Ox.Input({
elements: [$input, $button] label: Ox._('URL'),
labelWidth: 64,
width: 384
})
.css({
left: '16px',
position: 'absolute',
top: '16px'
})
.bindEvent({
change: submitURL
}) })
.appendTo($content), .appendTo($content),
$info = Ox.Element() $info = Ox.Element()
.css({
left: '16px',
position: 'absolute',
top: '48px'
})
.html(help) .html(help)
.appendTo($content), .appendTo($content),
$loading = Ox.LoadingScreen({
width: 512,
height: 224
}),
that = Ox.Dialog({ that = Ox.Dialog({
buttons: [ buttons: [
Ox.Button({ Ox.Button({
@ -51,7 +71,6 @@ pandora.ui.importMediaDialog = function(options) {
click: importMedia click: importMedia
}) })
], ],
closeButton: true,
content: $content, content: $content,
fixedSize: true, fixedSize: true,
height: 288, height: 288,
@ -59,7 +78,7 @@ pandora.ui.importMediaDialog = function(options) {
escape: 'close' escape: 'close'
}, },
removeOnClose: true, removeOnClose: true,
title: Ox._('Import Media'), title: Ox._('Import Video'),
width: 544 width: 544
}); });
@ -123,53 +142,50 @@ pandora.ui.importMediaDialog = function(options) {
function importMedia() { function importMedia() {
var url = $input.value(); var url = $input.value();
$info.empty(); $input.options({disabled: true});
$info.append(loadingIcon()); $button.options({disabled: true});
that.disableButton('import'); $info.empty().append($loading.start());
that.disableButton('close'); that.disableButton('close');
that.disableButton('import');
addMedia(url, function(item) { addMedia(url, function(item) {
if (item) { if (item) {
that.close(); that.close();
Ox.Request.clearCache(); Ox.Request.clearCache();
pandora.URL.push('/' + item + '/media'); pandora.URL.push('/' + item + '/media');
} else { } else {
$info.empty().html('Import failed.'); $input.options({disabled: false});
$button.options({disabled: false});
$info.empty().html(Ox._('Import failed. Please try again'));
that.enableButton('close'); that.enableButton('close');
} }
}); });
} }
function loadingIcon() {
return Ox.LoadingIcon().css({
margin: 'auto',
marginTop: '64px',
width: '100%'
}).start();
}
function submitURL() { function submitURL() {
var value = $input.value(); var value = $input.value();
if (value) { if (value) {
$info.empty(); $input.options({disabled: true});
$info.append(loadingIcon()); $button.options({disabled: true});
$info.empty().append($loading.start());
that.disableButton('close');
getInfo(value, function(items) { getInfo(value, function(items) {
$input.options({disabled: false});
$button.options({disabled: false});
$loading.stop();
$info.empty(); $info.empty();
if (items.length) { if (items.length) {
// FIXME: support playlists / multiple items // FIXME: support playlists / multiple items
var info = items[0]; var info = items[0];
$info.append($('<img>').css({ $info.append($('<img>').css({
position: 'absolute', position: 'absolute',
left: '16px',
top: '48px',
width: '248px' width: '248px'
}).attr('src', info.thumbnail)); }).attr('src', info.thumbnail));
$info.append($('<div>').addClass('OxText').css({ $info.append($('<div>').addClass('OxText').css({
height: '192px', height: '192px',
overflow: 'hidden', overflow: 'hidden',
position: 'absolute', position: 'absolute',
right: '16px', left: '264px',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
top: '48px',
width: '248px' width: '248px'
}).html( }).html(
'<span style="font-weight: bold">' + info.title '<span style="font-weight: bold">' + info.title
@ -180,6 +196,7 @@ pandora.ui.importMediaDialog = function(options) {
$info.html(help); $info.html(help);
} }
}); });
that.enableButton('close');
} }
} }