Search in sources :

Example 1 with BasePage

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);
}
Also used : Form(org.apache.wicket.markup.html.form.Form) Label(org.apache.wicket.markup.html.basic.Label) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) RepositoryModel(com.gitblit.models.RepositoryModel) PageParameters(org.apache.wicket.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxButton(org.apache.wicket.ajax.markup.html.form.AjaxButton) RedirectRequestTarget(org.apache.wicket.request.target.basic.RedirectRequestTarget) BasePage(com.gitblit.wicket.pages.BasePage)

Aggregations

RepositoryModel (com.gitblit.models.RepositoryModel)1 TicketModel (com.gitblit.models.TicketModel)1 Change (com.gitblit.models.TicketModel.Change)1 BasePage (com.gitblit.wicket.pages.BasePage)1 PageParameters (org.apache.wicket.PageParameters)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxButton (org.apache.wicket.ajax.markup.html.form.AjaxButton)1 Label (org.apache.wicket.markup.html.basic.Label)1 Form (org.apache.wicket.markup.html.form.Form)1 RedirectRequestTarget (org.apache.wicket.request.target.basic.RedirectRequestTarget)1