Add new strain
This commit is contained in:
		
							parent
							
								
									c5b28f7204
								
							
						
					
					
						commit
						dfc62cd1ac
					
				
					 6 changed files with 36 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -3,10 +3,15 @@ import Ember from 'ember';
 | 
			
		|||
export default Ember.Component.extend({
 | 
			
		||||
  classNames: ['grid-1'],
 | 
			
		||||
  isEditing: false,
 | 
			
		||||
  isNew: false,
 | 
			
		||||
  actions: {
 | 
			
		||||
    editStrain: function() {
 | 
			
		||||
      this.get('strain').get('errors').clear();
 | 
			
		||||
      if (this.get('isNew')) {
 | 
			
		||||
        this.get('strain').destroyRecord().then(this.sendAction());
 | 
			
		||||
      }
 | 
			
		||||
      this.toggleProperty('isEditing');
 | 
			
		||||
      this.get('strain').rollback();
 | 
			
		||||
    },
 | 
			
		||||
    saveStrain: function() {
 | 
			
		||||
      this.get('strain').save().then(this.toggleProperty('isEditing'));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,7 @@ Router.map(function() {
 | 
			
		|||
  this.route('login');
 | 
			
		||||
  this.route('about');
 | 
			
		||||
  this.resource('strains', function() {
 | 
			
		||||
    this.route('new');
 | 
			
		||||
    this.route('show', { path: ':strain_id' }, function() {
 | 
			
		||||
      this.resource('measurements', function() {});
 | 
			
		||||
    });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										12
									
								
								app/routes/strains/new.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/routes/strains/new.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,12 @@
 | 
			
		|||
import Ember from 'ember';
 | 
			
		||||
 | 
			
		||||
export default Ember.Route.extend({
 | 
			
		||||
  model: function() {
 | 
			
		||||
    return this.store.createRecord('strain');
 | 
			
		||||
  },
 | 
			
		||||
  actions: {
 | 
			
		||||
    cancelStrain: function() {
 | 
			
		||||
      this.transitionTo('strains.index');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -3,7 +3,9 @@
 | 
			
		|||
 | 
			
		||||
{{#if (can "add strain")}}
 | 
			
		||||
  {{! Does nothing ATM }}
 | 
			
		||||
  <a class="button-gray smaller">Add Strain</a>
 | 
			
		||||
  {{#link-to 'strains.new' class="button-gray smaller"}}
 | 
			
		||||
    Add Strain
 | 
			
		||||
  {{/link-to}}
 | 
			
		||||
{{/if}}
 | 
			
		||||
 | 
			
		||||
<table class="flakes-table">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										1
									
								
								app/templates/strains/new.hbs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								app/templates/strains/new.hbs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
{{strains/strain-details strain=model isEditing=true isNew=true action="cancelStrain"}}
 | 
			
		||||
		Reference in a new issue