Add Intel copyright header.
[profile/ivi/cowhide.git] / examples / hoofbeats / javascripts / app / models / mediaItemModel.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, Ember) {
11     var MediaItem = Ember.Object.extend({
12         id: null,
13         title: null,
14         artists: null,
15         duration: null,
16
17         durationString: function() {
18             return moment("0", "ss").add('milliseconds', this.duration).format("mm:ss");
19         }.property('duration')
20     });
21
22
23     MediaItem.reopenClass({
24         findAll: function() {
25             var items = [];
26
27             console.log("MediaItem.findAll: entered.");
28             app.Store.getMediaItems().done(function(data) {
29                 if (data !== undefined) {
30                     data.forEach(function(item) {
31                         console.log("MediaItem.findAll: pushing object.");
32                         items.pushObject(app.MediaItem.create(item));
33                     });
34                 }
35             });
36
37             return items;
38         },
39
40         find: function(item_id) {
41             var item;
42
43             console.log("MediaItem.find: entered.");
44             app.Store.getMediaItem(item_id).done(function(data) {
45                 item = app.MediaItem.create(data);
46             });
47
48             return item;
49         }
50     });
51
52     app.MediaItem = MediaItem;
53 })(window.Hoofbeats, window.Ember);