diff --git a/app/views/templates/_templates.haml b/app/views/templates/_templates.haml
index 506642d37..848b28618 100644
--- a/app/views/templates/_templates.haml
+++ b/app/views/templates/_templates.haml
@@ -29,3 +29,6 @@
%script{:id => "activity-streams-photo-template", :type => 'text/template'}
!= File.read("#{Rails.root}/app/views/templates/activity-streams-photo.ujs")
+%script{:id => "likes-info-template", :type => 'text/template'}
+ != File.read("#{Rails.root}/app/views/templates/likes_info.ujs")
+
diff --git a/app/views/templates/feedback.ujs b/app/views/templates/feedback.ujs
index f3ddd4f0b..fca230265 100644
--- a/app/views/templates/feedback.ujs
+++ b/app/views/templates/feedback.ujs
@@ -1,6 +1,6 @@
- <%= like ? "Unlike" : "Like" %>
+ <%= user_like ? "Unlike" : "Like" %>
ยท
diff --git a/app/views/templates/likes_info.ujs b/app/views/templates/likes_info.ujs
new file mode 100644
index 000000000..88c55cba9
--- /dev/null
+++ b/app/views/templates/likes_info.ujs
@@ -0,0 +1,6 @@
+<% if(likes_count > 0) { %>
+

+
+ <%= likes_count %> Like
+
+<% } %>
diff --git a/app/views/templates/stream_element.ujs b/app/views/templates/stream_element.ujs
index 894c04a94..13ef5ec15 100644
--- a/app/views/templates/stream_element.ujs
+++ b/app/views/templates/stream_element.ujs
@@ -48,6 +48,7 @@
<% } %>
+
diff --git a/public/javascripts/app/views/feedback_view.js b/public/javascripts/app/views/feedback_view.js
index b1dbc5eb7..6aecaa03a 100644
--- a/public/javascripts/app/views/feedback_view.js
+++ b/public/javascripts/app/views/feedback_view.js
@@ -6,30 +6,23 @@ app.views.Feedback = app.views.StreamObject.extend({
"click .reshare_action": "resharePost"
},
- initialize : function() {
- var user_like = this.model.get("user_like")
- this.like = user_like && this.model.likes.get(user_like.id);
-
- _.each(["change", "remove", "add"], function(listener) {
- this.model.likes.bind(listener, this.render, this);
- }, this)
- },
-
- presenter : function(){
- return _.extend(this.defaultPresenter(), {like : this.like});
- },
-
toggleLike: function(evt) {
if(evt) { evt.preventDefault(); }
- if(this.like){
- this.like.destroy({
- success : function() {
- this.like = null;
- }.apply(this)
+ var userLike = this.model.get("user_like");
+
+ if(userLike) {
+ this.model.likes.get(userLike.id).destroy({
+ success : $.proxy(function() {
+ this.model.set({user_like : null, likes_count : this.model.get("likes_count") - 1});
+ }, this)
});
} else {
- this.like = this.model.likes.create();
+ this.model.likes.create({}, {
+ success : $.proxy(function(like) {
+ this.model.set({user_like : like, likes_count : this.model.get("likes_count") + 1}); // this should be in a callback...
+ }, this)
+ });
}
},
diff --git a/public/javascripts/app/views/likes_info_view.js b/public/javascripts/app/views/likes_info_view.js
new file mode 100644
index 000000000..32302e841
--- /dev/null
+++ b/public/javascripts/app/views/likes_info_view.js
@@ -0,0 +1,8 @@
+app.views.LikesInfo = app.views.StreamObject.extend({
+
+ template_name : "#likes-info-template",
+
+ className : "likes_container",
+
+ events: { }
+});
diff --git a/public/javascripts/app/views/post_view.js b/public/javascripts/app/views/post_view.js
index b5f7be150..7b6077f39 100644
--- a/public/javascripts/app/views/post_view.js
+++ b/public/javascripts/app/views/post_view.js
@@ -6,12 +6,12 @@ app.views.Post = app.views.StreamObject.extend({
"click .focus_comment_textarea": "focusCommentTextarea",
"click .shield a": "removeNsfwShield",
"click .remove_post": "destroyModel",
- "click .expand_likes": "expandLikes",
"click .block_user": "blockUser"
},
subviews : {
".feedback" : "feedbackView",
+ ".likes" : "likesInfoView",
".comments" : "commentStreamView"
},
@@ -24,6 +24,7 @@ app.views.Post = app.views.StreamObject.extend({
initialize : function() {
// commentStream view
this.commentStreamView = new app.views.CommentStream({ model : this.model});
+ this.likesInfoView = new app.views.LikesInfo({ model : this.model});
// feedback view
if(window.app.user().current_user) {
@@ -70,51 +71,6 @@ app.views.Post = app.views.StreamObject.extend({
return this;
},
- expandLikes: function(evt){
- if(evt) { evt.preventDefault(); }
-
- var self = this;
-
- this.model.likes.fetch({
- success: function(){
- // this should be broken out
-
- self.$(".expand_likes").remove();
- var likesView = Backbone.View.extend({
-
- tagName: 'span',
-
- initialize: function(options){
- this.collection = options.collection;
- _.bindAll(this, "render", "appendLike");
- },
-
- render: function(){
- _.each(this.collection.models, this.appendLike)
- return this;
- },
-
- appendLike: function(model){
- $(this.el).append("