final UserSearchPanel userAbout =
new UserSearchPanel.Builder("userAbout").fiql(notificationTO.getUserAbout()).build();
aboutContainer.add(userAbout);
userAbout.setEnabled(checkUserAbout.getModelObject());
final RoleSearchPanel roleAbout =
new RoleSearchPanel.Builder("roleAbout").fiql(notificationTO.getRoleAbout()).build();
aboutContainer.add(roleAbout);
roleAbout.setEnabled(checkRoleAbout.getModelObject());
checkAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (checkAbout.getModelObject()) {
checkUserAbout.setModelObject(Boolean.FALSE);
checkRoleAbout.setModelObject(Boolean.FALSE);
userAbout.setEnabled(Boolean.FALSE);
roleAbout.setEnabled(Boolean.FALSE);
} else {
checkAbout.setModelObject(Boolean.TRUE);
}
target.add(aboutContainer);
}
});
checkUserAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (checkUserAbout.getModelObject()) {
checkAbout.setModelObject(!checkUserAbout.getModelObject());
checkRoleAbout.setModelObject(!checkUserAbout.getModelObject());
roleAbout.setEnabled(Boolean.FALSE);
} else {
checkUserAbout.setModelObject(Boolean.TRUE);
}
userAbout.setEnabled(Boolean.TRUE);
target.add(aboutContainer);
}
});
checkRoleAbout.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (checkRoleAbout.getModelObject()) {
checkAbout.setModelObject(Boolean.FALSE);
checkUserAbout.setModelObject(Boolean.FALSE);
userAbout.setEnabled(Boolean.FALSE);
} else {
checkRoleAbout.setModelObject(Boolean.TRUE);
}
roleAbout.setEnabled(Boolean.TRUE);
target.add(aboutContainer);
}
});
final AjaxDropDownChoicePanel<IntMappingType> recipientAttrType = new AjaxDropDownChoicePanel<IntMappingType>(
"recipientAttrType", new ResourceModel("recipientAttrType", "recipientAttrType").getObject(),
new PropertyModel<IntMappingType>(notificationTO, "recipientAttrType"));
recipientAttrType.setChoices(new ArrayList<IntMappingType>(
IntMappingType.getAttributeTypes(AttributableType.USER,
EnumSet.of(IntMappingType.UserId, IntMappingType.Password))));
recipientAttrType.setRequired(true);
form.add(recipientAttrType);
final AjaxDropDownChoicePanel<String> recipientAttrName = new AjaxDropDownChoicePanel<String>(
"recipientAttrName", new ResourceModel("recipientAttrName", "recipientAttrName").getObject(),
new PropertyModel<String>(notificationTO, "recipientAttrName"));
recipientAttrName.setChoices(getSchemaNames(recipientAttrType.getModelObject()));
recipientAttrName.setRequired(true);
form.add(recipientAttrName);
recipientAttrType.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
recipientAttrName.setChoices(getSchemaNames(recipientAttrType.getModelObject()));
target.add(recipientAttrName);
}
});
form.add(new LoggerCategoryPanel(
"eventSelection",
loggerRestClient.listEvents(),
new PropertyModel<List<String>>(notificationTO, "events"),
getPageReference(),
"Notification") {
private static final long serialVersionUID = 6429053774964787735L;
@Override
protected String[] getListRoles() {
return new String[] {};
}
@Override
protected String[] getChangeRoles() {
return new String[] {};
}
});
final WebMarkupContainer recipientsContainer = new WebMarkupContainer("recipientsContainer");
recipientsContainer.setOutputMarkupId(true);
form.add(recipientsContainer);
final AjaxCheckBoxPanel checkStaticRecipients = new AjaxCheckBoxPanel("checkStaticRecipients",
"recipients", new Model<Boolean>(!notificationTO.getStaticRecipients().isEmpty()));
form.add(checkStaticRecipients);
if (createFlag) {
checkStaticRecipients.getField().setDefaultModelObject(Boolean.FALSE);
}
final AjaxTextFieldPanel staticRecipientsFieldPanel =
new AjaxTextFieldPanel("panel", "staticRecipients", new Model<String>(null));
staticRecipientsFieldPanel.addValidator(EmailAddressValidator.getInstance());
staticRecipientsFieldPanel.setRequired(checkStaticRecipients.getModelObject());
if (notificationTO.getStaticRecipients().isEmpty()) {
notificationTO.getStaticRecipients().add(null);
}
final MultiFieldPanel<String> staticRecipients = new MultiFieldPanel<String>("staticRecipients",
new PropertyModel<List<String>>(notificationTO, "staticRecipients"), staticRecipientsFieldPanel);
staticRecipients.setEnabled(checkStaticRecipients.getModelObject());
form.add(staticRecipients);
final AjaxCheckBoxPanel checkRecipients =
new AjaxCheckBoxPanel("checkRecipients", "checkRecipients",
new Model<Boolean>(notificationTO.getRecipients() == null ? false : true));
recipientsContainer.add(checkRecipients);
if (createFlag) {
checkRecipients.getField().setDefaultModelObject(Boolean.TRUE);
}
final UserSearchPanel recipients =
new UserSearchPanel.Builder("recipients").fiql(notificationTO.getRecipients()).build();
recipients.setEnabled(checkRecipients.getModelObject());
recipientsContainer.add(recipients);
final AjaxCheckBoxPanel selfAsRecipient = new AjaxCheckBoxPanel("selfAsRecipient",
getString("selfAsRecipient"), new PropertyModel<Boolean>(notificationTO, "selfAsRecipient"));
form.add(selfAsRecipient);
if (createFlag) {
selfAsRecipient.getField().setDefaultModelObject(Boolean.FALSE);
}
selfAsRecipient.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (!selfAsRecipient.getModelObject()
&& !checkRecipients.getModelObject()
&& !checkStaticRecipients.getModelObject()) {
checkRecipients.getField().setDefaultModelObject(Boolean.TRUE);
target.add(checkRecipients);
recipients.setEnabled(checkRecipients.getModelObject());
target.add(recipients);
target.add(recipientsContainer);
}
}
});
checkRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (!checkRecipients.getModelObject()
&& !selfAsRecipient.getModelObject()
&& !checkStaticRecipients.getModelObject()) {
checkStaticRecipients.getField().setDefaultModelObject(Boolean.TRUE);
target.add(checkStaticRecipients);
staticRecipients.setEnabled(Boolean.TRUE);
target.add(staticRecipients);
staticRecipientsFieldPanel.setRequired(Boolean.TRUE);
target.add(staticRecipientsFieldPanel);
}
recipients.setEnabled(checkRecipients.getModelObject());
target.add(recipients);
target.add(recipientsContainer);
}
});
checkStaticRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (!checkStaticRecipients.getModelObject()
&& !selfAsRecipient.getModelObject()
&& !checkRecipients.getModelObject()) {
checkRecipients.getField().setDefaultModelObject(Boolean.TRUE);
checkRecipients.setEnabled(Boolean.TRUE);
target.add(checkRecipients);
}
staticRecipients.setEnabled(checkStaticRecipients.getModelObject());
staticRecipientsFieldPanel.setRequired(checkStaticRecipients.getModelObject());
recipients.setEnabled(checkRecipients.getModelObject());
target.add(staticRecipientsFieldPanel);
target.add(staticRecipients);
target.add(recipients);
target.add(recipientsContainer);
}
});
AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<String>(getString(SUBMIT))) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
notificationTO.setUserAbout(
!checkAbout.getModelObject() && checkUserAbout.getModelObject() ? userAbout.buildFIQL() : null);
notificationTO.setRoleAbout(
!checkAbout.getModelObject()
&& checkRoleAbout.getModelObject() ? roleAbout.buildFIQL() : null);
notificationTO.setRecipients(checkRecipients.getModelObject() ? recipients.buildFIQL() : null);
notificationTO.getStaticRecipients().removeAll(Collections.singleton(null));
try {
if (createFlag) {