From d644cba38ff06369cc43c1ebd08d344fd1d248ea Mon Sep 17 00:00:00 2001 From: Maxime Quandalle Date: Mon, 31 Aug 2015 15:09:53 +0200 Subject: 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 --- collections/unsavedEdits.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 collections/unsavedEdits.js (limited to 'collections') 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; +}); -- cgit v1.2.3-1-g7c22