Ver Fonte

Commits 8.2 and 8.3: Add event handler and helpers to body template.

Frederic G. MARAND há 8 anos atrás
pai
commit
5279ff72b5
1 ficheiros alterados com 14 adições e 1 exclusões
  1. 14 1
      simple-todos.js

+ 14 - 1
simple-todos.js

@@ -4,7 +4,16 @@ if (Meteor.isClient) {
   // This code only runs on the client
   Template.body.helpers({
     tasks: function () {
-      return Tasks.find({}, { sort: {createdAt: -1 }});
+      if (Session.get('hideCompleted')) {
+        return Tasks.find({ checked : { $ne : true }}, { sort: { createdAt: -1 }});
+      } else {
+        return Tasks.find({}, {sort: {createdAt: -1}});
+      }
+    },
+
+    hideCompleted: function () {
+      var ret = Session.get("hideCompleted");
+      return ret;
     }
   });
 
@@ -25,6 +34,10 @@ if (Meteor.isClient) {
 
       // Prevent default form submit
       return false;
+    },
+
+    'change .hide-completed input': function (e) {
+      Session.set('hideCompleted', e.target.checked);
     }
   });