fix document upload, add select callback option to document dialog, ctrl-alt-n works to add documents

This commit is contained in:
j 2013-07-08 11:40:18 +00:00
parent 7986b2487c
commit e6117dfc61
5 changed files with 39 additions and 16 deletions

View File

@ -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"},

View File

@ -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()),

View File

@ -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,

View File

@ -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();

View File

@ -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') {