From: David ‘Bombe’ Roden Date: Fri, 27 Jul 2012 23:35:37 +0000 (+0200) Subject: Add page that edits a track. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b43317266c8762334078bba06f8aeb2286f8e92c;p=demoscenemusic.git Add page that edits a track. --- diff --git a/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditTrackPage.java b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditTrackPage.java new file mode 100644 index 0000000..def00fb --- /dev/null +++ b/src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditTrackPage.java @@ -0,0 +1,86 @@ +/* + * DemosceneMusic - EditTrackPage.java - Copyright © 2012 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.demoscenemusic.page.admin; + +import net.pterodactylus.demoscenemusic.core.Core; +import net.pterodactylus.demoscenemusic.data.Track; +import net.pterodactylus.demoscenemusic.page.ServletRequest; +import net.pterodactylus.util.database.DatabaseException; +import net.pterodactylus.util.template.Template; +import net.pterodactylus.util.template.TemplateContext; +import net.pterodactylus.util.template.TemplateContextFactory; +import net.pterodactylus.util.web.Method; +import net.pterodactylus.util.web.RedirectException; + +/** + * Page that lets the user edit a track. + * + * @author David ‘Bombe’ Roden + */ +public class EditTrackPage extends AdminBasePage { + + /** + * Creates a new edit-track page. + * + * @param core + * The core + * @param templateContextFactory + * The template contex factory + * @param template + * The template to render + */ + public EditTrackPage(Core core, TemplateContextFactory templateContextFactory, Template template) { + super(core, templateContextFactory, template, "admin.edit-track"); + } + + // + // BASEPAGE METHODS + // + + /** + * {@inheritDoc} + */ + @Override + protected void processTemplate(TemplateContext templateContext, ServletRequest request) throws RedirectException { + super.processTemplate(templateContext, request); + String trackId = request.getServletRequest().getParameter("id"); + try { + Track track = getCore().getDataManager().getTrackById(trackId); + if (track == null) { + templateContext.set("error", "no-track-given"); + return; + } + + templateContext.set("track", track); + if (request.getMethod() == Method.POST) { + String name = request.getServletRequest().getParameter("name").trim(); + if (name.length() > 0) { + track.setName(name); + } + + /* process properties. */ + processProperties(request, track); + + getCore().getDataManager().saveTrack(track); + } + } catch (DatabaseException de1) { + throw new RuntimeException("Could not edit track.", de1); + } + } + +} diff --git a/src/main/resources/templates/admin.edit-track b/src/main/resources/templates/admin.edit-track new file mode 100644 index 0000000..2cbc3a9 --- /dev/null +++ b/src/main/resources/templates/admin.edit-track @@ -0,0 +1,87 @@ +<%include include/header title=="Edit Track"> + +

Edit Track

+ +
+ + + +
+ Name: + +
+ + + <%foreach track.properties property> + +
+ Property: <%property.key|html> + + Delete +
+ + <%/foreach> + + + +
+ New Property: + + +
+ + +
+ +

Derivatives

+ +<%foreach track.derivatives derivative> + +
+ + + + +
+ Path: + <%derivative.path|html> +
+
+ Size: + <%derivative.size|html> +
+ + <%foreach derivative.properties property> +
+ Property: <%property.key|html> + + Delete +
+ <%/foreach> + +
+ New Property: + + +
+ + +
+ +<%foreachelse> +

This track does not yet have any derivatives.

+<%/foreach> + +

Add a New Derivative

+ +
+ + + + + + + +
+ +<%include include/footer> \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml.template b/src/main/webapp/WEB-INF/web.xml.template index 7f6cde7..48dda54 100644 --- a/src/main/webapp/WEB-INF/web.xml.template +++ b/src/main/webapp/WEB-INF/web.xml.template @@ -78,6 +78,10 @@ admin.edit-artist net.pterodactylus.demoscenemusic.page.admin.EditArtistPage + + admin.edit-track + net.pterodactylus.demoscenemusic.page.admin.EditTrackPage + 0