Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* APPLICATION */
- window.Weather = Ember.Application.create();
- //Weather.ApplicationAdapter = DS.FixtureAdapter.extend();
- Weather.LocationAdapter = DS.Adapter.extend({
- host: "http://api.openweathermap.org/data/2.5/weather",
- cityKey: '?q=',
- latKey: '?lat=',
- lonKey: '&lon=',
- find: function(store, type, id) {
- return Ember.$.getJSON(this.host + this.cityKey + id);
- }
- });
- var slugify = function(str) {
- return str.replace(/([^\w\s\_\-\.]|(^\W+|\W+$))/g, '').replace(/[\s\-\_\.]+/g, '-');
- };
- /*Weather.store = DS.Store.create({
- adapter: Weather.LocationAdapter.create()
- });*/
- Weather.LocationSerializer = DS.JSONSerializer.extend({
- extractSingle: function(store, type, payload) {
- var name = payload.name;
- var lat = payload.coord.lat;
- var lon = payload.coord.lon;
- payload = {
- name: name,
- slug: slugify(name),
- lat: lat,
- lon: lon
- };
- console.log(payload);
- return this._super(store, type, payload);
- }
- });
- /* MODELS */
- Weather.Location = DS.Model.extend({
- name: DS.attr('string'),
- slug: DS.attr('string'),
- lat: DS.attr('number'),
- lon: DS.attr('number')
- });
- /* ROUTER */
- Weather.Router.map(function() {
- //this.resource('location', { path: '/' });
- this.resource('location', { path: '/:location_slug' });
- });
- /*Weather.Router.reopen({
- location: 'hash'
- });*/
- Weather.LocationRoute = Ember.Route.extend({
- model: function(params) {
- return this.store.find('location', params.location_slug);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement