* reorging music session page to have most code in JS file

This commit is contained in:
Seth Call 2014-02-04 23:09:13 +00:00
parent fe0c4a374d
commit ea48b6aa36
2 changed files with 55 additions and 52 deletions

View File

@ -1,10 +1,57 @@
$(function() {
(function(context, $) {
function like() {
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");
});
}
// search click handler
$('#btnlike').click(like);
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);
$(".landing-comment-scroller").prepend(comment);
});
}
}
});
function initialize(musicSessionId) {
sessionId = musicSessionId;
if (context.JK.currentUserId) {
var shareDialog = new JK.ShareDialog(context.JK.app, sessionId, "session");
shareDialog.initialize(context.JK.FacebookHelperInstance);
$("#btnShare").click(function(e) {
shareDialog.showDialog();
});
$("#txtSessionComment").keypress(function(e) {
if (e.which === 13) {
addComment();
}
});
}
else {
$("#txtSessionComment").attr("disabled", "disabled");
$("#txtSessionComment").val("You must be logged in to add a comment.");
}
$("#btnLike").click(like);
}
this.initialize = initialize;
}
})(window, jQuery);

View File

@ -81,54 +81,10 @@
<%= render :partial => "clients/shareDialog", :locals => {:session => @music_session, :share_token => @music_session.share_token} %>
<% content_for :extra_js do %>
<script type="text/javascript">
var context = window;
$(function () {
if (context.JK.currentUserId) {
var shareDialog = new JK.ShareDialog(context.JK.app, "<%= @music_session.id %>", "session");
shareDialog.initialize(context.JK.FacebookHelperInstance);
$("#btnShare").click(function(e) {
shareDialog.showDialog();
});
$("#txtSessionComment").keypress(function(e) {
if (e.which === 13) {
addComment();
}
});
}
else {
$("#txtSessionComment").attr("disabled", "disabled");
$("#txtSessionComment").val("You must be logged in to add a comment.");
}
JK.sessionId = "<%= @music_session.music_session_id %>";
var rest = new JK.Rest();
$("#btnLike").click(like);
function like() {
rest.addSessionLike(JK.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(JK.sessionId, JK.currentUserId, comment)
.done(function(response) {
$("#spnCommentCount").html(parseInt($("#spnCommentCount").text()) + 1);
$(".landing-comment-scroller").prepend(comment);
});
}
}
var showMusicSession = new JK.ShowMusicSession(JK.app);
showMusicSession.initialize("<%= @music_session.music_session_id %>");
})
</script>