Created
January 22, 2015 02:01
-
-
Save MOPineyro/3c15a85dca03fe31bc0b to your computer and use it in GitHub Desktop.
Ember checkin controller
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({ | |
actions: { | |
checkIn: function() { | |
var controller = this; | |
var checkIn = this.store.createRecord('check-in'); | |
var success = function(position) { | |
checkIn.set('latitude', position.coords.latitude); | |
checkIn.set('longitude', position.coords.longitude); | |
checkIn.save().then(function() { | |
controller.get('session').get('currentUser').set('checked_in', true); | |
}).catch(function(response) { | |
controller.set('errors', response.errors); | |
setTimeout(function() { | |
controller.set('errors', undefined); | |
}, 10000); | |
}); | |
}; | |
var failure = function(error) { | |
alert('Uh-oh. There was a problem.\nCode: ' + error.code + '\nMessage: ' + error.message + '\n'); | |
}; | |
var options = { }; | |
navigator.geolocation.getCurrentPosition(success, failure, options); | |
}, | |
sendCode: function() { | |
var controller = this; | |
var userBadge = this.store.createRecord('user-badge', { | |
code: this.get('code') | |
}); | |
userBadge.save().then(function() { | |
controller.set('code', ''); | |
controller.set('redeemed', true); | |
setTimeout(function() { | |
controller.set('redeemed', false); | |
}, 2500); | |
}).catch(function(response) { | |
controller.set('errors', response.errors); | |
setTimeout(function() { | |
controller.set('errors', undefined); | |
}, 10000); | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment