*/\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
\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
\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
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
}\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