cms/app-client/app/controllers/application.js
changeset 85 e95ca73cec54
parent 84 36f84e8f1ad5
child 86 15ded106ef1a
equal deleted inserted replaced
31:3e93c61f6be0 85:e95ca73cec54
       
     1 import Ember from 'ember';
       
     2 
       
     3 export default Ember.Controller.extend({
       
     4   queryParams: ['location', 'langue', 'discours', 'date', 'thematique'],
       
     5   location: null,
       
     6   langue: null,
       
     7   discours: null,
       
     8   date: [],
       
     9   thematique: null,
       
    10   isShowingModal: false,
       
    11   currentDetails: null,
       
    12   currentItem: {title: "example", master: 'http://www.noiseaddicts.com/samples_1w72b820/3921.mp3'},
       
    13   filteredSounds: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() {
       
    14     var location = this.get('location');
       
    15     var langue = this.get('langue');
       
    16     var discours = this.get('discours');
       
    17     var date = this.get('date');
       
    18     var thematique = this.get('thematique');
       
    19 
       
    20     var sounds = this.get('model');
       
    21 
       
    22     if (location) {
       
    23       sounds = sounds.filterBy('spatial', location);
       
    24     }
       
    25     if (langue) {
       
    26       sounds = sounds.filterBy('language', langue);
       
    27     }
       
    28     if (discours) {
       
    29       sounds = sounds.filterBy('type', discours);
       
    30     }
       
    31     if (date.length > 0) {
       
    32       var temp = sounds;
       
    33       sounds.map(function(elt, index){
       
    34         if (date.indexOf(elt.get('created')) === -1){
       
    35           temp = temp.without(elt);
       
    36         }
       
    37       });
       
    38       sounds = temp;
       
    39     }
       
    40     if (thematique) {
       
    41       sounds = sounds.filterBy('thematique', thematique);
       
    42     }
       
    43     return sounds;
       
    44   }),
       
    45   actions: {
       
    46     deleteTag: function(query, item){
       
    47       var queryParams = {};
       
    48       if (query === 'date'){
       
    49         var array = this.get('date');
       
    50         if(array.indexOf(item) !== -1) {
       
    51         	array.splice(array.indexOf(item), 1);
       
    52         }
       
    53       }
       
    54       queryParams[query] = array || null;
       
    55       this.transitionToRoute({queryParams: queryParams});
       
    56     },
       
    57     play: function(item){
       
    58       this.set("currentItem", item);
       
    59       $("#audio-player").load();
       
    60       $(".result-item").toggleClass("playing", false);
       
    61       $("#"+item.id).toggleClass("playing", true);
       
    62     },
       
    63     details: function(item){
       
    64       if ($("#"+item.id).hasClass("details")){
       
    65           $("#"+item.id).toggleClass("details", false);
       
    66       } else{
       
    67         $(".result-item").toggleClass("details", false);
       
    68         $("#"+item.id).toggleClass("details", true);
       
    69       }
       
    70     },
       
    71     toggleModal: function(item){
       
    72       this.set("isShowingModal", !this.isShowingModal);
       
    73       this.set("currentDetails", item);
       
    74     }
       
    75   }
       
    76 });