Last active
March 2, 2016 05:41
-
-
Save markprzepiora/dc8f2d604a3dc8e7bdc8 to your computer and use it in GitHub Desktop.
time zones select
This file contains 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 Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
model: null, | |
actions: { | |
// This is fired when the user selects a new time zone | |
// from the dropdown. | |
changeTimeZone(tz) { | |
this.set('model.timeZone', tz); | |
}, | |
}, | |
}); |
This file contains 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 Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
// In reality the model would be a bigger form object of | |
// some kind... Here it just has a timeZone property. | |
return Ember.Object.create({ | |
timeZone: null, | |
}); | |
}, | |
}); |
This file contains 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 Ember from 'ember'; | |
// Get this from ember-truth-helpers! Invaluable addon. | |
export function eq([a, b]) { | |
return a === b; | |
} | |
export default Ember.Helper.helper(eq); |
This file contains 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 Ember from 'ember'; | |
import DS from 'ember-data'; | |
// Imagine this does an Ajax request. Returns a promise | |
// resolving to an array of time zones as seen below. | |
function getTimeZones() { | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
// Simulate network lag. | |
Ember.run.later(function() { | |
resolve([ | |
{ | |
name: 'America/Los_Angeles', | |
label: 'Pacific Time (US & Canada)' | |
}, | |
{ | |
name: 'America/Chicago', | |
label: 'Central Time (US & Canada)' | |
} | |
]); | |
}, 1000); | |
}); | |
} | |
export default Ember.Component.extend({ | |
// Input | |
// ----- | |
timeZone: null, | |
// Private properties | |
// ------------------ | |
timeZones: null, | |
loadTimeZones: Ember.on('init', function() { | |
this.set('timeZones', DS.PromiseArray.create({ | |
promise: getTimeZones() | |
})); | |
}), | |
// Computed properties | |
// ------------------- | |
// Is none of the time zones currently selected? This can | |
// happen either because the selected timeZone is blank, | |
// or if it has a value not in the timeZones array. | |
noneSelected: Ember.computed('timeZone', 'timeZones.[]', function() { | |
const timeZone = this.get('timeZone'); | |
const timeZones = this.get('timeZones').mapBy('name'); | |
return timeZones.indexOf(timeZone) === -1; | |
}), | |
// Actions | |
// ------- | |
actions: { | |
changeOption(val) { | |
this.get('choose')(val); | |
}, | |
} | |
}); |
This file contains 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.6.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "release", | |
"ember-data": "release", | |
"ember-template-compiler": "release" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment