diff --git a/app/components/add-contributor/component.js b/app/components/add-contributor/component.js index 75398c2..cd2bdca 100644 --- a/app/components/add-contributor/component.js +++ b/app/components/add-contributor/component.js @@ -1,41 +1,58 @@ import Ember from 'ember'; +import Contributor from 'kredits-web/models/contributor'; -export default Ember.Component.extend({ +const { + Component, + isPresent, + inject: { + service + }, + computed +} = Ember; - id: null, - realName: null, - address: null, - ipfsHash: null, - isCore: false, +export default Component.extend({ + kredits: service(), + + newContributor: null, inProgress: false, - isValidId: function() { - return Ember.isPresent(this.get('id')); - }.property('id'), - - isValidRealName: function() { - return Ember.isPresent(this.get('realName')); - }.property('realName'), - isValidAddress: function() { - return this.get('kredits.web3Instance').isAddress(this.get('address')); - }.property('address'), + return this.get('kredits.web3Instance') + .isAddress(this.get('newContributor.address')); + }.property('newContributor.address'), - isValid: function() { - return this.get('isValidId') && this.get('isValidRealName') && this.get('isValidAddress'); - }.property('isValidAddress', 'isValidId', 'isValidRealName'), + isValidName: function() { + return isPresent(this.get('newContributor.name')); + }.property('newContributor.name'), + + isValidURL: function() { + return isPresent(this.get('newContributor.url')); + }.property('newContributor.name'), + + isValidGithubUID: function() { + return isPresent(this.get('newContributor.github_uid')); + }.property('newContributor.github_uid'), + + isValidGithubUsername: function() { + return isPresent(this.get('newContributor.github_username')); + }.property('newContributor.github_username'), + + isValidWikiUsername: function() { + return isPresent(this.get('newContributor.wiki_username')); + }.property('newContributor.wiki_username'), + + isValid: computed.and( + 'isValidAddress', + 'isValidName', + 'isValidGithubUID' + ), reset: function() { this.setProperties({ - id: null, - realName: null, - address: null, - ipfsHash: null, - isCore: true, + newContributor: Contributor.create({ kind: 'person' }), inProgress: false }); - }, actions: { @@ -49,12 +66,7 @@ export default Ember.Component.extend({ if (this.get('isValid')) { this.set('inProgress', true); - this.get('kredits').addContributor( - this.get('address'), - this.get('realName'), - this.get('isCore'), - this.get('id') - ).then(contributor => { + this.get('kredits').addContributor(this.get('newContributor')).then(contributor => { this.reset(); this.get('contributors').pushObject(contributor); window.scroll(0,0); diff --git a/app/components/add-contributor/template.hbs b/app/components/add-contributor/template.hbs index 076156e..397e8dc 100644 --- a/app/components/add-contributor/template.hbs +++ b/app/components/add-contributor/template.hbs @@ -1,31 +1,59 @@