'use strict'; pandora.ui.addItemDialog = function(options) { options = options || {}; var input = ''; var selected = options.selected ? options.selected : !pandora.site.itemRequiresVideo && !pandora.user.ui.item ? 'add' : 'upload'; var $button; var $panel = Ox.TabPanel({ content: function(id) { var $content = Ox.Element().css({padding: '8px'}); var $input = Ox.Input({ changeOnKeypress: true, disabled: id == 'upload', label: Ox._(id == 'add' ? 'Title' : id == 'upload' ? 'File': 'URL'), labelWidth: 64, placeholder: id == 'import' ? Ox._('YouTube, Vimeo, etc.') : '', width: 512 }).css({ margin: '8px' }).bindEvent({ change: function(data) { $button.options({disabled: !data.value}); input = data.value; } }).appendTo($content); return $content; }, tabs: [ { id: 'add', title: Ox._('Add {0}', [pandora.site.itemName.singular]), disabled: pandora.site.itemRequiresVideo, selected: selected == 'add' }, { id: 'upload', title: Ox._('Upload Video Files'), selected: selected == 'upload' }, { id: 'import', title: Ox._('Import Video Files'), disabled: !pandora.hasCapability('canImportItems'), selected: selected == 'import' } ] }).bindEvent({ change: function(data) { selected = data.selected; that.options({buttons: [createButton()]}); } }); var $screen = Ox.LoadingScreen({ size: 16 }); var that = Ox.Dialog({ buttons: [createButton()], closeButton: true, content: $panel, height: 72, removeOnClose: true, title: Ox._('Add {0}', [pandora.site.itemName.singular]), width: 544 }); if (options.files) { that.options({content: $screen.start()}); $button.options({disabled: true}); Ox.serialMap(options.files, function(file, index, files, callback) { getFileInfo(file, function(info) { callback(Ox.extend(info, {file: file})); }); }, onInfo); } function createButton() { $button = Ox[selected == 'upload' ? 'FileButton' : 'Button']({ disabled: selected != 'upload', id: selected, title: selected == 'add' ? Ox._('Add {0} Without Video Files', [pandora.site.itemName.singular]) : selected == 'upload' ? Ox._('Select Video Files') : Ox._('Import Video Files'), width: selected == 'add' ? 192 : 128 }).bindEvent({ click: function(data) { if (selected == 'add') { that.options({content: $screen.start()}); $button.options({disabled: true}); pandora.api.add({title: input}, function(result) { Ox.Request.clearCache('find'); $screen.stop(); that.close(); pandora.UI.set({ item: result.data.id, itemView: 'info' }); }); } else if (selected == 'upload' && data.files.length > 0) { that.options({content: $screen.start()}); $button.options({disabled: true}); Ox.serialMap(data.files, function(file, index, files, callback) { getFileInfo(file, function(info) { callback(Ox.extend(info, {file: file})); }); }, onInfo); } else { that.options({content: $screen.start()}); $button.options({disabled: true}); pandora.api.getMediaUrlInfo({ url: input }, function(result) { if (result.data.items.length) { onInfo(result.data.items.map(getVideoInfo)); } else { $screen.stop(); that.close(); var error = Ox.Dialog({ buttons: [ {}, Ox.Button({ id: 'close', title: Ox._('Close') }).bindEvent({ click: function() { error.close(); } }) ], closeButton: true, content: Ox.Element().css({padding: '32px'}).html('Import failed'), height: 96, keys: {escape: 'close'}, removeOnClose: true, title: Ox._('Import Error'), width: 192 }).open() } }); } } }); return $button; } function getFileInfo(file, callback) { var done = false; Ox.oshash(file, function(oshash) { var $video = $('