From f0d5c3992b03f4d6a82b272ac513d2989ffb8d81 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 20:46:36 +0800 Subject: issue ajax edit --- public/js/app.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 4 deletions(-) (limited to 'public/js') diff --git a/public/js/app.js b/public/js/app.js index 9299a6b7..b03d9070 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -56,6 +56,43 @@ var Gogits = { }, toggleShow: function () { $(this).removeClass("hidden"); + }, + toggleAjax: function (successCallback) { + var url = $(this).data("ajax"); + var method = $(this).data('ajax-method') || 'get'; + var ajaxName = $(this).data('ajax-name'); + var data = {}; + $('[data-ajax-rel=' + ajaxName + ']').each(function () { + var field = $(this).data("ajax-field"); + var t = $(this).data("ajax-val"); + if (t == "val") { + data[field] = $(this).val(); + return true; + } + if (t == "txt") { + data[field] = $(this).text(); + return true; + } + if (t == "html") { + data[field] = $(this).html(); + return true; + } + if (t == "data") { + data[field] = $(this).data("ajax-data"); + return true; + } + return true; + }); + $.ajax({ + url: url, + method: method.toUpperCase(), + data: data, + success: function (d) { + if (successCallback) { + successCallback(d); + } + } + }) } }) }(jQuery)); @@ -386,11 +423,11 @@ function initIssue() { var $openBtn = $('#issue-open-btn'); $('#issue-reply-content').on("keyup", function () { if ($(this).val().length) { - $closeBtn.text($closeBtn.data("text")); - $openBtn.text($openBtn.data("text")); + $closeBtn.val($closeBtn.data("text")); + $openBtn.val($openBtn.data("text")); } else { - $closeBtn.text($closeBtn.data("origin")); - $openBtn.text($openBtn.data("origin")); + $closeBtn.val($closeBtn.data("origin")); + $openBtn.val($openBtn.data("origin")); } }); }()); @@ -406,6 +443,16 @@ function initIssue() { $('#issue-edit-title,#issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleHide(); }) }()); + + // issue ajax update + $('.issue-edit-save').on("click", function () { + $(this).toggleAjax(function(json){ + if(json.ok){ + $('.issue-head h1.title').text(json.title); + $('.issue-main > .issue-content .content').html(json.content); + } + }); + }); } (function ($) { -- cgit v1.2.3 From ecce694d77756264864b03e6b06077592ed1676a Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 21:16:06 +0800 Subject: issue content ajax preview --- public/js/app.js | 61 ++++++++++++++++++++++++++++++--------------- routers/preview.go | 17 +++++++++++++ templates/issue/create.tmpl | 8 +++--- templates/issue/view.tmpl | 8 +++--- web.go | 1 + 5 files changed, 67 insertions(+), 28 deletions(-) create mode 100644 routers/preview.go (limited to 'public/js') diff --git a/public/js/app.js b/public/js/app.js index b03d9070..58bda989 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -399,21 +399,24 @@ function initRepository() { function initInstall() { // database type change - $('#install-database').on("change", function () { - var val = $(this).val(); - if (val != "sqlite") { - $('.server-sql').show(); - $('.sqlite-setting').addClass("hide"); - if (val == "pgsql") { - $('.pgsql-setting').removeClass("hide"); + (function () { + $('#install-database').on("change", function () { + var val = $(this).val(); + if (val != "sqlite") { + $('.server-sql').show(); + $('.sqlite-setting').addClass("hide"); + if (val == "pgsql") { + $('.pgsql-setting').removeClass("hide"); + } else { + $('.pgsql-setting').addClass("hide"); + } } else { - $('.pgsql-setting').addClass("hide"); + $('.server-sql').hide(); + $('.sqlite-setting').removeClass("hide"); } - } else { - $('.server-sql').hide(); - $('.sqlite-setting').removeClass("hide"); - } - }); + }); + }()); + } function initIssue() { @@ -445,14 +448,32 @@ function initIssue() { }()); // issue ajax update - $('.issue-edit-save').on("click", function () { - $(this).toggleAjax(function(json){ - if(json.ok){ - $('.issue-head h1.title').text(json.title); - $('.issue-main > .issue-content .content').html(json.content); - } + (function () { + $('.issue-edit-save').on("click", function () { + $(this).toggleAjax(function (json) { + if (json.ok) { + $('.issue-head h1.title').text(json.title); + $('.issue-main > .issue-content .content').html(json.content); + } + }); }); - }); + }()); + + // issue ajax preview + (function () { + $('[data-ajax-name=issue-preview]').on("click", function () { + var $this = $(this); + $this.toggleAjax(function (json) { + if (json.ok) { + $($this.data("preview")).html(json.content); + } + }) + }); + $('.issue-write a[data-toggle]').on("click", function () { + $('.issue-preview-content').html("loading..."); + }); + }()) + } (function ($) { diff --git a/routers/preview.go b/routers/preview.go new file mode 100644 index 00000000..cc34c8fa --- /dev/null +++ b/routers/preview.go @@ -0,0 +1,17 @@ +// Copyright 2014 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package routers + +import "github.com/gogits/gogs/modules/middleware" + +func Preview(ctx *middleware.Context) { + content := ctx.Query("content") + // todo : gfm render content + // content = Markdown(content) + ctx.Render.JSON(200, map[string]interface{}{ + "ok": true, + "content": "preview : " + content, + }) +} diff --git a/templates/issue/create.tmpl b/templates/issue/create.tmpl index cbc21f6c..b8a533a1 100644 --- a/templates/issue/create.tmpl +++ b/templates/issue/create.tmpl @@ -18,16 +18,16 @@ Content with Markdown
- +
-
preview
+
loading...
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl index 4266bcbf..431b1d10 100644 --- a/templates/issue/view.tmpl +++ b/templates/issue/view.tmpl @@ -72,17 +72,17 @@ Content with Markdown
- +
-
preview
+
loading...
diff --git a/web.go b/web.go index 35695f0b..451e52ff 100644 --- a/web.go +++ b/web.go @@ -95,6 +95,7 @@ func runWeb(*cli.Context) { m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/stars", reqSignIn, user.Stars) m.Get("/help", routers.Help) + m.Post("/preview", routers.Preview) avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") m.Get("/avatar/:hash", avt.ServeHTTP) -- cgit v1.2.3 From be45057c3aef74c4b8bdc28ebd84c7297d1a7b62 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Sat, 29 Mar 2014 23:03:01 +0800 Subject: fix issue ajax update --- public/js/app.js | 1 + 1 file changed, 1 insertion(+) (limited to 'public/js') diff --git a/public/js/app.js b/public/js/app.js index 58bda989..5181933d 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -454,6 +454,7 @@ function initIssue() { if (json.ok) { $('.issue-head h1.title').text(json.title); $('.issue-main > .issue-content .content').html(json.content); + $('.issue-edit-cancel').trigger("click"); } }); }); -- cgit v1.2.3