cms/app-client/app/controllers/application.js
author ymh <ymh.work@gmail.com>
Mon, 22 Feb 2016 18:06:39 +0100
changeset 126 e87a340711a4
parent 95 f7ab931581af
child 189 21b30ee23191
permissions -rw-r--r--
improve on dataloading. add fixture management with proper interface to load data.
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({
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
     4
  queryParams: ['location', 'langue', 'discours', 'date', 'thematique', 'detail'],
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,
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    10
  detail: null,
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    11
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    12
  currentId: null,
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    13
  currentItem: Ember.computed('currentId', function() {
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    14
    Ember.$(".result-item").toggleClass("playing", false);
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    15
    if (this.get('currentId') === null){
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    16
      return null;
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    17
    }
126
e87a340711a4 improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
    18
    Ember.$("#"+this.get('currentId').replace( /(:|\.|\[|\]|,)/g, "\\$1" )).toggleClass("playing", true);
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    19
    return this.store.findRecord('document', this.get('currentId'));
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    20
  }),
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    21
  modalItem: Ember.computed('detail', function() {
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    22
    return this.store.findRecord('document', this.get('detail'));
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    23
  }),
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    24
  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
    25
    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
    26
    var langue = this.get('langue');
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    27
    var discours = this.get('discours');
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    28
    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
    29
    var thematique = this.get('thematique');
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    30
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    31
    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
    32
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
    33
    if (location) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    34
      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
    35
    }
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
    36
    if (langue) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    37
      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
    38
    }
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    39
    if (discours) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    40
      documents = documents.filterBy('type', discours);
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    41
    }
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
    if (date.length > 0) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    43
      var temp = documents;
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    44
      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
    45
        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
    46
          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
    47
        }
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    48
      });
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    49
      documents = temp;
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    50
    }
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    51
    if (thematique) {
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    52
      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
    53
    }
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    54
    return documents;
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    55
  }),
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
    56
  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
    57
    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
    58
      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
    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
      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
    61
        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
    62
        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
    63
          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
    64
            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
    65
          }
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    66
        });
81
848e4a5ad4d9 update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents: 72
diff changeset
    67
      }
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
    68
89be68e13215 fix a problem after reloading the page the date tags couldn't be deleted
nowmad@nowmads-macbook-pro.local
parents: 88
diff changeset
    69
      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
    70
    },
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    71
    changeDocument: function(docDirection){
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents: 89
diff changeset
    72
      var direction = (docDirection === "next") ? 1 : -1;
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    73
      var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id'));
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    74
      if ( currentObject !== 'undefined'){
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    75
        var index = this.get("filteredDocuments").indexOf(currentObject);
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    76
          if ( typeof(this.get("filteredDocuments").objectAt(index+direction)) !== 'undefined'){
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    77
            return this.set('currentId', this.get("filteredDocuments").objectAt(index+direction).id);
87
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    78
          }
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    79
      }
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    80
      return this.set('currentId', this.get('filteredDocuments').get('firstObject').id);
86
15ded106ef1a add a player component to handle sound play/pause
nowmad@23.1.168.192.in-addr.arpa
parents: 84
diff changeset
    81
    },
87
24fef043ea0b add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents: 86
diff changeset
    82
    play: function(item){
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    83
      this.set("currentId", item.id);
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
    84
    },
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    85
    showMore: function(item){
126
e87a340711a4 improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
    86
      var domItem = Ember.$("#"+item.id.replace( /(:|\.|\[|\]|,)/g, "\\$1" ));
e87a340711a4 improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
    87
      if (domItem.hasClass("show-more")){
e87a340711a4 improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
    88
          domItem.toggleClass("show-more", 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
    89
      } else{
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    90
        Ember.$(".result-item").toggleClass("show-more", false);
126
e87a340711a4 improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents: 95
diff changeset
    91
        domItem.toggleClass("show-more", 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
    92
      }
84
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    93
    },
36f84e8f1ad5 add d3js for langue visu
nowmad@nowmads-macbook-pro.local
parents: 81
diff changeset
    94
    toggleModal: function(item){
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    95
      if (typeof(item) !== 'undefined'){
95
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    96
        this.set("detail", item.id);
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    97
      } else {
f7ab931581af improve interface
nowmad@23.1.168.192.in-addr.arpa
parents: 94
diff changeset
    98
        this.set("detail", null);
94
62984937a062 - add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents: 91
diff changeset
    99
      }
58
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
   100
    }
6c03fafb6b62 Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents: 51
diff changeset
   101
  }
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
   102
});