import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
    return this.store.createRecord('parseUser');
  },

  actions: {
    createUser: function(user) {
      var interestArray = [];
      $('input[name=interest]').each(function() {
        interestArray.push($(this).val());
      });

      var latitude = user.get('latitude');
      var longitude = user.get('longitude');
      var latlng = latitude.toString() + ',' + longitude.toString();
      var location;
      var locationCity = '';
      var locationCountry = '';
      var geoData;

      Ember.$.ajax({
        url: "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latlng,
        type: 'GET',
        dataType: 'json'
      }).then(function(data) {
        geoData = data.results;
        var arrAddress = geoData[0].address_components;
        //credit: http://stackoverflow.com/questions/5341023/retrieving-postal-code-with-google-maps-javascript-api-v3-reverse-geocode
        // iterate through address_component array
        $.each(arrAddress, function (i, address_component) {
          if (address_component.types[0] === "locality"){
              locationCity = address_component.long_name;
              return false;
          }
        });
        $.each(arrAddress, function (i, address_component) {
          if (address_component.types[0] === "country"){
              locationCountry = address_component.long_name;
          }
        });
        location = locationCity + ", " + locationCountry;
      }).then(function() {
        user.set('thinker', 0);
        user.set('enabler', 0);
        user.set('connector', 0);
        user.set('location', location);
        user.set('email', user.get('username'));
        user.set('interests', interestArray);
        user.save().then(function() {
          this.get('session').authenticate('authenticator:parse-token', {
            sessionToken: user.get('sessionToken')
          });
          this.transitionTo('index');
        }.bind(this));
      }.bind(this));
    }
  }
});

@@ -481,24 +481,20 @@
     var 
-location
+city
 ;%0A      
@@ -501,25 +501,13 @@
 var 
-locationCity = ''
+state
 ;%0A  
@@ -518,28 +518,15 @@
 var 
-locationC
+c
 ountry
- = ''
 ;%0A  
@@ -808,24 +808,25 @@
 components;%0A
+%0A
         //cr
@@ -1132,28 +1132,261 @@
         
-locationCity
+city = address_component.long_name;%0A              return false;%0A          %7D%0A        %7D);%0A        $.each(arrAddress, function (i, address_component) %7B%0A          if (address_component.types%5B0%5D === %22administrative_area_level_1%22)%7B%0A              state
  = addre
@@ -1593,25 +1593,17 @@
         
-locationC
+c
 ountry =
@@ -1660,66 +1660,8 @@
 %7D);%0A
-        location = locationCity + %22, %22 + locationCountry;%0A
     
@@ -1803,27 +1803,91 @@
 et('
-location', location
+city', city);%0A        user.set('state', state);%0A        user.set('country', country
 );%0A 

Add state property to user model and save to Parse when users/create route handler called