125 lines
4.4 KiB
JavaScript
125 lines
4.4 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();
|
|
var textMap = {
|
|
LIVE_SESSION: "LIVE SESSION",
|
|
SESSION: "SESSION",
|
|
RECORDING: "RECORDING",
|
|
RECORDED: "RECORDED"
|
|
};
|
|
|
|
function socialShare() {
|
|
var shareWithFacebook = $('.share-with-facebook').is(':checked');
|
|
var shareWithGoogle = $('.share-with-google').is(':checked');
|
|
var shareWithTwitter = $('.share-with-twitter').is(':checked');
|
|
|
|
if(!shareWithFacebook && !shareWithGoogle && !shareWithTwitter) {
|
|
$('.share-options').addClass('error')
|
|
}
|
|
}
|
|
function registerEvents(onOff) {
|
|
|
|
$('.dialog-share-button').unbind('click').click(function(e){
|
|
socialShare();
|
|
return false;
|
|
});
|
|
}
|
|
|
|
function showDialog() {
|
|
app.layout.showDialog('share-dialog');
|
|
}
|
|
|
|
function initDialog() {
|
|
var sessionText = textMap.SESSION;
|
|
var liveSessionText = textMap.LIVE_SESSION;
|
|
|
|
var fill = entityType === sessionText.toLowerCase() ? "teal-fill" : "orange-fill";
|
|
|
|
$("#shareType").text(entityType);
|
|
|
|
$("#divWidgetCodeHeader").addClass(fill);
|
|
$("#divWidgetPreviewHeader").addClass(fill);
|
|
$("#divWidgetPreview").addClass(entityType);
|
|
|
|
// SESSION
|
|
if (entityType === sessionText.toLowerCase() ) {
|
|
$("#lblWidgetCodeType").html(sessionText.toLowerCase());
|
|
$("#lblWidgetPreviewType").html(sessionText.toLowerCase());
|
|
$("#spnWidgetCodeBranding").text(liveSessionText.toLowerCase());
|
|
$("#spnWidgetPreviewBranding").text(liveSessionText.toLowerCase());
|
|
|
|
rest.getSessionHistory(entityId)
|
|
.done(function(response) {
|
|
var name, photoUrl;
|
|
});
|
|
}
|
|
|
|
// RECORDING
|
|
else {
|
|
var recordedText = textMap.RECORDED.toLowerCase();
|
|
$("#lblWidgetCodeType").text(textMap.RECORDING);
|
|
$("#lblWidgetPreviewType").text(textMap.RECORDING);
|
|
$("#spnWidgetCodeBranding").text(recordedText);
|
|
$("#spnWidgetPreviewBranding").text(recordedText);
|
|
|
|
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);
|
|
}
|
|
|
|
$("#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">' + '<img src="' + context.JK.resolveAvatarUrl(val.user.photo_url) + '" alt="" />' + '</div>');
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
function clearTextFields() {
|
|
|
|
}
|
|
|
|
function beforeShow() {
|
|
$('.share-with-selectors').removeClass('error');
|
|
registerEvents(true);
|
|
}
|
|
|
|
function afterHide() {
|
|
registerEvents(false);
|
|
}
|
|
|
|
function initialize(facebookHelper){
|
|
var dialogBindings = {
|
|
'beforeShow' : beforeShow,
|
|
'afterHide': afterHide
|
|
};
|
|
|
|
app.bindDialog('share-dialog', dialogBindings);
|
|
initDialog();
|
|
};
|
|
|
|
this.initialize = initialize;
|
|
this.showDialog = showDialog;
|
|
}
|
|
|
|
return this;
|
|
})(window,jQuery) |