cms/app-client/app/components/playlist-component.js
author Chloe Laisne <chloe.laisne@gmail.com>
Mon, 04 Jul 2016 23:54:48 +0200
changeset 226 2103e6c58266
parent 216 c174124d1849
child 227 5c9250f55f4b
permissions -rw-r--r--
Notice text-color

import Ember from 'ember';

export default Ember.Component.extend({

    classNames: ['playlist-component'],

    filter: Ember.inject.service(),
    player: Ember.inject.service(),

    documents: Ember.computed('model', 'filter.location', 'filter.language', 'filter.discourse', 'filter.date', 'filter.theme', function() {
        var self = this;
        var documents = this.get('model');
        if (this.get('filter.date').length > 0) {
            var copy = documents;
            documents.map(function(document) {
                if (self.get('filter.date').indexOf(document.get('created')) === -1){
                    copy = copy.without(document);
                }
            });
            documents = copy;
        }
        if (this.get('filter.discourse')) {
            documents = documents.filterBy('type', this.get('filter.discourse'));
        }
        if (this.get('filter.language')) {
            documents = documents.filterBy('language', this.get('filter.language'));
        }
        if (this.get('filter.location')) {
            documents = documents.filterBy('spatial', this.get('filter.location'));
        }
        if (this.get('filter.theme')) {
            documents = documents.filterBy('thematique', this.get('filter.theme'));
        }
        return documents;
    }),

    documentsLoaded: Ember.observer('documents', function() {
        this.get('player').set('items', this.get('documents').map(function(document) {
            return document.get('id');
        }));
        if(this.get('player').get('items').length) {
            this.get('player').set('item', this.get('player').get('items')[0]);    
        }
    }).on('init'),

    init: function() {
        this._super(...arguments);
    },

    didRender: function() {
        this._super(...arguments);
        this.$().find('ul').height(Ember.$('.corpus-app-wrapper').outerHeight() - (Ember.$('.filter-component').outerHeight() + this.$().find('h2').outerHeight()));
    },

    actions: {

        setItem: function(id) {
            this.get('player').trigger('reset', id);
        }

    }

});