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