26,6 → 26,9 |
import ak.kickup.core.model.ParticipantManager; |
import ak.kickup.core.model.Event; |
import ak.kickup.core.model.EventManager; |
import ak.kickup.core.model.ParticipantAct; |
import ak.kickup.core.model.EventAct; |
import ak.kickup.core.form.ParticipantActBean; |
|
public final class AdminParticipantAction |
extends Action |
38,17 → 41,22 |
if("submit".equals(mapping.getParameter())) { |
DynaActionForm theForm = (DynaActionForm)form; |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
Event event = EventManager.getInstance().get(eventId, false); |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
if(participantId == null) { |
participant = ParticipantManager.getInstance().create(); |
if(eventId != null) { |
Event event = EventManager.getInstance().get(eventId, false); |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
if(participantId == null) { |
participant = ParticipantManager.getInstance().create(); |
} |
else { |
participant = ParticipantManager.getInstance().get(participantId); |
} |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
|
initLists(request, event); |
// FIXME: if a list is changed between "edit" and "submit" then indicies are wrong |
} |
else { |
participant = ParticipantManager.getInstance().get(participantId); |
} |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
} |
} |
|
98,6 → 106,18 |
showForm.set("privateComment", participant.getPrivateComment()); |
} |
|
// acts |
List acts = new ArrayList(event.getActCollection()); |
ParticipantActBean[] a = new ParticipantActBean[acts.size()]; |
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR); |
for(int i = 0; i < acts.size(); i++) { |
EventAct act = (EventAct)acts.get(i); |
a[i] = new ParticipantActBean(act.getAct(), |
participant.getAct(act.getAct().getId())); |
} |
showForm.set("acts", a); |
|
initLists(request, event); |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
return mapping.findForward("default"); |
115,21 → 135,59 |
DynaActionForm theForm = (DynaActionForm)form; |
Long participantId = StringConverter.parseLong(theForm.get("id")); |
Participant participant; |
Event event; |
boolean newParticipant; |
|
// get instance |
if(participantId == null) { |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
Event event = EventManager.getInstance().get(eventId, false); |
Long eventId = StringConverter.parseLong(theForm.get("event")); |
event = EventManager.getInstance().get(eventId, false); |
|
participant = ParticipantManager.getInstance().create(); |
participant.setIdent(ParticipantManager.getInstance().generateIdent()); |
participant.setEvent(event); |
newParticipant = true; |
} |
else { |
participant = ParticipantManager.getInstance().get(participantId); |
event = participant.getEvent(); |
newParticipant = false; |
} |
|
// acts |
ParticipantActBean[] acts = (ParticipantActBean[])theForm.get("acts"); |
for(int i = 0; i < acts.length; i++) { |
// get bean |
Long actId = StringConverter.parseLong(acts[i].getActId()); |
EventAct act = event.getAct(actId); |
ParticipantAct participantAct = participant.getAct(actId); |
|
if(acts[i].getSelected() == null || !acts[i].getSelected().booleanValue()) { |
if(participantAct != null) participant.removeAct(participantAct); |
} |
else { |
if(participantAct == null) { |
participantAct = ParticipantManager.getInstance().createAct(); |
participantAct.setParticipant(participant); |
participantAct.setAct(act.getAct()); |
participant.addAct(participantAct); |
} |
participantAct.setComment(acts[i].getComment()); |
} |
} |
|
// email |
String email = (String)theForm.get("email"); |
if(ParticipantManager.getInstance().emailExists(participant, email)) { |
request.setAttribute("event", event); |
request.setAttribute("participant", participant); |
initLists(request, event); |
throw new UserException("ak.kickup.core.participant.email.nonunique.admin"); |
} |
participant.setEmail(email); |
|
// others |
participant.setNick((String)theForm.get("nick")); |
participant.setEmail((String)theForm.get("email")); |
participant.setEmailPublic((Boolean)theForm.get("emailPublic")); |
participant.setName((String)theForm.get("name")); |
participant.setPhone((String)theForm.get("phone")); |
146,6 → 204,9 |
participant.setPrivateComment((String)theForm.get("privateComment")); |
|
ParticipantManager.getInstance().save(participant); |
if(newParticipant) |
Messages.sendRegistrationMessage(participant, null); |
|
response.sendRedirect(BackPath.findBackPath(request).getBackwardUrl()); |
return null; |
} |
153,4 → 214,12 |
throw new Exception("unknown mapping parameter"); |
} |
} |
|
private void initLists(HttpServletRequest request, Event event) |
throws Exception |
{ |
List acts = new ArrayList(event.getActCollection()); |
Collections.sort(acts, EventManager.ACT_NAME_COMPARATOR); |
request.setAttribute("actList", new ObjectList(acts)); |
} |
} |