blob: 57a78a0d499a393d95ce1f2e88212c50c83d4f0d (
plain)
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
// See License.txt for license information.
var Utils = require('../utils/utils.jsx');
var client = require('../utils/client.jsx');
var UserStore = require('../stores/user_store.jsx');
var TeamStore = require('../stores/team_store.jsx');
var Constants = require('../utils/constants.jsx');
function getStateFromStores() {
return {teams: UserStore.getTeams(), currentTeam: TeamStore.getCurrent()};
}
export default class NavbarDropdown extends React.Component {
constructor(props) {
super(props);
this.blockToggle = false;
this.handleLogoutClick = this.handleLogoutClick.bind(this);
this.onListenerChange = this.onListenerChange.bind(this);
this.state = getStateFromStores();
}
handleLogoutClick(e) {
e.preventDefault();
client.logout();
}
componentDidMount() {
UserStore.addTeamsChangeListener(this.onListenerChange);
TeamStore.addChangeListener(this.onListenerChange);
$(React.findDOMNode(this.refs.dropdown)).on('hide.bs.dropdown', () => {
this.blockToggle = true;
setTimeout(() => {
this.blockToggle = false;
}, 100);
});
}
componentWillUnmount() {
UserStore.removeTeamsChangeListener(this.onListenerChange);
TeamStore.removeChangeListener(this.onListenerChange);
$(React.findDOMNode(this.refs.dropdown)).off('hide.bs.dropdown');
}
onListenerChange() {
var newState = getStateFromStores();
if (!Utils.areStatesEqual(newState, this.state)) {
this.setState(newState);
}
}
render() {
var teamLink = '';
var inviteLink = '';
var manageLink = '';
var sysAdminLink = '';
var adminDivider = '';
var currentUser = UserStore.getCurrentUser();
var isAdmin = false;
var isSystemAdmin = false;
var teamSettings = null;
if (currentUser != null) {
isAdmin = Utils.isAdmin(currentUser.roles);
isSystemAdmin = Utils.isSystemAdmin(currentUser.roles);
inviteLink = (
<li>
<a
href='#'
data-toggle='modal'
data-target='#invite_member'
>
{'Invite New Member'}
</a>
</li>
);
if (this.props.teamType === 'O') {
teamLink = (
<li>
<a
href='#'
data-toggle='modal'
data-target='#get_link'
data-title='Team Invite'
data-value={Utils.getWindowLocationOrigin() + '/signup_user_complete/?id=' + currentUser.team_id}
>
{'Get Team Invite Link'}
</a>
</li>
);
}
}
if (isAdmin) {
manageLink = (
<li>
<a
href='#'
data-toggle='modal'
data-target='#team_members'
>
{'Manage Team'}
</a>
</li>
);
adminDivider = (<li className='divider'></li>);
teamSettings = (
<li>
<a
href='#'
data-toggle='modal'
data-target='#team_settings'
>
{'Team Settings'}
</a>
</li>
);
}
if (isSystemAdmin) {
sysAdminLink = (
<li>
<a
href='/admin_console'
>
{'System Console'}
</a>
</li>
);
}
var teams = [];
teams.push(
<li
className='divider'
key='div'
>
</li>
);
if (this.state.teams.length > 1 && this.state.currentTeam) {
var curTeamName = this.state.currentTeam.name;
this.state.teams.forEach((teamName) => {
if (teamName !== curTeamName) {
teams.push(<li key={teamName}><a href={Utils.getWindowLocationOrigin() + '/' + teamName}>{'Switch to ' + teamName}</a></li>);
}
});
}
teams.push(<li key='newTeam_li'>
<a
key='newTeam_a'
target='_blank'
href={Utils.getWindowLocationOrigin() + '/signup_team'}
>
{'Create a New Team'}
</a>
</li>);
return (
<ul className='nav navbar-nav navbar-right'>
<li
ref='dropdown'
className='dropdown'
>
<a
href='#'
className='dropdown-toggle'
data-toggle='dropdown'
role='button'
aria-expanded='false'
>
<span
className='dropdown__icon'
dangerouslySetInnerHTML={{__html: Constants.MENU_ICON}}
/>
</a>
<ul
className='dropdown-menu'
role='menu'
>
<li>
<a
href='#'
data-toggle='modal'
data-target='#user_settings'
>
{'Account Settings'}
</a>
</li>
{inviteLink}
{teamLink}
<li>
<a
href='#'
onClick={this.handleLogoutClick}
>
{'Logout'}
</a>
</li>
{adminDivider}
{teamSettings}
{manageLink}
{sysAdminLink}
{teams}
<li className='divider'></li>
<li>
<a
target='_blank'
href='/static/help/help.html'
>
{'Help'}
</a>
</li>
<li>
<a
target='_blank'
href='/static/help/report_problem.html'
>
{'Report a Problem'}
</a>
</li>
</ul>
</li>
</ul>
);
}
}
NavbarDropdown.defaultProps = {
teamType: ''
};
NavbarDropdown.propTypes = {
teamType: React.PropTypes.string
};
|