From c1bee157dd6d06367c7e51064647c6454f60a733 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 4 Feb 2014 23:15:12 +0000 Subject: [PATCH] * refactor recordings in the same way --- web/app/assets/javascripts/web/recordings.js | 66 ++++++++++++++++++-- web/app/views/recordings/show.html.erb | 65 +------------------ 2 files changed, 62 insertions(+), 69 deletions(-) diff --git a/web/app/assets/javascripts/web/recordings.js b/web/app/assets/javascripts/web/recordings.js index 2ab8ba2bf..a98991cdc 100644 --- a/web/app/assets/javascripts/web/recordings.js +++ b/web/app/assets/javascripts/web/recordings.js @@ -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); + }); + } -}); \ No newline at end of file + 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); \ No newline at end of file diff --git a/web/app/views/recordings/show.html.erb b/web/app/views/recordings/show.html.erb index 6a3f4d926..d4f929e02 100644 --- a/web/app/views/recordings/show.html.erb +++ b/web/app/views/recordings/show.html.erb @@ -81,68 +81,7 @@