172 lines
6.2 KiB
JavaScript
172 lines
6.2 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
context.JK = context.JK || {};
|
|
context.JK.ShareDialog = function(app, entityId, entityType) {
|
|
var logger = context.JK.logger;
|
|
var rest = context.JK.Rest();
|
|
|
|
function registerEvents(onOff) {
|
|
if (onOff) {
|
|
|
|
}
|
|
else {
|
|
|
|
}
|
|
}
|
|
|
|
function showDialog() {
|
|
app.layout.showDialog('share-dialog');
|
|
}
|
|
|
|
function initDialog() {
|
|
|
|
var fill = entityType === "session" ? "teal-fill" : "orange-fill";
|
|
|
|
$("#shareType").html(entityType);
|
|
|
|
$("#divWidgetCodeHeader").addClass(fill);
|
|
$("#divWidgetPreviewHeader").addClass(fill);
|
|
$("#divWidgetPreview").addClass(entityType);
|
|
|
|
// SESSION
|
|
if (entityType === "session") {
|
|
$("#lblWidgetCodeType").html('LIVE SESSION');
|
|
$("#lblWidgetPreviewType").html('LIVE SESSION');
|
|
|
|
rest.getSessionHistory(entityId)
|
|
.done(function(response) {
|
|
var name, photoUrl;
|
|
|
|
|
|
});
|
|
}
|
|
|
|
// RECORDING
|
|
else {
|
|
$("#lblWidgetCodeType").html('RECORDING');
|
|
$("#lblWidgetPreviewType").html('RECORDING');
|
|
|
|
rest.getClaimedRecording(entityId)
|
|
.done(function(response) {
|
|
var name, photoUrl;
|
|
|
|
if (response.recording.band) {
|
|
name = response.recording.band.name;
|
|
photoUrl = context.JK.resolveBandAvatarUrl(response.recording.band.photo_url);
|
|
}
|
|
else {
|
|
name = response.recording.owner.name;
|
|
photoUrl = context.JK.resolveAvatarUrl(response.recording.owner.photo_url);
|
|
}
|
|
|
|
console.log("band photo url=" + photoUrl);
|
|
$("#imgWidgetCodeAvatar").attr('src', photoUrl);
|
|
$("#imgWidgetPreviewAvatar").attr('src', photoUrl);
|
|
|
|
$("#divWidgetPreviewTitle").html(response.recording.name);
|
|
|
|
$("#spnWidgetCodeArtistName").html(name);
|
|
$("#spnWidgetPreviewArtistName").html(name);
|
|
|
|
$.each(response.recording.recorded_tracks, function(index, val) {
|
|
$(".widget-members").append('<div class="widget-avatar-small">');
|
|
$(".widget-members").append('<img src="' + context.JK.resolveAvatarUrl(val.user.photo_url) + '" alt="" />');
|
|
$(".widget-members").append('</div>');
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
/*function showEmailDialog() {
|
|
$('#invitation-dialog').show();
|
|
$('#invitation-textarea-container').show();
|
|
$('#invitation-checkbox-container').hide();
|
|
$('#btn-send-invitation').show();
|
|
$('#btn-next-invitation').hide();
|
|
clearTextFields();
|
|
app.layout.showDialog('inviteUsers')
|
|
}
|
|
|
|
function showGoogleDialog() {
|
|
$('#invitation-dialog').show();
|
|
$('#invitation-textarea-container').hide();
|
|
$('#invitation-checkbox-container').show();
|
|
$('#btn-send-invitation').hide();
|
|
$('#btn-next-invitation').show();
|
|
clearTextFields();
|
|
|
|
app.layout.showDialog('inviteUsers')
|
|
|
|
$('#invitation-checkboxes').html('<div style="text-align: center; margin-top: 100px;">Loading your contacts...</div>');
|
|
window._oauth_callback = function() {
|
|
window._oauth_win.close();
|
|
window._oauth_win = null;
|
|
window._oauth_callback = null;
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "/gmail_contacts",
|
|
success: function(response) {
|
|
$('#invitation-checkboxes').html('');
|
|
for (var i in response) {
|
|
$('#invitation-checkboxes').append("<label><input type='checkbox' class='invitation-checkbox' data-email='" + response[i] + "' /> " + response[i] + "</label>");
|
|
}
|
|
|
|
$('.invitation-checkbox').change(function() {
|
|
var checkedBoxes = $('.invitation-checkbox:checkbox:checked');
|
|
var emails = '';
|
|
for (var i = 0; i < checkedBoxes.length; i++) {
|
|
emails += $(checkedBoxes[i]).data('email') + ', ';
|
|
}
|
|
emails = emails.replace(/, $/, '');
|
|
// track how many of these came from google
|
|
$('#txt-emails').val(emails).data('google_invite_count', checkedBoxes.length);
|
|
});
|
|
},
|
|
error: function() {
|
|
$('#invitation-checkboxes').html("Load failed!");
|
|
}
|
|
});
|
|
|
|
};
|
|
window._oauth_win = window.open("/auth/google_login", "_blank", "height=500,width=500,menubar=no,resizable=no,status=no");
|
|
}
|
|
|
|
function showFacebookDialog() {
|
|
window._oauth_callback = function() {
|
|
window._oauth_win.close();
|
|
window._oauth_win = null;
|
|
window._oauth_callback = null;
|
|
};
|
|
window._oauth_win = window.open("/auth/facebook_login", "_blank", "height=500,width=500,menubar=no,resizable=no,status=no");
|
|
}*/
|
|
|
|
function clearTextFields() {
|
|
|
|
}
|
|
|
|
function beforeShow() {
|
|
registerEvents(true);
|
|
}
|
|
|
|
function afterHide() {
|
|
registerEvents(false);
|
|
}
|
|
|
|
function initialize(){
|
|
var dialogBindings = {
|
|
'beforeShow' : beforeShow,
|
|
'afterHide': afterHide
|
|
};
|
|
|
|
app.bindDialog('shareSessionRecording', dialogBindings);
|
|
|
|
initDialog();
|
|
};
|
|
|
|
this.initialize = initialize;
|
|
this.showDialog = showDialog;
|
|
}
|
|
|
|
return this;
|
|
})(window,jQuery); |