preference 校验机制及重构
This commit is contained in:
parent
332213e3cf
commit
e001df500e
|
@ -156,5 +156,6 @@
|
||||||
"source": "Source",
|
"source": "Source",
|
||||||
"toggle_comment": "Toggle Comment",
|
"toggle_comment": "Toggle Comment",
|
||||||
"find_in_files": "Find in Files",
|
"find_in_files": "Find in Files",
|
||||||
"email": "Email"
|
"email": "Email",
|
||||||
|
"no_empty": "Can not Empty!"
|
||||||
}
|
}
|
|
@ -91,6 +91,10 @@ button {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.ft-red {
|
||||||
|
color: #9d0000;
|
||||||
|
}
|
||||||
|
|
||||||
.list li {
|
.list li {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
|
|
|
@ -85,7 +85,8 @@
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dialog-main input {
|
.dialog-main input,
|
||||||
|
.dialog-main select {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 2px auto;
|
margin: 2px auto;
|
||||||
}
|
}
|
||||||
|
@ -103,11 +104,10 @@
|
||||||
margin: 10px;
|
margin: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#dialogPreference .select {
|
|
||||||
width: 100%;
|
|
||||||
margin: 2px auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
#dialogPreference .tabs-panel {
|
#dialogPreference .tabs-panel {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#dialogPreference .preference {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
|
@ -146,6 +146,6 @@
|
||||||
color: #ebebeb;
|
color: #ebebeb;
|
||||||
}
|
}
|
||||||
|
|
||||||
#dialogPreference {
|
#dialogPreference .preference {
|
||||||
border: 1px solid #000;
|
border: 1px solid #000;
|
||||||
}
|
}
|
|
@ -123,6 +123,6 @@
|
||||||
border-top: 1px solid #919191;
|
border-top: 1px solid #919191;
|
||||||
}
|
}
|
||||||
|
|
||||||
#dialogPreference {
|
#dialogPreference .preference {
|
||||||
border: 1px solid #A4A4A4;
|
border: 1px solid #A4A4A4;
|
||||||
}
|
}
|
|
@ -285,40 +285,20 @@ var menu = {
|
||||||
},
|
},
|
||||||
_initPreference: function () {
|
_initPreference: function () {
|
||||||
$("#dialogPreference").load('/preference', function () {
|
$("#dialogPreference").load('/preference', function () {
|
||||||
$("#localeSelect").on('change', function () {
|
|
||||||
var $dialogPreference = $("#dialogPreference"),
|
|
||||||
$input = $dialogPreference.find("input[name=locale]")
|
|
||||||
|
|
||||||
$input.val(this.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#themeSelect").on('change', function () {
|
|
||||||
var $dialogPreference = $("#dialogPreference"),
|
|
||||||
$input = $dialogPreference.find("input[name=theme]")
|
|
||||||
|
|
||||||
$input.val(this.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#editorThemeSelect").on('change', function () {
|
|
||||||
var $dialogPreference = $("#dialogPreference"),
|
|
||||||
$input = $dialogPreference.find("input[name=editorTheme]")
|
|
||||||
|
|
||||||
$input.val(this.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#goFmtSelect").on('change', function () {
|
|
||||||
var $dialogPreference = $("#dialogPreference"),
|
|
||||||
$input = $dialogPreference.find("input[name=goFmt]")
|
|
||||||
|
|
||||||
$input.val(this.value);
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#dialogPreference input").keyup(function () {
|
$("#dialogPreference input").keyup(function () {
|
||||||
var isChange = false;
|
var isChange = false,
|
||||||
|
emptys = [],
|
||||||
|
emptysTip = '';
|
||||||
$("#dialogPreference input").each(function () {
|
$("#dialogPreference input").each(function () {
|
||||||
if ($(this).val() !== $(this).data("value")) {
|
var $it = $(this);
|
||||||
|
// data-value 如为数字,则不会和 value 一样转换为 String,再次不使用全等
|
||||||
|
if ($it.val() != $it.data("value")) {
|
||||||
isChange = true;
|
isChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($.trim($it.val()) === '') {
|
||||||
|
emptys.push($it);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
|
||||||
|
@ -327,11 +307,21 @@ var menu = {
|
||||||
} else {
|
} else {
|
||||||
$okBtn.prop("disabled", true);
|
$okBtn.prop("disabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (emptys.length === 0) {
|
||||||
|
$("#dialogPreference").find(".tip").html("");
|
||||||
|
} else {
|
||||||
|
for (var i = 0, max = emptys.length; i < max; i++) {
|
||||||
|
emptysTip += emptys[i].closest('div').data("index") + ' -> ' + emptys[i].attr("name")
|
||||||
|
+ ' ' + config.label.no_empty + "<br/>";
|
||||||
|
}
|
||||||
|
$("#dialogPreference").find(".tip").html(emptysTip);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#dialogPreference select").on("change", function () {
|
$("#dialogPreference select").on("change", function () {
|
||||||
var isChange = false;
|
var isChange = false;
|
||||||
$("#dialogPreference input").each(function () {
|
$("#dialogPreference select").each(function () {
|
||||||
if ($(this).val() !== $(this).data("value")) {
|
if ($(this).val() !== $(this).data("value")) {
|
||||||
isChange = true;
|
isChange = true;
|
||||||
}
|
}
|
||||||
|
@ -373,6 +363,11 @@ var menu = {
|
||||||
$editorTheme = $dialogPreference.find("input[name=editorTheme]"),
|
$editorTheme = $dialogPreference.find("input[name=editorTheme]"),
|
||||||
$editorTabSize = $dialogPreference.find("input[name=editorTabSize]");
|
$editorTabSize = $dialogPreference.find("input[name=editorTabSize]");
|
||||||
|
|
||||||
|
if ($.trim($email.val()) === "") {
|
||||||
|
$dialogPreference.find(".tip").html("user -> email " + config.label.no_empty);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$.extend(request, {
|
$.extend(request, {
|
||||||
"fontFamily": $fontFamily.val(),
|
"fontFamily": $fontFamily.val(),
|
||||||
"fontSize": $fontSize.val(),
|
"fontSize": $fontSize.val(),
|
||||||
|
|
|
@ -468,7 +468,8 @@
|
||||||
"file": "{{.i18n.file}}",
|
"file": "{{.i18n.file}}",
|
||||||
"uptodate": "{{.i18n.uptodate}}",
|
"uptodate": "{{.i18n.uptodate}}",
|
||||||
"perference": "{{.i18n.perference}}",
|
"perference": "{{.i18n.perference}}",
|
||||||
"apply": "{{.i18n.apply}}"
|
"apply": "{{.i18n.apply}}",
|
||||||
|
"no_empty": "{{.i18n.no_empty}}"
|
||||||
},
|
},
|
||||||
"channel": {
|
"channel": {
|
||||||
"editor": '{{.conf.EditorChannel}}',
|
"editor": '{{.conf.EditorChannel}}',
|
||||||
|
|
|
@ -25,15 +25,12 @@
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
{{.i18n.theme}}{{.i18n.colon}}
|
{{.i18n.theme}}{{.i18n.colon}}
|
||||||
<br/>
|
<select class="select" name="theme" data-value="{{.user.Theme}}">
|
||||||
<select class="select" id="themeSelect">
|
|
||||||
{{range $index, $theme := .themes }}
|
{{range $index, $theme := .themes }}
|
||||||
<option name="{{$theme}}" value="{{$theme}}" {{if eq $.user.Theme $theme}}selected="selected"{{end}}>{{$theme}}</option>
|
<option value="{{$theme}}" {{if eq $.user.Theme $theme}}selected="selected"{{end}}>{{$theme}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
|
||||||
</label>
|
</label>
|
||||||
<input data-value="{{.user.Theme}}" value="{{.user.Theme}}" name="theme" hidden="hidden"/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="fn-none" data-index="editor">
|
<div class="fn-none" data-index="editor">
|
||||||
<label>
|
<label>
|
||||||
|
@ -54,39 +51,31 @@
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
{{.i18n.theme}}{{.i18n.colon}}
|
{{.i18n.theme}}{{.i18n.colon}}
|
||||||
<br/>
|
<select class="select" name="editorTheme" data-value="{{.user.Editor.Theme}}">
|
||||||
<select class="select" id="editorThemeSelect">
|
|
||||||
{{range $index, $theme := .editorThemes }}
|
{{range $index, $theme := .editorThemes }}
|
||||||
<option name="{{$theme}}" value="{{$theme}}" {{if eq $.user.Editor.Theme $theme}}selected="selected"{{end}}>{{$theme}}</option>
|
<option value="{{$theme}}" {{if eq $.user.Editor.Theme $theme}}selected="selected"{{end}}>{{$theme}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
|
||||||
</label>
|
</label>
|
||||||
<input data-value="{{.user.Editor.Theme}}" value="{{.user.Editor.Theme}}" name="editorTheme" hidden="hidden"/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="fn-none" data-index="gotool">
|
<div class="fn-none" data-index="gotool">
|
||||||
<label>
|
<label>
|
||||||
{{.i18n.go_format}}{{.i18n.colon}}
|
{{.i18n.go_format}}{{.i18n.colon}}
|
||||||
<br/>
|
<select class="select" data-value="{{.user.GoFormat}}" name="goFmt">
|
||||||
<select class="select" id="goFmtSelect">
|
|
||||||
{{range $index, $gofmt := .gofmts }}
|
{{range $index, $gofmt := .gofmts }}
|
||||||
<option name="{{$gofmt}}" value="{{$gofmt}}" {{if eq $.user.GoFormat $gofmt}}selected="selected"{{end}}>{{$gofmt}}</option>
|
<option name="{{$gofmt}}" value="{{$gofmt}}" {{if eq $.user.GoFormat $gofmt}}selected="selected"{{end}}>{{$gofmt}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
|
||||||
</label>
|
</label>
|
||||||
<input data-value="{{.user.GoFormat}}" value="{{.user.GoFormat}}" name="goFmt" hidden="hidden" />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="fn-none" data-index="user">
|
<div class="fn-none" data-index="user">
|
||||||
<label>
|
<label>
|
||||||
{{.i18n.locale}}{{.i18n.colon}}
|
{{.i18n.locale}}{{.i18n.colon}}
|
||||||
<br/>
|
<select class="select" name="locale" data-value="{{.user.Locale}}">
|
||||||
<select class="select" id="localeSelect">
|
|
||||||
{{range $index, $localeName := .locales }}
|
{{range $index, $localeName := .locales }}
|
||||||
<option name="{{$localeName}}" value="{{$localeName}}" {{if eq $.user.Locale $localeName}}selected="selected"{{end}}>{{$localeName}}</option>
|
<option name="{{$localeName}}" value="{{$localeName}}" {{if eq $.user.Locale $localeName}}selected="selected"{{end}}>{{$localeName}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
|
||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
{{.i18n.email}}{{.i18n.colon}}
|
{{.i18n.email}}{{.i18n.colon}}
|
||||||
|
@ -104,3 +93,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tip ft-red"></div>
|
Loading…
Reference in New Issue