private Label descriptionPreview;
public EditTicketPage(PageParameters params) {
super(params);
UserModel currentUser = GitBlitWebSession.get().getUser();
if (currentUser == null) {
currentUser = UserModel.ANONYMOUS;
}
long ticketId = 0L;
try {
String h = WicketUtils.getObject(params);
ticketId = Long.parseLong(h);
} catch (Exception e) {
setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
}
TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), ticketId);
if (ticket == null
|| !currentUser.canEdit(ticket, getRepositoryModel())
|| !app().tickets().isAcceptingTicketUpdates(getRepositoryModel())) {
setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(repositoryName, "" + ticketId));
// create a placeholder object so we don't trigger NPEs
ticket = new TicketModel();
}
typeModel = Model.of(ticket.type);
titleModel = Model.of(ticket.title);
topicModel = Model.of(ticket.topic == null ? "" : ticket.topic);
responsibleModel = Model.of();
milestoneModel = Model.of();
mergeToModel = Model.of(ticket.mergeTo == null ? getRepositoryModel().mergeTo : ticket.mergeTo);
statusModel = Model.of(ticket.status);
setStatelessHint(false);
setOutputMarkupId(true);
Form<Void> form = new Form<Void>("editForm");
add(form);
List<Type> typeChoices;
if (ticket.isProposal()) {
typeChoices = Arrays.asList(Type.Proposal);
} else {
typeChoices = Arrays.asList(TicketModel.Type.choices());
}
form.add(new DropDownChoice<TicketModel.Type>("type", typeModel, typeChoices));
form.add(new TextField<String>("title", titleModel));
form.add(new TextField<String>("topic", topicModel));
final IModel<String> markdownPreviewModel = new Model<String>();
descriptionPreview = new Label("descriptionPreview", markdownPreviewModel);
descriptionPreview.setEscapeModelStrings(false);
descriptionPreview.setOutputMarkupId(true);
form.add(descriptionPreview);
descriptionEditor = new MarkdownTextArea("description", markdownPreviewModel, descriptionPreview);
descriptionEditor.setRepository(repositoryName);
descriptionEditor.setText(ticket.body);
form.add(descriptionEditor);
// status
List<Status> statusChoices;
if (ticket.isClosed()) {
statusChoices = Arrays.asList(ticket.status, Status.Open);
} else if (ticket.isProposal()) {
statusChoices = Arrays.asList(TicketModel.Status.proposalWorkflow);
} else if (ticket.isBug()) {
statusChoices = Arrays.asList(TicketModel.Status.bugWorkflow);
} else {
statusChoices = Arrays.asList(TicketModel.Status.requestWorkflow);
}
Fragment status = new Fragment("status", "statusFragment", this);
status.add(new DropDownChoice<TicketModel.Status>("status", statusModel, statusChoices));
form.add(status);
if (currentUser.canAdmin(ticket, getRepositoryModel())) {
// responsible
Set<String> userlist = new TreeSet<String>(ticket.getParticipants());
if (UserModel.ANONYMOUS.canPush(getRepositoryModel())) {
// anonymous push
userlist.addAll(app().users().getAllUsernames());
} else {
// authenticated push
for (RegistrantAccessPermission rp : app().repositories().getUserAccessPermissions(getRepositoryModel())) {
if (rp.permission.atLeast(AccessPermission.PUSH) && !rp.isTeam()) {
userlist.add(rp.registrant);
}
}
}
List<TicketResponsible> responsibles = new ArrayList<TicketResponsible>();
for (String username : userlist) {
UserModel user = app().users().getUserModel(username);
if (user != null && !user.disabled) {
TicketResponsible responsible = new TicketResponsible(user);
responsibles.add(responsible);
if (user.username.equals(ticket.responsible)) {
responsibleModel.setObject(responsible);