From b43317266c8762334078bba06f8aeb2286f8e92c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 28 Jul 2012 01:35:37 +0200 Subject: [PATCH] Add page that edits a track. --- .../demoscenemusic/page/admin/EditTrackPage.java | 86 +++++++++++++++++++++ src/main/resources/templates/admin.edit-track | 87 ++++++++++++++++++++++ src/main/webapp/WEB-INF/web.xml.template | 4 + 3 files changed, 177 insertions(+) create mode 100644 src/main/java/net/pterodactylus/demoscenemusic/page/admin/EditTrackPage.java create mode 100644 src/main/resources/templates/admin.edit-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 -- 2.7.4