update date params to be an array of date instead of a string
authornowmad@nowmads-macbook-pro.local
Thu, 07 Jan 2016 17:46:50 +0100
changeset 81 848e4a5ad4d9
parent 80 6e0272a9b3ca
child 82 d489885d116d
update date params to be an array of date instead of a string
cms/app-client/app/components/visu-chrono.js
cms/app-client/app/controllers/application.js
cms/app-client/app/routes/application.js
--- a/cms/app-client/app/components/visu-chrono.js	Thu Dec 31 10:22:55 2015 +0100
+++ b/cms/app-client/app/components/visu-chrono.js	Thu Jan 07 17:46:50 2016 +0100
@@ -5,7 +5,7 @@
     var _this = this;
 
     if (this.get('container').lookup('controller:application').date !== null){
-      this.highlightQuery(this.get('container').lookup('controller:application').date.split(','));
+      this.highlightQuery(this.get('container').lookup('controller:application').date);
     }
 
     var isMouseDown = false,
@@ -30,10 +30,10 @@
     });
   },
   sendUpdate: function(){
-    var dateQuery = $('.highlighted').map(function(index, elt) {
-      return parseInt($(elt).parent().attr('id')) + parseInt($(elt).html());
-    }).get().join(',');
-    dateQuery = (dateQuery == "") ? null : dateQuery;
+    var dateQuery = [];
+    $('.highlighted').map(function(index, elt) {
+      dateQuery.push(parseInt($(elt).parent().attr('id')) + parseInt($(elt).html()));
+    });
     this.sendAction('action', dateQuery);
   },
   highlightQuery: function(list){
--- a/cms/app-client/app/controllers/application.js	Thu Dec 31 10:22:55 2015 +0100
+++ b/cms/app-client/app/controllers/application.js	Thu Jan 07 17:46:50 2016 +0100
@@ -5,7 +5,7 @@
   location: null,
   langue: null,
   discours: null,
-  date: null,
+  date: [],
   thematique: null,
   currentItem: {title: "example", master: 'http://www.noiseaddicts.com/samples_1w72b820/3921.mp3'},
   filteredSounds: Ember.computed('location', 'langue', 'discours', 'date', 'thematique', 'model', function() {
@@ -13,7 +13,7 @@
     var langue = this.get('langue');
     var discours = this.get('discours');
     var date = this.get('date');
-    // var thematique = this.get('thematique');
+    var thematique = this.get('thematique');
 
     var sounds = this.get('model');
 
@@ -26,19 +26,30 @@
     if (discours) {
       sounds = sounds.filterBy('type', discours);
     }
-    if (date) {
-      sounds = sounds.filterBy('created', parseInt(date));
+    if (date.length > 0) {
+      var temp = sounds;
+      sounds.map(function(elt, index){
+        if (date.indexOf(elt.get('created')) === -1){
+          temp = temp.without(elt);
+        }
+      });
+      sounds = temp;
     }
-    // if (thematique) {
-    //   sounds = sounds.filterBy('thematique', thematique);
-    // }
-
+    if (thematique) {
+      sounds = sounds.filterBy('thematique', thematique);
+    }
     return sounds;
   }),
   actions: {
-    deleteTag: function(query){
+    deleteTag: function(query, item){
       var queryParams = {};
-      queryParams[query]  = null;
+      if (query === 'date'){
+        var array = this.get('date');
+        if(array.indexOf(item) !== -1) {
+        	array.splice(array.indexOf(item), 1);
+        }
+      }
+      queryParams[query] = array || null;
       this.transitionToRoute({queryParams: queryParams});
     },
     play: function(item){
--- a/cms/app-client/app/routes/application.js	Thu Dec 31 10:22:55 2015 +0100
+++ b/cms/app-client/app/routes/application.js	Thu Jan 07 17:46:50 2016 +0100
@@ -1,6 +1,23 @@
 import Ember from 'ember';
 
 export default Ember.Route.extend({
+  serializeQueryParam: function(value, urlKey, defaultValueType) {
+    if (urlKey === 'date') {
+      return value;
+    }
+    return '' + value;
+  },
+  deserializeQueryParam: function(value, urlKey, defaultValueType) {
+    if (urlKey === 'date') {
+      var arr = [];
+      for (var i = 0; i < value.length; i++) {
+        arr.push(parseInt(value[i]));
+      }
+      return arr;
+    }
+
+    return value;
+  },
   model() {
     return this.store.findAll('sound');
   },