fix adding video to current item

This commit is contained in:
j 2017-03-01 12:22:00 +01:00
parent 19141fe96d
commit 896b57810a
2 changed files with 104 additions and 57 deletions

View file

@ -100,37 +100,69 @@ pandora.ui.addFilesDialog = function(options) {
width: 640 width: 640
}); });
var $select = Ox.Select({ var selectItems = [];
items: [ if (!pandora.site.itemRequiresVideo && pandora.user.ui.item) {
{ selectItems.push({
id: 'add',
title: Ox._(
'Add to current {0}',
[pandora.site.itemName.singular.toLowerCase()]
)
});
selectItems.push({
id: 'one',
title: Ox._(
options.items.length > 1 ? 'Create new {0} with multiple parts' : 'Create new {0}',
[pandora.site.itemName.singular.toLowerCase()]
)
});
} else {
selectItems.push({
id: 'one', id: 'one',
title: Ox._( title: Ox._(
'Create one {0} with multiple parts', 'Create one {0} with multiple parts',
[pandora.site.itemName.singular.toLowerCase()] [pandora.site.itemName.singular.toLowerCase()]
) )
}, });
{ }
if (options.items.length > 1) {
selectItems.push({
id: 'multiple', id: 'multiple',
title: Ox._( title: Ox._(
'Create multiple {0}', 'Create multiple {0}',
[pandora.site.itemName.plural.toLowerCase()] [pandora.site.itemName.plural.toLowerCase()]
) )
});
} }
], var $select = Ox.Select({
items: selectItems,
width: 256 width: 256
}).css({ }).css({
display: options.items.length > 1 ? 'block' : 'none', display: selectItems.length > 1 ? 'block' : 'none',
margin: '4px' margin: '4px'
}); });
$($select.find('.OxButton')[0]).css({margin: '-1px'}); $($select.find('.OxButton')[0]).css({margin: '-1px'});
$button.parent().parent().append($select); $button.parent().parent().append($select);
function importVideos(callback) { function importVideos(callback) {
var id; var id, title;
($select.value() == 'add' ? pandora.api.get : Ox.noop)({
id: pandora.user.ui.item,
keys: ['title']
}, function(result) {
if ($select.value() == 'add') {
title = result.data.title;
}
Ox.serialForEach(options.items, function(item, index, items, callback) { Ox.serialForEach(options.items, function(item, index, items, callback) {
var isNewItem = index == 0 || $select.value() == 'multiple'; var isNewItem = index == 0 || $select.value() == 'multiple';
if ($select.value() == 'add') {
id = pandora.user.ui.item;
isNewItem = false;
} else {
title = items[$select.value() == 'one' ? 0 : index].title;
}
(isNewItem ? pandora.api.add : Ox.noop)({ (isNewItem ? pandora.api.add : Ox.noop)({
title: item.title title: title
}, function(result) { }, function(result) {
if (isNewItem) { if (isNewItem) {
id = result.data.id; id = result.data.id;
@ -149,13 +181,26 @@ pandora.ui.addFilesDialog = function(options) {
}); });
}); });
}, callback); }, callback);
});
} }
function uploadVideos(callback) { function uploadVideos(callback) {
var id; var id, title;
($select.value() == 'add' ? pandora.api.get : Ox.noop)({
id: pandora.user.ui.item,
keys: ['title']
}, function(result) {
if ($select.value() == 'add') {
title = result.data.title;
}
Ox.serialForEach(options.items, function(item, index, items, callback) { Ox.serialForEach(options.items, function(item, index, items, callback) {
var isNewItem = index == 0 || $select.value() == 'multiple'; var isNewItem = index == 0 || $select.value() == 'multiple';
var title = items[$select.value() == 'one' ? 0 : index].title; if ($select.value() == 'add') {
id = pandora.user.ui.item;
isNewItem = false;
} else {
title = items[$select.value() == 'one' ? 0 : index].title;
}
(isNewItem ? pandora.api.add : Ox.noop)({ (isNewItem ? pandora.api.add : Ox.noop)({
title: title title: title
}, function(result) { }, function(result) {
@ -169,8 +214,9 @@ pandora.ui.addFilesDialog = function(options) {
} }
})); }));
callback(); callback();
}); })
}, callback); }, callback);
});
} }
return that; return that;

View file

@ -5,7 +5,8 @@ pandora.ui.addItemDialog = function(options) {
var input = ''; var input = '';
var selected = options.selected ? options.selected : 'upload'; var selected = options.selected ? options.selected
: !pandora.site.itemRequiresVideo && !pandora.user.ui.item ? 'add' : 'upload';
var $button; var $button;