Skip to content

Instantly share code, notes, and snippets.

@bmax
Created August 23, 2014 19:16
Show Gist options
  • Save bmax/7d164d665c406473baec to your computer and use it in GitHub Desktop.
Save bmax/7d164d665c406473baec to your computer and use it in GitHub Desktop.
{{#if showForm}}
{{input id='operation_name' placeholder='Operation Name' value=operation_name}}
<button {{action 'submitOp'}}>Add Operation</button>
<button {{action 'hide'}}>Hide</button>
{{else}}
<button {{action 'show'}}>Add operation</button>
{{/if}}
{{#if showRoomForm}}
Hello
{{/if}}
<div class='row'>
{{#each}}
<div class='col-md-4'>
{{name}} -
{{#if showRoomForm}}
{{input id='room_name' placeholder='Room Name' value=room_name}}
<button {{action 'submitRoom' this}}>Add Room</button>
<button {{action 'hide' this}}>Hide</button>
{{else}}
<a {{action 'show' this}}>Add room</a>
{{/if}}
<ul>
{{#each room in rooms}}
<li>{{room.name}}</li>
{{/each}}
</ul>
</div>
{{/each}}
</div>
import Ember from 'ember';
export default Ember.Route.extend({
actions: {
show: function (item) {
if (item) {
item.set('showRoomForm', true);
} else {
this.controller.set('showForm', true);
}
},
hide: function (item) {
if (item) {
item.set('showRoomForm', false);
} else {
this.controller.set('showForm', false);
}
},
submitOp: function () {
var _this = this;
var op_name = this.controller.get('operation_name');
if (op_name) {
console.log(op_name);
var operation = this.store.createRecord('operation', { name: op_name }).save().then(function() {
// do something here?
_this.controller.set('showForm', false);
_this.controller.set('operation_name', null);
console.log('success');
},
function(jq) {
// do something here?
console.log('error submitting operation');
console.log(jq);
});
}
},
submitRoom: function(item) {
var _this = this;
var room_name = item.get('room_name');
if (room_name) {
console.log(room_name);
/*var operation = this.store.createRecord('operation', { name: op_name }).save().then(function() {
// do something here?
_this.controller.set('showForm', false);
_this.controller.set('operation_name', null);
console.log('success');
},
function(jq) {
// do something here?
console.log('error submitting operation');
console.log(jq);
});*/
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment