WIP (checkbox)

This commit is contained in:
Matthew Ryan Dillon 2015-11-03 15:48:35 -07:00
parent 406a33ccdb
commit 16d77dead7
3 changed files with 35 additions and 11 deletions

View file

@ -7,10 +7,12 @@ export default Mixin.create({
fallbackRoute: null, fallbackRoute: null,
actions: { actions: {
save: function() { save: function(properties) {
const model = this.get('model'); const model = this.get('model');
const fallbackRoute = this.get('fallbackRoute'); const fallbackRoute = this.get('fallbackRoute');
model.setProperties(properties);
if (model.get('hasDirtyAttributes')) { if (model.get('hasDirtyAttributes')) {
model.save().then((model) => { model.save().then((model) => {
this.transitionToRoute(fallbackRoute, model); this.transitionToRoute(fallbackRoute, model);

View file

@ -8,6 +8,21 @@ export default Component.extend({
species: null, species: null,
"on-save": null, "on-save": null,
"on-cancel": null, "on-cancel": null,
"on-update": null,
speciesName: null,
typeSpecies: null,
updateField: function(property, value) {
this.set(property, value);
},
resetOnInit: Ember.on('init', function() {
['speciesName', 'typeSpecies'].forEach((field) => {
const valueInSpecies = this.get('species').get(field);
this.set(field, valueInSpecies);
});
}),
setupMetaDataOnInit: Ember.on('init', function() { setupMetaDataOnInit: Ember.on('init', function() {
this.get('currentUser.account').then((user) => { this.get('currentUser.account').then((user) => {
@ -17,11 +32,20 @@ export default Component.extend({
actions: { actions: {
save: function() { save: function() {
return this.attrs['on-save'](); return this.attrs['on-save'](this.getProperties(['speciesName', 'typeSpecies']));
}, },
cancel: function() { cancel: function() {
return this.attrs['on-cancel'](); return this.attrs['on-cancel']();
}, },
}
nameDidChange: function(value) {
this.updateField('speciesName', value);
},
typeSpeciesDidChange: function() {
this.toggleProperty('typeSpecies');
console.log(this.get('typeSpecies'));
},
},
}); });

View file

@ -1,14 +1,14 @@
<form class="grid-form" {{action 'save' on='submit'}}> <form class="grid-form" {{action 'save' on='submit'}}>
<fieldset> <fieldset>
<legend><em>{{species.speciesName}}</em></legend> <legend><em>{{speciesName}}</em></legend>
<div data-row-span="2"> <div data-row-span="2">
<div data-field-span="1"> <div data-field-span="1">
<label>Species Name</label> <label>Species Name</label>
{{input value=species.speciesName class="species-name"}} {{one-way-input type="text" class="species-name" value=speciesName update=(action "nameDidChange")}}
</div> </div>
<div data-field-span="1"> <div data-field-span="1">
<label>Type Species?</label> <label>Type Species?</label>
{{input type="checkbox" checked=species.typeSpecies}} {{if species.typeSpecies 'Yes' 'No'}} {{one-way-input type="checkbox" value=typeSpecies update=(action "typeSpeciesDidChange")}} {{if typeSpecies 'Yes' 'No'}}
</div> </div>
</div> </div>
{{#unless species.isNew}} {{#unless species.isNew}}
@ -37,9 +37,7 @@
<a class="button-red smaller" {{action 'cancel'}}> <a class="button-red smaller" {{action 'cancel'}}>
Cancel Cancel
</a> </a>
{{#if species.hasDirtyAttributes}} <button type="submit" class="button-green smaller save-species">
<button type="submit" class="button-green smaller save-species"> Save
Save </button>
</button>
{{/if}}
</form> </form>