From 6c013ebc921c7dfb37d3ba21cdb6ec25987c8fab Mon Sep 17 00:00:00 2001 From: j Date: Thu, 15 Sep 2016 15:20:24 +0000 Subject: [PATCH] first version of new upload interface --- pandora/config.indiancinema.jsonc | 1 + pandora/config.padma.jsonc | 1 + pandora/config.pandora.jsonc | 1 + static/js/addFilesDialog.js | 177 ++++++++++++++++++++++ static/js/addItemDialog.js | 233 +++++++++++++++++++++++++++++ static/js/allItems.js | 10 +- static/js/deleteItemDialog.js | 41 ----- static/js/deleteItemsDialog.js | 55 +++++++ static/js/editItemDialog.js | 12 ++ static/js/infoView.0xdb.js | 4 +- static/js/infoView.indiancinema.js | 9 +- static/js/infoView.js | 4 +- static/js/infoView.padma.js | 4 +- static/js/list.js | 8 +- static/js/mainMenu.js | 70 +++++++-- static/js/mediaExistsDialog.js | 80 ++++++++++ static/js/mediaView.js | 4 +- static/js/tasksDialog.js | 230 ++++++++++++++++++++++++---- static/js/uploadButton.js | 27 ++++ static/js/utils.js | 97 +++++++++++- 20 files changed, 966 insertions(+), 102 deletions(-) create mode 100644 static/js/addFilesDialog.js create mode 100644 static/js/addItemDialog.js delete mode 100644 static/js/deleteItemDialog.js create mode 100644 static/js/deleteItemsDialog.js create mode 100644 static/js/editItemDialog.js create mode 100644 static/js/mediaExistsDialog.js create mode 100644 static/js/uploadButton.js diff --git a/pandora/config.indiancinema.jsonc b/pandora/config.indiancinema.jsonc index 2eacde6f7..f276ffe72 100644 --- a/pandora/config.indiancinema.jsonc +++ b/pandora/config.indiancinema.jsonc @@ -852,6 +852,7 @@ The plug-in architecture is not yet finalized, documentation forthcoming. */ "menuExtras": [ + "upload", "user", //"locale", "reload" diff --git a/pandora/config.padma.jsonc b/pandora/config.padma.jsonc index 1105efe2d..a14f73f09 100644 --- a/pandora/config.padma.jsonc +++ b/pandora/config.padma.jsonc @@ -738,6 +738,7 @@ The plug-in architecture is not yet finalized, documentation forthcoming. */ "menuExtras": [ + "upload", "user", //"locale", "reload" diff --git a/pandora/config.pandora.jsonc b/pandora/config.pandora.jsonc index af2f358a2..3a29ae965 100644 --- a/pandora/config.pandora.jsonc +++ b/pandora/config.pandora.jsonc @@ -672,6 +672,7 @@ examples (config.SITENAME.jsonc) that are part of this pan.do/ra distribution. The plug-in architecture is not yet finalized, documentation forthcoming. */ "menuExtras": [ + "upload", "user", // "locale", "reload" diff --git a/static/js/addFilesDialog.js b/static/js/addFilesDialog.js new file mode 100644 index 000000000..c7966b71f --- /dev/null +++ b/static/js/addFilesDialog.js @@ -0,0 +1,177 @@ +'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}); + (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, + width: 128 + }, + { + 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}) + }), + scrollbarsVisible: true, + 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 + }); + + var $select = Ox.Select({ + items: [ + { + 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 + }).css({ + display: options.items.length > 1 ? 'block' : 'none', + margin: '4px' + }); + $($select.find('.OxButton')[0]).css({margin: '-1px'}); + $button.parent().parent().append($select); + + function importVideos(callback) { + var id; + Ox.serialForEach(options.items, function(item, index, items, callback) { + var isNewItem = index == 0 || $select.value() == 'multiple'; + (isNewItem ? pandora.api.add : Ox.noop)({ + title: item.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'; + }), + {'id': id} + ), function(result) { + pandora.api.addMediaUrl({ + url: item.url, + item: id + }, callback); + }); + }); + }, callback); + } + + function uploadVideos(callback) { + var id; + Ox.serialForEach(options.items, function(item, index, items, callback) { + var isNewItem = index == 0 || $select.value() == 'multiple'; + var title = items[$select.value() == 'one' ? 0 : index].title; + (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); + } + + return that; + +}; diff --git a/static/js/addItemDialog.js b/static/js/addItemDialog.js new file mode 100644 index 000000000..d0a1fafc2 --- /dev/null +++ b/static/js/addItemDialog.js @@ -0,0 +1,233 @@ +'use strict'; + +pandora.ui.addItemDialog = function(options) { + options = options || {}; + + var input = ''; + + var selected = options.selected ? options.selected : '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.site.capabilities.canImportItems[pandora.user.level], + 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 + }); + + 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) { + onInfo(result.data.items); + }); + } + } + }); + return $button; + } + + function getFileInfo(file, callback) { + Ox.oshash(file, function(oshash) { + var $video = $('