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,77 +100,123 @@ pandora.ui.addFilesDialog = function(options) {
width: 640 width: 640
}); });
var selectItems = [];
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',
title: Ox._(
'Create one {0} with multiple parts',
[pandora.site.itemName.singular.toLowerCase()]
)
});
}
if (options.items.length > 1) {
selectItems.push({
id: 'multiple',
title: Ox._(
'Create multiple {0}',
[pandora.site.itemName.plural.toLowerCase()]
)
});
}
var $select = Ox.Select({ var $select = Ox.Select({
items: [ items: selectItems,
{
id: 'one',
title: Ox._(
'Create one {0} with multiple parts',
[pandora.site.itemName.singular.toLowerCase()]
)
},
{
id: 'multiple',
title: Ox._(
'Create multiple {0}',
[pandora.site.itemName.plural.toLowerCase()]
)
}
],
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;
Ox.serialForEach(options.items, function(item, index, items, callback) { ($select.value() == 'add' ? pandora.api.get : Ox.noop)({
var isNewItem = index == 0 || $select.value() == 'multiple'; id: pandora.user.ui.item,
(isNewItem ? pandora.api.add : Ox.noop)({ keys: ['title']
title: item.title }, function(result) {
}, function(result) { if ($select.value() == 'add') {
if (isNewItem) { title = result.data.title;
id = result.data.id; }
Ox.serialForEach(options.items, function(item, index, items, callback) {
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.edit : Ox.noop)(Ox.extend( (isNewItem ? pandora.api.add : Ox.noop)({
Ox.filter(item, function(value, key) { title: title
return key != 'title' && }, function(result) {
Object.keys(pandora.site.importMetadata).indexOf(key) > -1; if (isNewItem) {
}), id = result.data.id;
{'id': id} }
), function(result) { (isNewItem ? pandora.api.edit : Ox.noop)(Ox.extend(
pandora.api.addMediaUrl({ Ox.filter(item, function(value, key) {
url: item.url, return key != 'title' &&
item: id Object.keys(pandora.site.importMetadata).indexOf(key) > -1;
}, callback); }),
{'id': id}
), function(result) {
pandora.api.addMediaUrl({
url: item.url,
item: id
}, callback);
});
}); });
}); }, callback);
}, callback); });
} }
function uploadVideos(callback) { function uploadVideos(callback) {
var id; var id, title;
Ox.serialForEach(options.items, function(item, index, items, callback) { ($select.value() == 'add' ? pandora.api.get : Ox.noop)({
var isNewItem = index == 0 || $select.value() == 'multiple'; id: pandora.user.ui.item,
var title = items[$select.value() == 'one' ? 0 : index].title; keys: ['title']
(isNewItem ? pandora.api.add : Ox.noop)({ }, function(result) {
title: title if ($select.value() == 'add') {
}, function(result) { title = result.data.title;
if (isNewItem) { }
id = result.data.id; Ox.serialForEach(options.items, function(item, index, items, callback) {
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;
} }
pandora.uploadQueue.add(Ox.extend(item, { (isNewItem ? pandora.api.add : Ox.noop)({
item: { title: title
id: id, }, function(result) {
title: title if (isNewItem) {
} id = result.data.id;
})); }
callback(); pandora.uploadQueue.add(Ox.extend(item, {
}); item: {
}, callback); id: id,
title: title
}
}));
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;