2016-09-15 15:20:24 +00:00
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
pandora.ui.addFilesDialog = function(options) {
|
|
|
|
|
|
|
|
|
|
var $button = Ox.Button({
|
|
|
|
|
id: 'add',
|
|
|
|
|
title: Ox._(Ox.toTitleCase(options.action))
|
|
|
|
|
}).bindEvent({
|
|
|
|
|
click: function() {
|
|
|
|
|
$button.options({disabled: true});
|
2019-07-23 09:36:31 +00:00
|
|
|
|
that.disableCloseButton()
|
|
|
|
|
var $screen = Ox.LoadingScreen({
|
|
|
|
|
size: 16
|
|
|
|
|
});
|
|
|
|
|
that.options({content: $screen.start()});
|
2016-09-15 15:20:24 +00:00
|
|
|
|
(options.action == 'upload' ? uploadVideos : importVideos)(function() {
|
|
|
|
|
that.close();
|
|
|
|
|
pandora.ui.tasksDialog({
|
|
|
|
|
tasks: options.action == 'import' ? 'all' : 'uploads'
|
|
|
|
|
}).open();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var $list = Ox.TableList({
|
|
|
|
|
columns: [
|
|
|
|
|
{
|
|
|
|
|
id: 'id',
|
|
|
|
|
title: Ox._('ID')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'index',
|
|
|
|
|
title: Ox._('Index')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: function(value) {
|
|
|
|
|
return Ox.encodeHTMLEntities(value);
|
|
|
|
|
},
|
|
|
|
|
id: 'title',
|
|
|
|
|
title: Ox._('Title'),
|
|
|
|
|
visible: true,
|
|
|
|
|
width: 256
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: function(value, data) {
|
|
|
|
|
return data.width && data.height
|
|
|
|
|
? data.width + ' × ' + data.height + ' px'
|
|
|
|
|
: Ox._('unknown')
|
|
|
|
|
},
|
|
|
|
|
id: 'resolution',
|
|
|
|
|
title: Ox._('Resolution'),
|
|
|
|
|
align: 'right',
|
|
|
|
|
visible: true,
|
|
|
|
|
width: 128
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: function(value) {
|
|
|
|
|
return value ? Ox.formatDuration(value) : Ox._('unknown');
|
|
|
|
|
},
|
|
|
|
|
id: 'duration',
|
|
|
|
|
title: Ox._('Duration'),
|
|
|
|
|
align: 'right',
|
|
|
|
|
visible: true,
|
|
|
|
|
width: 128
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
format: function(value) {
|
|
|
|
|
return value ? Ox.formatValue(value, 'B') : Ox._('unknown');
|
|
|
|
|
},
|
|
|
|
|
id: 'size',
|
|
|
|
|
title: Ox._('Size'),
|
|
|
|
|
align: 'right',
|
|
|
|
|
visible: true,
|
2016-09-25 13:22:27 +00:00
|
|
|
|
width: 128 - Ox.SCROLLBAR_SIZE
|
2016-09-15 15:20:24 +00:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'width',
|
|
|
|
|
title: Ox._('Width')
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'height',
|
|
|
|
|
title: Ox._('Height')
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
columnsResizable: true,
|
|
|
|
|
columnsVisible: true,
|
|
|
|
|
items: options.items.map(function(value, index) {
|
|
|
|
|
return Ox.extend(value, {index: index})
|
|
|
|
|
}),
|
2016-09-23 21:43:28 +00:00
|
|
|
|
scrollbarVisible: true,
|
2016-09-15 15:20:24 +00:00
|
|
|
|
sort: [{key: 'index', operator: '+'}],
|
|
|
|
|
sortable: true
|
|
|
|
|
}).css({
|
|
|
|
|
height: '320px',
|
|
|
|
|
width: '640px'
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var that = Ox.Dialog({
|
|
|
|
|
buttons: [$button],
|
|
|
|
|
closeButton: true,
|
|
|
|
|
content: $list,
|
|
|
|
|
height: 320,
|
|
|
|
|
removeOnClose: true,
|
|
|
|
|
title: Ox._('{0} Video Files', [Ox.toTitleCase(options.action)]),
|
|
|
|
|
width: 640
|
|
|
|
|
});
|
|
|
|
|
|
2017-03-01 11:22:00 +00:00
|
|
|
|
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 {
|
2019-07-22 09:11:04 +00:00
|
|
|
|
if (options.items.length > 1) {
|
|
|
|
|
selectItems.push({
|
|
|
|
|
id: 'multiple',
|
|
|
|
|
title: Ox._(
|
|
|
|
|
'Create multiple {0}',
|
|
|
|
|
[pandora.site.itemName.plural.toLowerCase()]
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-03-01 11:22:00 +00:00
|
|
|
|
selectItems.push({
|
|
|
|
|
id: 'one',
|
|
|
|
|
title: Ox._(
|
|
|
|
|
'Create one {0} with multiple parts',
|
|
|
|
|
[pandora.site.itemName.singular.toLowerCase()]
|
|
|
|
|
)
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-09-15 15:20:24 +00:00
|
|
|
|
var $select = Ox.Select({
|
2017-03-01 11:22:00 +00:00
|
|
|
|
items: selectItems,
|
2016-09-15 15:20:24 +00:00
|
|
|
|
width: 256
|
|
|
|
|
}).css({
|
2017-03-01 11:22:00 +00:00
|
|
|
|
display: selectItems.length > 1 ? 'block' : 'none',
|
2016-09-15 15:20:24 +00:00
|
|
|
|
margin: '4px'
|
|
|
|
|
});
|
|
|
|
|
$($select.find('.OxButton')[0]).css({margin: '-1px'});
|
|
|
|
|
$button.parent().parent().append($select);
|
|
|
|
|
|
|
|
|
|
function importVideos(callback) {
|
2017-03-01 11:22:00 +00:00
|
|
|
|
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) {
|
|
|
|
|
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;
|
2016-09-15 15:20:24 +00:00
|
|
|
|
}
|
2017-03-01 11:22:00 +00:00
|
|
|
|
(isNewItem ? pandora.api.add : Ox.noop)({
|
|
|
|
|
title: title
|
|
|
|
|
}, function(result) {
|
|
|
|
|
if (isNewItem) {
|
|
|
|
|
id = result.data.id;
|
|
|
|
|
}
|
|
|
|
|
(isNewItem ? pandora.api.edit : Ox.noop)(Ox.extend(
|
|
|
|
|
Ox.filter(item, function(value, key) {
|
|
|
|
|
return key != 'title' &&
|
|
|
|
|
Object.keys(pandora.site.importMetadata).indexOf(key) > -1;
|
|
|
|
|
}),
|
|
|
|
|
{'id': id}
|
|
|
|
|
), function(result) {
|
|
|
|
|
pandora.api.addMediaUrl({
|
|
|
|
|
url: item.url,
|
|
|
|
|
item: id
|
|
|
|
|
}, callback);
|
|
|
|
|
});
|
2016-09-15 15:20:24 +00:00
|
|
|
|
});
|
2017-03-01 11:22:00 +00:00
|
|
|
|
}, callback);
|
|
|
|
|
});
|
2016-09-15 15:20:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function uploadVideos(callback) {
|
2017-03-01 11:22:00 +00:00
|
|
|
|
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) {
|
|
|
|
|
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;
|
2016-09-15 15:20:24 +00:00
|
|
|
|
}
|
2017-03-01 11:22:00 +00:00
|
|
|
|
(isNewItem ? pandora.api.add : Ox.noop)({
|
|
|
|
|
title: title
|
|
|
|
|
}, function(result) {
|
|
|
|
|
if (isNewItem) {
|
|
|
|
|
id = result.data.id;
|
|
|
|
|
}
|
|
|
|
|
pandora.uploadQueue.add(Ox.extend(item, {
|
|
|
|
|
item: {
|
|
|
|
|
id: id,
|
|
|
|
|
title: title
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
callback();
|
|
|
|
|
})
|
|
|
|
|
}, callback);
|
|
|
|
|
});
|
2016-09-15 15:20:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return that;
|
|
|
|
|
|
|
|
|
|
};
|