]> source.dussan.org Git - gitblit.git/commitdiff
Use AJAX to manage the SSH keys panel
authorJames Moger <james.moger@gitblit.com>
Thu, 5 Jun 2014 15:22:44 +0000 (11:22 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 5 Jun 2014 15:22:44 +0000 (11:22 -0400)
src/main/java/com/gitblit/wicket/pages/UserPage.java
src/main/java/com/gitblit/wicket/panels/SshKeysPanel.java

index 505f55d96a628fde60ecc3af317e06e034472610..00a36272ffdcf8bd0c60c3751a44689fbcaae69e 100644 (file)
@@ -283,7 +283,7 @@ public class UserPage extends RootPage {
 \r
        private void addSshKeys(final UserModel user) {\r
                Fragment keysTab = new Fragment("sshKeysTab", "sshKeysTabFragment", this);\r
-               keysTab.add(new SshKeysPanel("sshKeysPanel", user, getClass(), getPageParameters()));\r
+               keysTab.add(new SshKeysPanel("sshKeysPanel", user));\r
 \r
                // add the SSH keys tab\r
                add(new Fragment("sshKeysLink", "sshKeysLinkFragment", this).setRenderBodyOnly(true));\r
index 03cb93ca07c10ef66b4b98212ad6a48eddc3caa0..15ebd67b74bdf8f256c57920b63963cd57e07fbf 100644 (file)
  */\r
 package com.gitblit.wicket.panels;\r
 \r
+import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.List;\r
 \r
-import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.ajax.AjaxRequestTarget;\r
+import org.apache.wicket.ajax.markup.html.AjaxLink;\r
 import org.apache.wicket.ajax.markup.html.form.AjaxButton;\r
-import org.apache.wicket.markup.html.WebPage;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.form.Form;\r
-import org.apache.wicket.markup.html.link.Link;\r
 import org.apache.wicket.markup.repeater.Item;\r
 import org.apache.wicket.markup.repeater.data.DataView;\r
 import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
@@ -39,7 +38,7 @@ import com.gitblit.wicket.GitBlitWebSession;
 \r
 \r
 /**\r
- * A panel that enumerates and manages SSH public keys.\r
+ * A panel that enumerates and manages SSH public keys using AJAX.\r
  *\r
  * @author James Moger\r
  *\r
@@ -50,25 +49,21 @@ public class SshKeysPanel extends BasePanel {
 \r
        private final UserModel user;\r
 \r
-       private final Class<? extends WebPage> pageClass;\r
-\r
-       private final PageParameters params;\r
-\r
-       public SshKeysPanel(String wicketId, UserModel user, Class<? extends WebPage> pageClass, PageParameters params) {\r
+       public SshKeysPanel(String wicketId, UserModel user) {\r
                super(wicketId);\r
 \r
                this.user = user;\r
-               this.pageClass = pageClass;\r
-               this.params = params;\r
        }\r
 \r
        @Override\r
        protected void onInitialize() {\r
                super.onInitialize();\r
-               List<SshKey> keys = app().keys().getKeys(user.username);\r
 \r
+               setOutputMarkupId(true);\r
+\r
+               final List<SshKey> keys = new ArrayList<SshKey>(app().keys().getKeys(user.username));\r
                final ListDataProvider<SshKey> dp = new ListDataProvider<SshKey>(keys);\r
-               DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {\r
+               final DataView<SshKey> keysView = new DataView<SshKey>("keys", dp) {\r
                        private static final long serialVersionUID = 1L;\r
 \r
                        @Override\r
@@ -79,15 +74,19 @@ public class SshKeysPanel extends BasePanel {
                                item.add(new Label("permission", key.getPermission().toString()));\r
                                item.add(new Label("algorithm", key.getAlgorithm()));\r
 \r
-                               Link<Void> delete = new Link<Void>("delete") {\r
+                               AjaxLink<Void> delete = new AjaxLink<Void>("delete") {\r
 \r
                                        private static final long serialVersionUID = 1L;\r
 \r
                                        @Override\r
-                                       public void onClick() {\r
+                                       public void onClick(AjaxRequestTarget target) {\r
                                                if (app().keys().removeKey(user.username, key)) {\r
-                                                       setRedirect(true);\r
-                                                       setResponsePage(pageClass, params);\r
+                                                       // reset the keys list\r
+                                                       keys.clear();\r
+                                                       keys.addAll(app().keys().getKeys(user.username));\r
+\r
+                                                       // update the panel\r
+                                                       target.addComponent(SshKeysPanel.this);\r
                                                }\r
                                        }\r
                                };\r
@@ -150,8 +149,17 @@ public class SshKeysPanel extends BasePanel {
                                }\r
 \r
                                if (app().keys().addKey(user.username, key)) {\r
-                                       setRedirect(true);\r
-                                       setResponsePage(pageClass, params);\r
+                                       // reset add key fields\r
+                                       keyData.setObject("");\r
+                                       keyPermission.setObject(AccessPermission.PUSH);\r
+                                       keyComment.setObject("");\r
+\r
+                                       // reset the keys list\r
+                                       keys.clear();\r
+                                       keys.addAll(app().keys().getKeys(user.username));\r
+\r
+                                       // update the panel\r
+                                       target.addComponent(SshKeysPanel.this);\r
                                }\r
                        }\r
                });\r