preference 校验机制及重构

This commit is contained in:
Van 2014-12-08 15:18:28 +08:00
parent 332213e3cf
commit e001df500e
8 changed files with 50 additions and 59 deletions

View File

@ -156,5 +156,6 @@
"source": "Source",
"toggle_comment": "Toggle Comment",
"find_in_files": "Find in Files",
"email": "Email"
"email": "Email",
"no_empty": "Can not Empty!"
}

View File

@ -91,6 +91,10 @@ button {
font-size: 12px;
}
.ft-red {
color: #9d0000;
}
.list li {
cursor: pointer;
line-height: 20px;

View File

@ -85,7 +85,8 @@
overflow: hidden;
}
.dialog-main input {
.dialog-main input,
.dialog-main select {
width: 100%;
margin: 2px auto;
}
@ -103,11 +104,10 @@
margin: 10px;
}
#dialogPreference .select {
width: 100%;
margin: 2px auto;
}
#dialogPreference .tabs-panel {
padding: 10px;
}
#dialogPreference .preference {
margin-bottom: 10px;
}

View File

@ -146,6 +146,6 @@
color: #ebebeb;
}
#dialogPreference {
#dialogPreference .preference {
border: 1px solid #000;
}

View File

@ -123,6 +123,6 @@
border-top: 1px solid #919191;
}
#dialogPreference {
#dialogPreference .preference {
border: 1px solid #A4A4A4;
}

View File

@ -285,40 +285,20 @@ var menu = {
},
_initPreference: 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 () {
var isChange = false;
var isChange = false,
emptys = [],
emptysTip = '';
$("#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;
}
if ($.trim($it.val()) === '') {
emptys.push($it);
}
});
var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)");
@ -327,11 +307,21 @@ var menu = {
} else {
$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 () {
var isChange = false;
$("#dialogPreference input").each(function () {
$("#dialogPreference select").each(function () {
if ($(this).val() !== $(this).data("value")) {
isChange = true;
}
@ -373,6 +363,11 @@ var menu = {
$editorTheme = $dialogPreference.find("input[name=editorTheme]"),
$editorTabSize = $dialogPreference.find("input[name=editorTabSize]");
if ($.trim($email.val()) === "") {
$dialogPreference.find(".tip").html("user -> email " + config.label.no_empty);
return false;
}
$.extend(request, {
"fontFamily": $fontFamily.val(),
"fontSize": $fontSize.val(),

View File

@ -468,7 +468,8 @@
"file": "{{.i18n.file}}",
"uptodate": "{{.i18n.uptodate}}",
"perference": "{{.i18n.perference}}",
"apply": "{{.i18n.apply}}"
"apply": "{{.i18n.apply}}",
"no_empty": "{{.i18n.no_empty}}"
},
"channel": {
"editor": '{{.conf.EditorChannel}}',

View File

@ -25,15 +25,12 @@
</label>
<label>
{{.i18n.theme}}{{.i18n.colon}}
<br/>
<select class="select" id="themeSelect">
<select class="select" name="theme" data-value="{{.user.Theme}}">
{{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}}
</select>
<br/>
</label>
<input data-value="{{.user.Theme}}" value="{{.user.Theme}}" name="theme" hidden="hidden"/>
</div>
<div class="fn-none" data-index="editor">
<label>
@ -54,39 +51,31 @@
</label>
<label>
{{.i18n.theme}}{{.i18n.colon}}
<br/>
<select class="select" id="editorThemeSelect">
<select class="select" name="editorTheme" data-value="{{.user.Editor.Theme}}">
{{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}}
</select>
<br/>
</label>
<input data-value="{{.user.Editor.Theme}}" value="{{.user.Editor.Theme}}" name="editorTheme" hidden="hidden"/>
</div>
<div class="fn-none" data-index="gotool">
<label>
{{.i18n.go_format}}{{.i18n.colon}}
<br/>
<select class="select" id="goFmtSelect">
<select class="select" data-value="{{.user.GoFormat}}" name="goFmt">
{{range $index, $gofmt := .gofmts }}
<option name="{{$gofmt}}" value="{{$gofmt}}" {{if eq $.user.GoFormat $gofmt}}selected="selected"{{end}}>{{$gofmt}}</option>
{{end}}
</select>
<br/>
</label>
<input data-value="{{.user.GoFormat}}" value="{{.user.GoFormat}}" name="goFmt" hidden="hidden" />
</div>
<div class="fn-none" data-index="user">
<label>
{{.i18n.locale}}{{.i18n.colon}}
<br/>
<select class="select" id="localeSelect">
<select class="select" name="locale" data-value="{{.user.Locale}}">
{{range $index, $localeName := .locales }}
<option name="{{$localeName}}" value="{{$localeName}}" {{if eq $.user.Locale $localeName}}selected="selected"{{end}}>{{$localeName}}</option>
{{end}}
</select>
<br/>
</label>
<label>
{{.i18n.email}}{{.i18n.colon}}
@ -103,4 +92,5 @@
</label>
</div>
</div>
</div>
</div>
<div class="tip ft-red"></div>