Add party management on track page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 12:57:44 +0000 (14:57 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 30 Jul 2012 12:57:44 +0000 (14:57 +0200)
src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditTrackPage.java
src/main/resources/templates/admin.edit-track

index af02681..c8a9be2 100644 (file)
 
 package net.pterodactylus.demoscenemusic.page.admin;
 
+import java.util.Collection;
+
 import net.pterodactylus.demoscenemusic.core.Core;
+import net.pterodactylus.demoscenemusic.data.Party;
 import net.pterodactylus.demoscenemusic.data.Track;
 import net.pterodactylus.demoscenemusic.page.ServletRequest;
 import net.pterodactylus.util.database.DatabaseException;
@@ -68,12 +71,31 @@ public class EditTrackPage extends AdminBasePage {
 
                        templateContext.set("track", track);
                        if (request.getMethod() == Method.POST) {
-                               String name = request.getServletRequest().getParameter("name").trim();
-                               if (name.length() > 0) {
+
+                               /* check if a party should be removed. */
+                               if ("true".equals(request.getServletRequest().getParameter("delete-party"))) {
+                                       String partyId = request.getServletRequest().getParameter("party");
+                                       Party party = getCore().getDataManager().getPartyById(partyId);
+                                       Collection<Party> parties = track.getParties();
+                                       parties.remove(party);
+                                       track.setParties(parties);
+                               }
+
+                               /* check if a party should be added. */
+                               if ("true".equals(request.getServletRequest().getParameter("add-party"))) {
+                                       String partyId = request.getServletRequest().getParameter("party");
+                                       Party party = getCore().getDataManager().getPartyById(partyId);
+                                       Collection<Party> parties = track.getParties();
+                                       parties.add(party);
+                                       track.setParties(parties);
+                               }
+
+                               String name = request.getServletRequest().getParameter("name");
+                               if ((name != null) && (name.trim().length() > 0)) {
                                        track.setName(name);
                                }
-                               String remix = request.getServletRequest().getParameter("remix").trim();
-                               if (remix.length() > 0) {
+                               String remix = request.getServletRequest().getParameter("remix");
+                               if ((remix != null) && (remix.trim().length() > 0)) {
                                        track.setRemix(remix);
                                }
 
index c03d01d..cc535b9 100644 (file)
 
 </form>
 
+<h2>Parties</h2>
+
+<%foreach track.parties party>
+
+       <div>Released at: <a href="admin.edit-party?id=<%party.id|html>"><%party.name|html></a></div>
+
+       <form action="admin.edit-track" method="post" accept-charset="utf-8">
+               <input type="hidden" name="id" value="<%track.id|html>"/>
+               <input type="hidden" name="party" value="<%party.id|html>"/>
+               <button type="submit" name="delete-party" value="true"/>Delete Party</button>
+       </form>
+
+<%/foreach>
+
+<h3>Add Party</h3>
+
+<form action="admin.edit-track" method="post" accept-charset="utf-8">
+
+       <input type="hidden" name="id" value="<%track.id|html>"/>
+
+       <div>
+               Add Release:
+               <select name="party">
+                       <%foreach dataManager.allParties party|sort>
+                               <option value="<%party.id|html>"><%party.name|html></option>
+                       <%/foreach>
+               </select>
+       </div>
+
+       <button type="submit" name="add-party" value="true">Add Party</button>
+
+</form>
+
 <h2>Derivatives</h2>
 
 <%foreach track.derivatives derivative>