Skip to content

Instantly share code, notes, and snippets.

@MOPineyro
Created January 22, 2015 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MOPineyro/3c15a85dca03fe31bc0b to your computer and use it in GitHub Desktop.
Save MOPineyro/3c15a85dca03fe31bc0b to your computer and use it in GitHub Desktop.
Ember checkin controller
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