Cleaning up new species a bit
This commit is contained in:
		
							parent
							
								
									b58e86a3fd
								
							
						
					
					
						commit
						886fda6843
					
				
					 9 changed files with 82 additions and 26 deletions
				
			
		| 
						 | 
					@ -3,18 +3,12 @@ import Ember from 'ember';
 | 
				
			||||||
export default Ember.Component.extend({
 | 
					export default Ember.Component.extend({
 | 
				
			||||||
  classNames: ['grid-1'],
 | 
					  classNames: ['grid-1'],
 | 
				
			||||||
  isEditing: false,
 | 
					  isEditing: false,
 | 
				
			||||||
  isNew: false,
 | 
					 | 
				
			||||||
  actions: {
 | 
					  actions: {
 | 
				
			||||||
    editSpecies: function() {
 | 
					    save: function() {
 | 
				
			||||||
      this.get('species').get('errors').clear();
 | 
					      this.sendAction('save');
 | 
				
			||||||
      if (this.get('isNew')) {
 | 
					    },
 | 
				
			||||||
        this.get('species').destroyRecord().then(this.sendAction());
 | 
					    cancel: function() {
 | 
				
			||||||
      }
 | 
					      this.sendAction('cancel');
 | 
				
			||||||
      this.toggleProperty('isEditing');
 | 
					 | 
				
			||||||
      this.get('species').rollback();
 | 
					 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    saveSpecies: function() {
 | 
					 | 
				
			||||||
      this.get('species').save().then(this.toggleProperty('isEditing'));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										5
									
								
								app/controllers/species/index.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								app/controllers/species/index.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					import SortableController from '../sortable';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default SortableController.extend({
 | 
				
			||||||
 | 
					  sortBy: 'speciesName',
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										21
									
								
								app/controllers/species/new.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								app/controllers/species/new.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					import Ember from 'ember';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default Ember.Controller.extend({
 | 
				
			||||||
 | 
					  isEditing: true,
 | 
				
			||||||
 | 
					  actions: {
 | 
				
			||||||
 | 
					    save: function() {
 | 
				
			||||||
 | 
					      var species = this.get('model');
 | 
				
			||||||
 | 
					      if (species.get('isDirty')) {
 | 
				
			||||||
 | 
					        species.save();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      this.transitionToRoute('species.index');
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    cancel: function() {
 | 
				
			||||||
 | 
					      var species = this.get('model');
 | 
				
			||||||
 | 
					      if (species.get('isNew')) {
 | 
				
			||||||
 | 
					        species.deleteRecord();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      this.transitionToRoute('species.index');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
							
								
								
									
										22
									
								
								app/controllers/species/show.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								app/controllers/species/show.js
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,22 @@
 | 
				
			||||||
 | 
					import Ember from 'ember';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default Ember.Controller.extend({
 | 
				
			||||||
 | 
					  isEditing: false,
 | 
				
			||||||
 | 
					  actions: {
 | 
				
			||||||
 | 
					    save: function() {
 | 
				
			||||||
 | 
					      var species = this.get('model');
 | 
				
			||||||
 | 
					      if (species.get('isDirty')) {
 | 
				
			||||||
 | 
					        species.save();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      this.toggleProperty('isEditing');
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    cancel: function() {
 | 
				
			||||||
 | 
					      if (this.get('isEditing')) {
 | 
				
			||||||
 | 
					        var species = this.get('model');
 | 
				
			||||||
 | 
					        species.get('errors').clear();
 | 
				
			||||||
 | 
					        species.rollback();
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      this.toggleProperty('isEditing');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
| 
						 | 
					@ -22,11 +22,15 @@
 | 
				
			||||||
            {{/link-to}}
 | 
					            {{/link-to}}
 | 
				
			||||||
          {{/each}}
 | 
					          {{/each}}
 | 
				
			||||||
          {{#if (can "edit species" species)}}
 | 
					          {{#if (can "edit species" species)}}
 | 
				
			||||||
 | 
					            {{#if species.isNew}}
 | 
				
			||||||
 | 
					              PENDING SAVE
 | 
				
			||||||
 | 
					            {{else}}
 | 
				
			||||||
              <br>
 | 
					              <br>
 | 
				
			||||||
              {{#link-to 'strains.new' class="button-gray smaller"}}
 | 
					              {{#link-to 'strains.new' class="button-gray smaller"}}
 | 
				
			||||||
                Add Strain
 | 
					                Add Strain
 | 
				
			||||||
              {{/link-to}}
 | 
					              {{/link-to}}
 | 
				
			||||||
            {{/if}}
 | 
					            {{/if}}
 | 
				
			||||||
 | 
					          {{/if}}
 | 
				
			||||||
        </dd>
 | 
					        </dd>
 | 
				
			||||||
      </dl>
 | 
					      </dl>
 | 
				
			||||||
      <dl class="span-2">
 | 
					      <dl class="span-2">
 | 
				
			||||||
| 
						 | 
					@ -78,11 +82,11 @@
 | 
				
			||||||
      <div class="grid-4">
 | 
					      <div class="grid-4">
 | 
				
			||||||
        <div class="span-1">
 | 
					        <div class="span-1">
 | 
				
			||||||
          {{! Does nothing ATM }}
 | 
					          {{! Does nothing ATM }}
 | 
				
			||||||
          <a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'editSpecies'}}>
 | 
					          <a {{bind-attr class=":smaller isEditing:button-red:button-gray"}} {{action 'cancel'}}>
 | 
				
			||||||
            {{#if isEditing}}Cancel{{else}}Edit{{/if}}
 | 
					            {{#if isEditing}}Cancel{{else}}Edit{{/if}}
 | 
				
			||||||
          </a>
 | 
					          </a>
 | 
				
			||||||
          {{#if isEditing}}
 | 
					          {{#if isEditing}}
 | 
				
			||||||
            <a class="button-green smaller" {{action 'saveSpecies'}}>
 | 
					            <a class="button-green smaller" {{action 'save'}}>
 | 
				
			||||||
              Save
 | 
					              Save
 | 
				
			||||||
            </a>
 | 
					            </a>
 | 
				
			||||||
          {{/if}}
 | 
					          {{/if}}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +1,7 @@
 | 
				
			||||||
{{species/species-details species=model isEditing=true isNew=true action="cancelSpecies"}}
 | 
					{{
 | 
				
			||||||
 | 
					  species/species-details
 | 
				
			||||||
 | 
					  species=model
 | 
				
			||||||
 | 
					  isEditing=true
 | 
				
			||||||
 | 
					  save="save"
 | 
				
			||||||
 | 
					  cancel="cancel"
 | 
				
			||||||
 | 
					}}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1 +1,7 @@
 | 
				
			||||||
{{species/species-details species=model}}
 | 
					{{
 | 
				
			||||||
 | 
					  species/species-details
 | 
				
			||||||
 | 
					  species=model
 | 
				
			||||||
 | 
					  isEditing=isEditing
 | 
				
			||||||
 | 
					  save="save"
 | 
				
			||||||
 | 
					  cancel="cancel"
 | 
				
			||||||
 | 
					}}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,7 +80,8 @@ module.exports = function(app) {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  speciesRouter.post('/', function(req, res) {
 | 
					  speciesRouter.post('/', function(req, res) {
 | 
				
			||||||
    res.status(201).end();
 | 
					    req.body.species.id = Math.max.apply(Math, SPECIES.map(function(o){return o.id;})) + 1;
 | 
				
			||||||
 | 
					    res.status(201).send(req.body);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  speciesRouter.get('/:id', function(req, res) {
 | 
					  speciesRouter.get('/:id', function(req, res) {
 | 
				
			||||||
| 
						 | 
					@ -93,11 +94,7 @@ module.exports = function(app) {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  speciesRouter.put('/:id', function(req, res) {
 | 
					  speciesRouter.put('/:id', function(req, res) {
 | 
				
			||||||
    res.send({
 | 
					    res.send(req.body);
 | 
				
			||||||
      'species': {
 | 
					 | 
				
			||||||
        id: req.params.id
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  speciesRouter.delete('/:id', function(req, res) {
 | 
					  speciesRouter.delete('/:id', function(req, res) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -92,7 +92,8 @@ module.exports = function(app) {
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  strainsRouter.post('/', function(req, res) {
 | 
					  strainsRouter.post('/', function(req, res) {
 | 
				
			||||||
    res.status(201).end();
 | 
					    req.body.strain.id = Math.max.apply(Math, STRAINS.map(function(o){return o.id;})) + 1;
 | 
				
			||||||
 | 
					    res.status(201).send(req.body);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  strainsRouter.get('/:id', function(req, res) {
 | 
					  strainsRouter.get('/:id', function(req, res) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue