7 export default Ember.Route.extend({ |
7 export default Ember.Route.extend({ |
8 |
8 |
9 filter: Ember.inject.service(), |
9 filter: Ember.inject.service(), |
10 constants: Ember.inject.service(), |
10 constants: Ember.inject.service(), |
11 |
11 |
12 model: function(params) { |
12 model: function(params, transition) { |
13 let filterQueryArgs = _.clone(this.get('filter').get('queryParamsValues')); |
13 if(transition.targetName === 'document') { |
14 return this.store.query('document', _.merge(filterQueryArgs, { |
14 let documentId = transition.params['document']['doc_id']; |
15 page: params['page'], |
15 return this.store.query('document', { |
16 perpage: this.get('constants').DOCUMENTS_PAGINATION_PERPAGE |
16 id: documentId, |
17 })); |
17 page: 1, |
|
18 perpage: this.get('constants').DOCUMENTS_PAGINATION_PERPAGE |
|
19 }); |
|
20 } else { |
|
21 let filterQueryArgs = _.clone(this.get('filter').get('queryParamsValues')); |
|
22 return this.store.query('document', _.merge(filterQueryArgs, { |
|
23 page: params['page'], |
|
24 perpage: this.get('constants').DOCUMENTS_PAGINATION_PERPAGE |
|
25 })); |
|
26 } |
18 }, |
27 }, |
19 |
28 |
20 /** |
29 /** |
21 Serializes value of the query parameter based on defaultValueType |
30 Serializes value of the query parameter based on defaultValueType |
22 @method serializeQueryParam |
31 @method serializeQueryParam |
46 } |
55 } |
47 return this._super(value, urlKey, defaultValueType); |
56 return this._super(value, urlKey, defaultValueType); |
48 }, |
57 }, |
49 |
58 |
50 beforeModel: function(transition) { |
59 beforeModel: function(transition) { |
51 new RSVP.Promise((resolve) => { |
60 return new RSVP.Promise((resolve) => { |
52 // succeed |
61 // succeed |
53 this.get('filter').setProperties(transition['queryParams']); |
62 this.get('filter').setProperties(transition['queryParams']); |
54 resolve(); |
63 resolve(); |
55 }); |
64 }); |
56 return this._super(...arguments); |
65 //return this._super(...arguments); |
57 }, |
66 }, |
58 |
67 |
59 queryParams: Ember.computed('filter', function() { |
68 queryParams: Ember.computed('filter', function() { |
60 var res = this.get('filter').getRouteQueryParams(); |
69 var res = this.get('filter').getRouteQueryParams(); |
61 res['page'] = { refreshModel: true }; |
70 res['page'] = { refreshModel: true }; |
68 let controller = this.controllerFor('application'); |
77 let controller = this.controllerFor('application'); |
69 controller.set('isLoading', true); |
78 controller.set('isLoading', true); |
70 transition.promise.finally(function() { |
79 transition.promise.finally(function() { |
71 controller.set('isLoading', false); |
80 controller.set('isLoading', false); |
72 }); |
81 }); |
|
82 }, |
|
83 willTransition: function(transition) { |
|
84 if(this.controller.currentPath === 'document' || transition.targetName === 'document') { |
|
85 this.refresh(); |
|
86 } |
|
87 return true; |
73 }, |
88 }, |
74 |
89 |
75 didTransition: function() { |
90 didTransition: function() { |
76 // Append body classname depending on the route |
91 // Append body classname depending on the route |
77 Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize()); |
92 Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize()); |