cms/app-client/app/controllers/application.js
author nowmad@nowmads-macbook-pro.local
Wed, 20 Jan 2016 23:05:52 +0100
changeset 91 acfeddc7821d
parent 89 89be68e13215
child 94 62984937a062
permissions -rw-r--r--
rename "sound" to "document"
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     1
import Ember from 'ember';
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     2
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     3
export default Ember.Controller.extend({
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
     4
  queryParams: ['location', 'langue', 'discours', 'date', 'thematique'],
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     5
  location: null,
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     6
  langue: null,
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
     7
  discours: null,
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
     8
  date: [],
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
     9
  thematique: null,
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    10
  isShowingModal: false,
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    11
  currentDetails: null,
61
bbc8a582fcc3 introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents: 58
diff changeset
    12
  currentItem: {title: "example", master: 'http://www.noiseaddicts.com/samples_1w72b820/3921.mp3'},
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    13
  filteredDocuments: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() {
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    14
    var location = this.get('location');
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    15
    var langue = this.get('langue');
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    16
    var discours = this.get('discours');
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    17
    var date = this.get('date');
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    18
    var thematique = this.get('thematique');
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    19
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    20
    var documents = this.get('model');
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    21
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    22
    if (location) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    23
      documents = documents.filterBy('spatial', location);
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    24
    }
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    25
    if (langue) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    26
      documents = documents.filterBy('language', langue);
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    27
    }
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    28
    if (discours) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    29
      documents = documents.filterBy('type', discours);
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    30
    }
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    31
    if (date.length > 0) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    32
      var temp = documents;
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    33
      documents.map(function(elt){
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    34
        if (date.indexOf(elt.get('created')) === -1){
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    35
          temp = temp.without(elt);
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    36
        }
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    37
      });
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    38
      documents = temp;
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    39
    }
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    40
    if (thematique) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    41
      documents = documents.filterBy('thematique', thematique);
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    42
    }
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    43
    return documents;
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    44
  }),
88
1547a32aef60 add observable on currentItem to update the icon of the item being played
nowmad@23.1.168.192.in-addr.arpa
parents: 87
diff changeset
    45
  currentItemChanged: Ember.observer('currentItem', function() {
1547a32aef60 add observable on currentItem to update the icon of the item being played
nowmad@23.1.168.192.in-addr.arpa
parents: 87
diff changeset
    46
    Ember.$(".result-item").toggleClass("playing", false);
1547a32aef60 add observable on currentItem to update the icon of the item being played
nowmad@23.1.168.192.in-addr.arpa
parents: 87
diff changeset
    47
    Ember.$("#"+this.get('currentItem').id).toggleClass("playing", true);
1547a32aef60 add observable on currentItem to update the icon of the item being played
nowmad@23.1.168.192.in-addr.arpa
parents: 87
diff changeset
    48
  }),
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    49
  actions: {
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    50
    deleteTag: function(query, item){
89
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    51
      var newParams = null;
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    52
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    53
      if (query === 'date'){
89
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    54
        newParams = [];
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    55
        Ember.$.each(this.get('date'), function(index, elt){
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    56
          if (elt !== item){
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    57
            newParams.push(elt);
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    58
          }
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    59
        });
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    60
      }
89
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    61
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    62
      this.set(query, newParams);
61
bbc8a582fcc3 introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents: 58
diff changeset
    63
    },
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    64
    changeDocument: function(docDirection){
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    65
      var direction = (docDirection === "next") ? 1 : -1;
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    66
      var index = this.get("filteredDocuments").indexOf(this.get("currentItem"));
87
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    67
      if ( index !== -1){
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    68
          if (typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    69
            return this.set('currentItem', this.get("filteredDocuments").objectAt(index+direction));
87
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    70
          }
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    71
      }
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    72
      return this.set('currentItem', this.get('filteredDocuments').get('firstObject'));
86
15ded106ef1a add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents: 84
diff changeset
    73
    },
87
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    74
    play: function(item){
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    75
      this.set("currentItem", item);
61
bbc8a582fcc3 introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents: 58
diff changeset
    76
    },
bbc8a582fcc3 introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents: 58
diff changeset
    77
    details: function(item){
87
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    78
      if (Ember.$("#"+item.id).hasClass("details")){
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    79
          Ember.$("#"+item.id).toggleClass("details", false);
61
bbc8a582fcc3 introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents: 58
diff changeset
    80
      } else{
87
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    81
        Ember.$(".result-item").toggleClass("details", false);
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    82
        Ember.$("#"+item.id).toggleClass("details", true);
61
bbc8a582fcc3 introduce new action "play" to play the sounds and "details" to show more
nowmad@23.1.168.192.in-addr.arpa
parents: 58
diff changeset
    83
      }
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    84
    },
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    85
    toggleModal: function(item){
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    86
      this.set("isShowingModal", !this.isShowingModal);
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    87
      this.set("currentDetails", item);
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    88
    }
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    89
  }
51
70dff07a76ff add click event on visu-carto and visu-langue and update the url with the selected element as filter parameter
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    90
});