pandora/static/js/pandora/item.js

424 lines
20 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
2011-12-30 08:00:38 +00:00
+ (Ox.len(result.data.director)
2011-12-27 13:52:16 +00:00
? ' (' + result.data.director.join(', ') + ')'
: '')
2011-10-30 21:05:57 +00:00
+ (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-12-19 21:12:23 +00:00
var videoOptions = pandora.getVideoOptions(result.data);
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') {
2012-01-12 10:39:19 +00:00
pandora.$ui.contentPanel.replaceElement(1, pandora.$ui.player = Ox.VideoPanel({
2012-01-12 19:05:43 +00:00
annotationsFont: pandora.user.ui.annotationsFont,
annotationsRange: pandora.user.ui.annotationsRange,
2011-10-20 19:32:12 +00:00
annotationsSize: pandora.user.ui.annotationsSize,
2012-01-12 19:05:43 +00:00
annotationsSort: pandora.user.ui.annotationsSort,
2011-12-19 21:12:23 +00:00
censored: videoOptions.censored,
2011-10-20 19:32:12 +00:00
cuts: result.data.cuts || [],
duration: result.data.duration,
2011-12-22 15:48:48 +00:00
enableSubtitles: pandora.user.ui.videoSubtitles,
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'],
2012-01-12 19:05:43 +00:00
layers: videoOptions.layers,
2011-10-20 19:32:12 +00:00
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,
2011-12-20 13:08:30 +00:00
resolution: pandora.user.ui.videoResolution,
2011-10-20 19:32:12 +00:00
scaleToFill: pandora.user.ui.videoScale == 'fill',
showAnnotations: pandora.user.ui.showAnnotations,
2012-01-12 19:05:43 +00:00
showLayers: pandora.user.ui.showLayers,
showTimeline: pandora.user.ui.showTimeline,
2012-01-12 10:39:19 +00:00
showUsers: pandora.site.annotations.showUsers,
2011-12-19 21:12:23 +00:00
subtitles: videoOptions.subtitles,
2011-10-20 19:32:12 +00:00
tooltips: true,
timeline: '/' + pandora.user.ui.item + '/timeline16p.png',
2011-12-19 21:12:23 +00:00
video: videoOptions.video,
2011-10-20 19:32:12 +00:00
volume: pandora.user.ui.videoVolume,
width: pandora.$ui.document.width() - pandora.$ui.mainPanel.size(0) - 1
}).bindEvent({
2012-01-12 19:05:43 +00:00
annotationsfont: function(data) {
pandora.UI.set({annotationsFont: data.font});
},
annotationsrange: function(data) {
pandora.UI.set({annotationsRange: data.range});
},
annotationssize: function(data) {
pandora.UI.set({annotationsSize: data.size});
},
annotationssort: function(data) {
pandora.UI.set({annotationsSort: data.sort});
},
2011-10-30 09:49:12 +00:00
find: function(data) {
2012-01-12 19:05:43 +00:00
var textKey = Ox.getObjectById(pandora.site.layers, 'subtitles')
? 'subtitles'
: 'annotations';
2011-10-30 14:59:54 +00:00
pandora.UI.set('itemFind', data.find ? {
2012-01-12 19:05:43 +00:00
conditions: [{key: textKey, value: data.find, operator: '='}],
2011-10-30 09:49:12 +00:00
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);
},
2011-12-20 13:08:30 +00:00
resolution: function(data) {
pandora.UI.set('videoResolution', data.resolution);
},
2011-10-20 19:32:12 +00:00
scale: function(data) {
pandora.UI.set('videoScale', data.scale);
},
2011-12-22 15:48:48 +00:00
subtitles: function(data) {
pandora.UI.set('videoSubtitles', data.subtitles);
},
2011-10-20 19:32:12 +00:00
toggleannotations: function(data) {
pandora.UI.set('showAnnotations', data.showAnnotations);
},
2012-01-12 19:05:43 +00:00
togglelayer: function(data) {
pandora.UI.set('showLayers.' + data.layer, !data.collapsed);
},
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({
2012-01-13 16:26:07 +00:00
annotationsCalendarSize: pandora.user.ui.annotationsCalendarSize,
annotationsFont: pandora.user.ui.annotationsFont,
2012-01-13 16:26:07 +00:00
annotationsMapSize: pandora.user.ui.annotationsMapSize,
annotationsRange: pandora.user.ui.annotationsRange,
2011-10-30 09:49:12 +00:00
annotationsSize: pandora.user.ui.annotationsSize,
annotationsSort: pandora.user.ui.annotationsSort,
2011-12-20 13:08:30 +00:00
censored: videoOptions.censored,
2011-10-30 09:49:12 +00:00
cuts: result.data.cuts || [],
duration: result.data.duration,
2011-12-22 15:48:48 +00:00
enableSubtitles: pandora.user.ui.videoSubtitles,
2011-10-30 09:49:12 +00:00
find: pandora.user.ui.itemFind.conditions[0]
? pandora.user.ui.itemFind.conditions[0].value : '',
getFrameURL: function(position) {
return '/' + pandora.user.ui.item + '/' + pandora.user.ui.videoResolution + 'p' + position + '.jpg';
2011-10-30 09:49:12 +00:00
},
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: videoOptions.layers.map(function(layer) {
return Ox.extend({
editable: layer.canAddAnnotations[pandora.user.level]
}, layer);
}),
2011-10-30 09:49:12 +00:00
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,
2011-12-20 13:08:30 +00:00
posterFrame: parseInt(videoOptions.video.duration / 2),
resolution: pandora.user.ui.videoResolution,
2012-01-09 09:55:52 +00:00
selected: pandora.user.ui.videoPoints[pandora.user.ui.item].annotation
? pandora.user.ui.item + '/' + pandora.user.ui.videoPoints[pandora.user.ui.item].annotation
: '',
2011-10-30 09:49:12 +00:00
showAnnotations: pandora.user.ui.showAnnotations,
2012-01-13 16:26:07 +00:00
showAnnotationsCalendar: pandora.user.ui.showAnnotationsCalendar,
showAnnotationsMap: pandora.user.ui.showAnnotationsMap,
2011-10-30 09:49:12 +00:00
showLargeTimeline: true,
showLayers: pandora.user.ui.showLayers,
2012-01-12 10:39:19 +00:00
showUsers: pandora.site.annotations.showUsers,
2011-12-20 13:08:30 +00:00
subtitles: videoOptions.subtitles,
2011-10-30 09:49:12 +00:00
tooltips: true,
2011-12-20 13:08:30 +00:00
video: videoOptions.video,
2011-10-30 09:49:12 +00:00
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({
2012-01-12 10:39:19 +00:00
annotationsfont: function(data) {
pandora.UI.set({annotationsFont: data.font});
},
2012-01-12 10:39:19 +00:00
annotationsrange: function(data) {
pandora.UI.set({annotationsRange: data.range});
},
2012-01-12 10:39:19 +00:00
annotationssize: function(data) {
pandora.UI.set({annotationsSize: data.size});
},
2012-01-12 10:39:19 +00:00
annotationssort: function(data) {
pandora.UI.set({annotationsSort: data.sort});
},
2011-10-30 09:49:12 +00:00
find: function(data) {
2012-01-12 19:05:43 +00:00
var textKey = Ox.getObjectById(pandora.site.layers, 'subtitles')
? 'subtitles'
: 'annotations';
2011-10-30 14:59:54 +00:00
pandora.UI.set('itemFind', data.find ? {
2012-01-12 19:05:43 +00:00
conditions: [{key: textKey, value: data.find, operator: '='}],
2011-10-30 09:49:12 +00:00
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, {
2012-01-09 09:55:52 +00:00
annotation: pandora.user.ui.videoPoints[pandora.user.ui.item].annotation,
2011-10-30 09:49:12 +00:00
'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
});
},
2011-12-20 13:08:30 +00:00
resolution: function(data) {
pandora.UI.set('videoResolution', data.resolution);
},
2012-01-09 09:55:52 +00:00
select: function(data) {
pandora.UI.set('videoPoints.' + pandora.user.ui.item + '.annotation', data.id.split('/')[1]);
},
2011-12-22 15:48:48 +00:00
subtitles: function(data) {
pandora.UI.set('videoSubtitles', data.subtitles);
},
2011-10-30 09:49:12 +00:00
togglesize: function(data) {
pandora.UI.set({videoSize: data.size});
},
addannotation: function(data) {
2011-11-04 15:54:42 +00:00
Ox.Log('', 'addAnnotation', data);
pandora.api.addAnnotation({
'in': data['in'],
item: pandora.user.ui.item,
layer: data.layer,
out: data.out,
2012-01-03 10:26:50 +00:00
value: data.value,
}, function(result) {
result.data.editable = true;
result.data.duration = result.data.out - result.data['in'];
2011-10-30 09:49:12 +00:00
pandora.$ui.editor.addAnnotation(data.layer, result.data);
});
},
2012-01-03 10:26:50 +00:00
editannotation: function(data) {
Ox.Log('', 'editAnnotation', data);
2011-10-30 09:49:12 +00:00
//fixme: check that edit was successfull
pandora.api.editAnnotation({
id: data.id,
'in': data['in'],
out: data.out,
value: data.value,
}, function(result) {
2012-01-03 10:26:50 +00:00
Ox.Log('', 'editAnnotation result', result);
2012-01-13 16:26:07 +00:00
result.data.duration = result.data.out - result.data['in'];
pandora.$ui.editor.updateAnnotation(data.layer, result.data);
2011-10-30 09:49:12 +00:00
});
},
2012-01-03 10:26:50 +00:00
removeannotation: function(data) {
pandora.api.removeAnnotation({
id: data.id
}, function(result) {
//fixme: check for errors
2012-01-12 10:39:19 +00:00
//pandora.$ui.editor.removeAnnotation(data.layer, data.id);
2012-01-03 10:26:50 +00:00
});
},
toggleannotations: function(data) {
pandora.UI.set('showAnnotations', data.showAnnotations);
},
togglelayer: function(data) {
pandora.UI.set('showLayers.' + data.layer, !data.collapsed);
},
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
};