Skip to content

Commit 12fb42d

Browse files
Fix IE bug and show errors.
1 parent 4e2477a commit 12fb42d

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

public/css/gogs.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,4 +1836,11 @@ body {
18361836

18371837
#issue-create-form #attached {
18381838
margin-bottom: 0;
1839+
}
1840+
1841+
#submit-error {
1842+
display: none;
1843+
padding: 10px 15px 15px 15px;
1844+
font-weight: bold;
1845+
text-align: center;
18391846
}

public/js/app.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ function initIssue() {
568568
};
569569

570570
var out = function() {
571-
$hoverElement.hide();
571+
//$hoverElement.hide();
572572
};
573573

574574
$(".issue-main .attachments .attachment").hover(over, out);
@@ -598,6 +598,13 @@ function initIssue() {
598598

599599
$("button,input[type=\"submit\"]", fileInput.form).on("click", function() {
600600
clickedButton = this;
601+
602+
var $button = $(this);
603+
604+
$button.removeClass("btn-success");
605+
$button.addClass("btn-warning");
606+
607+
$button.text("Submiting...");
601608
});
602609

603610
fileInput.form.addEventListener("submit", function(event) {
@@ -630,16 +637,33 @@ function initIssue() {
630637
});
631638

632639
xhr.addEventListener("load", function() {
633-
if (xhr.response.ok === false) {
634-
$("#submit-error").text(xhr.response.error);
640+
var response = xhr.response;
641+
642+
if (typeof response == "string") {
643+
try {
644+
response = JSON.parse(response);
645+
} catch (err) {
646+
response = { ok: false, error: "Could not parse JSON" };
647+
}
648+
}
649+
650+
if (response.ok === false) {
651+
$("#submit-error").text(response.error);
652+
$("#submit-error").show();
653+
654+
var $button = $(clickedButton);
655+
656+
$button.removeClass("btn-warning");
657+
$button.addClass("btn-danger");
658+
659+
$button.text("An error encoured!")
660+
635661
return;
636662
}
637663

638-
window.location.href = xhr.response.data;
664+
window.location.href = response.data;
639665
});
640666

641-
xhr.responseType = "json";
642-
643667
xhr.open("POST", this.action, true);
644668
xhr.send(data);
645669

routers/repo/issue.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,9 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
189189

190190
func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
191191
send := func(status int, data interface{}, err error) {
192-
log.Error("issue.Comment(?): %s", err)
193-
194192
if err != nil {
193+
log.Error("issue.CreateIssuePost(?): %s", err.Error())
194+
195195
ctx.JSON(status, map[string]interface{}{
196196
"ok": false,
197197
"status": status,
@@ -711,9 +711,9 @@ func uploadFiles(ctx *middleware.Context, issueId, commentId int64) {
711711

712712
func Comment(ctx *middleware.Context, params martini.Params) {
713713
send := func(status int, data interface{}, err error) {
714-
log.Error("issue.Comment(?): %s", err)
715-
716714
if err != nil {
715+
log.Error("issue.Comment(?): %s", err.Error())
716+
717717
ctx.JSON(status, map[string]interface{}{
718718
"ok": false,
719719
"status": status,
@@ -860,7 +860,6 @@ func Comment(ctx *middleware.Context, params martini.Params) {
860860
}
861861
}
862862

863-
log.Error("url: %#v", fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index))
864863
send(200, fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index), nil)
865864
}
866865

templates/repo/issue/create.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<div class="tab-content">
9696
<div class="tab-pane" id="issue-textarea">
9797
<div class="form-group">
98-
<div id="submit-error"></div>
98+
<div id="submit-error" class="text-danger"></div>
9999
<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="text">{{.content}}</textarea>
100100
</div>
101101
</div>

templates/repo/issue/view.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
<div class="tab-content">
135135
<div class="tab-pane" id="issue-textarea">
136136
<div class="form-group">
137-
<div id="submit-error"></div>
137+
<div id="submit-error" class="text-danger"></div>
138138
<input type="hidden" value="{{.Issue.Index}}" name="issueIndex"/>
139139
<textarea class="form-control" name="content" id="issue-reply-content" rows="10" placeholder="Write some content" data-ajax-rel="issue-preview" data-ajax-val="val" data-ajax-field="text">{{.content}}</textarea>
140140
</div>

0 commit comments

Comments
 (0)