It should not be possible to edit or delete application periods that are connected to project ideas.
This commit is contained in:
parent
a4e13589e2
commit
55204b34fb
src
main/java/se/su/dsv/scipro
admin/pages/match
match/panel
test/java/se/su/dsv/scipro/match/dao
@ -4,7 +4,8 @@
|
||||
<body>
|
||||
<wicket:panel>
|
||||
<div class="margin">
|
||||
<div class="info-box rounded-box">If no application period is active, authors can not create new project ideas.</div>
|
||||
<div class="info-box rounded-box">If no application period is active, authors can not create new project ideas.
|
||||
It is not possible to edit or delete an application period with connected project ideas.</div>
|
||||
<a href=# wicket:id="createLink"><img wicket:id="addIcon" alt="" />Create application period</a>
|
||||
<div wicket:id="container">
|
||||
<table class="rounded-corner">
|
||||
|
@ -38,7 +38,7 @@ public class AdminMatchPeriodsPanel extends Panel {
|
||||
@SpringBean
|
||||
private ApplicationPeriodDao applicationPeriodDao;
|
||||
@SpringBean
|
||||
private ApplicationPeriodFacade facade;
|
||||
private ApplicationPeriodFacade applicationPeriodFacade;
|
||||
private final Dialog dialog;
|
||||
private Component localFeedbackPanel;
|
||||
public AdminMatchPeriodsPanel(String id, final Component feedbackPanel) {
|
||||
@ -91,7 +91,8 @@ public class AdminMatchPeriodsPanel extends Panel {
|
||||
item.add(new DateFormatter(DateFormatter.FORMAT.EXTENDED).createFormattedDateLabel("endDate", appPeriod.getEndDate()));
|
||||
item.add(new Label("type",appPeriod.getProjectClass().toString()));
|
||||
item.add(new Label("name",appPeriod.getName()));
|
||||
final AjaxLink<Void> editLink = new AjaxLink<Void>("editLink"){
|
||||
final boolean linksAreEnabled = !applicationPeriodFacade.projectIdeasExists(appPeriod);
|
||||
final AjaxLink<Void> editLink = new AjaxLink<Void>("editLink"){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
@ -100,7 +101,7 @@ public class AdminMatchPeriodsPanel extends Panel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public boolean isEditable(){
|
||||
return true;
|
||||
return linksAreEnabled;
|
||||
}
|
||||
});
|
||||
target.addComponent(dialog);
|
||||
@ -108,20 +109,22 @@ public class AdminMatchPeriodsPanel extends Panel {
|
||||
dialog.open(target);
|
||||
}
|
||||
};
|
||||
editLink.setVisible(linksAreEnabled);
|
||||
editLink.add(new ImageObject("editIcon", ImageObject.SIXTEEN + ImageObject.EDIT));
|
||||
final AjaxLink<Void> removeLink = new AjaxLink<Void>("removeLink"){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void onClick(AjaxRequestTarget target) {
|
||||
if(facade.removeApplicationPeriod(appPeriod)) {
|
||||
if(applicationPeriodFacade.removeApplicationPeriod(appPeriod)) {
|
||||
target.addComponent(container);
|
||||
Session.get().info("Removed : " + facade.getApplicationPeriodData(appPeriod));
|
||||
Session.get().info("Removed : " + applicationPeriodFacade.getApplicationPeriodData(appPeriod));
|
||||
} else {
|
||||
Session.get().error("It was not possible to remove : " + facade.getApplicationPeriodData(appPeriod));
|
||||
Session.get().error("It was not possible to remove : " + applicationPeriodFacade.getApplicationPeriodData(appPeriod));
|
||||
}
|
||||
target.addComponent(localFeedbackPanel);
|
||||
}
|
||||
};
|
||||
removeLink.setVisible(linksAreEnabled);
|
||||
removeLink.add(new JavascriptEventConfirmation("onclick", "Are you sure you want to remove this application period?"));
|
||||
removeLink.add(new ImageObject("removeIcon", ImageObject.SIXTEEN + ImageObject.DELETE));
|
||||
item.add(editLink);
|
||||
|
@ -26,7 +26,6 @@ import se.su.dsv.scipro.admin.pages.match.AdminManageMatchPeriodsPage;
|
||||
import se.su.dsv.scipro.components.CustomDateTimeField;
|
||||
import se.su.dsv.scipro.data.dao.interfaces.ProjectClassDao;
|
||||
import se.su.dsv.scipro.data.dataobjects.ProjectClass;
|
||||
import se.su.dsv.scipro.match.dao.interfaces.ApplicationPeriodDao;
|
||||
import se.su.dsv.scipro.match.dataobject.ApplicationPeriod;
|
||||
import se.su.dsv.scipro.match.facade.ApplicationPeriodFacade;
|
||||
|
||||
@ -35,16 +34,11 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SpringBean
|
||||
private ApplicationPeriodFacade facade;
|
||||
private ApplicationPeriodFacade applicationPeriodFacade;
|
||||
|
||||
@SpringBean
|
||||
private ProjectClassDao projectClassDao;
|
||||
|
||||
@SpringBean
|
||||
private ApplicationPeriodFacade applicationPeriodFacade;
|
||||
|
||||
|
||||
|
||||
private WebMarkupContainer containerForUpdate;
|
||||
private Component feedbackPanel;
|
||||
|
||||
@ -113,17 +107,11 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
return;
|
||||
}
|
||||
|
||||
if(applicationPeriodFacade.projectIdeasExists(appPeriod)) {
|
||||
error("It is not possible to edit dates when an application period has connected project ideas.");
|
||||
target.addComponent(feedbackPanel);
|
||||
return;
|
||||
}
|
||||
|
||||
appPeriod.setProjectClass(pClassesToSet);
|
||||
boolean isEditing = appPeriod.getId() != null;
|
||||
|
||||
if(!facade.doesPeriodOverlap(appPeriod)) {
|
||||
facade.saveApplicationPeriod(appPeriod);
|
||||
if(!applicationPeriodFacade.doesPeriodOverlap(appPeriod)) {
|
||||
applicationPeriodFacade.saveApplicationPeriod(appPeriod);
|
||||
StringBuilder saveMsg = new StringBuilder();
|
||||
if(isEditing) {
|
||||
saveMsg.append(" Updated : ");
|
||||
@ -131,7 +119,7 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
} else {
|
||||
saveMsg.append(" Saved : ");
|
||||
}
|
||||
Session.get().info(saveMsg.toString() + facade.getApplicationPeriodData(appPeriod));
|
||||
Session.get().info(saveMsg.toString() + applicationPeriodFacade.getApplicationPeriodData(appPeriod));
|
||||
if(isEditing) {
|
||||
setResponsePage(AdminManageMatchPeriodsPage.class); // to avoid HibernateOptimisticLockingFailureException when updating
|
||||
}
|
||||
@ -143,7 +131,7 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
} else {
|
||||
errorMsg.append(" Could not create : ");
|
||||
}
|
||||
Session.get().error(errorMsg.toString() + facade.getApplicationPeriodData(appPeriod) + " period already exists.");
|
||||
Session.get().error(errorMsg.toString() + applicationPeriodFacade.getApplicationPeriodData(appPeriod) + " period already exists.");
|
||||
}
|
||||
target.addComponent(containerForUpdate);
|
||||
target.addComponent(feedbackPanel);
|
||||
@ -158,7 +146,7 @@ public class MatchPeriodEditPanel extends Panel {
|
||||
protected void onError(AjaxRequestTarget target, Form<?> form) {
|
||||
final ApplicationPeriod appPeriod = ((ApplicationPeriod)form.getModelObject());
|
||||
if(appPeriod.getProjectClass().size() > 0 && !appPeriod.getEndDate().before(appPeriod.getStartDate())) {
|
||||
Session.get().error(" Could not add application period : " + facade.getApplicationPeriodData(appPeriod));
|
||||
Session.get().error(" Could not add application period : " + applicationPeriodFacade.getApplicationPeriodData(appPeriod));
|
||||
target.addComponent(feedbackPanel);
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public class TestApplicationPeriodDao {
|
||||
ProjectIdea projectIdea = createProjectIdea(applicationPeriod, bachelor);
|
||||
boolean periodRemoved = applicationPeriodFacade.removeApplicationPeriod(applicationPeriod);
|
||||
assertFalse(periodRemoved); // should be false
|
||||
assertNotNull(applicationPeriod);
|
||||
assertNotNull(applicationPeriod); // should not be null
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user