Add functions to manage groups of an artist.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 31 Jul 2012 05:09:04 +0000 (07:09 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 31 Jul 2012 05:09:04 +0000 (07:09 +0200)
src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditArtistPage.java
src/main/resources/templates/admin.edit-artist

index 8c141fa..e737e60 100644 (file)
 
 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;
@@ -59,19 +62,37 @@ public class EditArtistPage extends AdminBasePage {
        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());
                        }
index c63d238..77d2d35 100644 (file)
 
 </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>