From ba516f6c6aaabf7935ef42292f446bf375bf542b Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 03 Jun 2014 10:34:51 -0400
Subject: [PATCH] Extract re-usable conditional choice option panel

---
 src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java |   42 ++++++++++++++++++------------------------
 1 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
index d5ae344..f0aa224 100644
--- a/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/NewRepositoryPage.java
@@ -22,12 +22,8 @@
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
 import org.apache.wicket.behavior.SimpleAttributeModifier;
 import org.apache.wicket.markup.html.form.Button;
-import org.apache.wicket.markup.html.form.CheckBox;
-import org.apache.wicket.markup.html.form.DropDownChoice;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.model.CompoundPropertyModel;
 import org.apache.wicket.model.IModel;
@@ -60,6 +56,8 @@
 import com.gitblit.wicket.GitBlitWebSession;
 import com.gitblit.wicket.WicketUtils;
 import com.gitblit.wicket.panels.AccessPolicyPanel;
+import com.gitblit.wicket.panels.CheckboxOption;
+import com.gitblit.wicket.panels.ConditionalChoiceOption;
 import com.gitblit.wicket.panels.RepositoryNamePanel;
 
 public class NewRepositoryPage extends RootSubPage {
@@ -183,7 +181,10 @@
 
 		// add README
 		addReadmeModel = Model.of(false);
-		form.add(new CheckBox("addReadme", addReadmeModel));
+		form.add(new CheckboxOption("addReadme",
+				getString("gb.initWithReadme"),
+				getString("gb.initWithReadmeDescription"),
+				addReadmeModel));
 
 		// add .gitignore
 		File gitignoreDir = app().runtime().getFileOrFolder(Keys.git.gitignoreFolder, "${baseFolder}/gitignore");
@@ -198,29 +199,22 @@
 			}
 		}
 		Collections.sort(gitignores);
+
 		gitignoreModel = Model.of("");
-		final DropDownChoice<String> gitignoreChoice = new DropDownChoice<String>("gitignore", gitignoreModel, gitignores);
-		gitignoreChoice.setOutputMarkupId(true);
-		form.add(gitignoreChoice.setEnabled(false));
-
 		addGitignoreModel = Model.of(false);
-		final CheckBox gitignoreCheckbox = new CheckBox("addGitignore", addGitignoreModel);
-		form.add(gitignoreCheckbox);
+		form.add(new ConditionalChoiceOption<String>("addGitIgnore",
+				getString("gb.initWithGitignore"),
+				getString("gb.initWithGitignoreDescription"),
+				addGitignoreModel,
+				gitignoreModel,
+				gitignores));
 
-		gitignoreCheckbox.add(new AjaxFormComponentUpdatingBehavior("onchange") {
-
-			private static final long serialVersionUID = 1L;
-
-			@Override
-			protected void onUpdate(AjaxRequestTarget target) {
-				gitignoreChoice.setEnabled(addGitignoreModel.getObject());
-				target.addComponent(gitignoreChoice);
-			}
-		});
-
-		// TODO add .gitflow
+		// TODO consider gitflow at creation (ticket-55)
 		addGitflowModel = Model.of(false);
-		form.add(new CheckBox("addGitflow", addGitflowModel));
+		form.add(new CheckboxOption("addGitFlow",
+				"Include a .gitflow file",
+				"This will generate a config file which guides Git clients in setting up Gitflow branches.",
+				addGitflowModel).setVisible(false));
 
 		form.add(new Button("create"));
 

--
Gitblit v1.9.1