From 9fffd76e545d664704cd7495da43ac971800327a Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Tue, 31 May 2016 11:53:17 +0200
Subject: [PATCH] OO-2011: implement a back to submission step button for
 coaches in the group task element

---
 .../nodes/gta/ui/GTACoachController.java      | 61 ++++++++++++++++++-
 .../course/nodes/gta/ui/_content/coach.html   | 11 +++-
 .../gta/ui/_i18n/LocalStrings_de.properties   |  3 +
 .../gta/ui/_i18n/LocalStrings_en.properties   |  3 +
 4 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/olat/course/nodes/gta/ui/GTACoachController.java b/src/main/java/org/olat/course/nodes/gta/ui/GTACoachController.java
index ede12b0a42a..324842775c4 100644
--- a/src/main/java/org/olat/course/nodes/gta/ui/GTACoachController.java
+++ b/src/main/java/org/olat/course/nodes/gta/ui/GTACoachController.java
@@ -20,6 +20,7 @@
 package org.olat.course.nodes.gta.ui;
 
 import java.io.File;
+import java.util.Date;
 import java.util.List;
 
 import org.olat.basesecurity.GroupRoles;
@@ -72,10 +73,10 @@ public class GTACoachController extends GTAAbstractController {
 	private GTACoachedGroupGradingController groupGradingCtrl;
 	private GTACoachedParticipantGradingController participantGradingCtrl;
 	private GTACoachRevisionAndCorrectionsController revisionDocumentsCtrl;
-	private DialogBoxController confirmRevisionsCtrl, confirmReviewDocumentCtrl, confirmCollectCtrl;
+	private DialogBoxController confirmRevisionsCtrl, confirmReviewDocumentCtrl, confirmCollectCtrl, confirmBackToSubmissionCtrl;
 	private ContactFormController emailController;
 	private CloseableModalController cmc;
-	private Link emailLink, collectSubmissionsLink;
+	private Link emailLink, collectSubmissionsLink, backToSubmissionLink;
 	
 	
 	@Autowired
@@ -166,6 +167,9 @@ public class GTACoachController extends GTAAbstractController {
 		if(collectSubmissionsLink != null) {
 			mainVC.remove(collectSubmissionsLink);//clean up
 		}
+		if(backToSubmissionLink != null) {
+			mainVC.remove(backToSubmissionLink);
+		}
 		
 		//calculate state
 		boolean viewSubmittedDocument = false;
@@ -176,6 +180,9 @@ public class GTACoachController extends GTAAbstractController {
 				mainVC.contextPut("submitCssClass", "o_active");
 				collect(assignedTask);
 			} else {
+				if (assignedTask == null || assignedTask.getTaskStatus() == TaskProcess.review) {
+					backToSubmission(assignedTask);
+				}
 				mainVC.contextPut("submitCssClass", "o_done");
 				viewSubmittedDocument = true;
 			}	
@@ -183,6 +190,9 @@ public class GTACoachController extends GTAAbstractController {
 			mainVC.contextPut("submitCssClass", "o_active");
 			collect(assignedTask);
 		} else {
+			if (assignedTask == null || assignedTask.getTaskStatus() == TaskProcess.review) {
+				backToSubmission(assignedTask);
+			}
 			mainVC.contextPut("submitCssClass", "o_done");
 			viewSubmittedDocument = true;
 		}
@@ -210,6 +220,18 @@ public class GTACoachController extends GTAAbstractController {
 		return assignedTask;
 	}
 	
+	private void backToSubmission(Task assignedTask) {
+		if(config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT)) {
+		
+			Date now = new Date();
+			DueDate dueDate = getSubmissionDueDate(assignedTask);
+			if(dueDate == null || dueDate.getDueDate() == null || now.before(dueDate.getDueDate())) {
+				backToSubmissionLink = LinkFactory.createButton("coach.back.to.submission", mainVC, this);
+				backToSubmissionLink.setUserObject(assignedTask);
+			}
+		}
+	}
+	
 	private void collect(Task assignedTask) {
 		DueDate dueDate = getSubmissionDueDate(assignedTask);
 		if(dueDate == null || dueDate.getDueDate() == null) {
@@ -420,6 +442,8 @@ public class GTACoachController extends GTAAbstractController {
 			doOpenMailForm(ureq);
 		} else if(collectSubmissionsLink == source) {
 			doConfirmCollectTask(ureq, (Task)collectSubmissionsLink.getUserObject());
+		} else if(backToSubmissionLink == source) {
+			doConfirmBackToSubmission(ureq, (Task)backToSubmissionLink.getUserObject());
 		}
 		super.event(ureq, source, event);
 	}
@@ -455,6 +479,11 @@ public class GTACoachController extends GTAAbstractController {
 				Task assignedTask = (Task)confirmCollectCtrl.getUserObject();
 				doCollectTask(ureq, assignedTask);
 			}
+		}  else if(confirmBackToSubmissionCtrl == source) {
+			if(DialogBoxUIFactory.isOkEvent(event) || DialogBoxUIFactory.isYesEvent(event)) {
+				Task assignedTask = (Task)confirmBackToSubmissionCtrl.getUserObject();
+				doBackToSubmission(ureq, assignedTask);
+			}
 		} else if(source == cmc) {
 			doCloseMailForm(false);
 		} else if (source == emailController) {
@@ -578,6 +607,34 @@ public class GTACoachController extends GTAAbstractController {
 		doUpdateAttempts();
 	}
 	
+	private void doConfirmBackToSubmission(UserRequest ureq, Task assignedTask) {
+		String toName = null;
+		if (assessedGroup != null) {
+			toName = assessedGroup.getName();
+		} else if (assessedIdentity != null) {
+			toName = userManager.getUserDisplayName(assessedIdentity);			
+		}
+		
+		String title = translate("coach.back.to.submission.confirm.title");
+		String text = translate("coach.back.to.submission.confirm.text", new String[]{ toName });
+		text = "<div class='o_warning'>" + text + "</div>";
+		confirmBackToSubmissionCtrl = activateOkCancelDialog(ureq, title, text, confirmBackToSubmissionCtrl);
+		confirmBackToSubmissionCtrl.setUserObject(assignedTask);
+		listenTo(confirmBackToSubmissionCtrl);
+	}
+	
+	private void doBackToSubmission(UserRequest ureq, Task task) {
+		TaskProcess submit = gtaManager.previousStep(TaskProcess.review, gtaNode);//only submit allowed
+		if(submit == TaskProcess.submit) {
+			task = gtaManager.updateTask(task, submit);
+			
+			gtaManager.log("Back to submission", "revert status of task back to submission", task, getIdentity(), assessedIdentity, assessedGroup, courseEnv, gtaNode);
+			
+			cleanUpProcess();
+			process(ureq);
+		}
+	}
+	
 	private void doOpenMailForm(UserRequest ureq) {
 		// build recipient list
 		ContactList contactList = null;
diff --git a/src/main/java/org/olat/course/nodes/gta/ui/_content/coach.html b/src/main/java/org/olat/course/nodes/gta/ui/_content/coach.html
index bd859043109..205dd8260bf 100644
--- a/src/main/java/org/olat/course/nodes/gta/ui/_content/coach.html
+++ b/src/main/java/org/olat/course/nodes/gta/ui/_content/coach.html
@@ -60,8 +60,15 @@
 			<br />
 			$r.translate("coach.waiting.submitted.documents.description")
 		#end
-		#if($r.available("coach.collect.task") && $r.visible("coach.collect.task"))
-			<div class="o_button_group">$r.render("coach.collect.task")</div>
+		#if(($r.available("coach.collect.task") && $r.visible("coach.collect.task")) || ($r.available("coach.back.to.submission") && $r.visible("coach.back.to.submission")))
+			<div class="o_button_group">
+			#if($r.available("coach.collect.task") && $r.visible("coach.collect.task"))
+				$r.render("coach.collect.task")
+			#end
+			#if($r.available("coach.back.to.submission") && $r.visible("coach.back.to.submission"))
+				$r.render("coach.back.to.submission")
+			#end
+			</div>
 		#end
 		</div>
 	</div>
diff --git a/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_de.properties
index 78d965d71c4..ff5b11ba2be 100644
--- a/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_de.properties
@@ -18,6 +18,9 @@ choose.groups=Gruppe ausw\u00E4hlen
 choosed.areas=Lernbereich
 choosed.groups=Gruppe
 coach.assessment=Bewerten
+coach.back.to.submission=Zur\u00FCck zu Abgabeschritt
+coach.back.to.submission.confirm.title=Abgabe wieder \u00F6ffnen
+coach.back.to.submission.confirm.text=Wollen Sie wirklich erlauben neue Dokumente zu abgeben?
 coach.close.revision.button=Revision akzeptieren
 coach.collect.confirm.title=Dokument(e) einziehen
 coach.collect.confirm.text=Sie sind gerade dabei den Abgabeprozess f\u00FCr "{0}" zu beenden. Bitte klicken Sie nur dann auf "OK", wenn Sie sicher sind dass bereits alle ben\u00F6tigten Dokumente abgegeben wurden.
diff --git a/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_en.properties
index 63e9ac34dec..70f733d84d5 100644
--- a/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_en.properties
+++ b/src/main/java/org/olat/course/nodes/gta/ui/_i18n/LocalStrings_en.properties
@@ -18,6 +18,9 @@ choose.groups=Select groups
 choosed.areas=Areas
 choosed.groups=Groups
 coach.assessment=Grade
+coach.back.to.submission=Back to submission step
+coach.back.to.submission.confirm.title=Reopen submission
+coach.back.to.submission.confirm.text=Do you really to reopen the submission of new documents?
 coach.close.revision.button=Revision accepted
 coach.collect.confirm.title=Collect document(s)
 coach.collect.confirm.text=You are about to close the submission for "{0}". Please make sure all required documents were submitted before clicking "OK".
-- 
GitLab