package net.pterodactylus.demoscenemusic.page.admin;
+import java.util.Collection;
+
import net.pterodactylus.demoscenemusic.core.Core;
import net.pterodactylus.demoscenemusic.data.Artist;
+import net.pterodactylus.demoscenemusic.data.Group;
import net.pterodactylus.demoscenemusic.page.ServletRequest;
import net.pterodactylus.util.database.DatabaseException;
import net.pterodactylus.util.template.Template;
protected void processTemplate(TemplateContext templateContext, ServletRequest request) throws RedirectException {
super.processTemplate(templateContext, request);
String id = request.getServletRequest().getParameter("id");
- /* TODO - check for null. */
- Artist artist;
try {
- artist = getCore().getDataManager().getArtistById(id);
+ Artist artist = getCore().getDataManager().getArtistById(id);
/* TODO - check for null. */
templateContext.set("artist", artist);
if (request.getMethod() == Method.POST) {
String name = request.getServletRequest().getParameter("name");
- artist.setName(name);
+ if ((name != null) && (name.trim().length() > 0)) {
+ artist.setName(name);
+ }
/* process property changes. */
processProperties(request, artist);
+ /* check for new group. */
+ if ("true".equals(request.getServletRequest().getParameter("add-group"))) {
+ String groupId = request.getServletRequest().getParameter("group");
+ Group group = getCore().getDataManager().getGroupById(groupId);
+ Collection<Group> groups = artist.getGroups();
+ groups.add(group);
+ artist.setGroups(groups);
+ }
+
+ /* check for deleted groups. */
+ if ("true".equals(request.getServletRequest().getParameter("delete-group"))) {
+ String groupId = request.getServletRequest().getParameter("group");
+ Group group = getCore().getDataManager().getGroupById(groupId);
+ Collection<Group> groups = artist.getGroups();
+ groups.remove(group);
+ artist.setGroups(groups);
+ }
+
getCore().getDataManager().saveArtist(artist);
throw new RedirectException("admin.edit-artist?id=" + artist.getId());
}
</form>
+<h2>Groups</h2>
+
+<%foreach artist.groups group>
+
+ <form action="admin.edit-artist" method="post" accept-charset="utf-8">
+
+ <input type="hidden" name="id" value="<%artist.id|html>"/>
+ <input type="hidden" name="group" value="<%group.id|html>"/>
+
+ <div>
+ <%group.name|html> <a href="admin.edit-group?id=<%group.id|html>">edit</a>
+ </div>
+ <button type="submit" name="delete-group" value="true">Delete Group</button>
+
+ </form>
+
+<%foreachelse>
+ <p>This artists does not belong to any groups.</p>
+<%/foreach>
+
+<h3>Add a Group</h3>
+
+<form action="admin.edit-artist" method="post" accept-charset="utf-8">
+
+ <input type="hidden" name="id" value="<%artist.id|html>"/>
+
+ <div>
+ Add Group:
+ <select name="group">
+ <%foreach dataManager.allGroups group>
+ <option value="<%group.id|html>"><%group.name|html></option>
+ <%/foreach>
+ </select>
+ </div>
+ <button type="submit" name="add-group" value="true">Add Group</button>
+
+</form>
+
<h2>Tracks</h2>
<%foreach artist.tracks track>