-
-
Save mikegrassotti/5164647 to your computer and use it in GitHub Desktop.
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
App = Ember.Application.create({ | |
LOG_TRANSITIONS: true | |
}); | |
App.LoadingView = Ember.View.extend({ | |
templateName: 'loading', | |
classNames: 'loading-box' | |
}); | |
App.LoadingRoute = Ember.Route.extend({ | |
activate: function() { | |
console.log('Loading route activated'); | |
this.set('view', App.LoadingView.create()); | |
}, | |
renderTemplate: function() { | |
rootElement = this.get('router.namespace.rootElement'); | |
this.get('view').appendTo(rootElement); | |
}, | |
deactivate: function() { | |
console.log('Loading route deactivated'); | |
this.get('view').remove(); | |
} | |
}); | |
App.ApplicationRoute = Ember.Route.extend({ | |
model: function() { | |
promise = App.Deal.find({}); | |
promise.then( function() { | |
console.log('App.ApplicationRoute promise resolved!'); | |
}); | |
return promise; | |
} | |
}); | |
App.IndexRoute = Ember.Route.extend({ | |
model: function() { | |
promise = App.Deal.find({}); | |
promise.then(function(result) { | |
console.log('App.IndexRoute promise resolved!'); | |
console.log(result.content.length); | |
}, function(error) { | |
console.log("App.IndexRoute promise broken"); | |
}); | |
return promise; | |
} | |
}); | |
App.IndexController = Ember.ArrayController.extend({ | |
page: 1, | |
loadMore: function() { | |
this.incrementProperty('page'); | |
App.Deal.find({page: this.get('page')}); | |
} | |
}); | |
App.Store = DS.Store.extend({ | |
revision: 12 | |
}); | |
App.CustomSerializer = DS.JSONSerializer.extend({ | |
extractMany: function(loader, json, type, records) { | |
data = {}; | |
data.deals = json.deals.map(function(item) {return item.deal;}); | |
this._super(loader, data, type, records); | |
} | |
}); | |
DS.RESTAdapter.reopen({ | |
namespace: 'v2', | |
url: 'http://api.sqoot.com', | |
serializer: App.CustomSerializer, | |
ajax: function(url, type, hash) { | |
hash.url = url; | |
hash.type = type; | |
hash.dataType = 'jsonp'; | |
hash.contentType = 'application/json; charset=utf-8'; | |
hash.context = this; | |
hash.data = hash.data || {}; | |
hash.data.api_key = 'c6t5yl'; | |
if (hash.data && type !== 'GET') { | |
hash.data = JSON.stringify(hash.data); | |
} | |
console.log('scheduling ajax...'); | |
Ember.run.later(this, function() { | |
console.log('running ajax after delay...'); | |
jQuery.ajax(hash); | |
}, 1000); | |
} | |
}); | |
App.Deal = DS.Model.extend({ | |
title: DS.attr('string'), | |
image_url: DS.attr('string'), | |
thumbnailUrl: function() { | |
return this.get('image_url') + "&geometry=400x400C"; | |
}.property('image_url') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment