jam-cloud/web/app/assets/javascripts/shareDialog.js

117 lines
3.9 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 socialShare() {
var shareWithFacebook = $('.share-with-facebook').is(':checked');
var shareWithGoogle = $('.share-with-google').is(':checked');
var shareWithTwitter = $('.share-with-twitter').is(':checked');
console.log("")
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 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 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('shareRecording', dialogBindings);
};
this.initialize = initialize;
this.showDialog = showDialog;
}
return this;
})(window,jQuery)