App = Ember.Application.create(); App.ApplicationRoute = Ember.Route.extend({ setupController: function(controller) { controller.set('title', "Hello World"); }, actions: { openInfoModal: function(content) { this.controllerFor('movie').set('content', content); return this.render('movie', { into: 'application', outlet: 'modal' }); }, closeModal: function() { return this.disconnectOutlet({ outlet: 'modal', parentView: 'application' }); } } }); // var restUrl = 'http://showtimes.everyday.in.th/api'; var restUrl = 'http://localhost:5000'; var today = new Date(); // no more hashchange in browser location /*App.Router.reopen({ location: 'history' });*/ App.ApplicationController = Ember.Controller.extend({ appName: '#Movies', loginState: null }); // Routers App.Router.map(function() { this.resource('movies', { path: 'm' }, function() { this.route('nowshowing'); this.route('comingsoon'); this.route('older'); }); }); // redirect '/' to 'groups' by default App.IndexRoute = Ember.Route.extend({ redirect: function() { this.transitionTo('movies'); } }); /*App.MovieRoute = Ember.Route.extend({ model: function(params) { return $.getJSON(restUrl+'/movie/'+params+'/').then(function(data) { return data.objects.map(function(item) { console.log("get movie: " + item); return item; }); }); } });*/ App.MovieController = Ember.ObjectController.extend({ actions: { close: function() { return this.send('closeModal'); } } }); /* * ModalComponent */ App.BaseModalComponent = Ember.Component.extend({ actions: { ok: function() { this.$('.modal').modal('hide'); this.sendAction('ok'); } }, show: function(params) { this.$('.modal').modal().on('hidden.bs.modal', function() { this.sendAction('close'); }.bind(this)); }.on('didInsertElement') }); /*App.MoviesRoute = Ember.Route.extend({ setupController: function(controller, model) { this.controllerFor('nowshowing').set('model', model); } // model: function(params) { // return $.getJSON(restUrl+'/movies/').then(function(data) { // return data.objects.map(function(movies) { // return movies; // }); // }); // } });*/ App.MoviesNowshowingRoute = Ember.Route.extend({ model: function(params) { return $.getJSON(restUrl+'/movies/nowshowing/').then(function(data) { return data.objects.map(function(movies) { return movies; }); }); }, renderTemplate: function() { console.log("rendering!!"); this.render('movies.nowshowing'); /* // can render multiple thing at once too!! this.render('comments', { into: 'favoritePost', outlet: 'comment', controller: 'blogPost' });*/ }, actions: { createMovie: function() { var name = this.get('controller').get('newName'); Ember.$.ajax(restUrl+'/movie/new/', { type: 'POST', dataType: 'json', data: { name: name }, context: this, success: function(data) { var mv = App.Nowshowing.createMovie(data); // this.modelFor('nowshowing').set('newName', ''); // this.transitionTo }, error: function() { alert('Failed to save movie'); // this.modelFor('nowshowing').set('newName', ''); } }) } } }); App.MoviesComingsoonRoute = Ember.Route.extend({ model: function(params) { return $.getJSON(restUrl+'/movies/comingsoon/').then(function(data) { return data.objects.map(function(movies) { return movies; }); }); } }); App.MoviesComingsoonView = Ember.View.extend({ didInsertElement: function() { Ember.run.next(this, function() { this.$('#container').isotope({ layoutMode: 'masonry', itemSelector: '.thumbnail', transitionDuration: '0.7s', isResizeBound: true }); echo.init({ offset: 100, throttle: 250, unload: false }); }); } }); App.MoviesNowshowingView = Ember.View.extend({ didInsertElement: function() { Ember.run.next(this, function() { this.$('#container').isotope({ layoutMode: 'masonry', itemSelector: '.thumbnail', transitionDuration: '0.7s', isResizeBound: true }); echo.init({ offset: 100, throttle: 250, unload: false }); }); } }); App.MoviesOlderRoute = Ember.Route.extend({ model: function(params) { return $.getJSON(restUrl+'/movies/older/').then(function(data) { return data.objects.map(function(movies) { return movies; }); }); } }); App.MoviesOlderView = Ember.View.extend({ didInsertElement: function() { Ember.run.next(this, function() { this.$('#container').isotope({ layoutMode: 'masonry', itemSelector: '.thumbnail', transitionDuration: '0.7s', isResizeBound: true }); echo.init({ offset: 100, throttle: 250, unload: false }); }); } }); /*App.MoviesView = Ember.View.extend({ didInsertElement: function() { Ember.run.next(this, function() { this.$('#container').isotope({ layoutMode: 'masonry', itemSelector: '.thumbnail', transitionDuration: '0.7s', isResizeBound: true }); echo.init({ offset: 100, throttle: 250, unload: false }); }); } });*/ Ember.Handlebars.helper('format-date', function(date) { return moment(date).format('ll'); });