]> source.dussan.org Git - gitblit.git/commitdiff
Switch to ajax New|Edit Ticket page submission to handle empty titles 53/53/1
authorJames Moger <james.moger@gitblit.com>
Thu, 1 May 2014 18:21:52 +0000 (14:21 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 1 May 2014 18:21:52 +0000 (14:21 -0400)
src/main/java/com/gitblit/wicket/pages/EditTicketPage.java
src/main/java/com/gitblit/wicket/pages/NewTicketPage.java

index 64c0648af96ba5320e613b71a9e3c0778da3c88c..c3294ba29db2a43c76946ab1ba7f9216ffbdc984 100644 (file)
@@ -23,6 +23,8 @@ import java.util.Set;
 import java.util.TreeSet;\r
 \r
 import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.ajax.AjaxRequestTarget;\r
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.form.Button;\r
 import org.apache.wicket.markup.html.form.DropDownChoice;\r
@@ -117,103 +119,7 @@ public class EditTicketPage extends RepositoryPage {
                setStatelessHint(false);\r
                setOutputMarkupId(true);\r
 \r
-               Form<Void> form = new Form<Void>("editForm") {\r
-\r
-                       private static final long serialVersionUID = 1L;\r
-\r
-                       @Override\r
-                       protected void onSubmit() {\r
-                               long ticketId = 0L;\r
-                               try {\r
-                                       String h = WicketUtils.getObject(getPageParameters());\r
-                                       ticketId = Long.parseLong(h);\r
-                               } catch (Exception e) {\r
-                                       setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));\r
-                               }\r
-\r
-                               TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), ticketId);\r
-\r
-                               String createdBy = GitBlitWebSession.get().getUsername();\r
-                               Change change = new Change(createdBy);\r
-\r
-                               String title = titleModel.getObject();\r
-                               if (!StringUtils.isEmpty(title) && !ticket.title.equals(title)) {\r
-                                       // title change\r
-                                       change.setField(Field.title, title);\r
-                               }\r
-\r
-                               String description = descriptionEditor.getText();\r
-                               if ((StringUtils.isEmpty(ticket.body) && !StringUtils.isEmpty(description))\r
-                                               || (!StringUtils.isEmpty(ticket.body) && !ticket.body.equals(description))) {\r
-                                       // description change\r
-                                       change.setField(Field.body, description);\r
-                               }\r
-\r
-                               Status status = statusModel.getObject();\r
-                               if (!ticket.status.equals(status)) {\r
-                                       // status change\r
-                                       change.setField(Field.status, status);\r
-                               }\r
-\r
-                               Type type = typeModel.getObject();\r
-                               if (!ticket.type.equals(type)) {\r
-                                       // type change\r
-                                       change.setField(Field.type, type);\r
-                               }\r
-\r
-                               String topic = topicModel.getObject();\r
-                               if ((StringUtils.isEmpty(ticket.topic) && !StringUtils.isEmpty(topic))\r
-                                               || (!StringUtils.isEmpty(topic) && !topic.equals(ticket.topic))) {\r
-                                       // topic change\r
-                                       change.setField(Field.topic, topic);\r
-                               }\r
-\r
-                               TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();\r
-                               if (responsible != null && !responsible.username.equals(ticket.responsible)) {\r
-                                       // responsible change\r
-                                       change.setField(Field.responsible, responsible.username);\r
-                                       if (!StringUtils.isEmpty(responsible.username)) {\r
-                                               if (!ticket.isWatching(responsible.username)) {\r
-                                                       change.watch(responsible.username);\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                               TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();\r
-                               if (milestone != null && !milestone.name.equals(ticket.milestone)) {\r
-                                       // milestone change\r
-                                       if (NIL.equals(milestone.name)) {\r
-                                               change.setField(Field.milestone, "");\r
-                                       } else {\r
-                                               change.setField(Field.milestone, milestone.name);\r
-                                       }\r
-                               }\r
-\r
-                               String mergeTo = mergeToModel.getObject();\r
-                               if ((StringUtils.isEmpty(ticket.mergeTo) && !StringUtils.isEmpty(mergeTo))\r
-                                               || (!StringUtils.isEmpty(mergeTo) && !mergeTo.equals(ticket.mergeTo))) {\r
-                                       // integration branch change\r
-                                       change.setField(Field.mergeTo, mergeTo);\r
-                               }\r
-\r
-                               if (change.hasFieldChanges()) {\r
-                                       if (!ticket.isWatching(createdBy)) {\r
-                                               change.watch(createdBy);\r
-                                       }\r
-                                       ticket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);\r
-                                       if (ticket != null) {\r
-                                               TicketNotifier notifier = app().tickets().createNotifier();\r
-                                               notifier.sendMailing(ticket);\r
-                                               setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));\r
-                                       } else {\r
-                                               // TODO error\r
-                                       }\r
-                               } else {\r
-                                       // nothing to change?!\r
-                                       setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));\r
-                               }\r
-                       }\r
-               };\r
+               Form<Void> form = new Form<Void>("editForm");\r
                add(form);\r
 \r
                List<Type> typeChoices;\r
@@ -324,7 +230,109 @@ public class EditTicketPage extends RepositoryPage {
                        form.add(new Label("milestone").setVisible(false));\r
                        form.add(new Label("mergeto").setVisible(false));\r
                }\r
-               form.add(new Button("update"));\r
+\r
+               form.add(new AjaxButton("update") {\r
+\r
+                       private static final long serialVersionUID = 1L;\r
+\r
+                       @Override\r
+                       protected void onSubmit(AjaxRequestTarget target, Form<?> form) {\r
+                               long ticketId = 0L;\r
+                               try {\r
+                                       String h = WicketUtils.getObject(getPageParameters());\r
+                                       ticketId = Long.parseLong(h);\r
+                               } catch (Exception e) {\r
+                                       setResponsePage(TicketsPage.class, WicketUtils.newRepositoryParameter(repositoryName));\r
+                               }\r
+\r
+                               TicketModel ticket = app().tickets().getTicket(getRepositoryModel(), ticketId);\r
+\r
+                               String createdBy = GitBlitWebSession.get().getUsername();\r
+                               Change change = new Change(createdBy);\r
+\r
+                               String title = titleModel.getObject();\r
+                               if (StringUtils.isEmpty(title)) {\r
+                                       return;\r
+                               }\r
+\r
+                               if (!ticket.title.equals(title)) {\r
+                                       // title change\r
+                                       change.setField(Field.title, title);\r
+                               }\r
+\r
+                               String description = descriptionEditor.getText();\r
+                               if ((StringUtils.isEmpty(ticket.body) && !StringUtils.isEmpty(description))\r
+                                               || (!StringUtils.isEmpty(ticket.body) && !ticket.body.equals(description))) {\r
+                                       // description change\r
+                                       change.setField(Field.body, description);\r
+                               }\r
+\r
+                               Status status = statusModel.getObject();\r
+                               if (!ticket.status.equals(status)) {\r
+                                       // status change\r
+                                       change.setField(Field.status, status);\r
+                               }\r
+\r
+                               Type type = typeModel.getObject();\r
+                               if (!ticket.type.equals(type)) {\r
+                                       // type change\r
+                                       change.setField(Field.type, type);\r
+                               }\r
+\r
+                               String topic = topicModel.getObject();\r
+                               if ((StringUtils.isEmpty(ticket.topic) && !StringUtils.isEmpty(topic))\r
+                                               || (!StringUtils.isEmpty(topic) && !topic.equals(ticket.topic))) {\r
+                                       // topic change\r
+                                       change.setField(Field.topic, topic);\r
+                               }\r
+\r
+                               TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();\r
+                               if (responsible != null && !responsible.username.equals(ticket.responsible)) {\r
+                                       // responsible change\r
+                                       change.setField(Field.responsible, responsible.username);\r
+                                       if (!StringUtils.isEmpty(responsible.username)) {\r
+                                               if (!ticket.isWatching(responsible.username)) {\r
+                                                       change.watch(responsible.username);\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                               TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();\r
+                               if (milestone != null && !milestone.name.equals(ticket.milestone)) {\r
+                                       // milestone change\r
+                                       if (NIL.equals(milestone.name)) {\r
+                                               change.setField(Field.milestone, "");\r
+                                       } else {\r
+                                               change.setField(Field.milestone, milestone.name);\r
+                                       }\r
+                               }\r
+\r
+                               String mergeTo = mergeToModel.getObject();\r
+                               if ((StringUtils.isEmpty(ticket.mergeTo) && !StringUtils.isEmpty(mergeTo))\r
+                                               || (!StringUtils.isEmpty(mergeTo) && !mergeTo.equals(ticket.mergeTo))) {\r
+                                       // integration branch change\r
+                                       change.setField(Field.mergeTo, mergeTo);\r
+                               }\r
+\r
+                               if (change.hasFieldChanges()) {\r
+                                       if (!ticket.isWatching(createdBy)) {\r
+                                               change.watch(createdBy);\r
+                                       }\r
+                                       ticket = app().tickets().updateTicket(getRepositoryModel(), ticket.number, change);\r
+                                       if (ticket != null) {\r
+                                               TicketNotifier notifier = app().tickets().createNotifier();\r
+                                               notifier.sendMailing(ticket);\r
+                                               setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));\r
+                                       } else {\r
+                                               // TODO error\r
+                                       }\r
+                               } else {\r
+                                       // nothing to change?!\r
+                                       setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));\r
+                               }\r
+                       }\r
+               });\r
+\r
                Button cancel = new Button("cancel") {\r
                        private static final long serialVersionUID = 1L;\r
 \r
index fda2e9f3e4d8249cdf84420047f8b4f1a75087de..cc0474a2926389fcbfe3860d1eedc45261aa5ff0 100644 (file)
@@ -21,6 +21,8 @@ import java.util.Collections;
 import java.util.List;\r
 \r
 import org.apache.wicket.PageParameters;\r
+import org.apache.wicket.ajax.AjaxRequestTarget;\r
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;\r
 import org.apache.wicket.markup.html.basic.Label;\r
 import org.apache.wicket.markup.html.form.Button;\r
 import org.apache.wicket.markup.html.form.DropDownChoice;\r
@@ -94,56 +96,7 @@ public class NewTicketPage extends RepositoryPage {
                setStatelessHint(false);\r
                setOutputMarkupId(true);\r
 \r
-               Form<Void> form = new Form<Void>("editForm") {\r
-\r
-                       private static final long serialVersionUID = 1L;\r
-\r
-                       @Override\r
-                       protected void onSubmit() {\r
-                               String createdBy = GitBlitWebSession.get().getUsername();\r
-                               Change change = new Change(createdBy);\r
-                               change.setField(Field.title, titleModel.getObject());\r
-                               change.setField(Field.body, descriptionEditor.getText());\r
-                               String topic = topicModel.getObject();\r
-                               if (!StringUtils.isEmpty(topic)) {\r
-                                       change.setField(Field.topic, topic);\r
-                               }\r
-\r
-                               // type\r
-                               TicketModel.Type type = TicketModel.Type.defaultType;\r
-                               if (typeModel.getObject() != null) {\r
-                                       type = typeModel.getObject();\r
-                               }\r
-                               change.setField(Field.type, type);\r
-\r
-                               // responsible\r
-                               TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();\r
-                               if (responsible != null) {\r
-                                       change.setField(Field.responsible, responsible.username);\r
-                               }\r
-\r
-                               // milestone\r
-                               TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();\r
-                               if (milestone != null) {\r
-                                       change.setField(Field.milestone, milestone.name);\r
-                               }\r
-\r
-                               // integration branch\r
-                               String mergeTo = mergeToModel.getObject();\r
-                               if (!StringUtils.isEmpty(mergeTo)) {\r
-                                       change.setField(Field.mergeTo, mergeTo);\r
-                               }\r
-\r
-                               TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change);\r
-                               if (ticket != null) {\r
-                                       TicketNotifier notifier = app().tickets().createNotifier();\r
-                                       notifier.sendMailing(ticket);\r
-                                       setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));\r
-                               } else {\r
-                                       // TODO error\r
-                               }\r
-                       }\r
-               };\r
+               Form<Void> form = new Form<Void>("editForm");\r
                add(form);\r
 \r
                form.add(new DropDownChoice<TicketModel.Type>("type", typeModel, Arrays.asList(TicketModel.Type.choices())));\r
@@ -203,7 +156,62 @@ public class NewTicketPage extends RepositoryPage {
                        form.add(new Label("mergeto").setVisible(false));\r
                }\r
 \r
-               form.add(new Button("create"));\r
+               form.add(new AjaxButton("create") {\r
+\r
+                       private static final long serialVersionUID = 1L;\r
+\r
+                       @Override\r
+                       protected void onSubmit(AjaxRequestTarget target, Form<?> form) {\r
+                               String title = titleModel.getObject();\r
+                               if (StringUtils.isEmpty(title)) {\r
+                                       return;\r
+                               }\r
+\r
+                               String createdBy = GitBlitWebSession.get().getUsername();\r
+                               Change change = new Change(createdBy);\r
+                               change.setField(Field.title, title);\r
+                               change.setField(Field.body, descriptionEditor.getText());\r
+                               String topic = topicModel.getObject();\r
+                               if (!StringUtils.isEmpty(topic)) {\r
+                                       change.setField(Field.topic, topic);\r
+                               }\r
+\r
+                               // type\r
+                               TicketModel.Type type = TicketModel.Type.defaultType;\r
+                               if (typeModel.getObject() != null) {\r
+                                       type = typeModel.getObject();\r
+                               }\r
+                               change.setField(Field.type, type);\r
+\r
+                               // responsible\r
+                               TicketResponsible responsible = responsibleModel == null ? null : responsibleModel.getObject();\r
+                               if (responsible != null) {\r
+                                       change.setField(Field.responsible, responsible.username);\r
+                               }\r
+\r
+                               // milestone\r
+                               TicketMilestone milestone = milestoneModel == null ? null : milestoneModel.getObject();\r
+                               if (milestone != null) {\r
+                                       change.setField(Field.milestone, milestone.name);\r
+                               }\r
+\r
+                               // integration branch\r
+                               String mergeTo = mergeToModel.getObject();\r
+                               if (!StringUtils.isEmpty(mergeTo)) {\r
+                                       change.setField(Field.mergeTo, mergeTo);\r
+                               }\r
+\r
+                               TicketModel ticket = app().tickets().createTicket(getRepositoryModel(), 0L, change);\r
+                               if (ticket != null) {\r
+                                       TicketNotifier notifier = app().tickets().createNotifier();\r
+                                       notifier.sendMailing(ticket);\r
+                                       setResponsePage(TicketsPage.class, WicketUtils.newObjectParameter(getRepositoryModel().name, "" + ticket.number));\r
+                               } else {\r
+                                       // TODO error\r
+                               }\r
+                       }\r
+               });\r
+\r
                Button cancel = new Button("cancel") {\r
                        private static final long serialVersionUID = 1L;\r
 \r