cms/app-client/app/controllers/application.js
changeset 190 226ae8f2e8e9
parent 189 21b30ee23191
child 192 e1435b37301a
equal deleted inserted replaced
189:21b30ee23191 190:226ae8f2e8e9
     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', 'detail'],
       
     5   location: null,
       
     6   langue: null,
       
     7   discours: null,
       
     8   date: [],
       
     9   thematique: null,
       
    10   detail: null,
       
    11 
     4 
    12   dateIntervals: Ember.computed('date', function() {
     5     queryParams: ['location', 'langue', 'discours', 'date', 'thematique', 'detail'],
    13     var intervals = [];
     6     location: null,
       
     7     langue: null,
       
     8     discours: null,
       
     9     date: [],
       
    10     thematique: null,
       
    11     detail: null,
    14 
    12 
    15     this.get('date').forEach(function(date) {
    13     dateIntervals: Ember.computed('date', function() {
    16       var intervalDate = false;
    14         var intervals = [];
       
    15         this.get('date').forEach(function(date) {
       
    16             var intervalDate = false;
       
    17             intervals.forEach(function(interval) {
       
    18                 if(interval.length && (interval.includes(date + 1) || interval.includes(date - 1))) {
       
    19                     interval.push(date);
       
    20                     intervalDate = true;
       
    21                 }
       
    22             });
       
    23             if (!intervalDate) {
       
    24                 intervals.push([date]);
       
    25             }
       
    26         });
       
    27         return intervals;
       
    28     }),
    17 
    29 
    18       intervals.forEach(function(interval) {
    30     currentId: null,
    19         if(interval.length && (interval.includes(date + 1) || interval.includes(date - 1))) {
    31     currentItem: Ember.computed('currentId', function() {
    20           interval.push(date);
    32         Ember.$(".result-item").toggleClass("playing", false);
    21           intervalDate = true;
    33         if (this.get('currentId') === null){
       
    34             return null;
    22         }
    35         }
    23       });
    36         Ember.$("#"+this.get('currentId').replace( /(:|\.|\[|\]|,)/g, "\\$1" )).toggleClass("playing", true);
       
    37         return this.store.findRecord('document', this.get('currentId'));
       
    38     }),
    24 
    39 
    25       if (!intervalDate) { intervals.push([date]); }
    40     modalItem: Ember.computed('detail', function() {
    26     });
    41         return this.store.findRecord('document', this.get('detail'));
       
    42     }),
    27 
    43 
    28     return intervals;
    44     filteredDocuments: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() {
    29   }),
    45         var location = this.get('location');
       
    46         var langue = this.get('langue');
       
    47         var discours = this.get('discours');
       
    48         var date = this.get('date');
       
    49         var thematique = this.get('thematique');
    30 
    50 
    31   currentId: null,
    51         var documents = this.get('model');
    32   currentItem: Ember.computed('currentId', function() {
    52 
    33     Ember.$(".result-item").toggleClass("playing", false);
    53         if (location) {
    34     if (this.get('currentId') === null){
    54             documents = documents.filterBy('spatial', location);
    35       return null;
    55         }
       
    56         if (langue) {
       
    57             documents = documents.filterBy('language', langue);
       
    58         }
       
    59         if (discours) {
       
    60             documents = documents.filterBy('type', discours);
       
    61         }
       
    62         if (date.length > 0) {
       
    63             var temp = documents;
       
    64             documents.map(function(elt){
       
    65                 if (date.indexOf(elt.get('created')) === -1){
       
    66                     temp = temp.without(elt);
       
    67                 }
       
    68             });
       
    69             documents = temp;
       
    70         }
       
    71         if (thematique) {
       
    72             documents = documents.filterBy('thematique', thematique);
       
    73         }
       
    74         return documents;
       
    75     }),
       
    76 
       
    77     actions: {
       
    78 
       
    79         deleteTag: function(key, value){
       
    80             var newValue = null;
       
    81             if (key === 'date'){
       
    82                 newValue = [];
       
    83                 Ember.$.each(this.get('date'), function(index, date){
       
    84                     if(!value.includes(date)) {
       
    85                         newValue.push(date);
       
    86                     }
       
    87                 });
       
    88             }
       
    89             this.set(key, newValue);
       
    90         },
       
    91 
       
    92         changeDocument: function(docDirection){
       
    93             var direction = (docDirection === "next") ? 1 : -1;
       
    94             var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id'));
       
    95             if ( currentObject !== 'undefined'){
       
    96                 var index = this.get("filteredDocuments").indexOf(currentObject);
       
    97                 if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
       
    98                     return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id);
       
    99                 }
       
   100             }
       
   101             return this.set('currentId', this.get('filteredDocuments').get('firstObject').id);
       
   102         },
       
   103         play: function(item){
       
   104             this.set("currentId", item.id);
       
   105         },
       
   106 
       
   107         showMore: function(item){
       
   108             var domItem = Ember.$("#"+item.id.replace( /(:|\.|\[|\]|,)/g, "\\$1" ));
       
   109             if (domItem.hasClass("show-more")){
       
   110                 domItem.toggleClass("show-more", false);
       
   111             } else{
       
   112                 Ember.$(".result-item").toggleClass("show-more", false);
       
   113                 domItem.toggleClass("show-more", true);
       
   114             }
       
   115         },
       
   116 
       
   117         toggleModal: function(item){
       
   118             if (typeof(item) !== 'undefined'){
       
   119                 this.set("detail", item.id);
       
   120             } else {
       
   121                 this.set("detail", null);
       
   122             }
       
   123         }
       
   124 
    36     }
   125     }
    37     Ember.$("#"+this.get('currentId').replace( /(:|\.|\[|\]|,)/g, "\\$1" )).toggleClass("playing", true);
       
    38     return this.store.findRecord('document', this.get('currentId'));
       
    39   }),
       
    40   modalItem: Ember.computed('detail', function() {
       
    41     return this.store.findRecord('document', this.get('detail'));
       
    42   }),
       
    43   filteredDocuments: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() {
       
    44     var location = this.get('location');
       
    45     var langue = this.get('langue');
       
    46     var discours = this.get('discours');
       
    47     var date = this.get('date');
       
    48     var thematique = this.get('thematique');
       
    49 
       
    50     var documents = this.get('model');
       
    51 
       
    52     if (location) {
       
    53       documents = documents.filterBy('spatial', location);
       
    54     }
       
    55     if (langue) {
       
    56       documents = documents.filterBy('language', langue);
       
    57     }
       
    58     if (discours) {
       
    59       documents = documents.filterBy('type', discours);
       
    60     }
       
    61     if (date.length > 0) {
       
    62       var temp = documents;
       
    63       documents.map(function(elt){
       
    64         if (date.indexOf(elt.get('created')) === -1){
       
    65           temp = temp.without(elt);
       
    66         }
       
    67       });
       
    68       documents = temp;
       
    69     }
       
    70     if (thematique) {
       
    71       documents = documents.filterBy('thematique', thematique);
       
    72     }
       
    73     return documents;
       
    74   }),
       
    75 
       
    76   actions: {
       
    77 
       
    78     deleteTag: function(key, value){
       
    79       var newValue = null;
       
    80 
       
    81       if (key === 'date'){
       
    82         newValue = [];
       
    83         Ember.$.each(this.get('date'), function(index, date){
       
    84           if(!value.includes(date)) {
       
    85             newValue.push(date);
       
    86           }
       
    87         });
       
    88       }
       
    89 
       
    90       this.set(key, newValue);
       
    91     },
       
    92 
       
    93     changeDocument: function(docDirection){
       
    94       var direction = (docDirection === "next") ? 1 : -1;
       
    95       var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id'));
       
    96       if ( currentObject !== 'undefined'){
       
    97         var index = this.get("filteredDocuments").indexOf(currentObject);
       
    98           if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
       
    99             return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id);
       
   100           }
       
   101       }
       
   102       return this.set('currentId', this.get('filteredDocuments').get('firstObject').id);
       
   103     },
       
   104     play: function(item){
       
   105       this.set("currentId", item.id);
       
   106     },
       
   107     showMore: function(item){
       
   108       var domItem = Ember.$("#"+item.id.replace( /(:|\.|\[|\]|,)/g, "\\$1" ));
       
   109       if (domItem.hasClass("show-more")){
       
   110           domItem.toggleClass("show-more", false);
       
   111       } else{
       
   112         Ember.$(".result-item").toggleClass("show-more", false);
       
   113         domItem.toggleClass("show-more", true);
       
   114       }
       
   115     },
       
   116     toggleModal: function(item){
       
   117       if (typeof(item) !== 'undefined'){
       
   118         this.set("detail", item.id);
       
   119       } else {
       
   120         this.set("detail", null);
       
   121       }
       
   122     }
       
   123   }
       
   124 });
   126 });