Bläddra i källkod

W3.3: insert new document on Plus click, alert otherwise.

Frederic G. MARAND 9 år sedan
förälder
incheckning
d7e8c62a3d
2 ändrade filer med 24 tillägg och 2 borttagningar
  1. 1 1
      .eslintrc.js
  2. 23 1
      textcircle.js

+ 1 - 1
.eslintrc.js

@@ -105,7 +105,7 @@ module.exports = {
     "dot-notation": 2, // encourages use of dot notation whenever possible
     "eqeqeq": 2, // require the use of === and !==
     "guard-for-in": 2, // make sure for-in loops have an if statement (off by default)
-    "no-alert": 2, // disallow the use of alert, confirm, and prompt
+    "no-alert": 0, // disallow the use of alert, confirm, and prompt
     "no-caller": 2, // disallow use of arguments.caller or arguments.callee
     "no-div-regex": 2, // disallow division operators explicitly at beginning of regular expression (off by default)
     "no-else-return": 2, // disallow else after a return in an if (off by default)

+ 23 - 1
textcircle.js

@@ -56,7 +56,13 @@ if (Meteor.isClient) {
   Template.navbar.events({
     "click .js-add-doc": function (event) {
       event.preventDefault();
-      Meteor._debug("Add new doc", event, this);
+      // User not available.
+      if (!Meteor.user()) {
+        alert("You need to login first.");
+      }
+      else {
+        Meteor.call("addDoc");
+      }
     }
   });
 } // end isClient...
@@ -72,6 +78,22 @@ if (Meteor.isServer) {
 
 // Methods that provide write access to the data.
 Meteor.methods({
+  addDoc: function () {
+    Meteor._debug("addDoc, this", this);
+    // Not logged-in.
+    if (!this.userId) {
+      return;
+    }
+    else {
+      let doc = {
+        owner: this.userId,
+        createdOn: new Date(),
+        title: "my new doc"
+      };
+      Documents.insert(doc);
+    }
+  },
+
   addEditingUser: function () {
     let doc = Documents.findOne();
     if (!doc) {