author | nowmad@23.1.168.192.in-addr.arpa |
Thu, 21 Jan 2016 21:07:02 +0100 | |
changeset 94 | 62984937a062 |
parent 91 | acfeddc7821d |
child 95 | f7ab931581af |
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 |
queryParams: ['location', 'langue', 'discours', 'date', 'thematique', 'detailId'], |
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, |
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
|
10 |
detailId: 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
|
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 |
Ember.$("#"+this.get('currentId')).toggleClass("playing", true); |
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 |
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
|
17 |
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
|
18 |
} |
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 |
}), |
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
|
21 |
modalItem: Ember.computed('detailId', 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
|
22 |
return this.store.findRecord('document', this.get('detailId')); |
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 |
}, |
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
|
85 |
details: function(item){ |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
86 |
if (Ember.$("#"+item.id).hasClass("details")){ |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
87 |
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
|
88 |
} else{ |
87
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
89 |
Ember.$(".result-item").toggleClass("details", false); |
24fef043ea0b
add control to go next/previous sound
nowmad@nowmads-macbook-pro.local
parents:
86
diff
changeset
|
90 |
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
|
91 |
} |
84 | 92 |
}, |
93 |
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
|
94 |
if (typeof(item) !== '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
|
95 |
this.set("detailId", item.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
|
96 |
} |
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
|
97 |
this.set("detailId", null); |
58
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
98 |
} |
6c03fafb6b62
Add missing filters to the application controller
nowmad@nowmads-macbook-pro.local
parents:
51
diff
changeset
|
99 |
} |
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
|
100 |
}); |