pandora/static/js/pandora/item.js

371 lines
17 KiB
JavaScript
Raw Normal View History

2011-07-29 18:37:11 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-05-25 19:42:45 +00:00
pandora.ui.item = function() {
2011-09-17 07:07:59 +00:00
2011-06-19 17:49:25 +00:00
var that = Ox.Element();
2011-09-17 07:07:59 +00:00
2011-08-06 13:34:56 +00:00
pandora.api.get({
id: pandora.user.ui.item,
2011-10-30 21:05:57 +00:00
keys: ['video', 'timeline'].indexOf(pandora.user.ui.itemView) > -1
? [ 'cuts', 'director', 'duration', 'layers', 'parts', 'rendered', 'rightslevel', 'size', 'title', 'videoRatio', 'year'] : []
}, pandora.user.ui.itemView == 'info' && pandora.site.capabilities.canEditMetadata[pandora.user.level] ? 0 : -1, function(result) {
2011-09-17 07:07:59 +00:00
if (result.status.code == 200) {
2011-11-09 22:32:54 +00:00
// we want to cache the title in any way, so that after closing
// a dialog and getting to this item, the title is correct
var documentTitle = pandora.getDocumentTitle(result.data.title);
document.title = pandora.getPageTitle(document.location.pathname) || documentTitle;
2011-09-17 07:07:59 +00:00
}
/*if (result.status.code != 200) {
pandora.$ui.contentPanel.replaceElement(1,
Ox.Element()
.css({marginTop: '32px', fontSize: '12px', textAlign: 'center'})
.html(
'Sorry, we can\'t find the '
+ pandora.site.itemName.singular.toLowerCase()
+ ' you\'re looking for.'
)
);
}*/
2011-10-30 21:05:57 +00:00
pandora.$ui.itemTitle
.options({
title: '<b>' + result.data.title
+ (result.data.director ? ' (' + result.data.director.join(', ') + ')' : '')
+ (result.data.year ? ' ' + result.data.year : '') + '</b>'
})
.show();
2011-10-22 21:03:28 +00:00
if (['video', 'timeline'].indexOf(pandora.user.ui.itemView) > -1) {
2011-10-23 02:29:20 +00:00
// fixme: layers have value, subtitles has text?
2011-10-22 21:03:28 +00:00
var subtitles = result.data.layers.subtitles
? result.data.layers.subtitles.map(function(subtitle) {
return {'in': subtitle['in'], out: subtitle.out, text: subtitle.value};
})
: [],
2011-10-25 13:59:27 +00:00
canPlayClips = pandora.site.capabilities.canPlayClips[pandora.user.level] >= result.data.rightslevel,
canPlayVideo = pandora.site.capabilities.canPlayVideo[pandora.user.level] >= result.data.rightslevel,
2011-10-22 21:03:28 +00:00
censored = canPlayVideo ? []
: canPlayClips ? (
subtitles.length
? Ox.merge(
subtitles.map(function(subtitle, i) {
return {
'in': i == 0 ? 0 : subtitles[i - 1].out,
out: subtitle['in']
};
}),
[{'in': Ox.last(subtitles).out, out: result.data.duration}]
)
: Ox.range(0, result.data.duration - 5, 60).map(function(position) {
return {
'in': position + 5,
out: Math.min(position + 60, result.data.duration)
2011-10-22 21:03:28 +00:00
};
})
)
2011-10-23 02:29:20 +00:00
: [{'in': 0, out: result.data.duration}],
layers = [],
video = {};
pandora.site.layers.forEach(function(layer, i) {
layers[i] = Ox.extend({}, layer, {items: result.data.layers[layer.id]});
});
pandora.site.video.resolutions.forEach(function(resolution) {
video[resolution] = Ox.range(result.data.parts).map(function(i) {
2011-10-28 12:17:18 +00:00
var part = (i + 1),
prefix = pandora.site.site.videoprefix.replace('PART', part);
return prefix + '/' + pandora.user.ui.item + '/'
+ resolution + 'p' + part + '.' + pandora.user.videoFormat;
2011-10-23 02:29:20 +00:00
});
});
2011-10-22 21:03:28 +00:00
}
if (!result.data.rendered && [
'clips', 'map', 'video', 'timeline'
2011-10-22 21:03:28 +00:00
].indexOf(pandora.user.ui.itemView) > -1) {
2011-06-27 13:39:35 +00:00
pandora.$ui.contentPanel.replaceElement(1,
Ox.Element()
.css({marginTop: '32px', fontSize: '12px', textAlign: 'center'})
.html(
2011-10-23 02:29:20 +00:00
'Sorry, <i>' + result.data.title
+ '</i> currently doesn\'t have a '
+ pandora.user.ui.itemView + ' view.'
)
);
2011-09-17 07:07:59 +00:00
2011-06-06 15:48:11 +00:00
} else if (pandora.user.ui.itemView == 'info') {
2011-11-04 15:54:42 +00:00
//Ox.Log('', 'result.data', result.data)
2011-08-05 18:26:27 +00:00
if (pandora.user.level == 'admin' && false) {
2011-05-25 19:42:45 +00:00
var $form,
2011-06-19 17:49:25 +00:00
$edit = Ox.Element()
.append($form = Ox.FormElementGroup({
2011-06-27 13:39:35 +00:00
elements: Ox.map(pandora.site.sortKeys, function(key) {
2011-06-19 17:49:25 +00:00
return Ox.Input({
2011-05-25 19:42:45 +00:00
id: key.id,
label: key.title,
labelWidth: 100,
value: result.data[key.id],
2011-05-25 19:42:45 +00:00
type: 'text',
2011-10-29 17:46:46 +00:00
width: 500
2011-05-25 19:42:45 +00:00
});
}),
separators: [
{title: '', width: 0}
]
}))
2011-06-19 17:49:25 +00:00
.append(Ox.Button({
2011-05-25 19:42:45 +00:00
title: 'Save',
type: 'text'
}).bindEvent({
2011-09-17 17:40:15 +00:00
click: function(data) {
// fixme: cleanup
2011-05-25 19:42:45 +00:00
var values = $form.value();
var changed = {};
2011-06-06 15:48:11 +00:00
Ox.map(pandora.site.itemKeys, function(key, i) {
if(values[i] && values[i] != ''+result.data[key.id]) {
if(Ox.isArray(key.type) && key.type[0] == 'string') {
2011-05-25 19:42:45 +00:00
changed[key.id] = values[i].split(', ');
} else {
2011-05-25 19:42:45 +00:00
changed[key.id] = values[i];
}
2011-05-25 19:42:45 +00:00
}
});
if(changed) {
pandora.api.edit(Ox.extend(changed, {id: pandora.user.ui.item}), function(result) {
2011-05-25 19:42:45 +00:00
//fixme just reload parts that need reloading
window.location.reload();
2011-10-29 17:46:46 +00:00
});
2011-05-25 19:42:45 +00:00
}
}
}));
2011-06-06 15:48:11 +00:00
pandora.$ui.contentPanel.replaceElement(1, pandora.$ui.item = $edit);
2011-05-25 19:42:45 +00:00
} else {
2011-08-05 18:26:27 +00:00
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.infoView(result.data)
.bindEvent({
resize: function() {
pandora.$ui.item.resize();
}
})
);
2011-05-25 19:42:45 +00:00
}
} else if (pandora.user.ui.itemView == 'clips') {
2011-09-30 10:33:45 +00:00
pandora.$ui.contentPanel.replaceElement(1,
2011-10-30 15:36:14 +00:00
pandora.ui.clipsView(result.data.videoRatio)
2011-09-30 10:33:45 +00:00
);
} else if (pandora.user.ui.itemView == 'video') {
2011-10-20 19:32:12 +00:00
pandora.$ui.contentPanel.replaceElement(1, pandora.$ui.player = Ox.VideoPanelPlayer({
annotationsSize: pandora.user.ui.annotationsSize,
2011-10-22 21:03:28 +00:00
censored: censored,
2011-10-20 19:32:12 +00:00
cuts: result.data.cuts || [],
duration: result.data.duration,
2011-10-30 09:49:12 +00:00
find: pandora.user.ui.itemFind.conditions[0]
? pandora.user.ui.itemFind.conditions[0].value : '',
2011-10-20 19:32:12 +00:00
getTimelineImageURL: function(i) {
return '/' + pandora.user.ui.item + '/timeline64p' + i + '.png';
},
height: pandora.$ui.contentPanel.size(1),
'in': pandora.user.ui.videoPoints[pandora.user.ui.item]['in'],
muted: pandora.user.ui.videoMuted,
out: pandora.user.ui.videoPoints[pandora.user.ui.item].out,
position: pandora.user.ui.videoPoints[pandora.user.ui.item].position,
scaleToFill: pandora.user.ui.videoScale == 'fill',
showAnnotations: pandora.user.ui.showAnnotations,
showTimeline: pandora.user.ui.showTimeline,
2011-10-22 21:03:28 +00:00
subtitles: subtitles,
2011-10-20 19:32:12 +00:00
tooltips: true,
timeline: '/' + pandora.user.ui.item + '/timeline16p.png',
video: video,
volume: pandora.user.ui.videoVolume,
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
}).bindEvent({
2011-10-30 09:49:12 +00:00
find: function(data) {
2011-10-30 14:59:54 +00:00
pandora.UI.set('itemFind', data.find ? {
2011-10-30 09:49:12 +00:00
conditions: [{key: 'subtitles', value: data.find, operator: '='}],
operator: '&'
2011-10-30 14:59:54 +00:00
} : pandora.site.user.ui.itemFind);
2011-10-30 09:49:12 +00:00
},
2011-10-20 19:32:12 +00:00
muted: function(data) {
pandora.UI.set('videoMuted', data.muted);
2011-10-20 19:32:12 +00:00
},
position: function(data) {
2011-11-05 16:09:15 +00:00
pandora.UI.set(
'videoPoints.' + pandora.user.ui.item + '.position',
data.position
);
2011-10-20 19:32:12 +00:00
},
resizeannotations: function(data) {
pandora.UI.set('annotationsSize', data.annotationsSize);
},
scale: function(data) {
pandora.UI.set('videoScale', data.scale);
},
toggleannotations: function(data) {
pandora.UI.set('showAnnotations', data.showAnnotations);
},
toggletimeline: function(data) {
pandora.UI.set('showTimeline', data.showTimeline);
2011-10-20 19:32:12 +00:00
},
volume: function(data) {
pandora.UI.set('videoVolume', data.volume);
2011-10-20 19:32:12 +00:00
},
pandora_showannotations: function(data) {
pandora.$ui.player.options({showAnnotations: data.value});
},
pandora_showtimeline: function(data) {
pandora.$ui.player.options({showTimeline: data.value});
2011-10-20 19:32:12 +00:00
}
}));
2011-09-17 07:07:59 +00:00
2011-06-06 15:48:11 +00:00
} else if (pandora.user.ui.itemView == 'timeline') {
2011-10-30 09:49:12 +00:00
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.editor = Ox.VideoEditor({
annotationsSize: pandora.user.ui.annotationsSize,
censored: censored,
cuts: result.data.cuts || [],
duration: result.data.duration,
find: pandora.user.ui.itemFind.conditions[0]
? pandora.user.ui.itemFind.conditions[0].value : '',
getFrameURL: function(position) {
return '/' + pandora.user.ui.item + '/' + Ox.last(pandora.site.video.resolutions) + 'p' + position + '.jpg';
},
getLargeTimelineImageURL: function(i) {
return '/' + pandora.user.ui.item + '/timeline64p' + i + '.png';
},
getSmallTimelineImageURL: function(i) {
return '/' + pandora.user.ui.item + '/timeline16p' + i + '.png';
},
height: pandora.$ui.contentPanel.size(1),
id: 'editor',
'in': pandora.user.ui.videoPoints[pandora.user.ui.item]['in'],
layers: layers,
muted: pandora.user.ui.videoMuted,
out: pandora.user.ui.videoPoints[pandora.user.ui.item].out,
position: pandora.user.ui.videoPoints[pandora.user.ui.item].position,
posterFrame: parseInt(video.duration / 2),
showAnnotations: pandora.user.ui.showAnnotations,
showLargeTimeline: true,
subtitles: subtitles,
tooltips: true,
video: video,
videoRatio: result.data.videoRatio,
videoSize: pandora.user.ui.videoSize,
volume: pandora.user.ui.videoVolume,
2011-10-30 09:49:12 +00:00
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
}).bindEvent({
find: function(data) {
2011-10-30 14:59:54 +00:00
pandora.UI.set('itemFind', data.find ? {
2011-10-30 09:49:12 +00:00
conditions: [{key: 'subtitles', value: data.find, operator: '='}],
operator: '&'
2011-10-30 14:59:54 +00:00
} : pandora.site.user.ui.itemFind);
2011-10-30 09:49:12 +00:00
},
muted: function(data) {
pandora.UI.set('videoMuted', data.muted);
},
2011-10-30 09:49:12 +00:00
points: function(data) {
pandora.UI.set('videoPoints.' + pandora.user.ui.item, {
'in': data['in'],
out: data.out,
position: pandora.user.ui.videoPoints[pandora.user.ui.item].position
});
},
position: function(data) {
2011-11-05 16:09:15 +00:00
pandora.UI.set(
'videoPoints.' + pandora.user.ui.item + '.position',
data.position
);
2011-10-30 09:49:12 +00:00
},
resize: function(data) {
pandora.$ui.editor.options({
height: data.size
});
},
resizeend: function(data) {
pandora.UI.set({annotationsSize: data.size});
},
togglesize: function(data) {
pandora.UI.set({videoSize: data.size});
},
addannotation: function(data) {
2011-11-04 15:54:42 +00:00
Ox.Log('', 'addAnnotation', data);
2011-10-30 09:49:12 +00:00
data.item = pandora.user.ui.item;
data.value = 'Click to edit';
pandora.api.addAnnotation(data, function(result) {
pandora.$ui.editor.addAnnotation(data.layer, result.data);
});
},
removeannotations: function(data) {
pandora.api.removeAnnotations(data, function(result) {
//fixme: check for errors
pandora.$ui.editor.removeAnnotations(data.layer, data.ids);
});
},
toggleannotations: function(data) {
pandora.UI.set('showAnnotations', data.showAnnotations);
},
updateannotation: function(data) {
//fixme: check that edit was successfull
pandora.api.editAnnotation(data, function(result) {
2011-11-04 15:54:42 +00:00
Ox.Log('', 'done updateAnnotation', result);
2011-10-30 09:49:12 +00:00
});
},
pandora_showannotations: function(data) {
pandora.$ui.editor.options({showAnnotations: data.value});
}
})
);
2011-11-01 20:04:16 +00:00
pandora.$ui.editor.bindEvent('resize', function(data) {
2011-11-04 15:54:42 +00:00
//Ox.Log('', 'resize item', data)
2011-10-20 19:32:12 +00:00
pandora.$ui.editor.options({
height: data.size
});
});
/*
pandora.$ui.rightPanel.bindEvent('resize', function(data) {
2011-11-04 15:54:42 +00:00
Ox.Log('', '... rightPanel resize', data, pandora.$ui.timelinePanel.size(1))
2011-10-20 19:32:12 +00:00
pandora.$ui.editor.options({
width: data - pandora.$ui.timelinePanel.size(1) - 1
2011-05-25 19:42:45 +00:00
});
});
2011-10-20 19:32:12 +00:00
*/
} else if (pandora.user.ui.itemView == 'map') {
pandora.$ui.contentPanel.replaceElement(1, pandora.ui.navigationView('map', result.data.videoRatio));
} else if (pandora.user.ui.itemView == 'calendar') {
pandora.$ui.contentPanel.replaceElement(1, pandora.ui.navigationView('calendar', result.data.videoRatio));
2011-09-28 17:32:03 +00:00
} else if (pandora.user.ui.itemView == 'data') {
var stats = Ox.Container();
Ox.TreeList({
data: result.data,
width: pandora.$ui.mainPanel.size(1) - Ox.UI.SCROLLBAR_SIZE
}).appendTo(stats);
pandora.$ui.contentPanel.replaceElement(1, stats);
2011-06-06 15:48:11 +00:00
} else if (pandora.user.ui.itemView == 'files') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.filesView({
id: result.data.id
2011-05-25 19:42:45 +00:00
})
);
2011-09-17 07:07:59 +00:00
2011-06-06 18:40:24 +00:00
} else if (pandora.user.ui.itemView == 'frames' || pandora.user.ui.itemView == 'posters') {
pandora.$ui.contentPanel.replaceElement(1,
2011-06-07 03:17:36 +00:00
pandora.$ui.item = pandora.ui.mediaView().bindEvent({
resize: function() {
pandora.$ui.item.resize();
}
})
2011-06-06 18:40:24 +00:00
);
2011-05-25 19:42:45 +00:00
}
});
2011-09-17 07:07:59 +00:00
2011-05-25 19:42:45 +00:00
return that;
2011-09-17 07:07:59 +00:00
2011-05-25 19:42:45 +00:00
};