var dialog_width = 400; var dialog_height = 300; var dialog_y = Math.floor(($(window).height() - dialog_height) / 2); var video_requesting = false; var video_dialog_open = false; var photo_uploading = false; var photo_dialog_open = false; function showVideoDialog () { if (photo_dialog_open) { return false; } var dialog = $('#dlg_video').dialog({ modal: true, resizable: false, draggable: false, height: 'auto', width: dialog_width, open: function() { video_dialog_open = true; }, close: function() { if (!video_requesting) { $('#dlg_video_input').show(); $('#dlg_video_input_msg').empty(); $('#dlg_video_requesting').hide(); $('#dlg_video_confirm').hide(); $('#dlg_video_confirm_img').empty(); } video_dialog_open = false; } }); if (!video_requesting) { dialog.dialog('option', 'buttons', { '確認': startVideoRequest, 'キャンセル': function() { $(this).dialog('close'); } }) .dialog('widget').find('.ui-dialog-buttonset button:last').addClass('gig_gray'); } return false; } function startVideoRequest () { if (video_requesting) { return; } video_requesting = true; $('#dlg_video').dialog('option', 'buttons', null); $('#dlg_video_input').hide(); $('#dlg_video_requesting').show(); var request_url = '/artist/354087/request_video'; var data = {'artist_video[url]':$('#artist_video_url').val(), 'artist_video[site]':'youtube'}; $.post(request_url, data, onVideoResponse, 'json'); } function onVideoResponse (res) { if (video_dialog_open) { $('#dlg_video_requesting').hide(); var res_error = res.error; if (!res_error) { $('#dlg_video_confirm_img').empty() .append($('
'+res.title+'
')) .append($('')); $('#dlg_video_confirm').show(); $('#dlg_video').dialog('option', 'buttons', { '決定': function() { $(this).dialog('close'); $('#form_video_confirm') .append($('')) .append($('')) .submit(); }, 'キャンセル': function() { $(this).dialog('close'); } }) .dialog('widget').find('.ui-dialog-buttonset button:last').addClass('gig_gray'); } else { $('#dlg_video_input_msg').empty() .append($('
'+res_error+'
')); $('#dlg_video_input').show(); $('#dlg_video').dialog('option', 'buttons', { '確認': startVideoRequest, 'キャンセル': function() { $(this).dialog('close'); } }) .dialog('widget').find('.ui-dialog-buttonset button:last').addClass('gig_gray'); } } else { $('#dlg_video_input').show(); $('#dlg_video_requesting').hide(); $('#dlg_video_confirm').hide(); } video_requesting = false; } function showPhotoDialog () { if (video_dialog_open) { return false; } var dialog = $('#dlg_photo').dialog({ modal: true, resizable: false, draggable: false, height: 'auto', width: dialog_width, open: function() { photo_dialog_open = true; }, close: function() { if (!photo_uploading) { $('#dlg_photo_input').show(); $('#dlg_photo_input_msg').empty(); $('#dlg_photo_uploading').hide(); $('#dlg_photo_confirm').hide(); $('#dlg_photo_confirm_img').empty(); $('#artist_photo_image').val(''); } photo_dialog_open = false; } }); if (!photo_uploading) { dialog.dialog('option', 'buttons', { 'キャンセル': function() { $(this).dialog('close'); } }) .dialog('widget').find('.ui-dialog-buttonset button:last').addClass('gig_gray'); } return false; } function startPhotoRequest () { if (photo_uploading) { return; } photo_uploading = true; $('#dlg_photo').dialog('option', 'buttons', null); $('#dlg_photo_input').hide(); $('#dlg_photo_uploading').show(); var upload_url = '/artist/354087/upload_photo'; $(this).upload(upload_url, onPhotoResponse, 'xml'); } function onPhotoResponse (res) { if (photo_dialog_open) { $('#dlg_photo_uploading').hide(); var res_error = $(res).find('error').text(); if (!res_error) { var res_url = $(res).find('url').text(); var res_key = $(res).find('key').text(); $('#dlg_photo_confirm_img').empty() .append($('')); $('#dlg_photo_confirm').show(); $('#dlg_photo').dialog('option', 'buttons', { '決定': function() { $(this).dialog('close'); $('#form_photo_confirm') .append($('')) .submit(); }, 'キャンセル': function() { $(this).dialog('close'); } }) .dialog('widget').find('.ui-dialog-buttonset button:last').addClass('gig_gray'); } else { $('#dlg_photo_input_msg').empty(); $('
').appendTo('#dlg_photo_input_msg').upload_error_text(res_error); $('#dlg_photo_input').show(); $('#dlg_photo').dialog('option', 'buttons', { 'キャンセル': function() { $(this).dialog('close'); } }) .dialog('widget').find('.ui-dialog-buttonset button:last').addClass('gig_gray'); } } else { $('#dlg_photo_input').show(); $('#dlg_photo_uploading').hide(); $('#dlg_photo_confirm').hide(); $('#artist_photo_image').val(''); } photo_uploading = false; } $(function() { $('#btn_video').on('click', showVideoDialog); $('#form_video_input').on('submit', startVideoRequest); $('#btn_photo').on('click', showPhotoDialog); $('#artist_photo_image').on('change', startPhotoRequest); $("a[rel^='prettyPhoto']").pretty_photo(); });