summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-06-05 11:22:44 -0400
committerJames Moger <james.moger@gitblit.com>2014-06-05 11:22:44 -0400
commitb0658eedf4bc1590cd5003d17d9c71dd47b3c70c (patch)
treef2052a99be987e4df2bc0a78a4a948e438050c23
parentafbaebde11093fae8b420aaaf71dcd56d8c0f9fd (diff)
downloadgitblit-b0658eedf4bc1590cd5003d17d9c71dd47b3c70c.tar.gz
gitblit-b0658eedf4bc1590cd5003d17d9c71dd47b3c70c.zip
Use AJAX to manage the SSH keys panel
-rw-r--r--src/main/java/com/gitblit/wicket/pages/UserPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java46
2 files changed, 28 insertions, 20 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/UserPage.java b/src/main/java/com/gitblit/wicket/pages/UserPage.java
index 505f55d9..00a36272 100644
--- a/src/main/java/com/gitblit/wicket/pages/UserPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/UserPage.java
@@ -283,7 +283,7 @@ public class UserPage extends RootPage {
private void addSshKeys(final UserModel user) {
Fragment keysTab = new Fragment("sshKeysTab", "sshKeysTabFragment", this);
- keysTab.add(new SshKeysPanel("sshKeysPanel", user, getClass(), getPageParameters()));
+ keysTab.add(new SshKeysPanel("sshKeysPanel", user));
// add the SSH keys tab
add(new Fragment("sshKeysLink", "sshKeysLinkFragment", this).setRenderBodyOnly(true));
diff --git a/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java
index 03cb93ca..15ebd67b 100644
--- a/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java
+++ b/src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java
@@ -15,16 +15,15 @@
*/
package com.gitblit.wicket.panels;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
@@ -39,7 +38,7 @@ import com.gitblit.wicket.GitBlitWebSession;
/**
- * A panel that enumerates and manages SSH public keys.
+ * A panel that enumerates and manages SSH public keys using AJAX.
*
* @author James Moger
*
@@ -50,25 +49,21 @@ public class SshKeysPanel extends BasePanel {
private final UserModel user;
- private final Class<? extends WebPage> pageClass;
-
- private final PageParameters params;
-
- public SshKeysPanel(String wicketId, UserModel user, Class<? extends WebPage> pageClass, PageParameters params) {
+ public SshKeysPanel(String wicketId, UserModel user) {
super(wicketId);
this.user = user;
- this.pageClass = pageClass;
- this.params = params;
}
@Override
protected void onInitialize() {
super.onInitialize();
- List<SshKey> keys = app().keys().getKeys(user.username);
+ setOutputMarkupId(true);
+
+ final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));
final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);
- DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {
+ final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {
private static final long serialVersionUID = 1L;
@Override
@@ -79,15 +74,19 @@ public class SshKeysPanel extends BasePanel {
item.add(new Label("permission", key.getPermission().toString()));
item.add(new Label("algorithm", key.getAlgorithm()));
- Link<Void> delete = new Link<Void>("delete") {
+ AjaxLink<Void> delete = new AjaxLink<Void>("delete") {
private static final long serialVersionUID = 1L;
@Override
- public void onClick() {
+ public void onClick(AjaxRequestTarget target) {
if (app().keys().removeKey(user.username, key)) {
- setRedirect(true);
- setResponsePage(pageClass, params);
+ // reset the keys list
+ keys.clear();
+ keys.addAll(app().keys().getKeys(user.username));
+
+ // update the panel
+ target.addComponent(SshKeysPanel.this);
}
}
};
@@ -150,8 +149,17 @@ public class SshKeysPanel extends BasePanel {
}
if (app().keys().addKey(user.username, key)) {
- setRedirect(true);
- setResponsePage(pageClass, params);
+ // reset add key fields
+ keyData.setObject("");
+ keyPermission.setObject(AccessPermission.PUSH);
+ keyComment.setObject("");
+
+ // reset the keys list
+ keys.clear();
+ keys.addAll(app().keys().getKeys(user.username));
+
+ // update the panel
+ target.addComponent(SshKeysPanel.this);
}
}
});