65 lines
2.0 KiB
JavaScript
65 lines
2.0 KiB
JavaScript
(function(context, $) {
|
|
|
|
context.JK.ShowMusicSession = function(app) {
|
|
var logger = context.JK.logger;
|
|
var rest = new JK.Rest();
|
|
var sessionId = null;
|
|
|
|
function like() {
|
|
rest.addSessionLike(sessionId, JK.currentUserId)
|
|
.done(function(response) {
|
|
$("#spnLikeCount").html(parseInt($("#spnLikeCount").text()) + 1);
|
|
$("#btnLike").unbind("click");
|
|
});
|
|
}
|
|
|
|
function addComment() {
|
|
var comment = $("#txtSessionComment").val();
|
|
if ($.trim(comment).length > 0) {
|
|
rest.addSessionComment(sessionId, JK.currentUserId, comment)
|
|
.done(function(response) {
|
|
$("#spnCommentCount").html(parseInt($("#spnCommentCount").text()) + 1);
|
|
|
|
var template = $('#template-landing-comment').html();
|
|
var commentHtml = context.JK.fillTemplate(template, {
|
|
avatar_url: context.JK.currentUserAvatarUrl,
|
|
name: context.JK.currentUserName,
|
|
comment: comment
|
|
});
|
|
|
|
$(".landing-comment-scroller").prepend(commentHtml);
|
|
});
|
|
}
|
|
}
|
|
|
|
function initialize(musicSessionId) {
|
|
sessionId = musicSessionId;
|
|
|
|
if (JK.currentUserId) {
|
|
var shareDialog = new JK.ShareDialog(context.JK.app, sessionId, "session");
|
|
shareDialog.initialize(JK.FacebookHelperInstance);
|
|
|
|
$("#btnShare").click(function(e) {
|
|
shareDialog.showDialog();
|
|
});
|
|
|
|
$("#txtSessionComment").keypress(function(e) {
|
|
if (e.which === 13) {
|
|
addComment();
|
|
$(this).val('');
|
|
$(this).blur();
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$("#txtSessionComment").attr("disabled", "disabled");
|
|
$("#txtSessionComment").val("You must be logged in to add a comment.");
|
|
}
|
|
|
|
$("#btnLike").click(like);
|
|
}
|
|
|
|
this.initialize = initialize;
|
|
}
|
|
|
|
})(window, jQuery); |