diff options
Diffstat (limited to 'imdb-lookup/html/index-files/js/app.js')
-rw-r--r-- | imdb-lookup/html/index-files/js/app.js | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/imdb-lookup/html/index-files/js/app.js b/imdb-lookup/html/index-files/js/app.js index 3bba2a1..a3a9632 100644 --- a/imdb-lookup/html/index-files/js/app.js +++ b/imdb-lookup/html/index-files/js/app.js @@ -1,8 +1,6 @@ var App = Ember.Application.create(); App.ApplicationAdapter = DS.FixtureAdapter.extend(); - -App.Router.map(function() { // put your routes here -}); +App.Router.map(function() { }); App.IndexRoute = Ember.Route.extend({ model: function() { @@ -12,6 +10,7 @@ App.IndexRoute = Ember.Route.extend({ App.Movie = DS.Model.extend({ title: DS.attr('string'), + summary: DS.attr('string'), path: DS.attr('string'), poster: DS.attr('string'), tagline: DS.attr('string'), @@ -21,16 +20,14 @@ App.Movie = DS.Model.extend({ path: DS.attr(), tags: DS.attr(), - imdbRating: DS.attr('int'), - imdbVotes: DS.attr('int'), + imdbRating: DS.attr('number'), + imdbVotes: DS.attr('number'), omdbTomatoConsensus: DS.attr('string'), - omdbTomato: DS.attr('int'), - omdbUserTomato: DS.attr('int'), + omdbTomatoMeter: DS.attr('number'), omdbTomatoRating: DS.attr(), - omdbTomatoUserRating: DS.attr(), - tmdbId: DS.attr('int'), + tmdbId: DS.attr('number'), linkTmdb: function() { return "http://www.themoviedb.org/movie/" + this.get('tmdbId'); @@ -52,11 +49,19 @@ App.Movie = DS.Model.extend({ App.IndexController = Ember.ArrayController.extend({ page: 1, perPage: "10", + filterTextEntry: "", + filter: "", sortAscending: "false", sortProperties: function() { return [this.get("firstSortProperty")]; }.property("firstSortProperty"), firstSortProperty: "title", + possibleSortProperties: [ {value:"title",label:"Title"}, + {value:"imdbRating", label:"IMDB Rating"}, + {value:"imdbVotes", label:"IMDB Votes"}, + {value:"release", label:"Release Year"}, + {value:"omdbTomatoMeter", label:"RottenTomatoes Meter %"}, + {value:"omdbTomatoRating", label:"RottenTomatoes Rating"}], visiblePerPage: ["10", "20", "25", "50", "100", "250", "500"], pages: function() { var list = []; @@ -89,19 +94,39 @@ App.IndexController = Ember.ArrayController.extend({ list.push({number: i, runningLabel: runningLabel, style: style}); } return list; - }.property('page','perPage','sortProperties','sortAscending'), + }.property('page','perPage','sortProperties','sortAscending','pagesCount'), paginatedContent: function() { var page = this.get('page'); return this._getPaginatedContent(page); - }.property('arrangedContent.[]', 'page', 'perPage'), + }.property('filteredContent.[]', 'page', 'perPage'), + filteredContent: function() { + var filter = this.get("filter").toUpperCase().split(" "); + var content = this.get("arrangedContent"); + return content.filter(function(movie) { + if (movie) { + var title = movie.get("title"); + for (var i = 0; i<filter.length; i++) { + if (title.toUpperCase().indexOf(filter[i]) == -1) { + return false; + } + } + } + return true; + }); + }.property('arrangedContent.[]', 'page', 'perPage', 'filter'), pagesCount: function() { - return Math.ceil(this.get("content.length") / parseInt(this.get("perPage"))) - }.property('content.[]', 'perPage'), + var contentLength = this.get("filteredContent.length") ; + if (contentLength == 0) { + return 0; + } else { + return Math.ceil(contentLength / parseInt(this.get("perPage"))); + } + }.property('filteredContent.[]', 'perPage'), _getPaginatedContent: function(page) { var perPage = parseInt(this.get('perPage')); var start = (page - 1 ) * perPage; var end = page * perPage; - return this.get('arrangedContent').slice(start, end) + return this.get('filteredContent').slice(start, end) }, actions: { setPage: function(property) { @@ -118,6 +143,9 @@ App.IndexController = Ember.ArrayController.extend({ if (current > 1) { this.set('page', current-1); } + }, + applyFilter: function() { + this.set("filter", this.get("filterTextEntry")); } } }); @@ -141,5 +169,5 @@ App.RadioView = Ember.Checkbox.extend({ function dataCb(data) { App.Movie.reopenClass({FIXTURES:data}) } -window['dataCb'] = dataCb; +// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4: |