From e88ad1f63c7d114acca6d60dca13ca2c13fe664a Mon Sep 17 00:00:00 2001
From: Dirk Furrer <none@none>
Date: Tue, 10 Feb 2015 12:46:12 +0100
Subject: [PATCH] OO-1399: added deselect option to configuration, added
 warning-dialogbox for selecting

---
 .../ProjectEditDetailsFormController.java      | 18 +++++++++++++++++-
 .../projectbroker/ProjectListController.java   | 15 ++++++++++++++-
 .../_i18n/LocalStrings_de.properties           |  3 +++
 .../_i18n/LocalStrings_en.properties           |  1 +
 .../service/ProjectBrokerManagerImpl.java      |  4 ++++
 .../service/ProjectGroupManager.java           | 14 ++++++++++++++
 .../service/ProjectGroupManagerImpl.java       |  9 +++++++++
 7 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/olat/course/nodes/projectbroker/ProjectEditDetailsFormController.java b/src/main/java/org/olat/course/nodes/projectbroker/ProjectEditDetailsFormController.java
index c1f781f31be..d275e5128f7 100644
--- a/src/main/java/org/olat/course/nodes/projectbroker/ProjectEditDetailsFormController.java
+++ b/src/main/java/org/olat/course/nodes/projectbroker/ProjectEditDetailsFormController.java
@@ -99,6 +99,7 @@ public class ProjectEditDetailsFormController extends FormBasicController {
 	private Map<Project.EventType, DateChooser> eventEndElementList;
 
 	private MultipleSelectionElement selectionMaxMembers;
+	private MultipleSelectionElement allowDeselection;
 
 	private boolean enableCancel;
 
@@ -217,6 +218,15 @@ public class ProjectEditDetailsFormController extends FormBasicController {
 			selectionMaxMembers.select(keys[0], true);
 		}
 		selectionMaxMembers.addActionListener(FormEvent.ONCLICK);
+		
+		allowDeselection = uifactory.addCheckboxesHorizontal("detailsform.allow.deselection", formLayout, keys, values);
+		if(projectGroupManager.isDeselectionAllowed(project)){
+			allowDeselection.select(keys[0], true);
+		}else{
+			allowDeselection.select(keys[0], false);
+		}
+		allowDeselection.addActionListener(FormEvent.ONCLICK);
+		
 		uifactory.addSpacerElement("spacer_1", formLayout, false);
 
 		// customfields
@@ -426,7 +436,13 @@ public class ProjectEditDetailsFormController extends FormBasicController {
 				maxMembers.setVisible(false);
 				maxMembers.setIntValue(Project.MAX_MEMBERS_UNLIMITED);
 			}
-		} else if (source == removeAttachmentLink) {
+		} else if(source == allowDeselection){
+			if(!projectGroupManager.isDeselectionAllowed(project)){
+				projectGroupManager.setDeselectionAllowed(project, true);
+			}else{
+				projectGroupManager.setDeselectionAllowed(project, false);
+			}
+		}else if (source == removeAttachmentLink) {
 			attachmentFileName.setInitialFile(null);
 		}
 		this.flc.setDirty(true);
diff --git a/src/main/java/org/olat/course/nodes/projectbroker/ProjectListController.java b/src/main/java/org/olat/course/nodes/projectbroker/ProjectListController.java
index 3dc8cb86484..96612802369 100644
--- a/src/main/java/org/olat/course/nodes/projectbroker/ProjectListController.java
+++ b/src/main/java/org/olat/course/nodes/projectbroker/ProjectListController.java
@@ -50,6 +50,8 @@ import org.olat.core.gui.control.Event;
 import org.olat.core.gui.control.WindowControl;
 import org.olat.core.gui.control.controller.BasicController;
 import org.olat.core.gui.control.generic.closablewrapper.CloseableCalloutWindowController;
+import org.olat.core.gui.control.generic.modal.DialogBoxController;
+import org.olat.core.gui.control.generic.modal.DialogBoxUIFactory;
 import org.olat.core.gui.render.Renderer;
 import org.olat.core.gui.render.StringOutput;
 import org.olat.core.id.Identity;
@@ -106,6 +108,9 @@ public class ProjectListController extends BasicController implements GenericEve
 	private int nbrSelectedProjects;
 	private boolean isParticipantInAnyProject;
 	private CloseableCalloutWindowController calloutCtrl;
+	private Project currentProject;
+	
+	private DialogBoxController noDeselectWarning;
 
 	private final ProjectBrokerMailer projectBrokerMailer;
 	private final ProjectGroupManager projectGroupManager;
@@ -257,12 +262,16 @@ public class ProjectListController extends BasicController implements GenericEve
 				mainPanel.popContent();
 				updateProjectListModelOf(tableController, urequest.getIdentity());			
 			}
+		} else if (source == noDeselectWarning) {
+			if(DialogBoxUIFactory.isOkEvent(event)){
+				handleEnrollAction(urequest, currentProject);
+			}
 		}	
 	}
 
 
 	private void handleTableEvent(UserRequest urequest, TableEvent te) {
-		Project currentProject = (Project)tableController.getTableDataModel().getObject(te.getRowId());
+		currentProject = (Project)tableController.getTableDataModel().getObject(te.getRowId());
 		if ( projectBrokerManager.existsProject( currentProject.getKey() ) ) {
 			handleTableEventForProject(urequest, te, currentProject);
 		} else {
@@ -278,6 +287,10 @@ public class ProjectListController extends BasicController implements GenericEve
 		} else if ( te.getActionId().equals(TABLE_ACTION_ACCOUNT_MANAGER)) {
 			activateUserController(currentProject, urequest, te);
 		} else if ( te.getActionId().equals(TABLE_ACTION_SELECT)) {
+			if(!projectGroupManager.isDeselectionAllowed(currentProject)){
+				noDeselectWarning = activateOkCancelDialog(urequest, translate("info.projectbroker.no.deselect.title"), translate("info.projectbroker.no.deselect"), noDeselectWarning);
+				return;
+			}
 			handleEnrollAction(urequest, currentProject);
 		} else if ( te.getActionId().equals(TABLE_ACTION_CANCEL_SELECT)) {
 			handleCancelEnrollmentAction(urequest, currentProject);
diff --git a/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_de.properties
index 871334158ed..d9cbb8be8dc 100644
--- a/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_de.properties
@@ -89,6 +89,7 @@ detailsform.description.label=Beschreibung
 detailsform.mail.notification.label=E-Mail-Benachrichtigung bei $\:chelp.projectbroker.themaPl Auswahl/Abwahl
 detailsform.max.candidates.label=Anzahl Bewerber limitieren?
 detailsform.max.members.label=Anzahl Pl\u00E4tze limitieren?
+detailsform.allow.deselection=Abmelden von Thema erlauben?
 detailsform.places.candidates.label=Anzahl Bewerber (belegt/total)
 detailsform.places.label=Anzahl Pl\u00E4tze (belegt/total)
 detailsform.places.of=von
@@ -160,6 +161,8 @@ info.projectbroker.runmode.accept.automatically.unlimited=Information zur $\:che
 info.projectbroker.runmode.accept.manually.auto.sign.out=Information zur $\:chelp.projectbroker.themenboerse\:<br/>Themen m\u00FCssen vom Themenverantwortlichen manuell zugewiesen werden. Sie k\u00F6nnen sich in maximal {0} $\:chelp.projectbroker.themaSg / $\:chelp.projectbroker.themaPl provisorisch einschreiben. Wenn ein Themenverantwortlicher Sie f\u00FCr einen $\:detailsform.title.label akzeptiert, werden Sie aus allen anderen $\:chelp.projectbroker.themaPl ausgetragen.
 info.projectbroker.runmode.accept.manually.limited=Information zur $\:chelp.projectbroker.themenboerse\:<br/>Themen m\u00FCssen vom Themenverantwortlichen manuell zugewiesen werden. Maximal w\u00E4hlbare $\:chelp.projectbroker.themaPl\: {0}.
 info.projectbroker.runmode.accept.manually.unlimited=Information zur $\:chelp.projectbroker.themenboerse\:<br/>Themen m\u00FCssen vom Themenverantwortlichen manuell zugewiesen werden. Die Anzahl der $\:chelp.projectbroker.themaPl ist nicht beschr\u00E4nkt.
+info.projectbroker.no.deselect=Nach dem Einschreiben in dieses Thema ist keine abmeldung mehr möglich.
+info.projectbroker.no.deselect.title=Achtung!
 mail.accept.candidate.body=*** Das ist eine automatisch generierte Nachricht. Bitte antworten Sie nicht auf diese Nachricht *** \n\nSie haben das Thema "$projectTitle" gew\u00E4hlt. Der/die Themenverantwortliche $firstnameProjectManager $lastnameProjectManager (OLAT-Benutzername "$usernameProjectManager") hat Ihre Anmeldung am $currentDate f\u00FCr das Thema "$projectTitle" akzeptiert.
 mail.accept.candidate.subject=Bewerbung f\u00FCr das Thema $projectTitle akzeptiert
 mail.add.candidate.body=*** Das ist eine automatisch generierte Nachricht. Bitte antworten Sie nicht auf diese Nachricht *** \n\nDer/die Themenverantwortliche $firstnameProjectManager $lastnameProjectManager (OLAt-Benutzername "$usernameProjectManager") hat Sie am $currentDate als Kandidat in das Thema "$projectTitle" eingetragen.
diff --git a/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_en.properties
index acaeb54d15e..8f029618aca 100644
--- a/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_en.properties
+++ b/src/main/java/org/olat/course/nodes/projectbroker/_i18n/LocalStrings_en.properties
@@ -89,6 +89,7 @@ detailsform.description.label=Description
 detailsform.mail.notification.label=E-mail notification when selecting/deselecting $\:chelp.projectbroker.themaPl
 detailsform.max.candidates.label=Limit number of candidates?
 detailsform.max.members.label=Do you want to limit the vacancies?
+detailsform.allow.deselection=Allow deselection of topic?
 detailsform.places.candidates.label=Number of candidates (taken/total)
 detailsform.places.label=Number of vacancies (filled/total)
 detailsform.places.of=of
diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java
index 288e73e2854..47ceb6f8641 100644
--- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java
+++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectBrokerManagerImpl.java
@@ -343,6 +343,10 @@ public class ProjectBrokerManagerImpl extends BasicManager implements ProjectBro
 		if (moduleConfig.isAcceptSelectionManually()) {
 		  // could only cancel enrollment, when projectleader did not accept yet
 			return projectGroupManager.isProjectCandidate(identity, project) && !project.getState().equals(Project.STATE_ASSIGNED);
+		}
+		// disable deselection link
+		if(!projectGroupManager.isDeselectionAllowed(project)){
+			return false;
 		} else {
 		  // could always cancel enrollment
 			return projectGroupManager.isProjectParticipant(identity, project); 
diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManager.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManager.java
index c6fc446e728..01110be03f9 100644
--- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManager.java
+++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManager.java
@@ -203,4 +203,18 @@ public interface ProjectGroupManager {
    * @return
    */
   public boolean isCandidateListEmpty(SecurityGroup candidateGroup);
+  
+  /**
+   * Returns true when the leaving of the project group is allowed
+   * @param project
+   * @return
+   */
+  public boolean isDeselectionAllowed(Project project);
+  
+  /**
+   * set the leaving flag of the project group true or false;
+   * @param project
+   * @param allow
+   */
+  public void setDeselectionAllowed(Project project, boolean allow);
 }
\ No newline at end of file
diff --git a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java
index 3ee54b84107..207fa352728 100644
--- a/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java
+++ b/src/main/java/org/olat/course/nodes/projectbroker/service/ProjectGroupManagerImpl.java
@@ -364,5 +364,14 @@ public class ProjectGroupManagerImpl extends BasicManager implements ProjectGrou
 		List<Identity> candidates = securityManager.getIdentitiesOfSecurityGroup(candidateGroup);
 		return candidates.isEmpty();
 	}
+	
+	
+	public boolean isDeselectionAllowed(Project project){
+		return project.getProjectGroup().isAllowToLeave();
+	}
+	
+	public void setDeselectionAllowed(Project project, boolean allow){
+		project.getProjectGroup().setAllowToLeave(allow);
+	}
 
 }
-- 
GitLab