author | nowmad@nowmads-macbook-pro.local |
Wed, 20 Jan 2016 00:15:46 +0100 | |
changeset 87 | 24fef043ea0b |
parent 86 | 15ded106ef1a |
child 88 | 1547a32aef60 |
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({ |
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 | 10 |
isShowingModal: false, |
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'}, |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
13 |
filteredSounds: 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 |
|
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
|
20 |
var sounds = this.get('model'); |
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) { |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
23 |
sounds = sounds.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) { |
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 |
sounds = sounds.filterBy('language', langue); |
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) { |
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
29 |
sounds = sounds.filterBy('type', discours); |
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) { |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
32 |
var temp = sounds; |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
33 |
sounds.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 |
}); |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
38 |
sounds = 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) { |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
41 |
sounds = sounds.filterBy('thematique', thematique); |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
42 |
} |
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
|
43 |
return sounds; |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
44 |
}), |
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
45 |
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
|
46 |
deleteTag: function(query, item){ |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
47 |
var queryParams = {}, |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
48 |
newParams = 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
|
49 |
if (query === 'date'){ |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
50 |
newParams = this.get('date'); |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
51 |
if(newParams.indexOf(item) !== -1) { |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
52 |
newParams = newParams.splice(newParams.indexOf(item), 1); |
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 |
} |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
72
diff
changeset
|
54 |
} |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
55 |
queryParams[query] = newParams; |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
56 |
this.transitionToRoute({queryParams: queryParams}); |
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
|
57 |
}, |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
58 |
changeSong: function(songDirection){ |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
59 |
var direction = (songDirection === "next") ? 1 : -1; |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
60 |
var index = this.get("filteredSounds").indexOf(this.get("currentItem")); |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
61 |
if ( index !== -1){ |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
62 |
if (typeof(this.get("filteredSounds").objectAt(index+direction)) !== 'undefined'){ |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
63 |
return this.set('currentItem', this.get("filteredSounds").objectAt(index+direction)); |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
64 |
} |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
65 |
} |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
66 |
return this.set('currentItem', this.get('filteredSounds').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
|
67 |
}, |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
68 |
play: function(item){ |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
69 |
this.set("currentItem", item); |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
70 |
Ember.$(".result-item").toggleClass("playing", false); |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
71 |
Ember.$("#"+item.id).toggleClass("playing", 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
|
72 |
}, |
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
|
73 |
details: function(item){ |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
74 |
if (Ember.$("#"+item.id).hasClass("details")){ |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
75 |
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
|
76 |
} else{ |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
77 |
Ember.$(".result-item").toggleClass("details", false); |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
78 |
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
|
79 |
} |
84 | 80 |
}, |
81 |
toggleModal: function(item){ |
|
82 |
this.set("isShowingModal", !this.isShowingModal); |
|
83 |
this.set("currentDetails", item); |
|
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
84 |
} |
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
85 |
} |
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
|
86 |
}); |