ソースを参照

Add basic add task functionality
Move lots of previous code into templates
Add event handlers for templates

Adel Qalieh 12 年 前
コミット
b73d873c9c
2 ファイル変更46 行追加11 行削除
  1. 30 0
      astroid-web.js
  2. 16 11
      client/index.html

+ 30 - 0
astroid-web.js

@@ -1,4 +1,34 @@
+Tasks = new Meteor.Collection("tasks");
+Lists = new Meteor.Collection("lists");
+Folders = new Meteor.Collection("folders");
+
 if (Meteor.isClient) {
+  Template.todos.tasks = function () {
+    return Tasks.find();
+  }
+
+  Template.newTaskForm.events({
+    'submit #new-task, click #addTaskButton': function(e) {
+      e.preventDefault();
+      var body = $('#new-task-text').val();
+      $('#new-task-text').val("");
+      var now = moment();
+      var priority = 'low';
+      var list = 'Home';
+      Tasks.insert({
+        body: body,
+        date: now.format('D MMM YYYY'),
+        dateDue: now,
+        dateCreated: now,
+        dateCompleted: false,
+        modified: now,
+        list: list,
+        priority: priority,
+        complete: false,
+        repeating: false
+      });
+    }
+  });
 }
 
 if (Meteor.isServer) {

+ 16 - 11
client/index.html

@@ -86,14 +86,7 @@
 			<div class="col-xs-12 col-sm-8 col-lg-8">
 				<div class="well">
 					<h3 class="tasksHeading">My Tasks</h3>
-					<form action="submit" class="form-inline" role="form">
-						<div class="form-group">
-							<div id="addTaskInput">
-								<input type="text" class="form-control" placeholder="Add a new task...">
-								<button type="submit" class="btn btn-primary">Add a Task</button>
-							</div>
-						</div>
-					</form>
+          {{>newTaskForm}}
 					<div class="row" id="filters">
 					<hr>
 						<div class="col-xs-6 text-left dropdown">
@@ -159,6 +152,7 @@
 								<span class="dueDate">28 Nov 2012</span> | <span class="taskItemList">Programming</span>
 							</small>
 						</div>
+            {{>todos}}
 					</div>
 				</div>
 			</div>
@@ -314,13 +308,24 @@
 </div>
 </body>
 
+<template name="newTaskForm">
+<form id="new-task" class="form-inline" role="form">
+  <div class="form-group">
+    <div id="addTaskInput">
+      <input type="text" id="new-task-text" class="form-control" placeholder="Add a new task...">
+      <button type="submit" id="addTaskButton" class="btn btn-primary">Add a Task</button>
+    </div>
+  </div>
+</form>
+</template>
+
 <template name="todos">
-{{#each todo}}
+{{#each tasks}}
   <div class="taskListItem">
     <a href="#" class="completeBox"></a>
-    <div class="taskRowTop">{{task}}</div>
+    <div class="taskRowTop">{{body}}</div>
     <small class="taskRowBottom">
-      <span class="dueDate text-danger">{{dueDate}}</span> | <span class="taskItemList">{{list}}</span>
+      <span class="dueDate text-danger">{{date}}</span> | <span class="taskItemList">{{list}}</span>
     </small>
   </div>
 {{/each}}