summaryrefslogtreecommitdiff
path: root/imdb-lookup/js/app.js
blob: d5f7c53842cf39b60abeba8471630c795d0ac9fb (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
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'),
    movieFiles: 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",
    visiblePerPage: ["10", "20", "25", "50", "100", "250", "500"],
    pages: function() {
        var list = [];
        for (var i = 1; i <= this.get("pagesCount"); i++) {
            list.push(i);
        }
        return list;
    }.property('page','perPage'),
    paginatedContent: function() {
        var page = this.get('page');
        var perPage = parseInt(this.get('perPage'));
        var start   = (page - 1 ) * perPage;
        var end     = page * perPage;
        return this.get('arrangedContent').slice(start, end)
    }.property('arrangedContent.[]', 'page', 'perPage'),
    pagesCount: function() {
        return Math.ceil(this.get("content.length") / parseInt(this.get("perPage")))
    }.property('content.[]', 'perPage'),
    actions: {
        sortBy: function(property) {
            this.set('sortProperties', [property]);
            this.set('sortAscending', !this.get('sortAscending'));
        },
        setPage: function(property) {
            this.set('page', property)
        }
    }
});

Ember.Handlebars.helper('filelink', function(value, options) {
    var escaped = encodeURIComponent(value);
    return new Ember.Handlebars.SafeString('<a href="' + escaped + '">' + value + '</span>');
});

function dataCb(data) {
    App.Movie.FIXTURES = data;
}
window['dataCb'] = dataCb;