form.add(submit);
}
private void setupProfile() {
final WebMarkupContainer profile = new WebMarkupContainer("profile");
profile.setOutputMarkupId(true);
form.add(profile);
final ModalWindow reportletConfWin = new ModalWindow("reportletConfWin");
reportletConfWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
reportletConfWin.setCookieName("reportlet-conf-win-modal");
reportletConfWin.setInitialHeight(REPORTLET_CONF_WIN_HEIGHT);
reportletConfWin.setInitialWidth(REPORTLET_CONF_WIN_WIDTH);
reportletConfWin.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
private static final long serialVersionUID = 8804221891699487139L;
@Override
public void onClose(final AjaxRequestTarget target) {
int foundIdx = -1;
if (modalReportletConfOldName != null) {
for (int i = 0; i < reportTO.getReportletConfs().size() && foundIdx == -1; i++) {
if (reportTO.getReportletConfs().get(i).getName().equals(modalReportletConfOldName)) {
foundIdx = i;
}
}
}
if (modalReportletConf != null) {
if (foundIdx == -1) {
reportTO.addReportletConf(modalReportletConf);
} else {
reportTO.getReportletConfs().set(foundIdx, modalReportletConf);
}
}
target.add(profile);
}
});
add(reportletConfWin);
final Label idLabel = new Label("idLabel", new ResourceModel("id"));
profile.add(idLabel);
final AjaxTextFieldPanel id = new AjaxTextFieldPanel("id", getString("id"), new PropertyModel<String>(reportTO,
"id"));
id.setEnabled(false);
profile.add(id);
final Label nameLabel = new Label("nameLabel", new ResourceModel("name"));
profile.add(nameLabel);
final AjaxTextFieldPanel name = new AjaxTextFieldPanel("name", getString("name"), new PropertyModel<String>(
reportTO, "name"));
profile.add(name);
final AjaxTextFieldPanel lastExec = new AjaxTextFieldPanel("lastExec", getString("lastExec"),
new DateFormatROModel(new PropertyModel<String>(reportTO, "lastExec")));
lastExec.setEnabled(false);
profile.add(lastExec);
final AjaxTextFieldPanel nextExec = new AjaxTextFieldPanel("nextExec", getString("nextExec"),
new DateFormatROModel(new PropertyModel<String>(reportTO, "nextExec")));
nextExec.setEnabled(false);
profile.add(nextExec);
final SingleColumnPalette<ReportletConf> reportlets = new SingleColumnPalette<ReportletConf>("reportlets",
new PropertyModel<List<? extends ReportletConf>>(reportTO, "reportletConfs"),
new IChoiceRenderer<ReportletConf>() {
private static final long serialVersionUID = 1048000918946220007L;
@Override
public Object getDisplayValue(final ReportletConf object) {
return object.getName();
}
@Override
public String getIdValue(final ReportletConf object, int index) {
return object.getName();
}
}, 5, true);
reportlets.setOutputMarkupId(true);
reportlets.addRecordBehavior(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
}
});
reportlets.addRecordBehavior(new AjaxFormComponentUpdatingBehavior("onselect") {
private static final long serialVersionUID = -1107858522700306810L;
@Override
protected void onUpdate(final AjaxRequestTarget target) {
if (target.getLastFocusedElementId() != null
&& target.getLastFocusedElementId().startsWith(EDIT_BUTTON_ID)
&& reportlets.getSelectedItem() != null) {
reportletConfWin.setPageCreator(new ModalWindow.PageCreator() {
private static final long serialVersionUID = -7834632442532690940L;
@Override
public Page createPage() {
modalReportletConfOldName = reportlets.getSelectedItem().getName();
modalReportletConf = null;
return new ReportletConfModalPage(reportlets.getSelectedItem(), reportletConfWin,
ReportModalPage.this.getPageReference());
}
});
reportletConfWin.show(target);
}
}
});
reportlets.setAddLink(new AjaxLink(ADD_BUTTON_ID) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target) {
reportletConfWin.setPageCreator(new ModalWindow.PageCreator() {
private static final long serialVersionUID = -7834632442532690940L;
@Override
public Page createPage() {
modalReportletConfOldName = null;
modalReportletConf = null;
return new ReportletConfModalPage(null, reportletConfWin,
ReportModalPage.this.getPageReference());
}
});
reportletConfWin.show(target);
}
});
reportlets.setEditLink(new AjaxLink(EDIT_BUTTON_ID) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target) {
}
@Override
protected IAjaxCallDecorator getAjaxCallDecorator() {
return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
private static final long serialVersionUID = -7927968187160354605L;
@Override
public CharSequence preDecorateScript(final CharSequence script) {
return script + reportlets.getEditOnClickJS();
}
};
}
});
reportlets.setRemoveLink(new AjaxLink(REMOVE_BUTTON_ID) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
public void onClick(final AjaxRequestTarget target) {
}
@Override
protected IAjaxCallDecorator getAjaxCallDecorator() {
return new AjaxPreprocessingCallDecorator(super.getAjaxCallDecorator()) {
private static final long serialVersionUID = -7927968187160354605L;
@Override
public CharSequence preDecorateScript(final CharSequence script) {
return "if (confirm('" + getString("confirmDelete") + "')) {" + script
+ reportlets.getRemoveOnClickJS() + "}";
}
};
}
});
profile.add(reportlets);
}