You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.9 KiB
77 lines
1.9 KiB
App = Ember.Application.create(); |
|
|
|
App.ApplicationRoute = Ember.Route.extend({ |
|
setupController: function(controller) { |
|
controller.set('title', "Hello World"); |
|
}, |
|
}); |
|
|
|
// redirect '/' to 'groups' by default |
|
App.IndexRoute = Ember.Route.extend({ |
|
beforeModel: function() { |
|
this.transitionTo('groups'); |
|
} |
|
}); |
|
|
|
App.ApplicationController = Ember.Controller.extend({ |
|
appName: '#ShowtimesTH' |
|
}); |
|
|
|
var groups = [ |
|
{id: "1", name: "sf"}, {id: "2", name: "major"} |
|
]; |
|
|
|
var restUrl = 'http://showtimes.everyday.in.th/api'; |
|
var today = new Date(); |
|
|
|
App.Router.map(function() { |
|
this.resource('about'); |
|
this.resource('api'); |
|
this.resource('groups', {path: '/g'}, function() { |
|
this.resource('theaters', {path: ':name'}, function() { |
|
this.resource('showtimes', {path: ':code'}); |
|
}); |
|
}); |
|
}); |
|
|
|
App.GroupsRoute = Ember.Route.extend({ |
|
model: function() { |
|
return groups; |
|
} |
|
}); |
|
|
|
App.TheatersRoute = Ember.Route.extend({ |
|
model: function(params) { |
|
return $.getJSON(restUrl+'/theaters/'+params.name+'/').then(function(data) { |
|
return data.objects.map(function(theater) { |
|
return theater; |
|
}); |
|
}); |
|
} |
|
}); |
|
|
|
App.ShowtimesRoute = Ember.Route.extend({ |
|
model: function(params) { |
|
var theatersObjs = this.modelFor('theaters'); |
|
var url = [ |
|
restUrl, '/showtimes/', theatersObjs[0].group, |
|
'/', params.code, '/?d=', moment(today).format('YYYY-MM-DD') |
|
]; |
|
return $.getJSON(url.join('')).then(function(data) { |
|
return data.objects.map(function(showtimesItem) { |
|
return showtimesItem; |
|
}); |
|
}); |
|
} |
|
}); |
|
|
|
var showdown = new Showdown.converter(); |
|
|
|
Ember.Handlebars.helper('format-markdown', function(input) { |
|
return new Handlebars.SafeString(showdown.makeHtml(input)); |
|
}); |
|
|
|
Ember.Handlebars.helper('format-date', function(date) { |
|
return moment(date).format('ll'); |
|
}); |
|
|
|
|