Explorar el Código

Commit 13-2: Grey out upvote link when not logged in / already voted.

Frederic G. MARAND hace 9 años
padre
commit
034929a9c1
Se han modificado 2 ficheros con 11 adiciones y 2 borrados
  1. 1 1
      client/templates/posts/post_item.html
  2. 10 1
      client/templates/posts/post_item.js

+ 1 - 1
client/templates/posts/post_item.html

@@ -1,6 +1,6 @@
 <template name="postItem">
   <div class="post">
-    <a href="#" class="upvote btn btn-default">⬆</a>
+    <a href="#" class="upvote btn btn-default {{upvotedClass}}">⬆</a>
     <div class="post-content">
       <h3><a href="{{url}}">{{title}}</a><span>{{domain}}</span></h3>
       <p>

+ 10 - 1
client/templates/posts/post_item.js

@@ -8,11 +8,20 @@ Template.postItem.helpers({
     var a = document.createElement('a');
     a.href = this.url;
     return a.hostname;
+  },
+
+  upvotedClass: function () {
+    var userId = Meteor.userId();
+    if (userId && !_.include(this.upvoters, userId)) {
+      return "btn-primary upvotable";
+    } else {
+      return "disabled";
+    }
   }
 });
 
 Template.postItem.events({
-  'click .upvote': function (e) {
+  'click .upvotable': function (e) {
     e.preventDefault();
     Meteor.call('upvote', this._id);
   }