use placeholders for missing item pages, remove item from getItem result

This commit is contained in:
j 2011-05-26 09:34:52 +02:00
parent 1a2d34caab
commit 5ca80fd7ee
4 changed files with 46 additions and 37 deletions

View file

@ -312,7 +312,7 @@ def getItem(request):
info = item.get_json() info = item.get_json()
info['stream'] = item.get_stream() info['stream'] = item.get_stream()
info['layers'] = item.get_layers(request.user) info['layers'] = item.get_layers(request.user)
response['data']['item'] = info response['data'] = info
else: else:
response = json_response(status=403, text='permission denied') response = json_response(status=403, text='permission denied')
return render_to_json_response(response) return render_to_json_response(response)

View file

@ -11,7 +11,7 @@ from django.utils import simplejson as json
from django.conf import settings from django.conf import settings
from django.core.mail import send_mail, BadHeaderError from django.core.mail import send_mail, BadHeaderError
from ox.django.shortcuts import render_to_json_response, json_response from ox.django.shortcuts import render_to_json_response, json_response, get_object_or_404_json
from ox.django.decorators import login_required_json from ox.django.decorators import login_required_json
import ox import ox
@ -451,7 +451,7 @@ def setUI(request):
profile.save() profile.save()
if data.get('item', False): if data.get('item', False):
item = Item.objects.get(itemId=data['item']) item = get_object_or_404_json(Item, itemId=data['item'])
if request.user.is_authenticated(): if request.user.is_authenticated():
access, created = Access.objects.get_or_create(item=item, user=request.user) access, created = Access.objects.get_or_create(item=item, user=request.user)
else: else:

View file

@ -16,7 +16,7 @@ pandora.ui.info = function() {
position: 'absolute', position: 'absolute',
left: 0, left: 0,
bottom: 0, bottom: 0,
height: '16px', height: '16px'
}) })
) )
.bindEvent({ .bindEvent({
@ -27,7 +27,7 @@ pandora.ui.info = function() {
}); });
if(app.user.ui.item) { if(app.user.ui.item) {
pandora.api.getItem(app.user.ui.item, function(result) { pandora.api.getItem(app.user.ui.item, function(result) {
app.ui.infoRatio = result.data.item.stream.aspectRatio; app.ui.infoRatio = result.data.stream.aspectRatio;
var width = that.width() || 256, var width = that.width() || 256,
height = width / app.ui.infoRatio + 16; height = width / app.ui.infoRatio + 16;
app.$ui.infoStill.removeElement(); app.$ui.infoStill.removeElement();
@ -43,7 +43,7 @@ pandora.ui.info = function() {
!app.user.ui.showInfo && app.$ui.leftPanel.css({bottom: -height}); !app.user.ui.showInfo && app.$ui.leftPanel.css({bottom: -height});
app.$ui.leftPanel.size(2, height ); app.$ui.leftPanel.size(2, height );
}); });
app.$ui.infoTimeline.attr('src', '/'+app.user.ui.item+'/timeline.16.png') app.$ui.infoTimeline.attr('src', '/'+app.user.ui.item+'/timeline.16.png');
} }
return that; return that;
}; };

View file

@ -1,16 +1,17 @@
// vim: et:ts=4:sw=4:sts=4:ft=js // vim: et:ts=4:sw=4:sts=4:ft=js
pandora.ui.item = function() { pandora.ui.item = function() {
var that; var that = new Ox.Element();
if (app.user.ui.itemView == 'info' || app.user.ui.itemView == 'files') {
that = new Ox.Element();
} else if (app.user.ui.itemView == 'player') {
that = new Ox.Element();
} else if (app.user.ui.itemView == 'timeline') {
that = new Ox.Element();
}
pandora.api.getItem(app.user.ui.item, function(result) { pandora.api.getItem(app.user.ui.item, function(result) {
if (app.user.ui.itemView == 'info') { if (result.status.code != 200) {
//Ox.print('result.data.item', result.data.item) app.$ui.contentPanel.replaceElement(1,
Ox.Element().html(
'The '+app.config.itemName.singular+' you are looking for does not exist.'));
} else if (app.user.ui.itemView == 'calendar') {
app.$ui.contentPanel.replaceElement(1, Ox.Element().html('Calendar'));
} else if (app.user.ui.itemView == 'clips') {
app.$ui.contentPanel.replaceElement(1, Ox.Element().html('Clips'));
} else if (app.user.ui.itemView == 'info') {
//Ox.print('result.data', result.data)
if (app.user.level == 'admin') { if (app.user.level == 'admin') {
var $form, var $form,
$edit = new Ox.Element() $edit = new Ox.Element()
@ -20,7 +21,7 @@ pandora.ui.item = function() {
id: key.id, id: key.id,
label: key.title, label: key.title,
labelWidth: 100, labelWidth: 100,
value: result.data.item[key.id], value: result.data[key.id],
type: 'text', type: 'text',
width: 500 width: 500
}); });
@ -37,11 +38,12 @@ pandora.ui.item = function() {
var values = $form.value(); var values = $form.value();
var changed = {}; var changed = {};
Ox.map(app.config.itemKeys, function(key, i) { Ox.map(app.config.itemKeys, function(key, i) {
if(values[i] && values[i] != ''+result.data.item[key.id]) { if(values[i] && values[i] != ''+result.data[key.id]) {
if(Ox.isArray(key.type) && key.type[0] == 'string') if(Ox.isArray(key.type) && key.type[0] == 'string') {
changed[key.id] = values[i].split(', '); changed[key.id] = values[i].split(', ');
else } else {
changed[key.id] = values[i]; changed[key.id] = values[i];
}
} }
}); });
if(changed) { if(changed) {
@ -58,16 +60,17 @@ pandora.ui.item = function() {
//Ox.print(template); //Ox.print(template);
app.$ui.contentPanel.replaceElement(1, app.$ui.contentPanel.replaceElement(1,
app.$ui.item = new Ox.Element() app.$ui.item = new Ox.Element()
.append($.tmpl(template, result.data.item)) .append($.tmpl(template, result.data))
); );
}); });
} }
} else if (app.user.ui.itemView == 'map') {
app.$ui.contentPanel.replaceElement(1, Ox.Element().html('Map'));
} else if (app.user.ui.itemView == 'player') { } else if (app.user.ui.itemView == 'player') {
var video = result.data.item.stream, var video = result.data.stream,
subtitles = result.data.item.layers.subtitles,
format = $.support.video.supportedFormat(video.formats); format = $.support.video.supportedFormat(video.formats);
video.height = video.profiles[0] video.height = video.profiles[0];
video.width = parseInt(video.height * video.aspectRatio / 2) * 2; video.width = parseInt(video.height * video.aspectRatio / 2) * 2;
video.url = video.baseUrl + '/' + video.height + 'p.' + format; video.url = video.baseUrl + '/' + video.height + 'p.' + format;
app.$ui.contentPanel.replaceElement(1, app.$ui.player = new Ox.VideoPanelPlayer({ app.$ui.contentPanel.replaceElement(1, app.$ui.player = new Ox.VideoPanelPlayer({
@ -77,7 +80,9 @@ pandora.ui.item = function() {
position: app.user.ui.videoPosition[app.user.ui.item] || 0, position: app.user.ui.videoPosition[app.user.ui.item] || 0,
showAnnotations: app.user.ui.showAnnotations, showAnnotations: app.user.ui.showAnnotations,
showControls: app.user.ui.showControls, showControls: app.user.ui.showControls,
subtitles: subtitles, subtitles: result.data.layers.subtitles.map(function(subtitle) {
return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value};
}),
videoHeight: video.height, videoHeight: video.height,
videoId: app.user.ui.item, videoId: app.user.ui.item,
videoWidth: video.width, videoWidth: video.width,
@ -99,17 +104,21 @@ pandora.ui.item = function() {
}); });
} }
})); }));
} else if (app.user.ui.itemView == 'statistics') {
app.$ui.contentPanel.replaceElement(1, Ox.Element().html('Statistics'));
} else if (app.user.ui.itemView == 'timeline') { } else if (app.user.ui.itemView == 'timeline') {
var layers = [], var layers = [],
video = result.data.item.stream, video = result.data.stream,
cuts = result.data.item.cuts || {}, cuts = result.data.cuts || {},
format = $.support.video.supportedFormat(video.formats); format = $.support.video.supportedFormat(video.formats),
subtitles = result.data.item.layers.subtitles; streams = {};
video.height = video.profiles[0]; video.height = video.profiles[0];
video.width = parseInt(video.height * video.aspectRatio / 2) * 2; video.width = parseInt(video.height * video.aspectRatio / 2) * 2;
video.url = video.baseUrl + '/' + video.height + 'p.' + format; video.profiles.forEach(function(profile) {
streams[profile] = video.baseUrl + '/' + profile + 'p.' + format;
});
$.each(app.config.layers, function(i, layer) { $.each(app.config.layers, function(i, layer) {
layers[i] = $.extend({}, layer, {items: result.data.item.layers[layer.id]}); layers[i] = $.extend({}, layer, {items: result.data.layers[layer.id]});
}); });
app.$ui.contentPanel.replaceElement(1, app.$ui.editor = new Ox.VideoEditor({ app.$ui.contentPanel.replaceElement(1, app.$ui.editor = new Ox.VideoEditor({
annotationsSize: app.user.ui.annotationsSize, annotationsSize: app.user.ui.annotationsSize,
@ -117,7 +126,7 @@ pandora.ui.item = function() {
duration: video.duration, duration: video.duration,
find: '', find: '',
getFrameURL: function(position) { getFrameURL: function(position) {
return '/' + app.user.ui.item + '/frame/' + video.width.toString() + '/' + position.toString() + '.jpg' return '/' + app.user.ui.item + '/frame/' + video.width.toString() + '/' + position.toString() + '.jpg';
}, },
getLargeTimelineImageURL: function(i) { getLargeTimelineImageURL: function(i) {
return '/' + app.user.ui.item + '/timelines/timeline.64.' + i + '.png'; return '/' + app.user.ui.item + '/timelines/timeline.64.' + i + '.png';
@ -135,14 +144,14 @@ pandora.ui.item = function() {
showAnnotations: app.user.ui.showAnnotations, showAnnotations: app.user.ui.showAnnotations,
showLargeTimeline: true, showLargeTimeline: true,
// fixme: layers have value, subtitles has text? // fixme: layers have value, subtitles has text?
subtitles: subtitles.map(function(subtitle) { subtitles: result.data.layers.subtitles.map(function(subtitle) {
return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value}; return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value};
}), }),
videoHeight: video.height, videoHeight: video.height,
videoId: app.user.ui.item, videoId: app.user.ui.item,
videoWidth: video.width, videoWidth: video.width,
videoSize: app.user.ui.videoSize, videoSize: app.user.ui.videoSize,
video: video.url, video: streams,
width: app.$ui.document.width() - app.$ui.mainPanel.size(0) - 1 width: app.$ui.document.width() - app.$ui.mainPanel.size(0) - 1
}).bindEvent({ }).bindEvent({
resize: function(event, data) { resize: function(event, data) {
@ -190,12 +199,12 @@ pandora.ui.item = function() {
} else if (app.user.ui.itemView == 'files') { } else if (app.user.ui.itemView == 'files') {
app.$ui.contentPanel.replaceElement(1, app.$ui.contentPanel.replaceElement(1,
app.$ui.item = new Ox.FilesView({ app.$ui.item = new Ox.FilesView({
id: result.data.item.id id: result.data.id
}) })
); );
} }
var director = result.data.item.director?' ('+result.data.item.director.join(', ')+')':''; var director = result.data.director?' ('+result.data.director.join(', ')+')':'';
app.$ui.total.html(result.data.item.title + director); app.$ui.total.html(result.data.title + director);
}); });
return that; return that;
}; };