Skip to content

Instantly share code, notes, and snippets.

@jrhe
jrhe / Correct
Created September 17, 2013 21:18
Ember Inject problem. Inject was injecting currentUser to all controllers except application and index. Passing the promise directly to inject solved this.
var user = store.find('user', 'current');
container.lookup('controller:currentUser').set('content', user);
App.inject('controller', 'currentUser', 'controller:currentUser');
@jrhe
jrhe / gist:6602577
Created September 18, 2013 00:08
isMale / isFemale ember checkbox helpers
App.User = DS.Model.extend({
gender: DS.attr('string'),
isFemale: function() { return this.get('gender') == 'female'; },
isMale: function() { return this.get('gender') == 'male'; }
});
@jrhe
jrhe / gist:7242369
Created October 30, 2013 23:57
placeholder input ember-easyForm
{{#input firstName}}
{{input-field firstName placeholder='First Name'}}
<br/>
{{error-field firstName}}
{{/input}}
Ember.SimpleAuth.Session.reopen({
currentUser: function() {
return new Ember.RSVP.Promise(function(resolve, reject) {
Ember.$.ajax({
url: '/api/users/current',
type: 'GET'
}).then(function(response) {
Ember.run(function() {
var user = container.lookup("store:main").pushPayload(response);
resolve(user);
@jrhe
jrhe / gist:8978516
Created February 13, 2014 16:31
Facebook loader ember RSVP promises
var FacebookLoader = Ember.Object.create({
setup: function(settings) {
this.loadScript().then(function(fb) {
console.log('in setup callabck');
});
},
loadScript: function() {
return new Ember.RSVP.Promise(function(resolve) {
window.fbAsyncInit = function() {
resolve();
import Facebook from 'appkit/initializers/facebook';
var FacebookAuthenticator = Ember.SimpleAuth.Authenticators.OAuth2.extend({
authenticate: function() {
var _this = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
_this.facebookCallback().then(function(response) {
var expiresAt = _this.absolutizeExpirationTime(response.expires_in);
@jrhe
jrhe / gist:d519d23ffba65f20ba9e
Created May 28, 2014 00:54
Ember Simple Form + Select2 value binding (untested)
Ember.EasyForm.Select.reopen({
didInsertElement: function() {
// Listen for select2 value changes.
// Uses embers helper method to make sure this is bound correctly.
// See: http://balinterdi.com/2014/05/09/ember-dot-run-dot-bind.html
this.$().select2().on("change", Ember.run.bind(this, this.select2ValueChanged));
},
...
// When select2s value changes, update the components value
select2ValueChanged: function(e) {
import DeviseAPIAuthenticator from 'devon-discovery/authenticators/devise_api';
export default {
name: 'authentication',
initialize: function(container, application) {
container.register('ember-simple-auth-authenticator:devise_api', DeviseAPIAuthenticator);
// customize the session so that it allows access to the account object
Ember.SimpleAuth.Session.reopen({
user: function() {
Ember.SimpleAuth.Authenticators.OAuth2.reopen({
serverTokenEndpoint: ENV.api.host + '/' + ENV.api.namespace + '/oauth/token',
restore: function(properties) {
return new Ember.RSVP.Promise(function(resolve, reject) {
if (!Ember.isEmpty(properties.user_token) &&
!Ember.isEmpty(properties.user_email) &&
!Ember.isEmpty(properties.resource_owner_id)) {
resolve(properties);
} else {
reject();
Ember.SimpleAuth.Authenticators.OAuth2.reopen({
serverTokenEndpoint: ENV.api.host + '/' + ENV.api.namespace + '/oauth/token'
});
// customize the session so that it allows access to the account object
Ember.SimpleAuth.Session.reopen({
user: function() {
var resourceOwnerId = this.get('resource_owner_id');
if (!Ember.isEmpty(resourceOwnerId)) {
return this.container.lookup('store:main').find('user', resourceOwnerId);