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
|
import _ from 'underscore';
import Backbone from 'backbone';
import React from 'react';
import Defaults from './permission-template-defaults';
import SetDefaults from './permission-template-set-defaults';
import UsersView from './users-view';
import GroupsView from './groups-view';
import UpdateView from './update-view';
import DeleteView from './delete-view';
export default React.createClass({
propTypes: {
permissionTemplate: React.PropTypes.object.isRequired,
topQualifiers: React.PropTypes.array.isRequired,
refresh: React.PropTypes.func.isRequired
},
showGroups(permission, e) {
e.preventDefault();
new GroupsView({
permission: permission,
permissionTemplate: this.props.permissionTemplate,
refresh: this.props.refresh
}).render();
},
showUsers(permission, e) {
e.preventDefault();
new UsersView({
permission: permission,
permissionTemplate: this.props.permissionTemplate,
refresh: this.props.refresh
}).render();
},
onUpdate(e) {
e.preventDefault();
new UpdateView({
model: new Backbone.Model(this.props.permissionTemplate),
refresh: this.props.refresh
}).render();
},
onDelete(e) {
e.preventDefault();
new DeleteView({
model: new Backbone.Model(this.props.permissionTemplate),
refresh: this.props.refresh
}).render();
},
renderAssociation() {
let projectKeyPattern = this.props.permissionTemplate.projectKeyPattern;
if (!projectKeyPattern) {
return null;
}
return <div className="spacer-bottom">Project Key Pattern: <code>{projectKeyPattern}</code></div>;
},
renderDeleteButton() {
if (_.size(this.props.permissionTemplate.defaultFor) > 0) {
return null;
}
return <button onClick={this.onDelete} className="button-red">Delete</button>;
},
render() {
let permissions = this.props.permissionTemplate.permissions.map(p => {
return (
<td key={p.key}>
<table>
<tr>
<td className="spacer-right">Users</td>
<td className="spacer-left bordered-left">{p.usersCount}</td>
<td className="spacer-left">
<a onClick={this.showUsers.bind(this, p)} className="icon-bullet-list" title="Update Users"
data-toggle="tooltip" href="#"></a>
</td>
</tr>
<tr>
<td className="spacer-right">Groups</td>
<td className="spacer-left bordered-left">{p.groupsCount}</td>
<td className="spacer-left">
<a onClick={this.showGroups.bind(this, p)} className="icon-bullet-list" title="Update Users"
data-toggle="tooltip" href="#"></a>
</td>
</tr>
</table>
</td>
);
});
return (
<tr>
<td>
<strong>{this.props.permissionTemplate.name}</strong>
<p className="note little-spacer-top">{this.props.permissionTemplate.description}</p>
</td>
{permissions}
<td className="thin text-right">
{this.renderAssociation()}
<Defaults
permissionTemplate={this.props.permissionTemplate}
topQualifiers={this.props.topQualifiers}/>
<div className="nowrap">
<SetDefaults
permissionTemplate={this.props.permissionTemplate}
topQualifiers={this.props.topQualifiers}
refresh={this.props.refresh}/>
<div className="button-group">
<button onClick={this.onUpdate}>Update</button>
{this.renderDeleteButton()}
</div>
</div>
</td>
</tr>
);
}
});
|