add(new TextArea("comment").setRequired(true).add(new ErrorHighlighter()));
// custom fields ===================================================
User user = getPrincipal();
add(new CustomFieldsFormPanel("fields", model, item, user));
// =================================================================
final Space space = item.getSpace();
final List<UserSpaceRole> userSpaceRoles = getJtrac().findUserRolesForSpace(space.getId());
// assigned to =====================================================
final WebMarkupContainer border = new WebMarkupContainer("border");
border.setOutputMarkupId(true);
final WebMarkupContainer hide = new WebMarkupContainer("hide");
border.add(hide);
final List<User> emptyList = new ArrayList<User>(0); // will be populated over Ajax
assignedToChoice = new DropDownChoice("assignedTo", emptyList, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((User) o).getName();
}
public String getIdValue(Object o, int i) {
return ((User) o).getId() + "";
}
});
assignedToChoice.setOutputMarkupId(true);
assignedToChoice.setVisible(false);
assignedToChoice.setNullValid(true);
border.add(new ErrorHighlighter(assignedToChoice));
border.add(assignedToChoice);
add(border);
// status ==========================================================
final Map<Integer, String> statesMap = item.getPermittedTransitions(user);
List<Integer> states = new ArrayList(statesMap.keySet());
statusChoice = new IndicatingDropDownChoice("status", states, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return statesMap.get(o);
}
public String getIdValue(Object o, int i) {
return o.toString();
}
});
statusChoice.setNullValid(true);
statusChoice.add(new ErrorHighlighter());
statusChoice.add(new AjaxFormComponentUpdatingBehavior("onChange") {
protected void onUpdate(AjaxRequestTarget target) {
Integer selectedStatus = (Integer) getFormComponent().getConvertedInput();
if (selectedStatus == null) {
assignedToChoice.setVisible(false);
hide.setVisible(true);
} else {
List<User> assignable = UserUtils.filterUsersAbleToTransitionFrom(userSpaceRoles, space, selectedStatus);
assignedToChoice.setChoices(assignable);
assignedToChoice.setVisible(true);
hide.setVisible(false);
}
target.addComponent(border);
}
});
add(statusChoice);
// notify list =====================================================
List<ItemUser> choices = UserUtils.convertToItemUserList(userSpaceRoles);
ListMultipleChoice itemUsers = new JtracCheckBoxMultipleChoice("itemUsers", choices, new IChoiceRenderer() {
public Object getDisplayValue(Object o) {
return ((ItemUser) o).getUser().getName();
}
public String getIdValue(Object o, int i) {
return ((ItemUser) o).getUser().getId() + "";
}
}, true);
add(itemUsers);
// attachment ======================================================
fileUploadField = new FileUploadField("file");
add(fileUploadField);
setMaxSize(Bytes.megabytes(getJtrac().getAttachmentMaxSizeInMb()));
// send notifications===============================================
add(new CheckBox("sendNotifications"));
// validation that assignedTo is not null if status is not null and not CLOSED
// have to use FormValidator because this is conditional validation across two FormComponents
add(new AbstractFormValidator() {
public FormComponent[] getDependentFormComponents() {
// actually we depend on assignedToChoice also, but wicket logs a warning when the
// component is not visible but we are doing ajax. anyway we use assignedToChoice.getInput()
// not assignedToChoice.convertedInput() so no danger there
return new FormComponent[] {statusChoice};
}
public void validate(Form unused) {
if(assignedToChoice.getInput() == null || assignedToChoice.getInput().trim().length() == 0) {
Integer i = (Integer) statusChoice.getConvertedInput();
if (i != null && i != State.CLOSED) {
// user may have customized the name of the CLOSED State e.g. for i18n
// so when reporting the error, use the display name
String closedDisplayName = space.getMetadata().getStatusValue(State.CLOSED);
assignedToChoice.error(localize("item_view_form.assignedTo.error", closedDisplayName));
}
}
}
});