]> source.dussan.org Git - gitblit.git/commitdiff
New Setting "Default Language" when creating user. 1198/head
authorwilliam <william.fromtw@gmail.com>
Wed, 8 Feb 2017 00:35:01 +0000 (08:35 +0800)
committerwilliam <william.fromtw@gmail.com>
Wed, 8 Feb 2017 00:35:01 +0000 (08:35 +0800)
src/main/java/com/gitblit/wicket/pages/EditUserPage.html
src/main/java/com/gitblit/wicket/pages/EditUserPage.java
src/main/java/com/gitblit/wicket/pages/Language.java [new file with mode: 0644]
src/main/java/com/gitblit/wicket/pages/UserPage.java

index 3bccdd590369f10c3662163597f646e547903fde..48e5339f339fdc0c9c9b40a722e25fb9e773abc2 100644 (file)
                                <tr><th><wicket:message key="gb.confirmPassword"></wicket:message></th><td class="edit"><input type="password" wicket:id="confirmPassword" size="30" tabindex="3" /></td></tr>\r
                                <tr><th><wicket:message key="gb.displayName"></wicket:message></th><td class="edit"><input type="text" wicket:id="displayName" size="30" tabindex="4" /></td></tr>\r
                                <tr><th><wicket:message key="gb.emailAddress"></wicket:message></th><td class="edit"><input type="text" wicket:id="emailAddress" size="30" tabindex="5" /></td></tr>\r
-                               <tr><th><wicket:message key="gb.canAdmin"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canAdmin" tabindex="6" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canAdminDescription"></wicket:message></span></label></td></tr>\r
-                               <tr><th><wicket:message key="gb.canCreate"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canCreate" tabindex="7" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canCreateDescription"></wicket:message></span></label></td></tr>\r
-                               <tr><th><wicket:message key="gb.canFork"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canFork" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canForkDescription"></wicket:message></span></label></td></tr>\r
-                               <tr><th><wicket:message key="gb.excludeFromFederation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="excludeFromFederation" tabindex="9" /> &nbsp;<span class="help-inline"><wicket:message key="gb.excludeFromFederationDescription"></wicket:message></span></label></td></tr>                             \r
-                               <tr><th><wicket:message key="gb.disableUser"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="disabled" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.disableUserDescription"></wicket:message></span></label></td></tr>\r
+                               <tr><th><wicket:message key="gb.languagePreference"></wicket:message></th><td class="edit"><select wicket:id="language" ></select></td></tr>\r
+                               <tr><th><wicket:message key="gb.canAdmin"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canAdmin" tabindex="7" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canAdminDescription"></wicket:message></span></label></td></tr>\r
+                               <tr><th><wicket:message key="gb.canCreate"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canCreate" tabindex="8" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canCreateDescription"></wicket:message></span></label></td></tr>\r
+                               <tr><th><wicket:message key="gb.canFork"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="canFork" tabindex="9" /> &nbsp;<span class="help-inline"><wicket:message key="gb.canForkDescription"></wicket:message></span></label></td></tr>\r
+                               <tr><th><wicket:message key="gb.excludeFromFederation"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="excludeFromFederation" tabindex="10" /> &nbsp;<span class="help-inline"><wicket:message key="gb.excludeFromFederationDescription"></wicket:message></span></label></td></tr>                            \r
+                               <tr><th><wicket:message key="gb.disableUser"></wicket:message></th><td class="edit"><label class="checkbox"><input type="checkbox" wicket:id="disabled" tabindex="11" /> &nbsp;<span class="help-inline"><wicket:message key="gb.disableUserDescription"></wicket:message></span></label></td></tr>\r
                        </tbody>\r
                </table>\r
                </div>\r
index 72dee6b6de2f532913294f0339f3c041db0ab4d5..0a6981b3efe58c8b429f09dbfe20570c0d0c0644 100644 (file)
@@ -20,15 +20,18 @@ import java.util.ArrayList;
 import java.util.Collections;\r
 import java.util.Iterator;\r
 import java.util.List;\r
+import java.util.Locale;\r
 \r
 import org.apache.wicket.PageParameters;\r
 import org.apache.wicket.behavior.SimpleAttributeModifier;\r
 import org.apache.wicket.extensions.markup.html.form.palette.Palette;\r
 import org.apache.wicket.markup.html.form.Button;\r
 import org.apache.wicket.markup.html.form.CheckBox;\r
+import org.apache.wicket.markup.html.form.DropDownChoice;\r
 import org.apache.wicket.markup.html.form.Form;\r
 import org.apache.wicket.markup.html.form.TextField;\r
 import org.apache.wicket.model.CompoundPropertyModel;\r
+import org.apache.wicket.model.IModel;\r
 import org.apache.wicket.model.Model;\r
 import org.apache.wicket.model.util.CollectionModel;\r
 import org.apache.wicket.model.util.ListModel;\r
@@ -108,6 +111,30 @@ public class EditUserPage extends RootSubPage {
                final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(\r
                                new ArrayList<String>(userTeams)), new CollectionModel<String>(app().users()\r
                                .getAllTeamNames()), new StringChoiceRenderer(), 10, false);\r
+               Locale locale = userModel.getPreferences().getLocale();\r
+               if (locale == null) {\r
+                       locale = Locale.ENGLISH;\r
+               }\r
+\r
+               List<Language> languages = UserPage.getLanguages();\r
+               Language preferredLanguage = null;\r
+               if (locale != null) {\r
+                       String localeCode = locale.getLanguage();\r
+                       if (!StringUtils.isEmpty(locale.getCountry())) {\r
+                               localeCode += "_" + locale.getCountry();\r
+                       }\r
+\r
+                       for (Language lang : languages) {\r
+                               if (lang.code.equals(localeCode)) {\r
+                                       // language_COUNTRY match\r
+                                       preferredLanguage = lang;\r
+                               } else if (preferredLanguage != null && lang.code.startsWith(locale.getLanguage())) {\r
+                                       // language match\r
+                                       preferredLanguage = lang;\r
+                               }\r
+                       }\r
+               }\r
+               final IModel<Language> language = Model.of(preferredLanguage);          \r
                Form<UserModel> form = new Form<UserModel>("editForm", model) {\r
 \r
                        private static final long serialVersionUID = 1L;\r
@@ -123,6 +150,10 @@ public class EditUserPage extends RootSubPage {
                                        error(getString("gb.pleaseSetUsername"));\r
                                        return;\r
                                }\r
+                               Language lang = language.getObject();\r
+                               if (lang != null) {\r
+                                       userModel.getPreferences().setLocale(lang.code);\r
+                               }\r
                                // force username to lower-case\r
                                userModel.username = userModel.username.toLowerCase();\r
                                String username = userModel.username;\r
@@ -251,7 +282,10 @@ public class EditUserPage extends RootSubPage {
                form.add(confirmPasswordField.setEnabled(editCredentials));\r
                form.add(new TextField<String>("displayName").setEnabled(editDisplayName));\r
                form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));\r
+               \r
 \r
+               DropDownChoice<Language> choice = new DropDownChoice<Language>("language",language,languages    );\r
+               form.add( choice.setEnabled(languages.size()>0) );\r
                if (userModel.canAdmin() && !userModel.canAdmin) {\r
                        // user inherits Admin permission\r
                        // display a disabled-yet-checked checkbox\r
diff --git a/src/main/java/com/gitblit/wicket/pages/Language.java b/src/main/java/com/gitblit/wicket/pages/Language.java
new file mode 100644 (file)
index 0000000..6eafb4d
--- /dev/null
@@ -0,0 +1,21 @@
+package com.gitblit.wicket.pages;
+
+import java.io.Serializable;
+
+public class Language implements Serializable {
+
+       private static final long serialVersionUID = 1L;
+
+       final String name;
+       final String code;
+
+       public Language(String name, String code) {
+               this.name = name;
+               this.code = code;
+       }
+
+       @Override
+       public String toString() {
+               return name + " (" + code + ")";
+       }
+}
\ No newline at end of file
index ea68f25b1ca57ac4b0f8676d52cbc2cabd0746f3..25a2249b752775338c5e523a6c948fb0252321fd 100644 (file)
@@ -166,12 +166,9 @@ public class UserPage extends RootPage {
 \r
                navLinks.add(menu);\r
        }\r
-\r
-       private void addPreferences(UserModel user) {\r
-               // add preferences\r
-               Form<Void> prefs = new Form<Void>("prefsForm");\r
-\r
-               List<Language> languages = Arrays.asList(\r
+       \r
+       public static List<Language> getLanguages(){\r
+               return  Arrays.asList(\r
                                new Language("Deutsch","de"),\r
                                new Language("English","en"),\r
                                new Language("Español", "es"),\r
@@ -185,6 +182,13 @@ public class UserPage extends RootPage {
                                new Language("Português", "pt_BR"),\r
                                new Language("簡體中文", "zh_CN"),\r
                                new Language("正體中文", "zh_TW"));\r
+       }\r
+       \r
+       private void addPreferences(UserModel user) {\r
+               // add preferences\r
+               Form<Void> prefs = new Form<Void>("prefsForm");\r
+\r
+               List<Language> languages = getLanguages();\r
 \r
                Locale locale = user.getPreferences().getLocale();\r
                if (locale == null) {\r
@@ -315,22 +319,4 @@ public class UserPage extends RootPage {
                add(new Fragment("sshKeysLink", "sshKeysLinkFragment", this).setRenderBodyOnly(true));\r
                add(keysTab.setRenderBodyOnly(true));\r
        }\r
-\r
-       private class Language implements Serializable {\r
-\r
-               private static final long serialVersionUID = 1L;\r
-\r
-               final String name;\r
-               final String code;\r
-\r
-               public Language(String name, String code) {\r
-                       this.name = name;\r
-                       this.code = code;\r
-               }\r
-\r
-               @Override\r
-               public String toString() {\r
-                       return name + " (" + code +")";\r
-               }\r
-       }\r
 }\r