From a470c9869a8cf4cde582738c592452bc0ea514fb Mon Sep 17 00:00:00 2001 From: Van Date: Mon, 17 Nov 2014 14:15:28 +0800 Subject: [PATCH] preference --- conf/wide.json | 21 +++++++++++---- i18n/en_US.json | 3 ++- static/css/dialog.css | 10 +++++++ static/js/dialog.js | 9 ++++--- static/js/wide.js | 62 +++++++++++++++++++++++++++++++++++++++++-- views/index.html | 3 ++- views/preference.html | 29 +++++++++----------- 7 files changed, 108 insertions(+), 29 deletions(-) diff --git a/conf/wide.json b/conf/wide.json index 886f0da..2bb8046 100644 --- a/conf/wide.json +++ b/conf/wide.json @@ -18,18 +18,29 @@ "Password": "admin", "Workspace": "${GOPATH}", "Locale": "en_US", - "GoFormat": "gofmt", + "GoFormat": "", "FontFamily": "Helvetica", "FontSize": "13px", "Editor": { "FontFamily": "Consolas, 'Courier New', monospace", "FontSize": "13px", - "LineHeight": "17px" + "LineHeight": "" }, "LatestSessionContent": { - "FileTree": [], - "Files": [], - "CurrentFile": "" + "FileTree": [ + "E:\\Work\\go\\src", + "E:\\Work\\go\\src\\code.google.com\\p", + "E:\\Work\\go\\src\\code.google.com\\p\\go.net", + "E:\\Work\\go\\src\\code.google.com\\p\\go.net\\.hg", + "E:\\Work\\go\\src\\code.google.com\\p\\go.net\\.hg\\cache", + "E:\\Work\\go\\src\\github.com", + "E:\\Work\\go\\src\\github.com\\88250", + "E:\\Work\\go\\src\\github.com\\88250\\gohtml" + ], + "Files": [ + "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\doc.go" + ], + "CurrentFile": "E:\\Work\\go\\src\\github.com\\88250\\gohtml\\doc.go" } } ] diff --git a/i18n/en_US.json b/i18n/en_US.json index cd851e2..a77b8e7 100644 --- a/i18n/en_US.json +++ b/i18n/en_US.json @@ -131,5 +131,6 @@ "font_size": "Font Size", "line_height": "Line Height", "go_format": "Go Format", - "locale": "Locale" + "locale": "Locale", + "apply": "Apply" } \ No newline at end of file diff --git a/static/css/dialog.css b/static/css/dialog.css index 258810e..fb6e68d 100644 --- a/static/css/dialog.css +++ b/static/css/dialog.css @@ -105,4 +105,14 @@ margin-top: 5px; background-color: #FFF; border: 1px solid #9B9B9B; +} + +#dialogPreference { + margin: 10px; + border: 1px solid #A4A4A4; + border-top-width: 0; +} + +#dialogPreference .tabs-panel { + padding: 10px; } \ No newline at end of file diff --git a/static/js/dialog.js b/static/js/dialog.js index f5f4559..64fa24f 100644 --- a/static/js/dialog.js +++ b/static/js/dialog.js @@ -144,6 +144,9 @@ } else { // 20(footer) + 23(header) top = parseInt((windowH - dialogH - 43) / 2); + if (top < 0) { + top = 0; + } left = parseInt((windowW - dialogW) / 2); } $dialog.css({ @@ -215,12 +218,12 @@ if (positionX > $(window).width() - $(dialog).width()) { positionX = $(window).width() - $(dialog).width(); } - if (positionY < 0) { - positionY = 0; - } if (positionY > $(window).height() - $(dialog).height()) { positionY = $(window).height() - $(dialog).height(); } + if (positionY < 0) { + positionY = 0; + } dialog.style.left = positionX + "px"; dialog.style.top = positionY + "px"; }; diff --git a/static/js/wide.js b/static/js/wide.js index cf12eeb..c4f3e92 100644 --- a/static/js/wide.js +++ b/static/js/wide.js @@ -456,21 +456,79 @@ var wide = { }, _initPreference: function () { $("#dialogPreference").load('/preference', function () { + + $("#dialogPreference input").keyup(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, "width": 800, "title": config.label.perference, + "okText": config.label.apply, + "cancelText": config.label.cancel, + "afterOpen": function () { + var $okBtn = $("#dialogPreference").closest(".dialog-main").find(".dialog-footer > button:eq(0)"); + $okBtn.prop("disabled", true); + }, "ok": function () { - var request = newWideRequest(); - request.executable = data.executable; + var request = newWideRequest(), + $dialogPreference = $("#dialogPreference"), + $fontFamily = $dialogPreference.find("input[name=fontFamily]"), + $fontSize = $dialogPreference.find("input[name=fontSize]"), + $editorFontFamily = $dialogPreference.find("input[name=editorFontFamily]"), + $editorFontSize = $dialogPreference.find("input[name=editorFontSize]"), + $editorLineHeight = $dialogPreference.find("input[name=editorLineHeight]"), + $goFmt = $dialogPreference.find("input[name=goFmt]"), + $workspace = $dialogPreference.find("input[name=workspace]"), + $password = $dialogPreference.find("input[name=password]"), + $locale = $dialogPreference.find("input[name=locale]"); + + $.extend(request, { + "fontFamily": $fontFamily.val(), + "fontSize": $fontSize.val(), + "editorFontFamily": $editorFontFamily.val(), + "editorFontSize": $editorFontSize.val(), + "editorLineHeight": $editorLineHeight.val(), + "goFmt": $goFmt.val(), + "workspace": $workspace.val(), + "password": $password.val(), + "locale": $locale.val() + }); $.ajax({ type: 'POST', url: '/preference', data: JSON.stringify(request), success: function (data, textStatus, jqXHR) { + if (!data.succ) { + return false; + } + $fontFamily.data("value", $fontFamily.val()); + $fontSize.data("value", $fontSize.val()); + $editorFontFamily.data("value", $editorFontFamily.val()); + $editorFontSize.data("value", $editorFontSize.val()); + $editorLineHeight.data("value", $editorLineHeight.val()); + $goFmt.data("value", $goFmt.val()); + $workspace.data("value", $workspace.val()); + $password.data("value", $password.val()); + $locale.data("value", $locale.val()); + + $("#dialogPreference").dialog("close"); } }); } diff --git a/views/index.html b/views/index.html index 0a60e90..6713c77 100644 --- a/views/index.html +++ b/views/index.html @@ -295,7 +295,8 @@ "colon": "{{.i18n.colon}}", "file": "{{.i18n.file}}", "uptodate": "{{.i18n.uptodate}}", - "perference": "{{.i18n.perference}}" + "perference": "{{.i18n.perference}}", + "apply": "{{.i18n.apply}}" }, "channel": { "editor": '{{.conf.EditorChannel}}', diff --git a/views/preference.html b/views/preference.html index c357586..1329cf6 100644 --- a/views/preference.html +++ b/views/preference.html @@ -1,4 +1,3 @@ -DEV in progress...
@@ -18,49 +17,45 @@
-
+
-