commit | author | age
|
f13c4c
|
1 |
/*
|
JM |
2 |
* Copyright 2011 gitblit.com.
|
|
3 |
*
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
6 |
* You may obtain a copy of the License at
|
|
7 |
*
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9 |
*
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13 |
* See the License for the specific language governing permissions and
|
|
14 |
* limitations under the License.
|
|
15 |
*/
|
a4d249
|
16 |
package com.gitblit.wicket.panels;
|
JM |
17 |
|
8a2e9c
|
18 |
import java.text.MessageFormat;
|
JM |
19 |
import java.util.List;
|
|
20 |
|
a4d249
|
21 |
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
8a2e9c
|
22 |
import org.apache.wicket.markup.html.link.Link;
|
a4d249
|
23 |
import org.apache.wicket.markup.html.panel.Fragment;
|
JM |
24 |
import org.apache.wicket.markup.repeater.Item;
|
|
25 |
import org.apache.wicket.markup.repeater.data.DataView;
|
|
26 |
import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
|
27 |
|
|
28 |
import com.gitblit.GitBlit;
|
|
29 |
import com.gitblit.wicket.WicketUtils;
|
|
30 |
import com.gitblit.wicket.pages.EditUserPage;
|
|
31 |
|
|
32 |
public class UsersPanel extends BasePanel {
|
|
33 |
|
|
34 |
private static final long serialVersionUID = 1L;
|
|
35 |
|
|
36 |
public UsersPanel(String wicketId, final boolean showAdmin) {
|
|
37 |
super(wicketId);
|
|
38 |
|
|
39 |
Fragment adminLinks = new Fragment("adminPanel", "adminLinks", this);
|
|
40 |
adminLinks.add(new BookmarkablePageLink<Void>("newUser", EditUserPage.class));
|
|
41 |
add(adminLinks.setVisible(showAdmin));
|
8a2e9c
|
42 |
|
JM |
43 |
final List<String> usernames = GitBlit.self().getAllUsernames();
|
2a7306
|
44 |
DataView<String> usersView = new DataView<String>("userRow", new ListDataProvider<String>(
|
JM |
45 |
usernames)) {
|
a4d249
|
46 |
private static final long serialVersionUID = 1L;
|
2a7306
|
47 |
private int counter;
|
JM |
48 |
|
8a2e9c
|
49 |
@Override
|
JM |
50 |
protected void onBeforeRender() {
|
|
51 |
super.onBeforeRender();
|
|
52 |
counter = 0;
|
|
53 |
}
|
a4d249
|
54 |
|
JM |
55 |
public void populateItem(final Item<String> item) {
|
|
56 |
final String entry = item.getModelObject();
|
2a7306
|
57 |
LinkPanel editLink = new LinkPanel("username", "list", entry, EditUserPage.class,
|
JM |
58 |
WicketUtils.newUsernameParameter(entry));
|
a4d249
|
59 |
WicketUtils.setHtmlTooltip(editLink, getString("gb.edit") + " " + entry);
|
JM |
60 |
item.add(editLink);
|
|
61 |
Fragment userLinks = new Fragment("userLinks", "userAdminLinks", this);
|
2a7306
|
62 |
userLinks.add(new BookmarkablePageLink<Void>("editUser", EditUserPage.class,
|
JM |
63 |
WicketUtils.newUsernameParameter(entry)));
|
8a2e9c
|
64 |
Link<Void> deleteLink = new Link<Void>("deleteUser") {
|
JM |
65 |
|
|
66 |
private static final long serialVersionUID = 1L;
|
|
67 |
|
|
68 |
@Override
|
|
69 |
public void onClick() {
|
|
70 |
if (GitBlit.self().deleteUser(entry)) {
|
|
71 |
usernames.remove(entry);
|
|
72 |
info(MessageFormat.format("User ''{0}'' deleted.", entry));
|
|
73 |
} else {
|
|
74 |
error(MessageFormat.format("Failed to delete user ''{0}''!", entry));
|
|
75 |
}
|
|
76 |
}
|
|
77 |
};
|
2a7306
|
78 |
deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format(
|
JM |
79 |
"Delete user \"{0}\"?", entry)));
|
8a2e9c
|
80 |
userLinks.add(deleteLink);
|
a4d249
|
81 |
item.add(userLinks);
|
JM |
82 |
|
|
83 |
WicketUtils.setAlternatingBackground(item, counter);
|
|
84 |
counter++;
|
|
85 |
}
|
|
86 |
};
|
|
87 |
add(usersView.setVisible(showAdmin));
|
|
88 |
}
|
|
89 |
}
|