issue content ajax preview

pull/197/head
FuXiaoHei 11 years ago
parent 035facc564
commit ecce694d77
  1. 21
      public/js/app.js
  2. 17
      routers/preview.go
  3. 8
      templates/issue/create.tmpl
  4. 8
      templates/issue/view.tmpl
  5. 1
      web.go

@ -399,6 +399,7 @@ function initRepository() {
function initInstall() { function initInstall() {
// database type change // database type change
(function () {
$('#install-database').on("change", function () { $('#install-database').on("change", function () {
var val = $(this).val(); var val = $(this).val();
if (val != "sqlite") { if (val != "sqlite") {
@ -414,6 +415,8 @@ function initInstall() {
$('.sqlite-setting').removeClass("hide"); $('.sqlite-setting').removeClass("hide");
} }
}); });
}());
} }
function initIssue() { function initIssue() {
@ -445,6 +448,7 @@ function initIssue() {
}()); }());
// issue ajax update // issue ajax update
(function () {
$('.issue-edit-save').on("click", function () { $('.issue-edit-save').on("click", function () {
$(this).toggleAjax(function (json) { $(this).toggleAjax(function (json) {
if (json.ok) { if (json.ok) {
@ -453,6 +457,23 @@ function initIssue() {
} }
}); });
}); });
}());
// 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 ($) { (function ($) {

@ -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,
})
}

@ -18,16 +18,16 @@
Content with <a href="#">Markdown</a> Content with <a href="#">Markdown</a>
</div> </div>
<ul class="nav nav-tabs" data-init="tabs"> <ul class="nav nav-tabs" data-init="tabs">
<li class="active"><a href="#issue-textarea" data-toggle="tab">Write</a></li> <li class="active issue-write"><a href="#issue-textarea" data-toggle="tab">Write</a></li>
<li><a href="#issue-preview" data-toggle="tab">Preview</a></li> <li class="issue-preview"><a href="#issue-preview" data-toggle="tab" data-ajax="/preview?repo=repo_id&issue=new" data-ajax-name="issue-preview" data-ajax-method="post" data-preview="#issue-preview">Preview</a></li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane" id="issue-textarea"> <div class="tab-pane" id="issue-textarea">
<div class="form-group"> <div class="form-group">
<textarea class="form-control" name="content" id="issue-content" rows="10" placeholder="Write some content">{{.content}}</textarea> <textarea class="form-control" name="content" id="issue-content" rows="10" placeholder="Write some content" data-ajax-rel="issue-preview" data-ajax-val="val" data-ajax-field="content">{{.content}}</textarea>
</div> </div>
</div> </div>
<div class="tab-pane" id="issue-preview">preview</div> <div class="tab-pane issue-preview-content" id="issue-preview">loading...</div>
</div> </div>
</div> </div>
<div class="text-right panel-body"> <div class="text-right panel-body">

@ -72,17 +72,17 @@
Content with <a href="#">Markdown</a> Content with <a href="#">Markdown</a>
</div> </div>
<ul class="nav nav-tabs" data-init="tabs"> <ul class="nav nav-tabs" data-init="tabs">
<li class="active"><a href="#issue-textarea" data-toggle="tab">Write</a></li> <li class="active issue-write"><a href="#issue-textarea" data-toggle="tab">Write</a></li>
<li><a href="#issue-preview" data-toggle="tab">Preview</a></li> <li class="issue-preview"><a href="#issue-preview" data-toggle="tab" data-ajax="/preview?repo=repo_id&issue=issue_id&comment=new" data-ajax-name="issue-preview" data-ajax-method="post" data-preview="#issue-preview">Preview</a></li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane" id="issue-textarea"> <div class="tab-pane" id="issue-textarea">
<div class="form-group"> <div class="form-group">
<input type="hidden" value="{{.Issue.Index}}" name="issueIndex"/> <input type="hidden" value="{{.Issue.Index}}" name="issueIndex"/>
<textarea class="form-control" name="content" id="issue-reply-content" rows="10" placeholder="Write some content">{{.content}}</textarea> <textarea class="form-control" name="content" id="issue-content" rows="10" placeholder="Write some content" data-ajax-rel="issue-preview" data-ajax-val="val" data-ajax-field="content">{{.content}}</textarea>
</div> </div>
</div> </div>
<div class="tab-pane" id="issue-preview">preview</div> <div class="tab-pane issue-preview-content" id="issue-preview">loading...</div>
</div> </div>
</div> </div>
<div class="text-right"> <div class="text-right">

@ -95,6 +95,7 @@ func runWeb(*cli.Context) {
m.Get("/pulls", reqSignIn, user.Pulls) m.Get("/pulls", reqSignIn, user.Pulls)
m.Get("/stars", reqSignIn, user.Stars) m.Get("/stars", reqSignIn, user.Stars)
m.Get("/help", routers.Help) m.Get("/help", routers.Help)
m.Post("/preview", routers.Preview)
avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg") avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg")
m.Get("/avatar/:hash", avt.ServeHTTP) m.Get("/avatar/:hash", avt.ServeHTTP)

Loading…
Cancel
Save