summaryrefslogtreecommitdiff
path: root/movietool/html/movies-files/js/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'movietool/html/movies-files/js/app.js')
-rw-r--r--movietool/html/movies-files/js/app.js173
1 files changed, 173 insertions, 0 deletions
diff --git a/movietool/html/movies-files/js/app.js b/movietool/html/movies-files/js/app.js
new file mode 100644
index 0000000..a3a9632
--- /dev/null
+++ b/movietool/html/movies-files/js/app.js
@@ -0,0 +1,173 @@
+var App = Ember.Application.create();
+App.ApplicationAdapter = DS.FixtureAdapter.extend();
+App.Router.map(function() { });
+
+App.IndexRoute = Ember.Route.extend({
+ model: function() {
+ return this.store.findAll('movie');
+ }
+});
+
+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'),
+ plot: DS.attr('string'),
+ website: DS.attr('string'),
+ release: DS.attr('string'),
+ path: DS.attr(),
+ tags: DS.attr(),
+
+ imdbRating: DS.attr('number'),
+ imdbVotes: DS.attr('number'),
+
+ omdbTomatoConsensus: DS.attr('string'),
+ omdbTomatoMeter: DS.attr('number'),
+ omdbTomatoRating: DS.attr(),
+
+ tmdbId: DS.attr('number'),
+
+ linkTmdb: function() {
+ return "http://www.themoviedb.org/movie/" + this.get('tmdbId');
+ }.property('tmdbId'),
+ linkImdb: function() {
+ return "http://www.imdb.com/title/" + this.get('id');
+ }.property('id'),
+ linkLetterboxd: function() {
+ return "http://letterboxd.com/tmdb/" + this.get('tmdbId');
+ }.property('tmdbId'),
+ linkOfdb: function() {
+ return "http://www.ofdb.de/view.php?page=suchergebnis&Kat=IMDb&SText=" + this.get('id');
+ }.property('id'),
+ linkRotten: function() {
+ return "http://www.rottentomatoes.com/search/?search=" + encodeURIComponent(this.get('title'));
+ }.property('title')
+});
+
+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 = [];
+ var prev = null;
+ var sortProperty = this.get("sortProperties")[0];
+ for (var i = 1; i <= this.get("pagesCount"); i++) {
+ var pageContent = this._getPaginatedContent(i);
+ var p1 = pageContent[0].get(sortProperty);
+ var runningLabel = "";
+ if (sortProperty == "title") {
+ p1 = p1[0];
+ } else if (sortProperty == "imdbRating") {
+ p1 = Math.round(p1);
+ } else if (sortProperty == "imdbVotes") {
+ p1 = Math.floor(p1 / 1000) + "k";
+ } else if (sortProperty == "release") {
+ p1 = parseInt(p1.slice(0,4));
+ p1 = Math.floor(p1 / 10) * 10;
+ } else {
+ prev = p1;
+ }
+ if (p1 != prev) {
+ runningLabel = "" + p1;
+ prev = p1;
+ }
+ var style = "";
+ if (i == this.get('page')) {
+ style = "background-color: red;";
+ }
+ list.push({number: i, runningLabel: runningLabel, style: style});
+ }
+ return list;
+ }.property('page','perPage','sortProperties','sortAscending','pagesCount'),
+ paginatedContent: function() {
+ var page = this.get('page');
+ return this._getPaginatedContent(page);
+ }.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() {
+ 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('filteredContent').slice(start, end)
+ },
+ actions: {
+ setPage: function(property) {
+ this.set('page', property);
+ },
+ nextPage: function() {
+ var current = this.get('page');
+ if (current < this.get('pagesCount')) {
+ this.set('page', current+1);
+ }
+ },
+ prevPage: function() {
+ var current = this.get('page');
+ if (current > 1) {
+ this.set('page', current-1);
+ }
+ },
+ applyFilter: function() {
+ this.set("filter", this.get("filterTextEntry"));
+ }
+ }
+});
+
+App.Movie.reopenClass({FIXTURES:[]})
+
+App.RadioView = Ember.Checkbox.extend({
+ type: "radio",
+ checked: function() {
+ var property = this.get("property");
+ var value = this.get("value");
+ return this.get("controller").get(property) == value;
+ }.property(),
+ click: function() {
+ var property = this.get("property");
+ var value = this.get("value");
+ this.get("controller").set(property, value);
+ }
+})
+
+function dataCb(data) {
+ App.Movie.reopenClass({FIXTURES:data})
+}
+
+// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4: