forked from HospitalRun/hospitalrun-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabstract-paged-controller.js
89 lines (80 loc) · 2.67 KB
/
abstract-paged-controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import Ember from 'ember';
import PaginationProps from 'hospitalrun/mixins/pagination-props';
import ProgressDialog from 'hospitalrun/mixins/progress-dialog';
import UserSession from 'hospitalrun/mixins/user-session';
export default Ember.Controller.extend(PaginationProps, ProgressDialog, UserSession, {
addPermission: null,
deletePermission: null,
nextStartKey: null,
previousStartKey: null,
previousStartKeys: [],
progressMessage: 'Loading Records. Please wait...',
progressTitle: 'Loading',
queryParams: ['startKey', 'sortKey', 'sortDesc'],
sortDesc: false,
sortKey: null,
canAdd: function() {
return this.currentUserCan(this.get('addPermission'));
}.property(),
canDelete: function() {
return this.currentUserCan(this.get('deletePermission'));
}.property(),
canEdit: function() {
// Default to using add permission
return this.currentUserCan(this.get('addPermission'));
}.property(),
showActions: function() {
return (this.get('canAdd') || this.get('canEdit') || this.get('canDelete'));
}.property('canAdd', 'canEdit', 'canDelete'),
disablePreviousPage: function() {
return (Ember.isEmpty(this.get('previousStartKey')));
}.property('previousStartKey'),
disableNextPage: function() {
return (Ember.isEmpty(this.get('nextStartKey')));
}.property('nextStartKey'),
showPagination: function() {
return (!Ember.isEmpty(this.get('previousStartKey')) || !Ember.isEmpty(this.get('nextStartKey')));
}.property('nextStartKey', 'previousStartKey'),
hasRecords: Ember.computed('model.length', {
get() {
let model = this.get('model');
if (!Ember.isEmpty(model)) {
return (model.get('length') > 0);
} else {
return false;
}
}
}),
actions: {
nextPage() {
let key = this.get('nextStartKey');
let previousStartKeys = this.get('previousStartKeys');
let firstKey = this.get('firstKey');
this.set('previousStartKey', firstKey);
previousStartKeys.push(firstKey);
this.set('startKey', key);
this.showProgressModal();
},
previousPage() {
let key = this.get('previousStartKey');
let previousStartKeys = this.get('previousStartKeys');
previousStartKeys.pop();
this.set('startKey', key);
this.set('previousStartKey', previousStartKeys.pop());
this.set('previousStartKeys', previousStartKeys);
this.showProgressModal();
},
sortByKey(sortKey, sortDesc) {
this.setProperties({
previousStartKey: null,
previousStartKeys: [],
nextStartKey: null,
sortDesc,
sortKey,
startKey: null,
firstKey: null
});
this.showProgressModal();
}
}
});