From efa039a0f75ff9ba9376af1cbd3d948752c074fc Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Mon, 10 Mar 2014 21:12:49 +0800 Subject: [PATCH] finish ssh key pages ui --- public/css/gogs.css | 4 ++++ public/js/app.js | 41 ++++++++++++++++++++++++++++++++++- routers/user/setting.go | 32 +++++++++++++++++++++++++++ templates/base/footer.tmpl | 5 +++-- templates/base/navbar.tmpl | 2 +- templates/user/publickey.tmpl | 4 ++-- 6 files changed, 82 insertions(+), 6 deletions(-) diff --git a/public/css/gogs.css b/public/css/gogs.css index 9205178f4..4a4144bab 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -32,6 +32,10 @@ body { background-color: transparent; } +.btn{ + cursor: pointer; +} + /* gogits nav header */ .gogs-masthead { background-color: #428bca; diff --git a/public/js/app.js b/public/js/app.js index 59d521090..f6e147120 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -30,7 +30,8 @@ var Gogits = { return; } $.each(modals, function (i, item) { - $(item).modal("hide"); + var hide = $(item).data('modal'); + $(item).modal(hide ? hide : "hide"); }); }; Gogits.initTooltips = function () { @@ -39,6 +40,30 @@ var Gogits = { //container: "body" }); }; + Gogits.initTabs = function () { + var $tabs = $('[data-toggle=tab]'); + $tabs.tab("show"); + $tabs.find("li:eq(" + index + ") a").tab("show"); + } +})(jQuery); + +// ajax utils +(function ($) { + Gogits.ajaxDelete = function (url, data, success) { + data = data || {}; + data._method = "DELETE"; + $.ajax({ + url: url, + data: data, + method: "POST", + dataType: "json", + success: function (json) { + if (success) { + success(json); + } + } + }) + } })(jQuery); @@ -72,4 +97,18 @@ function initRegister() { } }); }); +} + +function initUserSetting(){ + $('#gogs-ssh-keys').on("click",".delete",function(){ + var $this = $(this); + Gogits.ajaxDelete("",{"id":$this.data("del")},function(json){ + if(json.ok){ + $this.parent().remove(); + }else{ + alert(json.err); + } + }); + return false; + }); } \ No newline at end of file diff --git a/routers/user/setting.go b/routers/user/setting.go index 84be13817..aabbc2129 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -12,6 +12,7 @@ import ( "github.com/martini-contrib/render" "github.com/martini-contrib/sessions" "net/http" + "strconv" ) func Setting(r render.Render, data base.TmplData, session sessions.Session) { @@ -21,6 +22,37 @@ func Setting(r render.Render, data base.TmplData, session sessions.Session) { } func SettingSSHKeys(r render.Render, data base.TmplData, req *http.Request, session sessions.Session) { + // del ssh ky + if req.Method == "DELETE" || req.FormValue("_method") == "DELETE" { + id, err := strconv.ParseInt(req.FormValue("id"), 10, 64) + if err != nil { + data["ErrorMsg"] = err + log.Error("ssh.DelPublicKey: %v", err) + r.JSON(200, map[string]interface{}{ + "ok": false, + "err": err.Error(), + }) + return + } + k := &models.PublicKey{ + Id: id, + OwnerId: auth.SignedInId(session), + } + err = models.DeletePublicKey(k) + if err != nil { + data["ErrorMsg"] = err + log.Error("ssh.DelPublicKey: %v", err) + r.JSON(200, map[string]interface{}{ + "ok": false, + "err": err.Error(), + }) + } else { + r.JSON(200, map[string]interface{}{ + "ok": true, + }) + } + return + } // add ssh key if req.Method == "POST" { k := &models.PublicKey{OwnerId: auth.SignedInId(session), diff --git a/templates/base/footer.tmpl b/templates/base/footer.tmpl index 4ae4a95fa..a2131a953 100644 --- a/templates/base/footer.tmpl +++ b/templates/base/footer.tmpl @@ -1,7 +1,8 @@ diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl index e78f6bb22..38fc0a399 100644 --- a/templates/base/navbar.tmpl +++ b/templates/base/navbar.tmpl @@ -2,7 +2,7 @@