diff --git a/i18n/locales.go b/i18n/locales.go index a45cb74..a339207 100644 --- a/i18n/locales.go +++ b/i18n/locales.go @@ -1,11 +1,11 @@ // Copyright (c) 2014, B3log -// +// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -81,3 +81,14 @@ func Get(locale, key string) interface{} { func GetAll(locale string) map[string]interface{} { return Locales[locale].Langs } + +// GetLocalesNames gets names of all locales. Returns ["zh_CN", "en_US"] for example. +func GetLocalesNames() []string { + ret := []string{} + + for name, _ := range Locales { + ret = append(ret, name) + } + + return ret +} diff --git a/session/users.go b/session/users.go index 4ab9e03..8dfb8c1 100644 --- a/session/users.go +++ b/session/users.go @@ -58,7 +58,8 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) { if "GET" == r.Method { model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(user.Locale), "user": user, - "ver": conf.WideVersion, "goos": runtime.GOOS, "goarch": runtime.GOARCH, "gover": runtime.Version()} + "ver": conf.WideVersion, "goos": runtime.GOOS, "goarch": runtime.GOARCH, "gover": runtime.Version(), + "locales": i18n.GetLocalesNames()} t, err := template.ParseFiles("views/preference.html") diff --git a/static/css/dialog.css b/static/css/dialog.css index fb6e68d..c812536 100644 --- a/static/css/dialog.css +++ b/static/css/dialog.css @@ -113,6 +113,11 @@ border-top-width: 0; } +#dialogPreference .select { + width: 100%; + margin: 2px auto; +} + #dialogPreference .tabs-panel { padding: 10px; } \ No newline at end of file diff --git a/static/js/menu.js b/static/js/menu.js index b65b4a3..c09f4f3 100644 --- a/static/js/menu.js +++ b/static/js/menu.js @@ -285,6 +285,12 @@ var menu = { }, _initPreference: function () { $("#dialogPreference").load('/preference', function () { + $("#localeSelect").on('change', function () { + var $dialogPreference = $("#dialogPreference"), + $locale = $dialogPreference.find("input[name=locale]") + + $locale.val(this.value); + }); $("#dialogPreference input").keyup(function () { var isChange = false; @@ -302,6 +308,22 @@ var menu = { } }); + $("#dialogPreference select").on("change", function () { + var isChange = false; + $("#dialogPreference input").each(function () { + if ($(this).val() !== $(this).data("value")) { + isChange = true; + } + }); + + var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); + if (isChange) { + $okBtn.prop("disabled", false); + } else { + $okBtn.prop("disabled", true); + } + }); + $("#dialogPreference").dialog({ "modal": true, "height": 460, diff --git a/views/preference.html b/views/preference.html index 36f25ad..1a4c62c 100644 --- a/views/preference.html +++ b/views/preference.html @@ -47,15 +47,22 @@
+