Manage properties on artist.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 26 Jul 2012 11:54:28 +0000 (13:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 26 Jul 2012 11:54:28 +0000 (13:54 +0200)
src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditArtistPage.java
src/main/resources/templates/admin.edit-artist

index c51e584..ba36ff7 100644 (file)
 
 package net.pterodactylus.demoscenemusic.page.admin;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+
 import net.pterodactylus.demoscenemusic.core.Core;
 import net.pterodactylus.demoscenemusic.data.Artist;
 import net.pterodactylus.demoscenemusic.page.ServletRequest;
@@ -68,6 +72,34 @@ public class EditArtistPage extends AdminBasePage {
                        if (request.getMethod() == Method.POST) {
                                String name = request.getServletRequest().getParameter("name");
                                artist.setName(name);
+
+                               /* check if properties were changed. */
+                               List<String> propertiesToDelete = new ArrayList<String>();
+                               for (Entry<String, String> property : artist.getProperties()) {
+                                       if (request.getServletRequest().getParameter("delete." + property.getKey()) != null) {
+                                               propertiesToDelete.add(property.getKey());
+                                               continue;
+                                       }
+                                       String value = request.getServletRequest().getParameter("value." + property.getKey()).trim();
+                                       artist.getProperties().set(property.getKey(), value);
+                               }
+
+                               /* check if properties are deleted. */
+                               if (!propertiesToDelete.isEmpty()) {
+                                       for (String propertyToDelete : propertiesToDelete) {
+                                               artist.getProperties().remove(propertyToDelete);
+                                       }
+                               }
+
+                               /* check for a new property. */
+                               if ("true".equals(request.getServletRequest().getParameter("new-property"))) {
+                                       String property = request.getServletRequest().getParameter("property").trim();
+                                       String value = request.getServletRequest().getParameter("value").trim();
+                                       if ((property.length() > 0) && (value.length() > 0)) {
+                                               artist.getProperties().set(property, value);
+                                       }
+                               }
+
                                getCore().getDataManager().saveArtist(artist);
                                throw new RedirectException("admin.artists");
                        }
index 23d945e..3734264 100644 (file)
@@ -4,15 +4,26 @@
 
 <form method="post" accept-charset="utf-8">
 
-       <label>Name: <input type="text" name="name" value="<% artist.name|html>"/></label>
+       <label>Name: <input type="text" name="name" value="<% artist.name|html>"></label>
        <button type="submit">Edit Artist</button>
 
        <%foreach artist.properties property>
 
-               <label>Property: <input type="text" name="property.<%loop.count>" value="<%property.key|html>"/> <input type="text" name="value.<%loop.count>" value="<%property.value|html>"/>
+               <label>
+                       Property: <%property.key|html>
+                       <input type="text" name="value.<%property.key|html>" value="<%property.value|html>">
+                       <input type="checkbox" name="delete.<%property.key|html>">Delete
+               </label>
 
        <%/foreach>
 
+       <label>
+               New Property:
+               <input type="text" name="property" value="">
+               <input type="text" name="value" value="">
+               <button type="submit" name="new-property" value="true">Add Property</button>
+       </label>
+
 </form>
 
 <%include include/footer>
\ No newline at end of file