diff --git a/app/connectors/ApplicationClient.scala b/app/connectors/ApplicationClient.scala index 7386d4a..c9010ff 100644 --- a/app/connectors/ApplicationClient.scala +++ b/app/connectors/ApplicationClient.scala @@ -108,7 +108,8 @@ trait ApplicationClient { data.aLevel.getOrElse(false), data.stemLevel.getOrElse(false), data.civilServant == "Yes", - data.department + data.department, + data.departmentOther ) ).map { case x: HttpResponse if x.status == CREATED => () diff --git a/app/connectors/ExchangeObjects.scala b/app/connectors/ExchangeObjects.scala index 0df5d6e..1bc0ff9 100644 --- a/app/connectors/ExchangeObjects.scala +++ b/app/connectors/ExchangeObjects.scala @@ -56,7 +56,8 @@ object ExchangeObjects { aLevel: Boolean, stemLevel: Boolean, civilServant: Boolean, - department: Option[String] + department: Option[String], + departmentOther: Option[String] ) case class AddMedia(userId: UniqueIdentifier, media: String) diff --git a/app/controllers/FastTrackApplication.scala b/app/controllers/FastTrackApplication.scala index 3348f26..601ae73 100644 --- a/app/controllers/FastTrackApplication.scala +++ b/app/controllers/FastTrackApplication.scala @@ -17,7 +17,6 @@ package controllers import _root_.forms.GeneralDetailsForm -import com.mohiva.play.silhouette.api.Silhouette import config.{ CSRCache, CSRHttp } import connectors.ApplicationClient.PersonalDetailsNotFound import connectors.ExchangeObjects.PersonalDetails @@ -28,11 +27,10 @@ import mappings.{ Address, DayMonthYear } import models.ApplicationData.ApplicationStatus._ import models.CachedDataWithApp import org.joda.time.LocalDate -import play.api.Play import security.Roles.PersonalDetailsRole import play.api.i18n.Messages.Implicits._ import play.api.Play.current -import security.{ SecurityEnvironment, SilhouetteComponent } +import security.SilhouetteComponent import scala.concurrent.Future import uk.gov.hmrc.http.HeaderCarrier @@ -54,15 +52,16 @@ trait FastTrackApplication extends BaseController with ApplicationClient with Us user.user.lastName, user.user.firstName, DayMonthYear("", "", ""), - None, + outsideUk = None, Address("", None, None, None), - None, - None, - None, - None, - None, - "No", - None + postCode = None, + country = None, + phone = None, + aLevel = None, + stemLevel = None, + civilServant = "No", + department = None, + departmentOther = None )) def presentPersonalDetails(availableSchemes: List[SchemeInfo]) = { getPersonalDetails(user.user.userID, user.application.applicationId).map { gd => @@ -79,7 +78,8 @@ trait FastTrackApplication extends BaseController with ApplicationClient with Us Some(gd.aLevel), Some(gd.stemLevel), if (gd.civilServant) "Yes" else "No", - gd.department + gd.department, + gd.departmentOther )) Ok(views.html.application.personalDetails(form, availableSchemes)) diff --git a/app/forms/GeneralDetailsForm.scala b/app/forms/GeneralDetailsForm.scala index ff0879d..5ce3c48 100644 --- a/app/forms/GeneralDetailsForm.scala +++ b/app/forms/GeneralDetailsForm.scala @@ -62,6 +62,23 @@ object GeneralDetailsForm { override def unbind(key: String, value: Option[String]): Map[String, String] = Map(key -> value.getOrElse("")) } + val otherDepartmentDependentFormatter = new Formatter[Option[String]] { + override def bind(key: String, data: Map[String, String]): Either[Seq[FormError], Option[String]] = { + val check1 = data.get("civilServant") + val check2 = data.get("department") + val value = data.get(key).filterNot(_.trim.isEmpty) + + (check1, check2, value) match { + case (Some("Yes"), Some("Other"), Some(v)) if v.trim.length > deptMaxLength => Left(List(FormError(key, s"error.$key.maxLength"))) + case (Some("Yes"), Some("Other"), Some(v)) => Right(value) + case (Some("Yes"), Some("Other"), None) => Left(List(FormError(key, s"error.$key.required"))) + case _ => Right(None) + } + } + + override def unbind(key: String, value: Option[String]): Map[String, String] = Map(key -> value.getOrElse("")) + } + def form(implicit now: LocalDate) = { val maxDob = Some(ageReference.minusYears(minAge)) @@ -79,7 +96,8 @@ object GeneralDetailsForm { "alevel-d" -> optional(boolean).verifying("aleveld.required", _.isDefined), "alevel" -> optional(boolean).verifying("alevel.required", _.isDefined), "civilServant" -> nonEmptyTrimmedText("error.civilServant.required", 3), - "department" -> of(civilServantDependentFormatter) + "department" -> of(civilServantDependentFormatter), + "departmentOther" -> of(otherDepartmentDependentFormatter) )(Data.apply)(Data.unapply) ) } @@ -132,6 +150,7 @@ object GeneralDetailsForm { aLevel: Option[Boolean], stemLevel: Option[Boolean], civilServant: String, - department: Option[String] + department: Option[String], + departmentOther: Option[String] ) } diff --git a/app/models/CivilServiceDepartments.scala b/app/models/CivilServiceDepartments.scala new file mode 100644 index 0000000..f533860 --- /dev/null +++ b/app/models/CivilServiceDepartments.scala @@ -0,0 +1,49 @@ +/* + * Copyright 2018 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package models + +object CivilServiceDepartments { + val list = List( + ("Business, Energy and Industrial Strategy", false), + ("Cabinet Office", false), + ("Competition and Markets Authority", false), + ("Crown Commercial Service", false), + ("Crown Prosecution Service", false), + ("Department for Communities and Local Government", false), + ("Department for Culture, Media and Sport", false), + ("Department for Education", false), + ("Department for Environment, Food and Rural Affairs", false), + ("Department for Exiting the European Union", false), + ("Department for International Development", false), + ("Department for International Trade", false), + ("Department for Transport", false), + ("Department for Work and Pensions", false), + ("Department of Health", false), + ("Education and Skills Funding Agency", false), + ("Foreign and Commonwealth Office", false), + ("Insolvency Service", false), + ("Health and Safety Executive", false), + ("Her Majesty's Prison and Probation Service", false), + ("Her Majesty's Revenue and Customs", false), + ("Her Majesty's Treasury", false), + ("Home Office", false), + ("Ministry of Defence", false), + ("Ministry of Justice", false), + ("Valuation Office Agency", false), + ("Other", true) + ) +} diff --git a/app/views/application/personalDetails.scala.html b/app/views/application/personalDetails.scala.html index cdededa..d90f16b 100644 --- a/app/views/application/personalDetails.scala.html +++ b/app/views/application/personalDetails.scala.html @@ -19,7 +19,7 @@ @(form: Form[_root_.forms.GeneralDetailsForm.Data], availableSchemes: List[SchemeInfo])(implicit request: Request[_], messages: Messages, flash: Flash, user: Option[CachedData], feedbackUrl: String) @import helpers.CSRFieldConstructor._ -@import views.html.widgets.{ pageProgress, checkbox, date, radioBox, radioBoxHorizontal } +@import views.html.widgets.{ pageProgress, date, radioBox, radioBoxHorizontal, select_guard } @isOutsideUkChecked = @{ form("outsideUk").value match { @@ -212,13 +212,17 @@

Civil servants

@radioBoxHorizontal(form("civilServant"), options = List(("yes", "Yes", true), ("no", "No", false)), optionTrigger = "civilservant-panel")