use of org.apache.wicket.request.target.basic.RedirectRequestTarget in project gitblit by gitblit.
the class BranchesPanel method createDeleteBranchLink.
private Link<Void> createDeleteBranchLink(final RepositoryModel repositoryModel, final RefModel entry) {
Link<Void> deleteLink = new Link<Void>("deleteBranch") {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
Repository r = app().repositories().getRepository(repositoryModel.name);
if (r == null) {
if (app().repositories().isCollectingGarbage(repositoryModel.name)) {
error(MessageFormat.format(getString("gb.busyCollectingGarbage"), repositoryModel.name));
} else {
error(MessageFormat.format("Failed to find repository {0}", repositoryModel.name));
}
return;
}
final String branch = entry.getName();
Ref ref = null;
try {
ref = r.getRef(branch);
if (ref == null && !branch.startsWith(Constants.R_HEADS)) {
ref = r.getRef(Constants.R_HEADS + branch);
}
} catch (IOException e) {
}
if (ref != null) {
boolean success = JGitUtils.deleteBranchRef(r, ref.getName());
if (success) {
// clear commit cache
CommitCache.instance().clear(repositoryModel.name, branch);
// optionally update reflog
if (RefLogUtils.hasRefLogBranch(r)) {
UserModel user = GitBlitWebSession.get().getUser();
RefLogUtils.deleteRef(user, r, ref);
}
}
if (success) {
info(MessageFormat.format("Branch \"{0}\" deleted", branch));
} else {
error(MessageFormat.format("Failed to delete branch \"{0}\"", branch));
}
}
r.close();
// redirect to the owning page
PageParameters params = WicketUtils.newRepositoryParameter(repositoryModel.name);
String relativeUrl = urlFor(getPage().getClass(), params).toString();
String absoluteUrl = RequestUtils.toAbsolutePath(relativeUrl);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
};
deleteLink.add(new JavascriptEventConfirmation("onclick", MessageFormat.format("Delete branch \"{0}\"?", entry.displayName)));
return deleteLink;
}
use of org.apache.wicket.request.target.basic.RedirectRequestTarget in project gitblit by gitblit.
the class BasePage method redirectTo.
protected void redirectTo(Class<? extends BasePage> pageClass, PageParameters parameters) {
String absoluteUrl = getCanonicalUrl(pageClass, parameters);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
use of org.apache.wicket.request.target.basic.RedirectRequestTarget 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);
}
use of org.apache.wicket.request.target.basic.RedirectRequestTarget in project gitblit by gitblit.
the class TicketSearchForm method onSubmit.
@Override
public void onSubmit() {
String searchString = searchBoxModel.getObject();
if (StringUtils.isEmpty(searchString)) {
// redirect to self to avoid wicket page update bug
String absoluteUrl = getAbsoluteUrl();
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
return;
}
// use an absolute url to workaround Wicket-Tomcat problems with
// mounted url parameters (issue-111)
PageParameters params = WicketUtils.newRepositoryParameter(repositoryName);
params.add("s", searchString);
String absoluteUrl = getAbsoluteUrl(pageClass, params);
getRequestCycle().setRequestTarget(new RedirectRequestTarget(absoluteUrl));
}
Aggregations