summaryrefslogtreecommitdiff
path: root/imdb-lookup/html/index-files/js/app.js
blob: 3bba2a1800da868b88cb42a91db5038bd748a2ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var App = Ember.Application.create();
App.ApplicationAdapter = DS.FixtureAdapter.extend();

App.Router.map(function() { // put your routes here
});

App.IndexRoute = Ember.Route.extend({
    model: function() {
        return this.store.findAll('movie');
    }
});

App.Movie = DS.Model.extend({
    title: 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('int'),
    imdbVotes: DS.attr('int'),

    omdbTomatoConsensus: DS.attr('string'),
    omdbTomato: DS.attr('int'),
    omdbUserTomato: DS.attr('int'),
    omdbTomatoRating: DS.attr(),
    omdbTomatoUserRating: DS.attr(),

    tmdbId: DS.attr('int'),

    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",
    sortAscending: "false",
    sortProperties: function() {
        return [this.get("firstSortProperty")];
    }.property("firstSortProperty"),
    firstSortProperty: "title",
    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'),
    paginatedContent: function() {
        var page = this.get('page');
        return this._getPaginatedContent(page);
    }.property('arrangedContent.[]', 'page', 'perPage'),
    pagesCount: function() {
        return Math.ceil(this.get("content.length") / parseInt(this.get("perPage")))
    }.property('content.[]', '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)
    },
    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);
            }
        }
    }
});

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})
}
window['dataCb'] = dataCb;