author | Chloe Laisne <chloe.laisne@gmail.com> |
Thu, 23 Jun 2016 17:22:57 +0200 | |
changeset 201 | 9ae2cf79d167 |
parent 199 | b7c691c6179d |
child 203 | 2ee21302dc47 |
permissions | -rw-r--r-- |
42
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
2 |
|
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
3 |
export default Ember.Route.extend({ |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
4 |
|
201
9ae2cf79d167
Quickfix this is undefined
Chloe Laisne <chloe.laisne@gmail.com>
parents:
199
diff
changeset
|
5 |
model: function() { |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
6 |
return this.store.findAll('document'); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
7 |
}, |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
8 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
9 |
serializeQueryParam: function(value, urlKey) { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
10 |
if (urlKey === 'date') { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
11 |
return value; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
12 |
} |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
13 |
return '' + value; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
14 |
}, |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
15 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
16 |
deserializeQueryParam: function(value, urlKey) { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
17 |
if (urlKey === 'date') { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
18 |
var arr = []; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
19 |
for (var i = 0; i < value.length; i++) { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
20 |
arr.push(parseInt(value[i])); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
21 |
} |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
22 |
return arr; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
23 |
} |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
24 |
return value; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
25 |
}, |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
26 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
27 |
actions: { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
28 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
29 |
willTransition: function() { |
199
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
30 |
// Prevent navigation from removing query parameters |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
31 |
var _this = this, |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
32 |
queryParams = {}; |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
33 |
this.controller.get('queryParams').map(function(parameter){ |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
34 |
if(typeof parameter === 'object') { |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
35 |
Object.keys(parameter).forEach(function(value, key, array) { |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
36 |
queryParams[value] = _this.controller.get(value); |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
37 |
}); |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
38 |
} else { |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
39 |
queryParams[parameter] = _this.controller.get(parameter); |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
40 |
} |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
41 |
}); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
42 |
this.transitionTo({ queryParams: queryParams }); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
43 |
}, |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
44 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
45 |
didTransition: function() { |
199
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
46 |
// Append body classname depending on the route |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
47 |
Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize()); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
48 |
Ember.run.once(this, function() { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
49 |
Ember.$('body').addClass((this.controller.get('currentPath') ||'').replace(/\//g, '-').dasherize()); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
50 |
}); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
51 |
} |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
52 |
|
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
74
diff
changeset
|
53 |
} |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
74
diff
changeset
|
54 |
|
42
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
55 |
}); |