From 04a7f9139df78ab57ea12788b87424c12adbd59e Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 10 Dec 2019 13:40:08 +0300 Subject: [PATCH] Allow partial override of contribution attributes --- app/components/add-contribution/component.js | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/app/components/add-contribution/component.js b/app/components/add-contribution/component.js index b9533f8..b50b80f 100644 --- a/app/components/add-contribution/component.js +++ b/app/components/add-contribution/component.js @@ -24,18 +24,25 @@ export default Component.extend({ init () { this._super(...arguments); this.set('defaultDate', moment().startOf('hour').toDate()); + this.set('defaultAttr', { + contributorId: null, + kind: null, + date: this.defaultDate, + amount: null, + description: null, + url: null, + details: null + }); // Default attributes used by reset if (isEmpty(this.attributes)) { - this.set('attributes', { - contributorId: null, - kind: null, - date: this.defaultDate, - amount: null, - description: null, - url: null, - details: null - }); + this.set('attributes', this.defaultAttr); + } else { + Object.keys(this.defaultAttr).forEach(a => { + if (typeof this.attributes[a] === 'undefined') { + this.attributes[a] = this.defaultAttr[a]; + } + }) } this.reset();