From 02397d5c6bbed53e9241f6513480eacdd23870c0 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Mon, 30 Sep 2013 00:20:05 +0200 Subject: [PATCH] Full admin page functionality is working. --- .../org/wamblee/photos/wicket/AdminPage.html | 28 ++++++ .../org/wamblee/photos/wicket/AdminPage.java | 92 ++++++++++++++----- 2 files changed, 97 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/wamblee/photos/wicket/AdminPage.html b/src/main/java/org/wamblee/photos/wicket/AdminPage.html index 5567558..ccd9907 100644 --- a/src/main/java/org/wamblee/photos/wicket/AdminPage.html +++ b/src/main/java/org/wamblee/photos/wicket/AdminPage.html @@ -101,6 +101,34 @@

Add user to group

+
+ + + + + + + + + + + + + +
User + +
Group + +
+
+ + diff --git a/src/main/java/org/wamblee/photos/wicket/AdminPage.java b/src/main/java/org/wamblee/photos/wicket/AdminPage.java index 0449028..95b2566 100644 --- a/src/main/java/org/wamblee/photos/wicket/AdminPage.java +++ b/src/main/java/org/wamblee/photos/wicket/AdminPage.java @@ -22,7 +22,9 @@ import javax.inject.Inject; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.WebMarkupContainer; import org.apache.wicket.markup.html.basic.Label; +import org.apache.wicket.markup.html.form.DropDownChoice; import org.apache.wicket.markup.html.form.Form; +import org.apache.wicket.markup.html.form.IChoiceRenderer; import org.apache.wicket.markup.html.form.PasswordTextField; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.markup.html.link.Link; @@ -175,30 +177,7 @@ public class AdminPage extends BasePage { { final TextField newUser = new TextField("user", new Model("")); final PasswordTextField passwordNewUser = new PasswordTextField("password", new Model("")); - IModel> groups = new LoadableDetachableModel>() { - @Override - protected List load() { - return _userAdmin.getGroups(); - } - }; - /* - final DropDownChoice groupChoice = - new DropDownChoice("group", new Model(""), groups, new IChoiceRenderer() { - @Override - public Object getDisplayValue(Object object) { - return object.toString(); - } - - @Override - public String getIdValue(Object object, int index) { - if (index < 0) { - return ""; - } - return object.toString(); - } - }); - */ Form createUserForm = new Form("createUserForm") { @Override protected void onSubmit() { @@ -232,10 +211,77 @@ public class AdminPage extends BasePage { createUserForm.add(passwordNewUser); // createUserForm.add(groupChoice); } + + { + IModel> users = new LoadableDetachableModel>() { + @Override + protected List load() { + return _userAdmin.getUsers(); + } + }; + final DropDownChoice userChoice = + new DropDownChoice("userChoice", new Model(""), users, new MyChoiceRenderer()); + + IModel> groups = new LoadableDetachableModel>() { + @Override + protected List load() { + return _userAdmin.getGroups(); + } + }; + final DropDownChoice groupChoice = + new DropDownChoice("groupChoice", new Model(""), groups, new MyChoiceRenderer()); + + Form userToGroupForm = new Form("userToGroupForm") { + @Override + protected void onSubmit() { + String user = userChoice.getValue(); + String group = groupChoice.getValue(); + if (!_userAdmin.getUsers().contains(user)) { + return; + } + if (!_userAdmin.getGroups().contains(group)) { + return; + } + if (_userAdmin.isInGroup(user, group)) { + info("User '" + user + "' is already in group '" + group + "'"); + return; + } + + try { + _userAdmin.addUserToGroup(user, group); + info("Added user '" + user + "' to group '" + group + "'"); + } + catch (UserMgtException e) { + error("Could not add user '" + user + "' to group '" + group + "': " + e.getMessage()); + } + } + + ; + }; + userToGroupForm.add(userChoice); + userToGroupForm.add(groupChoice); + add(userToGroupForm); + } } @Override protected boolean isAdminPage() { return true; } + + private static class MyChoiceRenderer implements IChoiceRenderer { + + @Override + public Object getDisplayValue(Object object) { + return object.toString(); + } + + @Override + public String getIdValue(Object object, int index) { + if (index < 0) { + return ""; + } + return object.toString(); + } + } } \ No newline at end of file -- 2.31.1