-
Notifications
You must be signed in to change notification settings - Fork 0
/
Permissions.jsx
208 lines (192 loc) · 8.23 KB
/
Permissions.jsx
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
Permissions = React.createClass({
getInitialState: function() {
return {HandleUser: ""};
},
mixins: [ReactMeteorData],
getMeteorData() {
return {
users: Meteor.users.find().fetch(),
institutions: Institutions.find().fetch()
};
},
render() {
return <div className='container' id='globalSearch'>
<div className='col-md-12'>
<table className='table table-hover'>
<thead>
<tr>
<td><p>Użytkownik</p><td><p>Posiadane uprawnienia</p></td></td> <td> </td> <td> </td>
</tr>
</thead>
<tbody>
{this.insertRow()}
</tbody>
</table>
{/*okno nadawania uprawnien lokalnych: */}
<div className="modal fade" id="addLocalRights" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Dodaj uprawnienia użytkownikowi: {this.state.HandleUser}</h4>
</div >
<table className='table table-hover' >
<thead>
<tr>
<td><p>Instytucja</p></td> <td> </td>
</tr>
</thead>
<tbody>
{this.insertInstisutions()}
{this.checked()}
</tbody>
</table>
<div className="modal-footer">
<button type="button" className="btn btn-success" onClick={this.saveRights} data-dismiss="modal">
Zapisz
</button>
<button type="button" className="btn btn-default" data-dismiss="modal">
Anuluj
</button>
</div>
</div>
</div>
</div>
{/*okno nadawania uprawnien globalnych */}
<div className="modal fade" id="addGlobalRight" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Czy chcesz nadach użytkownikowi {this.state.HandleUser} uprawnienia globalne?</h4>
</div >
<div className="modal-footer">
<button type="button" className="btn btn-success" onClick={this.saveGlobalRights} data-dismiss="modal">
TAK
</button>
<button type="button" className="btn btn-default" data-dismiss="modal">
Anuluj
</button>
</div>
</div>
</div>
</div>
{/*okno usuwania uprawnien globalnych */}
<div className="modal fade" id="removeGlobalRight" role="dialog">
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<button type="button" className="close" data-dismiss="modal">×</button>
<h4 className="modal-title">Czy na pewno chcesz odebrać użytkownikowi {this.state.HandleUser} uprawnienia globalne?</h4>
</div >
<div className="modal-footer">
<button type="button" className="btn btn-success" onClick={this.removeGlobalRights} data-dismiss="modal">
TAK
</button>
<button type="button" className="btn btn-default" data-dismiss="modal">
Anuluj
</button>
</div>
</div>
</div>
</div>
</div>
</div>
},
handleClick: function(value) {
this.setState({HandleUser:value});
},
whatRights: function(value){
var Right
if(value.GlobalRight){
Right="Globalne";
}else if(value.institutions) {
Right="Lokalne:"+value.institutions.length;
}else{
Right="Brak";
}
return <td>{Right}</td>
},
insertRow(){
return this.data.users.map((el)=>{
return <tr >
<td><p>{el.username}</p></td>
{this.whatRights(el)}
<td>
<button type="button" id={el.username} onClick={this.handleClick.bind(this,el.username)} className="btn btn-info" data-toggle="modal" data-target="#addLocalRights">
Dodaj Uprawnienia Lokalne
</button>
</td>
<td>
{this.globalRightButton(el)}
</td>
</tr>
})
},
globalRightButton: function(value){
if(value.GlobalRight===true){
return <div>
<button type="button" id={value.username} onClick={this.handleClick.bind(this,value.username)} className="btn btn-info" data-toggle="modal" data-target="#removeGlobalRight">
Usuń uprawnienia Globalne
</button>
</div>
}else{
return <div>
<button type="button" id={value.username} onClick={this.handleClick.bind(this,value.username)} className="btn btn-info" data-toggle="modal" data-target="#addGlobalRight">
Dodaj uprawnienia Globalne
</button>
</div>
}
},
checked(){
var us;
for(var i=0;i<this.data.users.length;i++){
if(this.data.users[i].username === this.state.HandleUser) {
us=this.data.users[i];
break;
}
}
if(us){
if(us.institutions && us.GlobalRight===false){
for(var j=0;j<this.data.institutions.length;j++){
if(us.institutions.indexOf(this.data.institutions[j]._id)!=-1){
document.getElementById(this.data.institutions[j]._id).checked = true;
}else{
document.getElementById(this.data.institutions[j]._id).checked = false;
}
}
}else if(us.GlobalRight===true){
for(var j=0;j<this.data.institutions.length;j++){
document.getElementById(this.data.institutions[j]._id).checked = true;
}
}else{
for(var j=0;j<this.data.institutions.length;j++){
document.getElementById(this.data.institutions[j]._id).checked = false;
}
}
}
},
insertInstisutions(){
return this.data.institutions.map((el)=>{
return <tr>
<td> <p>{el.name}</p></td>
return <td><input type="checkbox" id={el._id} /></td>
</tr>
})
},
saveGlobalRights(){
Meteor.call('addGlobalAdminRights',this.state.HandleUser)
},
removeGlobalRights(){
Meteor.call('removeGlobalAdminRights',this.state.HandleUser)
},
saveRights(){
var ins=[];
this.data.institutions.map((el)=>{
if (document.getElementById(el._id).checked) {
ins.push(el._id);
}
})
Meteor.call('addAdminRights',this.state.HandleUser,ins)
}
});