瀏覽代碼

Handle posts.

- readded 'insecure' to allow inserts.
Frederic G. MARAND 9 年之前
父節點
當前提交
3512ae8948

+ 1 - 0
.meteor/packages

@@ -11,3 +11,4 @@ underscore
 sacha:spin
 ian:accounts-ui-bootstrap-3
 accounts-password
+insecure

+ 1 - 0
.meteor/versions

@@ -20,6 +20,7 @@ htmljs@1.0.4
 http@1.1.0
 ian:accounts-ui-bootstrap-3@1.2.79
 id-map@1.0.3
+insecure@1.0.3
 iron:controller@1.0.8
 iron:core@1.0.8
 iron:dynamic-template@1.0.8

+ 3 - 0
client/templates/includes/header.html

@@ -11,6 +11,9 @@
     </div>
 
     <div class="collapse navbar-collapse" id="navigation">
+      <ul class="nav navbar-nav">
+        <li><a href="{{ pathFor 'postSubmit' }}">Submit Post</a></li>
+      </ul>
       <ul class="nav navbar-nav navbar-right">
         {{> loginButtons}}
       </ul>

+ 0 - 0
client/templates/posts/not_found.html → client/templates/not_found.html


+ 0 - 0
client/templates/post_page.html → client/templates/posts/post_page.html


+ 15 - 0
client/templates/posts/post_submit.html

@@ -0,0 +1,15 @@
+<template name="postSubmit">
+  <form class="main form page">
+    <div class="form-group">
+      <label class="control-label" for="url">URL</label>
+      <div class="controls">
+        <input name="url" id="url" type="text" value="" placeholder="Your URL" class="form-control" />
+      </div>
+    </div>
+    <div class="form-group">
+      <label class="control-label" for="title">Title</label>
+      <input name="title" id="title" type="text" value="" placeholder="Name your post" class="form-control" />
+    </div>
+    <input type="submit" value="Submit" class="btn btn-primary" />
+  </form>
+</template>

+ 22 - 0
client/templates/posts/post_submit.js

@@ -0,0 +1,22 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 31/08/15
+ * Time: 20:47
+ */
+
+Template.postSubmit.events({
+  'submit form': function (e) {
+    e.preventDefault();
+
+    var post = {
+      url: $(e.target).find('[name=url]').val(),
+      title: $(e.target).find('[name=title]').val()
+    };
+
+    post._id = Posts.insert(post);
+    Router.go('postPage', post);
+  }
+});

+ 0 - 1
lib/collections/posts.js

@@ -9,4 +9,3 @@
 
 // Not a "var", to make it global.
 Posts = new Mongo.Collection('posts');
-

+ 4 - 0
lib/router.js

@@ -29,6 +29,10 @@ Router.route('/posts/:_id', {
   }
 });
 
+Router.route('/submit', {
+  name: 'postSubmit'
+});
+
 // Faire une 404 si la page matche la route postPage, mais pas son argument.
 // Déclenché pour toute valeur "falsy" (null, false, undefined, empty).
 Router.onBeforeAction('dataNotFound', {