Add Intel copyright header.
[profile/ivi/cowhide.git] / examples / calf / javascripts / app / store.js
1 /*
2  * Copyright (c) 2012, Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 (function(app, _) {
11     'use strict';
12
13     var Store = function() {}
14
15     Store.prototype = {
16         artists: [
17             {"id": 0,
18              "firstName": "Regina",
19              "lastName": "Spektor",
20              "picture": "regina-spektor.jpg"
21             },
22             {"id": 1,
23              "firstName": "Ani",
24              "lastName": "diFranco",
25              "picture": "ani-difranco.jpg"
26             },
27             {"id": 2,
28              "firstName": "Emily",
29              "lastName": "Haynes",
30              "bandName": "Metric",
31              "picture": "emily-haines.jpg"
32             },
33             {"id": 3,
34              "firstName": "Casey",
35              "lastName": "Dienel",
36              "picture": "casey-dienel.jpg"
37             }
38         ],
39
40         albums: [
41             {"id": 0,
42              "artist_id": 0,
43              "name": "11:11",
44              "year": 2001,
45              "picture": "regina-spektor/11-11.jpg"
46             },
47             {"id": 1,
48              "artist_id": 0,
49              "name": "Songs",
50              "year": 2002,
51              "picture": "regina-spektor/songs.jpg"
52             },
53             {"id": 2,
54              "artist_id": 0,
55              "name": "Soviet Kitsch",
56              "year": 2004,
57              "picture": "regina-spektor/soviet-kitsch.jpg"
58             },
59             {"id": 3,
60              "artist_id": 0,
61              "name": "Begin to Hope",
62              "year": 2006,
63              "picture": "regina-spektor/begin-to-hope.jpg"
64             },
65             {"id": 4,
66              "artist_id": 0,
67              "name": "Far",
68              "year": 2009,
69              "picture": "regina-spektor/far.jpg"
70             },
71             {"id": 5,
72              "artist_id": 0,
73              "name": "What We Saw from the Cheap Seats",
74              "year": 2012,
75              "picture": "regina-spektor/what-we-saw-from-the-cheap-seats.jpg"
76             }
77         ],
78
79         songs: [
80             {"id": 0,
81              "album_id": 0,
82              "title": "Love Affair",
83              "duration": "2:22"
84             },
85             {"id": 1,
86              "album_id": 0,
87              "title": "Rejazz",
88              "duration": "3:37"
89             },
90             {"id": 2,
91              "album_id": 0,
92              "title": "Back of a Truck",
93              "duration": "5:52"
94             }
95         ],
96
97         getArtist: function(id) {
98             var artist = app.Artist.create(
99                 _.find(this.artists, function(artist_data) {
100                     return artist_data.id === id;
101                 })
102             );
103
104             return artist;
105         },
106         getArtists: function() {
107             var artists = [];
108
109             _.each(this.artists, function(artist_data) {
110                 artists.push(app.Artist.create(artist_data));
111             });
112
113             return artists;
114         },
115
116         getAlbum: function(id) {
117             var album_data = _.find(this.albums, function(album_data) {
118                 return album_data.id === id;
119             });
120
121             var album = app.Album.create(album_data);
122             var artist = this.getArtist(album_data.artist_id);
123
124             album.set('artist', artist);
125
126             return album;
127         },
128         getAlbums: function(artist) {
129             var albums = [];
130             var self = this;
131
132             _.each(this.albums, function(album_data) {
133                 var album = app.Album.create(album_data);
134                 var album_artist = self.getArtist(album_data.artist_id);
135
136                 if (artist === undefined || artist.get('id') === album_artist.get('id')) {
137                     album.set('artist', album_artist);
138                     albums.push(album);
139                 }
140             });
141
142             return albums;
143         },
144
145         getSongs: function(album) {
146             var songs = [];
147             var self = this;
148
149             _.each(this.songs, function(song_data) {
150                 var song = app.Album.create(song_data);
151                 var song_album = self.getAlbum(song_data.album_id);
152
153                 if (album === undefined || album.get('id') === song_album.get('id')) {
154                     song.set('album', song_album);
155                     songs.push(song);
156                 }
157             });
158
159             return songs;
160         }
161     };
162
163     app.Store = new Store();
164 })(window.Calf, window._);