Last active
August 1, 2018 13:43
-
-
Save corrspt/417bca3fb3b46432ba255a608a56555e to your computer and use it in GitHub Desktop.
power-select-with-ember-3.2
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
| import { later } from '@ember/runloop'; | |
| import { Promise } from 'rsvp'; | |
| import Controller from '@ember/controller'; | |
| import { inject as service } from '@ember/service'; | |
| import RSVP from 'rsvp'; | |
| export default Controller.extend({ | |
| store: service(), | |
| baseMaterial: null, | |
| init() { | |
| this._super(...arguments); | |
| this.set('baseMaterial', this.get('store').createRecord('base-material')); | |
| }, | |
| // Actions | |
| actions: { | |
| setSpecification(spec) { | |
| this.set('baseMaterial.specification', spec); | |
| this.set('specificationsSearched', null); | |
| }, | |
| suggestSpecification(/*term*/) { | |
| 'Add this'; | |
| }, | |
| createSpecification(/*term*/) { | |
| // Can be empty, does not need to work | |
| }, | |
| searchSpecification(/*term*/) { | |
| let results = []; | |
| results.push(this.get('store').createRecord('base-material-specification', { | |
| 'specification': 'SA 1008', | |
| })); | |
| results.push(this.get('store').createRecord('base-material-specification', { | |
| 'specification': 'SA 1010', | |
| })); | |
| this.set('results', results); | |
| return new RSVP.Promise((resolve, reject) => { | |
| this.createSlowPromise(results).then((materials) => { | |
| resolve(materials); | |
| }, reject); | |
| }); | |
| }, | |
| showWhenCreateSpec() { | |
| let specs = this.get('specificationsSearched'); | |
| if (specs != null) { | |
| if (specs.get('length') === 0) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| }, | |
| createSlowPromise(results) { | |
| return new Promise(function(resolve) { | |
| later(() => resolve(results), 100); | |
| }); | |
| }, | |
| }); |
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
| import DS from 'ember-data'; | |
| export default DS.Model.extend({ | |
| specification: DS.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 characters
| import DS from 'ember-data'; | |
| export default DS.Model.extend({ | |
| specification: DS.belongsTo('base-material-specification') | |
| }); |
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
| body { | |
| margin: 12px 16px; | |
| font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
| font-size: 12pt; | |
| } |
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
| { | |
| "version": "0.15.0", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
| "ember": "3.2.2", | |
| "ember-template-compiler": "3.2.2", | |
| "ember-testing": "3.2.2" | |
| }, | |
| "addons": { | |
| "ember-data": "3.2.0", | |
| "ember-power-select-with-create": "0.6.0" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment