From 6209dc4fd442887e18e3dd6fe7056f4b842091c2 Mon Sep 17 00:00:00 2001 From: James Moger Date: Sun, 27 Apr 2014 19:49:33 -0400 Subject: [PATCH] Use ajax buttons in the New|Edit Milestone pages --- .../wicket/pages/EditMilestonePage.java | 37 ++++++++++--------- .../wicket/pages/NewMilestonePage.java | 26 +++++++------ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java index b92ba8ba..967d8f35 100644 --- a/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java +++ b/src/main/java/com/gitblit/wicket/pages/EditMilestonePage.java @@ -21,6 +21,8 @@ import java.util.List; import org.apache.wicket.PageParameters; import org.apache.wicket.RestartResponseException; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.extensions.markup.html.form.DateTextField; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.DropDownChoice; @@ -90,13 +92,26 @@ public class EditMilestonePage extends RepositoryPage { setStatelessHint(false); setOutputMarkupId(true); - Form form = new Form("editForm") { + Form form = new Form("editForm"); + add(form); + + nameModel = Model.of(tm.name); + dueModel = Model.of(tm.due); + statusModel = Model.of(tm.status); + notificationModel = Model.of(true); + + form.add(new TextField("name", nameModel)); + form.add(new DateTextField("due", dueModel, "yyyy-MM-dd")); + + List statusChoices = Arrays.asList(Status.Open, Status.Closed); + form.add(new DropDownChoice("status", statusModel, statusChoices)); + + form.add(new AjaxButton("save") { private static final long serialVersionUID = 1L; @Override - protected void onSubmit() { - + protected void onSubmit(AjaxRequestTarget target, Form form) { String name = nameModel.getObject(); if (StringUtils.isEmpty(name)) { return; @@ -126,21 +141,7 @@ public class EditMilestonePage extends RepositoryPage { // TODO error } } - }; - add(form); - - nameModel = Model.of(tm.name); - dueModel = Model.of(tm.due); - statusModel = Model.of(tm.status); - notificationModel = Model.of(true); - - form.add(new TextField("name", nameModel)); - form.add(new DateTextField("due", dueModel, "yyyy-MM-dd")); - - List statusChoices = Arrays.asList(Status.Open, Status.Closed); - form.add(new DropDownChoice("status", statusModel, statusChoices)); - - form.add(new Button("save")); + }); Button cancel = new Button("cancel") { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java index 4c393786..d6e34cb0 100644 --- a/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java +++ b/src/main/java/com/gitblit/wicket/pages/NewMilestonePage.java @@ -19,6 +19,8 @@ import java.util.Date; import org.apache.wicket.PageParameters; import org.apache.wicket.RestartResponseException; +import org.apache.wicket.ajax.AjaxRequestTarget; +import org.apache.wicket.ajax.markup.html.form.AjaxButton; import org.apache.wicket.extensions.markup.html.form.DateTextField; import org.apache.wicket.markup.html.form.Button; import org.apache.wicket.markup.html.form.Form; @@ -68,13 +70,21 @@ public class NewMilestonePage extends RepositoryPage { setStatelessHint(false); setOutputMarkupId(true); - Form form = new Form("editForm") { + Form form = new Form("editForm"); + add(form); + + nameModel = Model.of(""); + dueModel = Model.of(new Date(System.currentTimeMillis() + TimeUtils.ONEDAY)); + + form.add(new TextField("name", nameModel)); + form.add(new DateTextField("due", dueModel, "yyyy-MM-dd")); + + form.add(new AjaxButton("create") { private static final long serialVersionUID = 1L; @Override - protected void onSubmit() { - + protected void onSubmit(AjaxRequestTarget target, Form form) { String name = nameModel.getObject(); if (StringUtils.isEmpty(name)) { return; @@ -94,16 +104,8 @@ public class NewMilestonePage extends RepositoryPage { // TODO error } } - }; - add(form); - - nameModel = Model.of(""); - dueModel = Model.of(new Date(System.currentTimeMillis() + TimeUtils.ONEDAY)); - - form.add(new TextField("name", nameModel)); - form.add(new DateTextField("due", dueModel, "yyyy-MM-dd")); + }); - form.add(new Button("create")); Button cancel = new Button("cancel") { private static final long serialVersionUID = 1L; -- 2.39.5