Skip to content

Instantly share code, notes, and snippets.

@Bestra
Last active September 22, 2017 20:49
Show Gist options
  • Save Bestra/e2bd7210727e934a0fe9bca2762ced11 to your computer and use it in GitHub Desktop.
Save Bestra/e2bd7210727e934a0fe9bca2762ced11 to your computer and use it in GitHub Desktop.
Rolodex Test Page
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'A Really Simple Rolodex',
newEntry: null,
entries: Ember.computed.alias('model'),
showForm: false,
actions: {
addEntry() {
this.set('newEntry', {});
this.set('showForm', true);
},
saveEntry() {
this.get('entries').pushObject(this.get('newEntry'));
this.set('showForm', false);
}
}
});
import Collection from 'ember-cli-mirage/orm/collection';
export default function() {
window.server = this;
this.get('/entries', function (schema, request) {
var entries = [
{firstName: "Bob", lastName: "Jones", phone: "123-4455"},
{firstName: "Jeff", lastName: "Davidson", phone: "551-1830"},
];
return entries;
});
};
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return $.get('/entries');
},
afterModel(model) {
console.log('model is ', model);
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
.contacts-header {
display: inline-block;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{#if showForm}}
<h3 class="contacts-header">Create a Contact</h3>
<button {{action "saveEntry"}}>Done</button>
<div>
<label>First Name{{input value=newEntry.firstName}}</label>
<label>Last Name{{input value=newEntry.lastName}}</label>
<label>Phone{{input value=newEntry.phone}}</label>
</div>
{{else}}
<h3 class="contacts-header">Your Contacts</h3>
<button {{action "addEntry"}}>+</button>
{{#each entries as |entry|}}
<div>
<span>{{entry.firstName}}</span>
<span>{{entry.lastName}}</span>
<span>{{entry.phone}}</span>
</div>
{{/each}}
{{/if}}
<br>
<br>
{
"version": "0.12.1",
"ENV": {
"ember-cli-mirage": {
"enabled": true
}
},
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1",
"ember-cli-mirage": "0.3.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment