use of com.gitblit.wicket.pages.BasePage in project gitblit by gitblit.
the class CommentPanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
Form<String> form = new Form<String>("editorForm");
add(form);
form.add(new AjaxButton("submit", new Model<String>(getString("gb.comment")), form) {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit(AjaxRequestTarget target, Form<?> form) {
String txt = markdownEditor.getText();
if (change == null) {
// new comment
Change newComment = new Change(user.username);
newComment.comment(txt);
if (!ticket.isWatching(user.username)) {
newComment.watch(user.username);
}
RepositoryModel repository = app().repositories().getRepositoryModel(ticket.repository);
TicketModel updatedTicket = app().tickets().updateTicket(repository, ticket.number, newComment);
if (updatedTicket != null) {
app().tickets().createNotifier().sendMailing(updatedTicket);
redirectTo(pageClass, WicketUtils.newObjectParameter(updatedTicket.repository, "" + ticket.number));
} else {
error("Failed to add comment!");
}
} else {
// TODO update comment
}
}
/**
* Steal from BasePage to realize redirection.
*
* @see BasePage
* @author krulls@GitHub; ECG Leipzig GmbH, Germany, 2015
*
* @param pageClass
* @param parameters
* @return
*/
private void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
String relativeUrl = urlFor(pageClass, parameters).toString();
String canonicalUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(canonicalUrl));
}
}.setVisible(ticket != null && ticket.number > 0));
final IModel<String> markdownPreviewModel = Model.of();
markdownPreview = new Label("markdownPreview", markdownPreviewModel);
markdownPreview.setEscapeModelStrings(false);
markdownPreview.setOutputMarkupId(true);
add(markdownPreview);
markdownEditor = new MarkdownTextArea("markdownEditor", markdownPreviewModel, markdownPreview);
markdownEditor.setRepository(repositoryName);
WicketUtils.setInputPlaceholder(markdownEditor, getString("gb.leaveComment"));
add(markdownEditor);
}
Aggregations