diff options
author | James Moger <james.moger@gitblit.com> | 2014-05-01 14:21:52 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-05-01 14:21:52 -0400 |
commit | 9d60ffabc71084efe00d1c33cd3cd87417407246 (patch) | |
tree | 91fadd70e558497b549bd4927ceb868df1eff755 /src/main/java/com | |
parent | c32e24b337227fd357068489310e243e68807ed1 (diff) | |
download | gitblit-9d60ffabc71084efe00d1c33cd3cd87417407246.tar.gz gitblit-9d60ffabc71084efe00d1c33cd3cd87417407246.zip |
Switch to ajax New|Edit Ticket page submission to handle empty titles
Diffstat (limited to 'src/main/java/com')
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/EditTicketPage.java | 204 | ||||
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/NewTicketPage.java | 110 |
2 files changed, 165 insertions, 149 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java index 64c0648a..c3294ba2 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditTicketPage.java @@ -23,6 +23,8 @@ import java.util.Set; import java.util.TreeSet;
import org.apache.wicket.PageParameters;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
@@ -117,103 +119,7 @@ public class EditTicketPage extends RepositoryPage { setStatelessHint(false);
setOutputMarkupId(true);
- Form<Void> form = new Form<Void>("editForm") {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void onSubmit() {
- long ticketId = 0L;
- try {
- String h = WicketUtils.getObject(getPageParameters());
- ticketId = Long.parseLong(h);
- } catch (Exception e) {
- setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
- }
-
- TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), ticketId);
-
- String createdBy = GitBlitWebSession.get().getUsername();
- Change change = new Change(createdBy);
-
- String title = titleModel.getObject();
- if (!StringUtils.isEmpty(title) && !ticket.title.equals(title)) {
- // title change
- change.setField(Field.title, title);
- }
-
- String description = descriptionEditor.getText();
- if ((StringUtils.isEmpty(ticket.body) && !StringUtils.isEmpty(description))
- || (!StringUtils.isEmpty(ticket.body) && !ticket.body.equals(description))) {
- // description change
- change.setField(Field.body, description);
- }
-
- Status status = statusModel.getObject();
- if (!ticket.status.equals(status)) {
- // status change
- change.setField(Field.status, status);
- }
-
- Type type = typeModel.getObject();
- if (!ticket.type.equals(type)) {
- // type change
- change.setField(Field.type, type);
- }
-
- String topic = topicModel.getObject();
- if ((StringUtils.isEmpty(ticket.topic) && !StringUtils.isEmpty(topic))
- || (!StringUtils.isEmpty(topic) && !topic.equals(ticket.topic))) {
- // topic change
- change.setField(Field.topic, topic);
- }
-
- TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();
- if (responsible != null && !responsible.username.equals(ticket.responsible)) {
- // responsible change
- change.setField(Field.responsible, responsible.username);
- if (!StringUtils.isEmpty(responsible.username)) {
- if (!ticket.isWatching(responsible.username)) {
- change.watch(responsible.username);
- }
- }
- }
-
- TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();
- if (milestone != null && !milestone.name.equals(ticket.milestone)) {
- // milestone change
- if (NIL.equals(milestone.name)) {
- change.setField(Field.milestone, "");
- } else {
- change.setField(Field.milestone, milestone.name);
- }
- }
-
- String mergeTo = mergeToModel.getObject();
- if ((StringUtils.isEmpty(ticket.mergeTo) && !StringUtils.isEmpty(mergeTo))
- || (!StringUtils.isEmpty(mergeTo) && !mergeTo.equals(ticket.mergeTo))) {
- // integration branch change
- change.setField(Field.mergeTo, mergeTo);
- }
-
- if (change.hasFieldChanges()) {
- if (!ticket.isWatching(createdBy)) {
- change.watch(createdBy);
- }
- ticket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);
- if (ticket != null) {
- TicketNotifier notifier = app().tickets().createNotifier();
- notifier.sendMailing(ticket);
- setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));
- } else {
- // TODO error
- }
- } else {
- // nothing to change?!
- setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));
- }
- }
- };
+ Form<Void> form = new Form<Void>("editForm");
add(form);
List<Type> typeChoices;
@@ -324,7 +230,109 @@ public class EditTicketPage extends RepositoryPage { form.add(new Label("milestone").setVisible(false));
form.add(new Label("mergeto").setVisible(false));
}
- form.add(new Button("update"));
+
+ form.add(new AjaxButton("update") {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ long ticketId = 0L;
+ try {
+ String h = WicketUtils.getObject(getPageParameters());
+ ticketId = Long.parseLong(h);
+ } catch (Exception e) {
+ setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));
+ }
+
+ TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), ticketId);
+
+ String createdBy = GitBlitWebSession.get().getUsername();
+ Change change = new Change(createdBy);
+
+ String title = titleModel.getObject();
+ if (StringUtils.isEmpty(title)) {
+ return;
+ }
+
+ if (!ticket.title.equals(title)) {
+ // title change
+ change.setField(Field.title, title);
+ }
+
+ String description = descriptionEditor.getText();
+ if ((StringUtils.isEmpty(ticket.body) && !StringUtils.isEmpty(description))
+ || (!StringUtils.isEmpty(ticket.body) && !ticket.body.equals(description))) {
+ // description change
+ change.setField(Field.body, description);
+ }
+
+ Status status = statusModel.getObject();
+ if (!ticket.status.equals(status)) {
+ // status change
+ change.setField(Field.status, status);
+ }
+
+ Type type = typeModel.getObject();
+ if (!ticket.type.equals(type)) {
+ // type change
+ change.setField(Field.type, type);
+ }
+
+ String topic = topicModel.getObject();
+ if ((StringUtils.isEmpty(ticket.topic) && !StringUtils.isEmpty(topic))
+ || (!StringUtils.isEmpty(topic) && !topic.equals(ticket.topic))) {
+ // topic change
+ change.setField(Field.topic, topic);
+ }
+
+ TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();
+ if (responsible != null && !responsible.username.equals(ticket.responsible)) {
+ // responsible change
+ change.setField(Field.responsible, responsible.username);
+ if (!StringUtils.isEmpty(responsible.username)) {
+ if (!ticket.isWatching(responsible.username)) {
+ change.watch(responsible.username);
+ }
+ }
+ }
+
+ TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();
+ if (milestone != null && !milestone.name.equals(ticket.milestone)) {
+ // milestone change
+ if (NIL.equals(milestone.name)) {
+ change.setField(Field.milestone, "");
+ } else {
+ change.setField(Field.milestone, milestone.name);
+ }
+ }
+
+ String mergeTo = mergeToModel.getObject();
+ if ((StringUtils.isEmpty(ticket.mergeTo) && !StringUtils.isEmpty(mergeTo))
+ || (!StringUtils.isEmpty(mergeTo) && !mergeTo.equals(ticket.mergeTo))) {
+ // integration branch change
+ change.setField(Field.mergeTo, mergeTo);
+ }
+
+ if (change.hasFieldChanges()) {
+ if (!ticket.isWatching(createdBy)) {
+ change.watch(createdBy);
+ }
+ ticket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);
+ if (ticket != null) {
+ TicketNotifier notifier = app().tickets().createNotifier();
+ notifier.sendMailing(ticket);
+ setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));
+ } else {
+ // TODO error
+ }
+ } else {
+ // nothing to change?!
+ setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));
+ }
+ }
+ });
+
Button cancel = new Button("cancel") {
private static final long serialVersionUID = 1L;
diff --git a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java index fda2e9f3..cc0474a2 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewTicketPage.java @@ -21,6 +21,8 @@ import java.util.Collections; import java.util.List;
import org.apache.wicket.PageParameters;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.DropDownChoice;
@@ -94,56 +96,7 @@ public class NewTicketPage extends RepositoryPage { setStatelessHint(false);
setOutputMarkupId(true);
- Form<Void> form = new Form<Void>("editForm") {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void onSubmit() {
- String createdBy = GitBlitWebSession.get().getUsername();
- Change change = new Change(createdBy);
- change.setField(Field.title, titleModel.getObject());
- change.setField(Field.body, descriptionEditor.getText());
- String topic = topicModel.getObject();
- if (!StringUtils.isEmpty(topic)) {
- change.setField(Field.topic, topic);
- }
-
- // type
- TicketModel.Type type = TicketModel.Type.defaultType;
- if (typeModel.getObject() != null) {
- type = typeModel.getObject();
- }
- change.setField(Field.type, type);
-
- // responsible
- TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();
- if (responsible != null) {
- change.setField(Field.responsible, responsible.username);
- }
-
- // milestone
- TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();
- if (milestone != null) {
- change.setField(Field.milestone, milestone.name);
- }
-
- // integration branch
- String mergeTo = mergeToModel.getObject();
- if (!StringUtils.isEmpty(mergeTo)) {
- change.setField(Field.mergeTo, mergeTo);
- }
-
- TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change);
- if (ticket != null) {
- TicketNotifier notifier = app().tickets().createNotifier();
- notifier.sendMailing(ticket);
- setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));
- } else {
- // TODO error
- }
- }
- };
+ Form<Void> form = new Form<Void>("editForm");
add(form);
form.add(new DropDownChoice<TicketModel.Type>("type", typeModel, Arrays.asList(TicketModel.Type.choices())));
@@ -203,7 +156,62 @@ public class NewTicketPage extends RepositoryPage { form.add(new Label("mergeto").setVisible(false));
}
- form.add(new Button("create"));
+ form.add(new AjaxButton("create") {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ String title = titleModel.getObject();
+ if (StringUtils.isEmpty(title)) {
+ return;
+ }
+
+ String createdBy = GitBlitWebSession.get().getUsername();
+ Change change = new Change(createdBy);
+ change.setField(Field.title, title);
+ change.setField(Field.body, descriptionEditor.getText());
+ String topic = topicModel.getObject();
+ if (!StringUtils.isEmpty(topic)) {
+ change.setField(Field.topic, topic);
+ }
+
+ // type
+ TicketModel.Type type = TicketModel.Type.defaultType;
+ if (typeModel.getObject() != null) {
+ type = typeModel.getObject();
+ }
+ change.setField(Field.type, type);
+
+ // responsible
+ TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();
+ if (responsible != null) {
+ change.setField(Field.responsible, responsible.username);
+ }
+
+ // milestone
+ TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();
+ if (milestone != null) {
+ change.setField(Field.milestone, milestone.name);
+ }
+
+ // integration branch
+ String mergeTo = mergeToModel.getObject();
+ if (!StringUtils.isEmpty(mergeTo)) {
+ change.setField(Field.mergeTo, mergeTo);
+ }
+
+ TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change);
+ if (ticket != null) {
+ TicketNotifier notifier = app().tickets().createNotifier();
+ notifier.sendMailing(ticket);
+ setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));
+ } else {
+ // TODO error
+ }
+ }
+ });
+
Button cancel = new Button("cancel") {
private static final long serialVersionUID = 1L;
|