Ver Fonte

W3.8: add editable title, private field. Use method to set privacy.

Frederic G. MARAND há 9 anos atrás
pai
commit
f8cde9d73f
4 ficheiros alterados com 60 adições e 0 exclusões
  1. 1 0
      .meteor/packages
  2. 5 0
      .meteor/versions
  3. 16 0
      textcircle.html
  4. 38 0
      textcircle.js

+ 1 - 0
.meteor/packages

@@ -24,3 +24,4 @@ check
 ecmascript
 accounts-password
 ian:accounts-ui-bootstrap-3
+babrahams:editable-text

+ 5 - 0
.meteor/versions

@@ -5,6 +5,7 @@ autopublish@1.0.4
 autoupdate@1.2.4
 babel-compiler@5.8.24_1
 babel-runtime@0.1.4
+babrahams:editable-text@0.8.10
 base64@1.0.4
 binary-heap@1.0.4
 blaze@2.1.3
@@ -16,6 +17,7 @@ caching-html-compiler@1.0.2
 callback-hook@1.0.4
 check@1.1.0
 coffeescript@1.0.11
+dburles:mongo-collection-instances@0.3.4
 ddp@1.2.2
 ddp-client@1.2.1
 ddp-common@1.2.2
@@ -23,12 +25,14 @@ ddp-rate-limiter@1.0.0
 ddp-server@1.2.2
 deps@1.0.9
 diff-sequence@1.0.1
+djedi:sanitize-html@1.11.2
 ecmascript@0.1.6
 ecmascript-runtime@0.2.6
 ejson@1.0.7
 email@1.0.8
 fastclick@1.0.7
 geojson-utils@1.0.4
+gwendall:body-events@0.1.6
 handlebars@1.0.4
 hot-code-push@1.0.0
 html-tools@1.0.5
@@ -37,6 +41,7 @@ http@1.1.1
 ian:accounts-ui-bootstrap-3@1.2.89
 id-map@1.0.4
 jquery@1.11.4
+lai:collection-extensions@0.1.4
 launch-screen@1.0.4
 livedata@1.0.15
 localstorage@1.0.5

+ 16 - 0
textcircle.html

@@ -5,6 +5,11 @@
 <body>
   {{> navbar }}
   <div class="container top-margin">
+    <div class="row">
+      <div class="col-md-12">
+        {{> docMeta }}
+      </div>
+    </div>
     <div class="row">
       <div class="col-md-12">
         {{> editingUsers }}
@@ -63,6 +68,17 @@
   </iframe>
 </template>
 
+<template name="docMeta">
+  {{#with document }}
+    <span class="h1">{{> editableText collection="documents" field="title" }}</span>
+  {{/with}}
+  <div class="checkbox">
+    <label>
+      <input type="checkbox" class="js-tog-private" />Private
+    </label>
+  </div>
+</template>
+
 <template name="editingUsers">
   Editors:
   {{#each users }}

+ 38 - 0
textcircle.js

@@ -59,6 +59,24 @@ if (Meteor.isClient) {
     }
   });
 
+  Template.docMeta.helpers({
+    document: function () {
+      return Documents.findOne({ _id: Session.get("docid") });
+    }
+  });
+
+  Template.editableText.helpers({
+    userCanEdit: function (doc, collection) {
+      Meteor._debug("userCanEdit", doc, collection);
+      // Can edit if the document is owned by me.
+      doc = Documents.findOne({
+        _id: Session.get("docid"),
+        owner: Meteor.userId()
+      });
+      return !!doc;
+    }
+  });
+
   Template.navbar.events({
     "click .js-add-doc": function (event) {
       event.preventDefault();
@@ -81,6 +99,17 @@ if (Meteor.isClient) {
       Session.set("docid", this._id);
     }
   });
+
+  Template.docMeta.events({
+    "click .js-tog-private": function (event) {
+      const docid = Session.get("docid");
+      if (docid) {
+        const doc = { _id: docid, isPrivate: event.target.checked };
+        Meteor.call("updateDocPrivacy", doc);
+      }
+    }
+  });
+
 } // end isClient...
 
 if (Meteor.isServer) {
@@ -111,6 +140,15 @@ Meteor.methods({
     }
   },
 
+  updateDocPrivacy: function (doc) {
+    Meteor._debug("updatedocPrivacy", this.userId, doc)
+    if (!this.userId) {
+      return;
+    }
+    let res = Documents.update({ _id: doc._id, owner: this.userId }, { $set: { private: doc.isPrivate } });
+    Meteor._debug("update", res);
+  },
+
   addEditingUser: function () {
     let doc = Documents.findOne();
     if (!doc) {