private SchemaRestClient schemaRestClient;
public NotificationModalPage(final PageReference pageRef, final ModalWindow window,
final NotificationTO notificationTO, final boolean createFlag) {
Form form = new Form("form", new CompoundPropertyModel(notificationTO));
form.setModel(new CompoundPropertyModel(notificationTO));
final AjaxTextFieldPanel sender = new AjaxTextFieldPanel("sender", getString("sender"),
new PropertyModel<String>(notificationTO, "sender"));
sender.addRequiredLabel();
sender.addValidator(EmailAddressValidator.getInstance());
form.add(sender);
final AjaxTextFieldPanel subject = new AjaxTextFieldPanel("subject", getString("subject"),
new PropertyModel<String>(notificationTO, "subject"));
subject.addRequiredLabel();
form.add(subject);
final AjaxDropDownChoicePanel<String> template = new AjaxDropDownChoicePanel<String>(
"template", getString("template"),
new PropertyModel<String>(notificationTO, "template"));
template.setChoices(restClient.getMailTemplates());
template.addRequiredLabel();
form.add(template);
final AjaxDropDownChoicePanel<TraceLevel> traceLevel = new AjaxDropDownChoicePanel<TraceLevel>(
"traceLevel", getString("traceLevel"),
new PropertyModel<TraceLevel>(notificationTO, "traceLevel"));
traceLevel.setChoices(Arrays.asList(TraceLevel.values()));
traceLevel.addRequiredLabel();
form.add(traceLevel);
final UserSearchPanel about = new UserSearchPanel("about", notificationTO.getAbout());
form.add(about);
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(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
recipientAttrName.setChoices(getSchemaNames(recipientAttrType.getModelObject()));
target.add(recipientAttrName);
}
});
final AjaxPalettePanel events = new AjaxPalettePanel("events", new PropertyModel(notificationTO, "events"),
new ListModel<String>(restClient.getEvents()));
form.add(events);
final WebMarkupContainer recipientsContainer = new WebMarkupContainer("recipientsContainer");
recipientsContainer.setOutputMarkupId(true);
form.add(recipientsContainer);
final AjaxCheckBoxPanel selfAsRecipient = new AjaxCheckBoxPanel("selfAsRecipient",
getString("selfAsRecipient"), new PropertyModel(notificationTO, "selfAsRecipient"));
form.add(selfAsRecipient);
if (createFlag) {
selfAsRecipient.getField().setDefaultModelObject(Boolean.TRUE);
}
final AjaxCheckBoxPanel checkRecipients =
new AjaxCheckBoxPanel("checkRecipients", "checkRecipients",
new Model<Boolean>(notificationTO.getRecipients() == null ? false : true));
recipientsContainer.add(checkRecipients);
final UserSearchPanel recipients =
new UserSearchPanel("recipients",
notificationTO.getRecipients() == null ? null : notificationTO.getRecipients());
recipientsContainer.add(recipients);
recipients.setEnabled(checkRecipients.getModelObject());
selfAsRecipient.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (!Boolean.valueOf(selfAsRecipient.getField().getValue())) {
checkRecipients.getField().setDefaultModelObject(Boolean.TRUE);
target.add(checkRecipients);
recipients.setEnabled(checkRecipients.getModelObject());
target.add(recipients);
target.add(recipientsContainer);
}
}
});
checkRecipients.getField().add(new AjaxFormComponentUpdatingBehavior(ON_CHANGE) {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (!checkRecipients.getModelObject()) {
selfAsRecipient.getField().setDefaultModelObject(Boolean.TRUE);
target.add(selfAsRecipient);
}
recipients.setEnabled(checkRecipients.getModelObject());
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.setAbout(about.buildSearchCond());
notificationTO.setRecipients(checkRecipients.getModelObject() ? recipients.buildSearchCond() : null);
try {
if (createFlag) {
restClient.createNotification(notificationTO);
} else {
restClient.updateNotification(notificationTO);
}
info(getString("operation_succeeded"));
Configuration callerPage = (Configuration) pageRef.getPage();
callerPage.setModalResult(true);
window.close(target);
} catch (SyncopeClientCompositeErrorException scee) {
error(getString("error") + ":" + scee.getMessage());
target.add(feedbackPanel);
}
}
@Override
protected void onError(final AjaxRequestTarget target, final Form<?> form) {
target.add(feedbackPanel);
}
};
final AjaxButton cancel = new IndicatingAjaxButton("cancel", new ResourceModel("cancel")) {
private static final long serialVersionUID = -958724007591692537L;
@Override
protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
window.close(target);
}
};
cancel.setDefaultFormProcessing(false);
String allowedRoles = createFlag
? xmlRolesReader.getAllAllowedRoles("Notification", "create")
: xmlRolesReader.getAllAllowedRoles("Notification", "update");
MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, allowedRoles);
form.add(submit);
form.setDefaultButton(submit);
form.add(cancel);
add(form);
}