Skip to content

Instantly share code, notes, and snippets.

@jdcauley
Created January 2, 2015 19:00
Show Gist options
  • Save jdcauley/a60ec9d64e815bfca6fc to your computer and use it in GitHub Desktop.
Save jdcauley/a60ec9d64e815bfca6fc to your computer and use it in GitHub Desktop.
ember app
/*
function emberUp(data){
var Properties = Ember.Application.create({
rootElement: '#ember-app'
});
Properties.Store = DS.Store.extend({
adapter: DS.RESTAdapter.extend()
});
Properties.IndexController = Ember.ObjectController.extend({
url : function () {
console.log(this);
return "/listings/"+this.get('sid');
}.property()
});
Properties.IndexRoute = Ember.Route.extend({
model: function() {
return data.properties;
}
});
}
function getProperties(count, offset){
if(!count && !offset){
var url = '/api/properties';
} else {
var url = '/api/properties/?count=' + count + '&offset=' + offset;
}
io.socket.get(url, function(resData, jwres){
var data = resData.data;
console.log(data);
emberUp(data);
});
}
getProperties();
*/
var get = Ember.get, set = Ember.set;
Ember.PaginationMixin = Ember.Mixin.create({
pages: function() {
var availablePages = this.get('availablePages'),
pages = [],
page;
for (i = 0; i < availablePages; i++) {
page = i + 1;
pages.push({ page_id: page.toString() });
}
return pages;
}.property('availablePages'),
currentPage: function() {
return parseInt(this.get('selectedPage'), 10) || 1;
}.property('selectedPage'),
nextPage: function() {
var nextPage = this.get('currentPage') + 1;
var availablePages = this.get('availablePages');
if (nextPage <= availablePages) {
return Ember.Object.create({id: nextPage});
}else{
return Ember.Object.create({id: this.get('currentPage')});
}
}.property('currentPage', 'availablePages'),
prevPage: function() {
var prevPage = this.get('currentPage') - 1;
if (prevPage > 0) {
return Ember.Object.create({id: prevPage});
}else{
return Ember.Object.create({id: this.get('currentPage')});
}
}.property('currentPage'),
availablePages: function() {
return Math.ceil((this.get('content.length') / this.get('itemsPerPage')) || 1);
}.property('content.length'),
paginatedContent: function() {
var selectedPage = this.get('selectedPage') || 1;
var upperBound = (selectedPage * this.get('itemsPerPage'));
var lowerBound = (selectedPage * this.get('itemsPerPage')) - this.get('itemsPerPage');
var models = this.get('content');
return models.slice(lowerBound, upperBound);
}.property('selectedPage', 'content.@each')
});
var App = Ember.Application.create({
rootElement: '#ember-app'
});
App.Store = DS.Store.extend();
App.ApplicationAdapter = DS.RESTAdapter.extend();
DS.RESTAdapter.reopen({
namespace: 'api'
});
App.ListingRoute = Ember.Route.extend({
model: function() {
return this.store.find('listing', {count: 12});
},
setupController: function(controller, model) {
this._super(controller, model);
},
});
App.Router.map(function(){
this.resource('listing', { path: '/'});
// this.resource('nextTwelve', {path: '/'})
});
App.ListingController = Ember.ArrayController.extend({
sortProperties: ['id'],
sortAscending: false,
firstLoad: function(){
console.log(this.store.all());
return this.store.all('listing');
}.property('length'),
actions: {
nextTwelve: function(){
var offset = $('.ember-listing').length;
this.store.find('listing', {count: 12, offset: 12});
}
}
});
App.Listing = DS.Model.extend({
sid: DS.attr('string'),
url: DS.attr('string'),
image: DS.attr('string'),
name: DS.attr('string'),
address: DS.attr('string'),
city: DS.attr('string'),
state: DS.attr('string'),
zip: DS.attr('string'),
market: DS.attr('string')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment