Fix #318. Switch to JS(ON) implementation for issue/comment creation.
This commit is contained in:
parent
f7617997ce
commit
4e2477a1a5
4 changed files with 147 additions and 38 deletions
|
@ -579,26 +579,97 @@ function initIssue() {
|
|||
var $attachedList = $("#attached-list");
|
||||
var $addButton = $("#attachments-button");
|
||||
|
||||
var files = [];
|
||||
|
||||
var fileInput = document.getElementById("attachments-input");
|
||||
|
||||
if (fileInput === null) {
|
||||
return;
|
||||
}
|
||||
fileInput.addEventListener("change", function(event) {
|
||||
$attachedList.empty();
|
||||
$attachedList.append("<b>Attachments:</b> ");
|
||||
|
||||
$attachedList.on("click", "span.attachment-remove", function(event) {
|
||||
var $parent = $(this).parent();
|
||||
|
||||
files.splice($parent.data("index"), 1);
|
||||
$parent.remove();
|
||||
});
|
||||
|
||||
var clickedButton = undefined;
|
||||
|
||||
$("button,input[type=\"submit\"]", fileInput.form).on("click", function() {
|
||||
clickedButton = this;
|
||||
});
|
||||
|
||||
fileInput.form.addEventListener("submit", function(event) {
|
||||
event.stopImmediatePropagation();
|
||||
event.preventDefault();
|
||||
|
||||
//var data = new FormData(this);
|
||||
|
||||
// Internet Explorer ... -_-
|
||||
var data = new FormData();
|
||||
|
||||
$.each($("[name]", this), function(i, e) {
|
||||
if (e.name == "attachments" || e.type == "submit") {
|
||||
return;
|
||||
}
|
||||
|
||||
data.append(e.name, $(e).val());
|
||||
});
|
||||
|
||||
data.append(clickedButton.name, $(clickedButton).val());
|
||||
|
||||
files.forEach(function(file) {
|
||||
data.append("attachments", file);
|
||||
});
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
xhr.addEventListener("error", function() {
|
||||
debugger;
|
||||
});
|
||||
|
||||
xhr.addEventListener("load", function() {
|
||||
if (xhr.response.ok === false) {
|
||||
$("#submit-error").text(xhr.response.error);
|
||||
return;
|
||||
}
|
||||
|
||||
window.location.href = xhr.response.data;
|
||||
});
|
||||
|
||||
xhr.responseType = "json";
|
||||
|
||||
xhr.open("POST", this.action, true);
|
||||
xhr.send(data);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
fileInput.addEventListener("change", function(event) {
|
||||
for (var index = 0; index < fileInput.files.length; index++) {
|
||||
var file = fileInput.files[index];
|
||||
|
||||
if (files.indexOf(file) > -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var $span = $("<span></span>");
|
||||
|
||||
$span.addClass("label");
|
||||
$span.addClass("label-default");
|
||||
|
||||
$span.append(file.name.toLowerCase());
|
||||
$span.data("index", files.length);
|
||||
|
||||
$span.append(file.name);
|
||||
$span.append(" <span class=\"attachment-remove fa fa-times-circle\"></span>");
|
||||
|
||||
$attachedList.append($span);
|
||||
|
||||
files.push(file);
|
||||
}
|
||||
|
||||
this.value = "";
|
||||
});
|
||||
|
||||
$addButton.on("click", function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue