* refactor recordings in the same way

This commit is contained in:
Seth Call 2014-02-04 23:15:12 +00:00
parent ea48b6aa36
commit c1bee157dd
2 changed files with 62 additions and 69 deletions

View File

@ -1,10 +1,64 @@
$(function() {
(function(context, $) {
function like() {
context.JK.ShowRecording = function(app) {
var logger = context.JK.logger;
var rest = new JK.Rest();
var recordingId = null;
}
function like() {
rest.addRecordingLike(recordingId, JK.currentUserId)
.done(function(response) {
$("#spnLikeCount").html(parseInt($("#spnLikeCount").text()) + 1);
$("#btnLike").unbind("click");
});
}
// search click handler
$('#btnlike').click(like);
function play() {
rest.addRecordingPlay(recordingId, JK.currentUserId)
.done(function(response) {
$("#spnPlayCount").html(parseInt($("#spnPlayCount").text()) + 1);
});
}
});
function addComment() {
var comment = $("#txtRecordingComment").val();
if ($.trim(comment).length > 0) {
rest.addRecordingComment(recordingId, JK.currentUserId, comment)
.done(function(response) {
$("#spnCommentCount").html(parseInt($("#spnCommentCount").text()) + 1);
$(".landing-comment-scroller").prepend(comment);
});
}
}
function initialize(_recordingId) {
recordingId = _recordingId;
if (JK.currentUserId) {
var shareDialog = new JK.ShareDialog(JK.app, recordingId, "recording");
shareDialog.initialize(context.JK.FacebookHelperInstance);
$("#btnShare").click(function(e) {
shareDialog.showDialog();
});
$("#txtRecordingComment").keypress(function(e) {
if (e.which === 13) {
addComment();
}
});
}
else {
$("#txtRecordingComment").attr("disabled", "disabled");
$("#txtRecordingComment").val("You must be logged in to add a comment.");
}
$("#btnLike").click(like);
$("#btnPlay").click(play);
}
this.initialize = initialize;
}
})(window, jQuery);

View File

@ -81,68 +81,7 @@
<script type="text/javascript">
$(function () {
JK = JK || {};
<% if current_user %>
JK.currentUserId = '<%= current_user.id %>';
<% else %>
JK.currentUserId = null;
<% end %>
if (JK.currentUserId) {
JK.app = JK.JamKazam();
JK.app.initialize({inClient: false, layoutOpts: {layoutFooter: false}});
var shareDialog = new JK.ShareDialog(JK.app, '<%= @claimed_recording.id %>', "recording");
shareDialog.initialize();
$("#btnShare").click(function(e) {
shareDialog.showDialog();
});
$("#txtRecordingComment").keypress(function(e) {
if (e.which === 13) {
addComment();
}
});
}
else {
$("#txtRecordingComment").attr("disabled", "disabled");
$("#txtRecordingComment").val("You must be logged in to add a comment.");
}
JK.recordingId = "<%= @claimed_recording.recording.id %>";
var rest = new JK.Rest();
$("#btnLike").click(like);
$("#btnPlay").click(play);
function like() {
rest.addRecordingLike(JK.recordingId, JK.currentUserId)
.done(function(response) {
$("#spnLikeCount").html(parseInt($("#spnLikeCount").text()) + 1);
$("#btnLike").unbind("click");
});
}
function play() {
rest.addRecordingPlay(JK.recordingId, JK.currentUserId)
.done(function(response) {
$("#spnPlayCount").html(parseInt($("#spnPlayCount").text()) + 1);
});
}
function addComment() {
var comment = $("#txtRecordingComment").val();
if ($.trim(comment).length > 0) {
rest.addRecordingComment(JK.recordingId, JK.currentUserId, comment)
.done(function(response) {
$("#spnCommentCount").html(parseInt($("#spnCommentCount").text()) + 1);
$(".landing-comment-scroller").prepend(comment);
});
}
}
var showRecording = new JK.ShowRecording(JK.app);
showRecording.initialize("<%= @claimed_recording.recording_id %>");
})
</script>