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 --- client/components/cards/cardDetails.js | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'client/components/cards/cardDetails.js') diff --git a/client/components/cards/cardDetails.js b/client/components/cards/cardDetails.js index c0ea6a05..caa5993f 100644 --- a/client/components/cards/cardDetails.js +++ b/client/components/cards/cardDetails.js @@ -1,7 +1,3 @@ -// XXX Obviously this shouldn't be a global, but this is currently the only way -// to share a variable between two files. - - BlazeComponent.extendComponent({ template: function() { return 'cardDetails'; @@ -80,6 +76,37 @@ BlazeComponent.extendComponent({ } }).register('cardDetails'); +// We extends the normal InlinedForm component to support UnsavedEdits draft +// feature. +(class extends InlinedForm { + _getUnsavedEditKey() { + return { + fieldName: 'cardDescription', + docId: Session.get('currentCard'), + } + } + + close(isReset = false) { + if (this.isOpen.get() && ! isReset) { + UnsavedEdits.set(this._getUnsavedEditKey(), this.getValue()); + } + super(); + } + + reset() { + UnsavedEdits.reset(this._getUnsavedEditKey()); + this.close(true); + } + + events() { + const parentEvents = InlinedForm.prototype.events()[0]; + return [{ + ...parentEvents, + 'click .js-close-inlined-form': this.reset, + }]; + } +}).register('inlinedCardDescription'); + Template.cardDetailsActionsPopup.events({ 'click .js-members': Popup.open('cardMembers'), 'click .js-labels': Popup.open('cardLabels'), -- cgit v1.2.3-1-g7c22