cms/app-client/app/controllers/application.js
changeset 94 62984937a062
parent 91 acfeddc7821d
child 95 f7ab931581af
equal deleted inserted replaced
93:f7223e2f3023 94:62984937a062
     1 import Ember from 'ember';
     1 import Ember from 'ember';
     2 
     2 
     3 export default Ember.Controller.extend({
     3 export default Ember.Controller.extend({
     4   queryParams: ['location', 'langue', 'discours', 'date', 'thematique'],
     4   queryParams: ['location', 'langue', 'discours', 'date', 'thematique', 'detailId'],
     5   location: null,
     5   location: null,
     6   langue: null,
     6   langue: null,
     7   discours: null,
     7   discours: null,
     8   date: [],
     8   date: [],
     9   thematique: null,
     9   thematique: null,
    10   isShowingModal: false,
    10   detailId: null,
    11   currentDetails: null,
    11 
    12   currentItem: {title: "example", master: 'http://www.noiseaddicts.com/samples_1w72b820/3921.mp3'},
    12   currentId: null,
       
    13   currentItem: Ember.computed('currentId', function() {
       
    14     Ember.$(".result-item").toggleClass("playing", false);
       
    15     Ember.$("#"+this.get('currentId')).toggleClass("playing", true);
       
    16     if (this.get('currentId') === null){
       
    17       return null;
       
    18     }
       
    19     return this.store.findRecord('document', this.get('currentId'));
       
    20   }),
       
    21   modalItem: Ember.computed('detailId', function() {
       
    22     return this.store.findRecord('document', this.get('detailId'));
       
    23   }),
    13   filteredDocuments: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() {
    24   filteredDocuments: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() {
    14     var location = this.get('location');
    25     var location = this.get('location');
    15     var langue = this.get('langue');
    26     var langue = this.get('langue');
    16     var discours = this.get('discours');
    27     var discours = this.get('discours');
    17     var date = this.get('date');
    28     var date = this.get('date');
    40     if (thematique) {
    51     if (thematique) {
    41       documents = documents.filterBy('thematique', thematique);
    52       documents = documents.filterBy('thematique', thematique);
    42     }
    53     }
    43     return documents;
    54     return documents;
    44   }),
    55   }),
    45   currentItemChanged: Ember.observer('currentItem', function() {
       
    46     Ember.$(".result-item").toggleClass("playing", false);
       
    47     Ember.$("#"+this.get('currentItem').id).toggleClass("playing", true);
       
    48   }),
       
    49   actions: {
    56   actions: {
    50     deleteTag: function(query, item){
    57     deleteTag: function(query, item){
    51       var newParams = null;
    58       var newParams = null;
    52 
    59 
    53       if (query === 'date'){
    60       if (query === 'date'){
    61 
    68 
    62       this.set(query, newParams);
    69       this.set(query, newParams);
    63     },
    70     },
    64     changeDocument: function(docDirection){
    71     changeDocument: function(docDirection){
    65       var direction = (docDirection === "next") ? 1 : -1;
    72       var direction = (docDirection === "next") ? 1 : -1;
    66       var index = this.get("filteredDocuments").indexOf(this.get("currentItem"));
    73       var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id'));
    67       if ( index !== -1){
    74       if ( currentObject !== 'undefined'){
    68           if (typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
    75         var index = this.get("filteredDocuments").indexOf(currentObject);
    69             return this.set('currentItem', this.get("filteredDocuments").objectAt(index+direction));
    76           if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
       
    77             return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id);
    70           }
    78           }
    71       }
    79       }
    72       return this.set('currentItem', this.get('filteredDocuments').get('firstObject'));
    80       return this.set('currentId', this.get('filteredDocuments').get('firstObject').id);
    73     },
    81     },
    74     play: function(item){
    82     play: function(item){
    75       this.set("currentItem", item);
    83       this.set("currentId", item.id);
    76     },
    84     },
    77     details: function(item){
    85     details: function(item){
    78       if (Ember.$("#"+item.id).hasClass("details")){
    86       if (Ember.$("#"+item.id).hasClass("details")){
    79           Ember.$("#"+item.id).toggleClass("details", false);
    87           Ember.$("#"+item.id).toggleClass("details", false);
    80       } else{
    88       } else{
    81         Ember.$(".result-item").toggleClass("details", false);
    89         Ember.$(".result-item").toggleClass("details", false);
    82         Ember.$("#"+item.id).toggleClass("details", true);
    90         Ember.$("#"+item.id).toggleClass("details", true);
    83       }
    91       }
    84     },
    92     },
    85     toggleModal: function(item){
    93     toggleModal: function(item){
    86       this.set("isShowingModal", !this.isShowingModal);
    94       if (typeof(item) !== 'undefined'){
    87       this.set("currentDetails", item);
    95         this.set("detailId", item.id);
       
    96       }
       
    97       this.set("detailId", null);
    88     }
    98     }
    89   }
    99   }
    90 });
   100 });