// vim: et:ts=4:sw=4:sts=4:ft=javascript
'use strict';
pandora.ui.item = function() {
var that = Ox.Element(),
isVideoView = [
'timeline', 'player', 'editor'
].indexOf(pandora.user.ui.itemView) > -1;
pandora.api.get({
id: pandora.user.ui.item,
keys: isVideoView ? [
'cuts', 'director', 'duration', 'editable', 'layers',
'parts', 'posterFrame', 'rendered', 'rightslevel',
'size', 'title', 'videoRatio', 'year'
] : []
}, pandora.user.ui.itemView == 'info' && pandora.site.capabilities.canEditMetadata[pandora.user.level] ? 0 : -1, function(result) {
if (result.status.code == 200) {
// 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;
}
/*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.'
)
);
}*/
pandora.$ui.itemTitle
.options({
title: '' + result.data.title
+ (Ox.len(result.data.director)
? ' (' + result.data.director.join(', ') + ')'
: '')
+ (result.data.year ? ' ' + result.data.year : '') + ''
})
.show();
// fixme: layers have value, subtitles has text?
isVideoView && Ox.extend(result.data, pandora.getVideoOptions(result.data));
if (!result.data.rendered && [
'clips', 'timeline', 'player', 'editor', 'map', 'calendar'
].indexOf(pandora.user.ui.itemView) > -1) {
pandora.$ui.contentPanel.replaceElement(1,
Ox.Element()
.css({marginTop: '32px', fontSize: '12px', textAlign: 'center'})
.html(
'Sorry, ' + result.data.title
+ ' currently doesn\'t have a '
+ pandora.user.ui.itemView + ' view.'
)
);
} else if (pandora.user.ui.itemView == 'info') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.infoView(result.data)
.bindEvent({
resize: function() {
pandora.$ui.item.resize();
}
})
);
} else if (pandora.user.ui.itemView == 'clips') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.ui.clipsView(result.data.videoRatio)
);
} else if (pandora.user.ui.itemView == 'timeline') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.timeline = pandora.ui.timeline(result.data)
);
} else if (pandora.user.ui.itemView == 'player') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.player = pandora.ui.player(result.data)
);
} else if (pandora.user.ui.itemView == 'editor') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.editor = pandora.ui.editor(result.data)
);
} 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)
);
} else if (pandora.user.ui.itemView == 'data') {
pandora.$ui.item = Ox.TreeList({
data: result.data,
width: pandora.$ui.mainPanel.size(1) - Ox.UI.SCROLLBAR_SIZE
});
pandora.$ui.contentPanel.replaceElement(1,
Ox.Container().append(pandora.$ui.item)
);
} else if (pandora.user.ui.itemView == 'files') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.filesView({
id: result.data.id
})
);
} else if (pandora.user.ui.itemView == 'frames' || pandora.user.ui.itemView == 'posters') {
pandora.$ui.contentPanel.replaceElement(1,
pandora.$ui.item = pandora.ui.mediaView().bindEvent({
resize: function() {
pandora.$ui.item.resize();
}
})
);
}
if (isVideoView && result.data.rendered) {
// handle links in annotations
pandora.$ui[pandora.user.ui.itemView].bindEvent(
'pandora_videopoints.' + pandora.user.ui.item.toLowerCase(),
function(data) {
//Ox.print('DATA.VALUE', JSON.stringify(data.value));
var options = {};
if (data.value.annotation) {
options.selected = pandora.user.ui.item + '/' + data.value.annotation;
} else {
// if annotation got set to something other than '',
// points and position will be set in consequence,
// so lets try to keep events from looping
['annotation', 'in', 'out', 'position'].forEach(function(key) {
if (!Ox.isUndefined(data.value[key])) {
options[key == 'annotation' ? 'selected' : key] = data.value[key];
}
});
}
pandora.$ui[pandora.user.ui.itemView].options(options);
}
);
}
});
return that;
};