Last active
July 24, 2017 13:18
-
-
Save alexBaizeau/d61e7533518d589e87e35ff5c01d9fd6 to your computer and use it in GitHub Desktop.
Revisions
-
alexBaizeau created this gist
Jul 24, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ import Ember from 'ember'; export default Ember.Controller.extend({ appName: 'Ember Twiddle', actions: { validate(){ return this.get('model').validate(); } } }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import Model from "ember-data/model"; import attr from "ember-data/attr"; import { belongsTo, hasMany } from "ember-data/relationships"; import { validator, buildValidations } from 'ember-cp-validations'; const Validations = buildValidations({ system: validator('belongs-to'), lines: validator('has-many') }); export default Model.extend( Validations, { system: belongsTo('system'), lines: hasMany('line') }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ import Model from "ember-data/model"; import attr from "ember-data/attr"; import { belongsTo, hasMany } from "ember-data/relationships"; import { validator, buildValidations } from 'ember-cp-validations'; const Validations = buildValidations({ name: validator('presence', true) }); export default Model.extend( Validations, { name: attr('string') }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import Model from "ember-data/model"; import attr from "ember-data/attr"; import { belongsTo, hasMany } from "ember-data/relationships"; import { validator, buildValidations } from 'ember-cp-validations'; const Validations = buildValidations({ name: validator('length', { max: 10 }) }); export default Model.extend( Validations, { name: attr('string') }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ import Ember from 'ember'; import config from './config/environment'; const Router = Ember.Router.extend({ location: 'none', rootURL: config.rootURL }); Router.map(function() { }); export default Router; 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ import Ember from 'ember'; export default Ember.Route.extend({ model() { let line = this.store.createRecord('line'), system = this.store.createRecord('system'), invoice = this.store.createRecord('invoice'); invoice.set('system', system); line.set('name', 'An invoice line'); invoice.get('system').set('name', 'foooo'); invoice.get('lines').pushObject(line); return invoice; } }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ System Name: <input value = {{model.system.name}}/> <br> ======================================================= <div> Lines: {{#each model.lines as |line|}} <div> name: <input value={{line.name}}/> </div> {{/each}} </div> <button {{action 'validate'}}>Validate</button> <table> <tr> <th> Property </th> <th> Value </th> </tr> <tr> <td><pre>model.lines.firstObject.validations.isValid</pre></td> <td>{{model.lines.firstObject.validations.isValid}}</td> </tr> <tr> <td><pre>model.system.validations.isValid</pre></td> <td>{{model.system.validations.isValid}}</td> </tr> <tr> <td><pre>model.validations.isValid</pre></td> <td>{{model.validations.isValid}}</td> </tr> </table> {{outlet}} <br> <br> 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ { "version": "0.12.1", "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-cp-validations": "3.3.2" } }