Created
April 28, 2014 18:52
-
-
Save dysbulic/11380767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Put your CSS here */ | |
| html, body { | |
| margin: 20px; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Ember Starter Kit</title> | |
| <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/normalize/2.1.0/normalize.css"> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
| <script src="http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-v1.3.0.js"></script> | |
| <script src="http://builds.emberjs.com/tags/v1.5.0/ember.js"></script> | |
| <script src="http://builds.emberjs.com/tags/v1.0.0-beta.4/ember-data.min.js"></script> | |
| </head> | |
| <body> | |
| <script type="text/x-handlebars"> | |
| <h2> Welcome to Ember.js</h2> | |
| {{outlet}} | |
| </script> | |
| <script type="text/x-handlebars" data-template-name="index"> | |
| <ul> | |
| {{#each well in model}} | |
| <li> | |
| {{well.name}} | |
| <ul> | |
| {{#each reading in well.readings}} | |
| <li>{{reading.time}}</li> | |
| {{/each}} | |
| </ul> | |
| </li> | |
| {{/each}} | |
| </ul> | |
| <form class="form-horizontal" role="form"> | |
| <div class="form-group"> | |
| <label for="title" class="col-sm-2 control-label">Well</label> | |
| <div class="col-sm-10"> | |
| {{view Ember.Select | |
| id="well" | |
| class="form-control" | |
| content=model | |
| optionValuePath="content.id" | |
| optionLabelPath="content.name"}} | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <label for="excerpt" class="col-sm-2 control-label">MCF</label> | |
| <div class="col-sm-10"> | |
| <input type="number" class="form-control" id="mcf" name="mcf" placeholder="MCF" required step="any"/> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <label for="url" class="col-sm-2 control-label">Line</label> | |
| <div class="col-sm-10"> | |
| <input type="number" class="form-control" id="line" name="line" placeholder="Line" required/> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <label for="url" class="col-sm-2 control-label">TBG</label> | |
| <div class="col-sm-10"> | |
| <input type="number" class="form-control" id="tbg" name="tbg" placeholder="TBG" required/> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <label for="url" class="col-sm-2 control-label">CSG</label> | |
| <div class="col-sm-10"> | |
| <input type="number" class="form-control" id="csg" name="csg" placeholder="CSG" required/> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <div class="col-sm-offset-2 col-sm-10"> | |
| <button type="submit" class="btn btn-success" {{action 'save'}}>Add</button> | |
| </div> | |
| </div> | |
| </form> | |
| </script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| App = Ember.Application.create() | |
| App.ApplicationAdapter = DS.FixtureAdapter.extend() | |
| App.Well = DS.Model.extend( { | |
| name: DS.attr( 'string' ), | |
| asset_id: DS.attr( 'number' ), | |
| readings: DS.hasMany( 'reading', { async: true } ) | |
| } ) | |
| App.Reading = DS.Model.extend( { | |
| time: DS.attr( 'date' ), | |
| mcf: DS.attr( 'number' ), | |
| line: DS.attr( 'number' ), | |
| tbg: DS.attr( 'number' ), | |
| csg: DS.attr( 'number' ), | |
| well: DS.belongsTo( 'well' ) | |
| } ) | |
| App.IndexRoute = Ember.Route.extend({ | |
| init: function() { | |
| this._super() | |
| this.set( 'wells', this.get( 'store' ).find( 'well' ) ) | |
| }, | |
| actions: { | |
| save: function() { | |
| var self = this | |
| var store = this.get( 'store' ) | |
| store.find( 'well', $('#well').val() ).then( function( well ) { | |
| var reading = store.createRecord( 'reading', { | |
| well: well, | |
| time: new Date(), | |
| mcf: $('#mcf').val(), | |
| line: $('#line').val(), | |
| tbg: $('#tbg').val(), | |
| csg: $('#csg').val() | |
| } ) | |
| reading.save() | |
| well.get( 'readings' ).then( function( readings ) { | |
| readings.pushObject( reading ) | |
| } ) | |
| } ) | |
| } | |
| }, | |
| model: function() { | |
| return this.get( 'store' ).find( 'well' ) | |
| } | |
| } ) | |
| App.Well.FIXTURES = [ | |
| { id: 1, asset_id: 1219, name: "GLASS 7", readings: [1, 2, 5] }, | |
| { id: 2, asset_id: 1224, name: "GASTON 2" }, | |
| { id: 3, asset_id: 1225, name: "GASTON 3", readings: [3, 4] } | |
| ] | |
| App.Reading.FIXTURES = [ | |
| { id: 1, time: new Date(), well: 1, mcf: 1.2, line: 34.5, tbg: 76, csg: 56 }, | |
| { id: 2, time: new Date(), well: 1, mcf: 1.2, line: 34.5, tbg: 76, csg: 56 }, | |
| { id: 3, time: new Date(), well: 3, mcf: 1.2, line: 34.5, tbg: 76, csg: 56 }, | |
| { id: 4, time: new Date(), well: 3, mcf: 1.2, line: 34.5, tbg: 76, csg: 56 }, | |
| { id: 5, time: new Date(), well: 1, mcf: 1.2, line: 34.5, tbg: 76, csg: 56 } | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment