cms/app-client/app/components/notice-component.js
author Chloe Laisne <chloe.laisne@gmail.com>
Fri, 26 Aug 2016 11:42:10 +0200
changeset 271 e234339fe8df
parent 270 6ddc52965fb8
child 278 f2c2c80a49f7
permissions -rw-r--r--
Fix display notice error + Hide notice/transcript/video when changing route
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     1
import Ember from 'ember';
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     2
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     3
export default Ember.Component.extend({
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     4
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     5
    player: Ember.inject.service(),
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     6
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     7
    classNames: ['notice-component'],
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     8
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
     9
    item: Ember.computed('model', 'player.model', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    10
        return this.get('model') || this.get('player').get('model');
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    11
    }),
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    12
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    13
    participants: Ember.computed('item.contributors', function() {
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    14
        var participants = [];
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    15
        if(this.get('item')) {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    16
            this.get('item').get('contributors').forEach(function(contributor) {
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    17
                if(contributor.name) {
270
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    18
                    var participant = participants.find(participant => participant.name === contributor.name);
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    19
                    if(participant) {
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    20
                        participant['role'].push(contributor.role.split('/').pop())
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    21
                    } else {
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    22
                        participants.push({ name: contributor.name, role: [ contributor.role.split('/').pop() ] });
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    23
                    }    
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    24
                }
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    25
            });
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    26
        }
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    27
        return participants;
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    28
    }),
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    29
270
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    30
    subjects: Ember.computed('item.subjects', function() {
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    31
        var subjects = [];
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    32
        if(this.get('item')) {
271
e234339fe8df Fix display notice error + Hide notice/transcript/video when changing route
Chloe Laisne <chloe.laisne@gmail.com>
parents: 270
diff changeset
    33
            this.get('item').get('subjects').forEach(function(subject) {
270
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    34
                var object = {};
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    35
                if(typeof subject === 'object') {
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    36
                    if(subject.datatype) {
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    37
                        object['url'] = subject.datatype;
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    38
                    }
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    39
                    if(subject.value) {
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    40
                        object['name'] = subject.value;
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    41
                    }
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    42
                } else {
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    43
                    object['url'] = subject;
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    44
                }
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    45
                subjects.push(object);
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    46
            });
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    47
        }
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    48
        return subjects;
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    49
    }),
6ddc52965fb8 Remove participants doubles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 228
diff changeset
    50
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    51
    location: Ember.computed('item.geoInfo', function() {
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    52
        var location = '';
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    53
        if(this.get('item')) {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    54
            var meta = this.get('item').get('geoInfo').notes.find(element => element.lang);
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    55
            if(meta) {
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    56
                location = meta.value;
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    57
            }
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    58
        }
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    59
        return location;
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    60
    }),
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    61
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    62
    actions: {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    63
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    64
        close: function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    65
            this.set('model', null);
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    66
        }
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    67
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    68
    }
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    69
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    70
});