Commit 08c88ff6 by Antti Tönkyrä

Add edits for tournament rules.

Closes #5
1 parent 5ae54e65
......@@ -268,6 +268,7 @@ public class MenuBean implements MenuBeanLocal {
tournamentsadm.addPage(menuitemfacade.findOrCreate("/tournaments/admin/view_tournament_team"), TournamentPermission.MANAGE_ALL).setVisible(false);
tournamentsadm.addPage(menuitemfacade.findOrCreate("/tournaments/admin/edit"), TournamentPermission.MANAGE_ALL).setVisible(false);
tournamentsadm.addPage(menuitemfacade.findOrCreate("/tournaments/admin/delete"), TournamentPermission.MANAGE_ALL).setVisible(false);
tournamentsadm.addPage(menuitemfacade.findOrCreate("/tournaments/admin/editrules"), TournamentPermission.MANAGE_ALL).setVisible(false);
/*
* MenuNavigation profileTopmenu = new MenuNavigation(ev,
* "topnavi.profile", menusort = +10);
......
......@@ -102,6 +102,17 @@ public class TournamentBean implements TournamentBeanLocal {
}
@Override
@RolesAllowed(TournamentPermission.S_MANAGE_ALL)
public void updateTournamentRules(TournamentRule tr) throws Exception {
// Assert correct event
if(eventBean.getCurrentEvent().equals(tr.getTournamentGame().getLanEvent())) {
tournamentRuleFacade.merge(tr);
} else {
throw new Exception("tournament.invalid_event");
}
}
@Override
@RolesAllowed(TournamentPermission.S_VIEW)
public List<Tournament> getTournamentsInStatus(TournamentStatus status, boolean useTimeConstraints, boolean invertMatch) {
if(useTimeConstraints)
......
......@@ -32,5 +32,6 @@ public interface TournamentBeanLocal {
boolean useTimeConstraints, boolean invertMatch);
List<TournamentParticipant> findOwnParticipations();
void deleteParticipationById(Integer tpid) throws Exception;
void updateTournamentRules(TournamentRule tr) throws Exception;
}
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:users="http://java.sun.com/jsf/composite/cditools/user" xmlns:tools="http://java.sun.com/jsf/composite/cditools" xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="tournament_id" value="#{tournamentEditRulesView.tournamentId}"/>
<f:event type="preRenderView" listener="#{tournamentEditRulesView.initView()}" />
</f:metadata>
<ui:define name="content">
<h:form>
<h1>#{i18n['tournaments.admin.edit_rules']}</h1>
<h:panelGrid columns="1">
<p:inputText value="#{tournamentEditRulesView.selectedRules.name}" />
<p:inputTextarea value="#{tournamentEditRulesView.selectedRules.rules}" />
<p:commandButton value="#{i18n['tournament.admin.edit']}" action="#{tournamentEditRulesView.commit()}" ajax="false" />
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -54,7 +54,9 @@
<f:facet name="header">
<h:outputText value="#{i18n['tournament.rules']}" />
</f:facet>
<h:outputText value="#{tournament.rules.name}" />
<h:link value="#{tournament.rules.name}" outcome="/tournaments/showrules.xhtml">
<f:param name="tournament_id" value="#{tournament.id}" />
</h:link>
</p:column>
<p:column>
<f:facet name="header">
......
......@@ -10,14 +10,23 @@
</f:metadata>
<ui:define name="content">
<h:form>
<p>
<h:link outcome="/tournaments/index.xhtml" value="#{i18n['tournaments.back_to_tournament_list']}" />
</p>
<h1>#{i18n['tournament.rules_for_tournament']} #{tournamentRulesView.tournament.tournamentName} (#{tournamentRulesView.tournament.rules.name})</h1>
<h:panelGroup layout="block" rendered="#{tournamentRulesView.canEdit}" style="margin-bottom: 16px;">
<p:button value="#{i18n['tournaments.admin.edit_rules']}" outcome="/tournaments/admin/editrules.xhtml">
<f:param name="tournament_id" value="#{tournamentRulesView.tournamentId}" />
</p:button>
</h:panelGroup>
<div>
<h:outputText value="#{tournamentRulesView.tournament.rules.rules}" escape="false" />
</div>
<p>
<h:link outcome="/tournaments/index.xhtml" value="#{i18n['tournaments.back_to_tournament_list']}" />
</p>
</h:form>
</ui:define>
</ui:composition>
</h:body>
......
......@@ -1044,6 +1044,8 @@ tournament.admin.delete_cancel = Cancel Deletio
tournament.admin.delete_confirm = Confirm Deletion
tournament.admin.edit = Edit
tournament.admin.tournament_edited_successfully = Edited successfully
tournament.admin.tournament_rules_edit_failed = Rule Edit Failed
tournament.admin.tournament_rules_edited_successfully = Rules successfully edited
tournament.admin.view = View
tournament.already_participated_into_tournament = Already participated into the selected tournament!
tournament.backup_player_successfully_added_to_team = Backup player added
......@@ -1094,6 +1096,7 @@ tournaments.admin.create_new_ruleset = Create a new r
tournaments.admin.create_tournament = Create a tournament
tournaments.admin.description = Manage tournaments
tournaments.admin.edit = Edit tournament
tournaments.admin.edit_rules = Edit Rules
tournaments.admin.edit_tournament = Edit Tournament
tournaments.admin.game_description = Game description
tournaments.admin.game_name = Game name
......
......@@ -1029,6 +1029,8 @@ tournament.admin.delete_cancel = Peruuta
tournament.admin.delete_confirm = Vahvista Poisto
tournament.admin.edit = Muokkaa
tournament.admin.tournament_edited_successfully = Turnauksen asetuksia muutettu
tournament.admin.tournament_rules_edit_failed = S\u00E4\u00E4nt\u00F6jen muutos ep\u00E4onnistui
tournament.admin.tournament_rules_edited_successfully = S\u00E4\u00E4nt\u00F6jen muutos tehty
tournament.admin.view = Tarkastele
tournament.already_participated_into_tournament = Olet jo osallistunut valittuun turnaukseen!
tournament.backup_player_successfully_added_to_team = Varapelaaja lis\u00E4tty
......@@ -1079,6 +1081,7 @@ tournaments.admin.create_new_ruleset = Luo uusi s\u00
tournaments.admin.create_tournament = Luo turnaus
tournaments.admin.description = Hallinnoi turnauksia
tournaments.admin.edit = Muokkaa turnausta
tournaments.admin.edit_rules = Editoi s\u00E4\u00E4nt\u00F6j\u00E4
tournaments.admin.edit_tournament = Muokkaa turnausta
tournaments.admin.game_description = Pelin kuvaus
tournaments.admin.game_name = Pelin nimi
......
package fi.codecrew.moya.web.cdiview.tournaments;
import java.io.IOException;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import fi.codecrew.moya.beans.TournamentBeanLocal;
import fi.codecrew.moya.enums.TournamentType;
import fi.codecrew.moya.enums.apps.TournamentPermission;
import fi.codecrew.moya.model.Tournament;
import fi.codecrew.moya.model.TournamentRule;
import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.jsf.MessageHelper;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class TournamentEditRulesView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = -2655058086651272660L;
@EJB
private TournamentBeanLocal tournamentBean;
private Tournament tournament = null;
private Integer tournamentId;
private TournamentRule selectedRules = null;
public void initView()
{
if (super.requirePermissions(TournamentPermission.MANAGE_ALL) && selectedRules == null) {
super.beginConversation();
tournament = tournamentBean.getTournamentById(tournamentId);
selectedRules = tournament.getRules();
System.out.println(this.selectedRules.getName());
}
}
public Integer getTournamentId() {
return tournamentId;
}
public void setTournamentId(Integer tournamentId) {
this.tournamentId = tournamentId;
}
public Tournament getTournament() {
return tournament;
}
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
public TournamentRule getSelectedRules() {
return selectedRules;
}
public void setSelectedRules(TournamentRule selectedRules) {
this.selectedRules = selectedRules;
}
public String commit() {
if (this.selectedRules != null) {
try {
this.tournamentBean.updateTournamentRules(selectedRules);
MessageHelper.info("tournament.admin.tournament_rules_edited_successfully");
} catch (Exception e) {
MessageHelper.err("tournament.admin.tournament_rules_edit_failed");
}
} else {
MessageHelper.err("tournament.admin.tournament_rules_edit_failed");
}
this.endConversation();
return "/tournaments/admin/index.xhtml";
}
}
......@@ -45,4 +45,8 @@ public class TournamentRulesView extends GenericCDIView {
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
public Boolean getCanEdit() {
return super.hasPermission(TournamentPermission.MANAGE_ALL);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!