diff --git a/pandora/config.padma.jsonc b/pandora/config.padma.jsonc index 5464cc6d..1917ccc5 100644 --- a/pandora/config.padma.jsonc +++ b/pandora/config.padma.jsonc @@ -517,6 +517,7 @@ "itemRequiresVideo": true, "itemViews": [ {"id": "info", "title": "Info"}, + {"id": "documents", "title": "Documents"}, {"id": "player", "title": "Player"}, {"id": "editor", "title": "Editor"}, {"id": "timeline", "title": "Timeline"}, diff --git a/pandora/document/views.py b/pandora/document/views.py index e5237d83..96fc19db 100644 --- a/pandora/document/views.py +++ b/pandora/document/views.py @@ -272,7 +272,7 @@ def upload(request): file.extension = extension file.uploading = True file.save() - upload_url = request.build_absolute_uri('/api/upload/file?id=%s' % file.get_id()) + upload_url = request.build_absolute_uri('/api/upload/document?id=%s' % file.get_id()) return render_to_json_response({ 'uploadUrl': upload_url, 'url': request.build_absolute_uri(file.get_absolute_url()), diff --git a/static/js/pandora/documentsDialog.js b/static/js/pandora/documentsDialog.js index ec8fa8ac..695944d8 100644 --- a/static/js/pandora/documentsDialog.js +++ b/static/js/pandora/documentsDialog.js @@ -2,7 +2,8 @@ 'use strict'; -pandora.ui.documentsDialog = function() { +pandora.ui.documentsDialog = function(options) { + options = options || {}; var dialogHeight = Math.round((window.innerHeight - 48) * 0.9), dialogWidth = Math.round(window.innerWidth * 0.9), @@ -165,6 +166,9 @@ pandora.ui.documentsDialog = function() { select: function(data) { selected = data.ids[0]; selectFile(); + options.callback && $doneButton.options({ + disabled: !data.ids.length + }); } }), @@ -218,6 +222,18 @@ pandora.ui.documentsDialog = function() { click: deleteFile }) .appendTo($itemToolbar), + + $doneButton = Ox.Button({ + disabled: !!options.callback, + id: 'done', + title: options.callback ? Ox._('Select') : Ox._('Done'), + width: 48 + }).bindEvent({ + click: function() { + options.callback && options.callback($list.options('selected')); + that.close(); + } + }), $uploadButton = Ox.FileButton({ maxFiles: 1, @@ -293,17 +309,7 @@ pandora.ui.documentsDialog = function() { }), that = Ox.Dialog({ - buttons: [ - Ox.Button({ - id: 'done', - title: Ox._('Done'), - width: 48 - }).bindEvent({ - click: function() { - that.close(); - } - }) - ], + buttons: [$doneButton], closeButton: true, content: $content, height: dialogHeight, diff --git a/static/js/pandora/documentsView.js b/static/js/pandora/documentsView.js index 6e55f65d..3eba5d04 100644 --- a/static/js/pandora/documentsView.js +++ b/static/js/pandora/documentsView.js @@ -82,7 +82,22 @@ pandora.ui.documentsView = function(options, self) { }) .bindEvent({ add: function(data) { - pandora.$ui.documentsDialog = pandora.ui.documentsDialog().open(); + pandora.$ui.documentsDialog = pandora.ui.documentsDialog({ + callback: function(ids) { + if (ids) { + pandora.api.addDocument({ + item: pandora.user.ui.item, + ids: ids + }, function() { + Ox.Request.clearCache(); + //fixme just upload list here + //self.$documentsList.reloadList(); + pandora.$ui.contentPanel.replaceElement(1, + pandora.$ui.item = pandora.ui.item()); + }); + } + } + }).open(); }, 'delete': function(data) { if (data.ids.length > 0 && options.editable) { @@ -124,7 +139,8 @@ pandora.ui.documentsView = function(options, self) { }); function renderPreview() { - var isImage = Ox.contains(['jpg', 'png'], self.selected.split('.').pop()), + var isImage = Ox.contains(['jpg', 'png'], + self.selected ? self.selected.split('.').pop() : ''), size = {width: 256, height: 256}, src = '/documents/' + self.selected + (isImage ? '' : '.jpg'); self.$preview.empty(); diff --git a/static/js/pandora/item.js b/static/js/pandora/item.js index 5f48e506..2883f8a4 100644 --- a/static/js/pandora/item.js +++ b/static/js/pandora/item.js @@ -76,7 +76,7 @@ pandora.ui.item = function() { } else if (pandora.user.ui.itemView == 'documents') { pandora.$ui.contentPanel.replaceElement(1, - pandora.$ui.documentsView = pandora.ui.documentsView(result.data) + pandora.$ui.documents = pandora.ui.documentsView(result.data) ); } else if (pandora.user.ui.itemView == 'player') {