summaryrefslogtreecommitdiffstats
path: root/collections
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-08-31 15:09:53 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-08-31 15:52:16 +0200
commitd644cba38ff06369cc43c1ebd08d344fd1d248ea (patch)
treebad4bcef1f549132792301cf134b3c8234ad1d13 /collections
parentcc88e78483d2f39048d3558193f0c82b711c12c8 (diff)
downloadwekan-d644cba38ff06369cc43c1ebd08d344fd1d248ea.tar.gz
wekan-d644cba38ff06369cc43c1ebd08d344fd1d248ea.tar.bz2
wekan-d644cba38ff06369cc43c1ebd08d344fd1d248ea.zip
Replace the component bounded `cachedValue` by a global `UnsavedEdits`
This new draft saving system is currently only implemented for the card description and comment. We need better a component inheritance/composition model to support this for all editable fields. Fixes #186
Diffstat (limited to 'collections')
-rw-r--r--collections/unsavedEdits.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/collections/unsavedEdits.js b/collections/unsavedEdits.js
new file mode 100644
index 00000000..e9105daf
--- /dev/null
+++ b/collections/unsavedEdits.js
@@ -0,0 +1,34 @@
+// This collection shouldn't be manipulated directly by instead throw the
+// `UnsavedEdits` API on the client.
+UnsavedEditCollection = new Mongo.Collection('unsaved-edits');
+
+UnsavedEditCollection.attachSchema(new SimpleSchema({
+ fieldName: {
+ type: String
+ },
+ docId: {
+ type: String
+ },
+ value: {
+ type: String
+ },
+ userId: {
+ type: String
+ },
+}));
+
+if (Meteor.isServer) {
+ function isAuthor(userId, doc, fieldNames = []) {
+ return userId === doc.userId && fieldNames.indexOf('userId') === -1;
+ }
+ UnsavedEditCollection.allow({
+ insert: isAuthor,
+ update: isAuthor,
+ remove: isAuthor,
+ fetch: ['userId']
+ });
+}
+
+UnsavedEditCollection.before.insert(function(userId, doc) {
+ doc.userId = userId;
+});