Fix IE bug and show errors.

This commit is contained in:
Justin Nuß 2014-07-25 11:13:42 +02:00
parent 4e2477a1a5
commit 12fb42de5a
5 changed files with 43 additions and 13 deletions

View file

@ -1836,4 +1836,11 @@ body {
#issue-create-form #attached { #issue-create-form #attached {
margin-bottom: 0; margin-bottom: 0;
}
#submit-error {
display: none;
padding: 10px 15px 15px 15px;
font-weight: bold;
text-align: center;
} }

View file

@ -568,7 +568,7 @@ function initIssue() {
}; };
var out = function() { var out = function() {
$hoverElement.hide(); //$hoverElement.hide();
}; };
$(".issue-main .attachments .attachment").hover(over, out); $(".issue-main .attachments .attachment").hover(over, out);
@ -598,6 +598,13 @@ function initIssue() {
$("button,input[type=\"submit\"]", fileInput.form).on("click", function() { $("button,input[type=\"submit\"]", fileInput.form).on("click", function() {
clickedButton = this; clickedButton = this;
var $button = $(this);
$button.removeClass("btn-success");
$button.addClass("btn-warning");
$button.text("Submiting...");
}); });
fileInput.form.addEventListener("submit", function(event) { fileInput.form.addEventListener("submit", function(event) {
@ -630,16 +637,33 @@ function initIssue() {
}); });
xhr.addEventListener("load", function() { xhr.addEventListener("load", function() {
if (xhr.response.ok === false) { var response = xhr.response;
$("#submit-error").text(xhr.response.error);
if (typeof response == "string") {
try {
response = JSON.parse(response);
} catch (err) {
response = { ok: false, error: "Could not parse JSON" };
}
}
if (response.ok === false) {
$("#submit-error").text(response.error);
$("#submit-error").show();
var $button = $(clickedButton);
$button.removeClass("btn-warning");
$button.addClass("btn-danger");
$button.text("An error encoured!")
return; return;
} }
window.location.href = xhr.response.data; window.location.href = response.data;
}); });
xhr.responseType = "json";
xhr.open("POST", this.action, true); xhr.open("POST", this.action, true);
xhr.send(data); xhr.send(data);

View file

@ -189,9 +189,9 @@ func CreateIssue(ctx *middleware.Context, params martini.Params) {
func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) { func CreateIssuePost(ctx *middleware.Context, params martini.Params, form auth.CreateIssueForm) {
send := func(status int, data interface{}, err error) { send := func(status int, data interface{}, err error) {
log.Error("issue.Comment(?): %s", err)
if err != nil { if err != nil {
log.Error("issue.CreateIssuePost(?): %s", err.Error())
ctx.JSON(status, map[string]interface{}{ ctx.JSON(status, map[string]interface{}{
"ok": false, "ok": false,
"status": status, "status": status,
@ -711,9 +711,9 @@ func uploadFiles(ctx *middleware.Context, issueId, commentId int64) {
func Comment(ctx *middleware.Context, params martini.Params) { func Comment(ctx *middleware.Context, params martini.Params) {
send := func(status int, data interface{}, err error) { send := func(status int, data interface{}, err error) {
log.Error("issue.Comment(?): %s", err)
if err != nil { if err != nil {
log.Error("issue.Comment(?): %s", err.Error())
ctx.JSON(status, map[string]interface{}{ ctx.JSON(status, map[string]interface{}{
"ok": false, "ok": false,
"status": status, "status": status,
@ -860,7 +860,6 @@ func Comment(ctx *middleware.Context, params martini.Params) {
} }
} }
log.Error("url: %#v", fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index))
send(200, fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index), nil) send(200, fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, index), nil)
} }

View file

@ -95,7 +95,7 @@
<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">
<div id="submit-error"></div> <div id="submit-error" class="text-danger"></div>
<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> <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>
</div> </div>
</div> </div>

View file

@ -134,7 +134,7 @@
<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">
<div id="submit-error"></div> <div id="submit-error" class="text-danger"></div>
<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" data-ajax-rel="issue-preview" data-ajax-val="val" data-ajax-field="text">{{.content}}</textarea> <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>
</div> </div>