221
226
* @description Opens a pop-up with the movie player in it.
223
228
_createMoviePlayerDialog: function (movie) {
224
var dimensions, movieTitle, uploadURL, tags, html,
227
// Suggested YouTube tags
231
$.each(movie.layers.split("],["), function (i, layerStr) {
232
var parts = layerStr.replace(']', "").replace('[', "")
233
.split(",").slice(0, 4);
235
// Add observatories, instruments, detectors and
236
// measurements to tag list
237
$.each(parts, function (i, item) {
238
if ($.inArray(item, tags) === -1) {
244
// Suggested movie title
245
movieTitle = movie.name + " (" + movie.startDate + " - " +
246
movie.endDate + " UTC)";
248
uploadURL = "api/index.php?action=uploadMovieToYouTube&id=" + movie.id;
249
uploadURL += "&title=" + movieTitle;
250
uploadURL += "&tags=" + tags.join(", ");
229
var dimensions, title, uploadURL, html, dialog, self = this;
252
231
// Make sure dialog fits nicely inside the browser window
253
232
dimensions = this.getVideoPlayerDimensions(movie.width, movie.height);
255
234
// Movie player HTML
256
235
html = self.getVideoPlayerHTML(movie.id, dimensions.width,
257
dimensions.height, uploadURL, movie.url);
236
dimensions.height, movie.url);
259
238
// Movie player dialog
282
265
// Initialize YouTube upload button
283
266
$('#youtube-upload-' + movie.id).click(function () {
284
var loadingIndicator, auth = false;
286
loadingIndicator = $("#loading").show();
288
// Synchronous request (otherwise Google will not allow opening of
289
// request in a new tab)
292
url : "api/index.php?action=checkYouTubeAuth",
294
success: function (response) {
299
loadingIndicator.hide();
301
// If user is already authenticated we can simply display the
302
// upload form in a dialog
304
self.showYouTubeUploadDialog(uploadURL, movie.id);
267
self.showYouTubeUploadDialog(movie);
311
273
* Opens YouTube uploader either in a separate tab or in a dialog
313
showYouTubeUploadDialog: function (url, id) {
275
showYouTubeUploadDialog: function (movie) {
276
var title, tags, description;
278
// Suggested movie title
279
title = movie.name + " (" + movie.startDate + " - " +
280
movie.endDate + " UTC)";
282
// Suggested YouTube tags
285
$.each(movie.layers.split("],["), function (i, layerStr) {
286
var parts = layerStr.replace(']', "").replace('[', "")
287
.split(",").slice(0, 4);
289
// Add observatories, instruments, detectors and measurements
290
$.each(parts, function (i, item) {
291
if ($.inArray(item, tags) === -1) {
297
// Suggested Description
298
description = "This movie was produced by Helioviewer.org. " +
299
"A high quality version of this movie can be " +
300
"downloaded from " + helioviewer.serverSettings.rootURL +
301
"/?action=downloadMovie&id=" + movie.id + "&format=mp4&hq=true";
303
// Update form defaults
304
$("#youtube-title").val(title);
305
$("#youtube-tags").val(tags);
306
$("#youtube-desc").val(description);
307
$("#youtube-movie-id").val(movie.id);
314
309
// Hide movie dialogs (Flash player blocks upload form)
315
310
$(".movie-player-dialog").dialog("close");
317
var iframe = "<div class='youtube-upload-dialog'>" +
318
"<iframe src='" + url + "&dialogMode=true' " +
319
"scrolling='no' width='100%' height='100%' " +
320
"style='border: none' /></div>";
312
// Open upload dialog
313
$("#upload-dialog").dialog({
323
314
"title" : "Upload video to YouTube",
323
submitVideoUploadForm: function (event) {
324
var params, successMsg, errorConsole, loadingIndicator, url, auth = false;
326
// Validate and submit form
328
this._validateVideoUploadForm();
330
errorConsole = $("#upload-error-console");
331
errorConsole.html("<b>Error:</b> " + ex).fadeIn(function () {
332
window.setTimeout(function () {
333
errorConsole.fadeOut();
339
loadingIndicator = $("#loading").show();
341
// Check authorization using a synchronous request (otherwise Google
342
// will not allow opening of request in a new tab)
345
url : "api/index.php?action=checkYouTubeAuth",
347
success: function (response) {
352
loadingIndicator.hide();
355
url = "api/index.php?" + $("#youtube-video-info").serialize();
357
// If the user has already authorized Helioviewer, upload the movie
359
$.getJSON(url + "&action=uploadMovieToYouTube");
361
// Otherwise open an authorization page in a new tab/window
362
window.open(url + "&action=getYouTubeAuth", "_blank");
366
$("#upload-dialog").dialog("close");
371
* Validates title, description and keyword fields for YouTube upload.
373
* @see http://code.google.com/apis/youtube/2.0/reference.html#Media_RSS_elements_reference
375
_validateVideoUploadForm: function () {
376
var keywords = $("#youtube-tags").val(),
377
keywordMinLength = 2,
378
keywordMaxLength = 30;
380
// Make sure the title field is not empty
381
if ($("#youtube-title").val().length === 0) {
382
throw "Please specify a title for the movie.";
386
// User must specify at least one keyword
387
if (keywords.length === 0) {
388
throw "You must specifiy at least one tag for your video.";
392
// Make sure each keywords are between 2 and 30 characters each
393
$.each(keywords.split(","), function(i, keyword) {
394
var len = $.trim(keyword).length;
396
if (len > keywordMaxLength) {
397
throw "YouTube tags must not be longer than " + keywordMaxLength + " characters each.";
398
} else if (len < keywordMinLength) {
399
throw "YouTube tags must be at least " + keywordMinLength + " characters each.";
404
// < and > are not allowed in title, description or keywords
405
$.each($("#youtube-video-info input[type='text'], #youtube-video-info textarea"), function (i, input) {
406
if ($(input).val().match(/[<>]/)) {
407
throw "< and > characters are not allowed";