summaryrefslogtreecommitdiffstats
path: root/public/js
diff options
context:
space:
mode:
authorJustin Nuß <justin.nuss@hmmh.de>2014-07-25 10:47:37 +0200
committerJustin Nuß <justin.nuss@hmmh.de>2014-07-25 10:47:37 +0200
commit4e2477a1a5ae59ff4cb34d58eab74297b4ea2d24 (patch)
treefc9216380ac1db126db0022d08a70f3e80b58acc /public/js
parentf7617997cebd0f347415da47545fbf16e5d0653e (diff)
downloadgitea-4e2477a1a5ae59ff4cb34d58eab74297b4ea2d24.tar.gz
gitea-4e2477a1a5ae59ff4cb34d58eab74297b4ea2d24.zip
Fix #318. Switch to JS(ON) implementation for issue/comment creation.
Diffstat (limited to 'public/js')
-rw-r--r--public/js/app.js79
1 files changed, 75 insertions, 4 deletions
diff --git a/public/js/app.js b/public/js/app.js
index 62482965e0..a88c8f6bc7 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -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() {