use of de.symeda.sormas.api.task.TaskType in project SORMAS-Project by hzi-braunschweig.
the class TaskEditForm method addFields.
@Override
protected void addFields() {
addField(TaskDto.CAZE, ComboBox.class);
addField(TaskDto.EVENT, ComboBox.class);
addField(TaskDto.CONTACT, ComboBox.class);
DateTimeField startDate = addDateField(TaskDto.SUGGESTED_START, DateTimeField.class, -1);
DateTimeField dueDate = addDateField(TaskDto.DUE_DATE, DateTimeField.class, -1);
dueDate.setImmediate(true);
addField(TaskDto.PRIORITY, ComboBox.class);
NullableOptionGroup taskStatus = addField(TaskDto.TASK_STATUS, NullableOptionGroup.class);
NullableOptionGroup taskContext = addField(TaskDto.TASK_CONTEXT, NullableOptionGroup.class);
taskContext.setImmediate(true);
taskContext.addValueChangeListener(event -> updateByTaskContext());
ComboBox taskTypeField = addField(TaskDto.TASK_TYPE, ComboBox.class);
taskTypeField.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
taskTypeField.setImmediate(true);
taskTypeField.addValueChangeListener(e -> {
TaskType taskType = (TaskType) e.getProperty().getValue();
if (taskType != null) {
setRequired(taskType.isCreatorCommentRequired(), TaskDto.CREATOR_COMMENT);
}
});
ComboBox assigneeUser = addField(TaskDto.ASSIGNEE_USER, ComboBox.class);
assigneeUser.addValueChangeListener(e -> {
updateObserversList();
updateByCreatingAndAssignee();
checkIfUserEmailOrPhoneIsProvided((UserReferenceDto) e.getProperty().getValue(), Strings.infoAssigneeMissingEmail, Strings.infoAssigneeMissingEmailOrPhoneNumber, ASSIGNEE_MISSING_INFO);
});
assigneeUser.setImmediate(true);
TextArea creatorComment = addField(TaskDto.CREATOR_COMMENT, TextArea.class);
creatorComment.setRows(2);
creatorComment.setImmediate(true);
addField(TaskDto.ASSIGNEE_REPLY, TextArea.class).setRows(4);
MultiSelect<UserReferenceDto> observerUsers = addField(TaskDto.OBSERVER_USERS, MultiSelect.class);
observerUsers.addValueChangeListener(e -> {
Collection<UserReferenceDto> userReferences = (Collection<UserReferenceDto>) e.getProperty().getValue();
for (UserReferenceDto userReference : userReferences) {
checkIfUserEmailOrPhoneIsProvided(userReference, Strings.infoObserverMissingEmail, Strings.infoObserverMissingEmailOrPhoneNumber, OBSERVER_MISSING_INFO);
}
});
observerUsers.setImmediate(true);
CssStyles.style(observerUsers, CssStyles.OPTIONGROUP_MAX_HEIGHT_150);
setRequired(true, TaskDto.TASK_CONTEXT, TaskDto.TASK_TYPE, TaskDto.ASSIGNEE_USER, TaskDto.DUE_DATE, TaskDto.TASK_STATUS);
setReadOnly(true, TaskDto.TASK_CONTEXT, TaskDto.CAZE, TaskDto.CONTACT, TaskDto.EVENT);
addValueChangeListener(e -> {
TaskDto taskDto = getValue();
if (taskDto.getTaskType() == TaskType.CASE_INVESTIGATION && taskDto.getCaze() != null) {
taskStatus.addValidator(new TaskStatusValidator(taskDto.getCaze().getUuid(), I18nProperties.getValidationError(Validations.investigationStatusUnclassifiedCase)));
if (!editedFromTaskGrid) {
final HorizontalLayout saveInfoLayout = new HorizontalLayout(new Label(VaadinIcons.INFO_CIRCLE.getHtml() + " " + I18nProperties.getString(Strings.infoSaveOfTask), ContentMode.HTML));
saveInfoLayout.setSpacing(true);
saveInfoLayout.setMargin(new MarginInfo(true, false, true, false));
getContent().addComponent(saveInfoLayout, SAVE_INFO);
}
}
final UserDto userDto = UserProvider.getCurrent().getUser();
availableUsers = new ArrayList<>();
if (taskDto.getCaze() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingCaseInJurisdiction(taskDto.getCaze()));
} else if (taskDto.getContact() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingContactInJurisdiction(taskDto.getContact()));
} else if (taskDto.getEvent() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingEventInJurisdiction(taskDto.getEvent()));
} else if (taskDto.getTravelEntry() != null) {
availableUsers.addAll(FacadeProvider.getUserFacade().getUsersHavingTravelEntryInJurisdiction(taskDto.getTravelEntry()));
} else {
availableUsers.addAll(FacadeProvider.getUserFacade().getAllUserRefs(false));
}
// For national users, there is no higher level
if (FacadeProvider.getFeatureConfigurationFacade().isFeatureEnabled(FeatureType.ASSIGN_TASKS_TO_HIGHER_LEVEL) && UserRole.getJurisdictionLevel(userDto.getUserRoles()) != JurisdictionLevel.NATION) {
List<UserReferenceDto> superordinateUsers = FacadeProvider.getUserFacade().getUsersWithSuperiorJurisdiction(userDto);
if (superordinateUsers != null) {
availableUsers.addAll(superordinateUsers);
}
}
// Validation
startDate.addValidator(new DateComparisonValidator(startDate, dueDate, true, false, I18nProperties.getValidationError(Validations.beforeDate, startDate.getCaption(), dueDate.getCaption())));
dueDate.addValidator(new DateComparisonValidator(dueDate, startDate, false, false, I18nProperties.getValidationError(Validations.afterDate, dueDate.getCaption(), startDate.getCaption())));
Map<String, Long> userTaskCounts = FacadeProvider.getTaskFacade().getPendingTaskCountPerUser(availableUsers.stream().map(ReferenceDto::getUuid).collect(Collectors.toList()));
for (UserReferenceDto user : availableUsers) {
assigneeUser.addItem(user);
Long userTaskCount = userTaskCounts.get(user.getUuid());
assigneeUser.setItemCaption(user, user.getCaption() + " (" + (userTaskCount != null ? userTaskCount.toString() : "0") + ")");
if (!user.equals(assigneeUser.getValue())) {
// If a user has been assigned to the task, do not make it available for observers field
observerUsers.addItem(user);
observerUsers.setItemCaption(user, user.getCaption());
}
}
});
}
Aggregations