aboutsummaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-rw-r--r--public/js/app.js250
1 files changed, 247 insertions, 3 deletions
diff --git a/public/js/app.js b/public/js/app.js
index 7d4e7839..9451407b 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -470,8 +470,8 @@ function initRepository() {
function initInstall() {
// database type change
(function () {
- var mysql_default = '127.0.0.1:3306'
- var postgres_default = '127.0.0.1:5432'
+ var mysql_default = '127.0.0.1:3306';
+ var postgres_default = '127.0.0.1:5432';
$('#install-database').on("change", function () {
var val = $(this).val();
@@ -520,6 +520,244 @@ function initIssue() {
});
}());
+ // store unsend text in session storage.
+ (function() {
+ var $textArea = $("#issue-content,#issue-reply-content");
+ var current = "";
+
+ if ($textArea == null || !('sessionStorage' in window)) {
+ return;
+ }
+
+ var path = location.pathname.split("/");
+ var key = "issue-" + path[1] + "-" + path[2] + "-";
+
+ if (/\/issues\/\d+$/.test(location.pathname)) {
+ key = key + path[4];
+ } else {
+ key = key + "new";
+ }
+
+ if ($textArea.val() !== undefined && $textArea.val() !== "") {
+ sessionStorage.setItem(key, $textArea.val());
+ } else {
+ $textArea.val(sessionStorage.getItem(key) || "");
+
+ if ($textArea.attr("id") == "issue-reply-content") {
+ var $closeBtn = $('#issue-close-btn');
+ var $openBtn = $('#issue-open-btn');
+
+ if ($textArea.val().length) {
+ $closeBtn.val($closeBtn.data("text"));
+ $openBtn.val($openBtn.data("text"));
+ } else {
+ $closeBtn.val($closeBtn.data("origin"));
+ $openBtn.val($openBtn.data("origin"));
+ }
+ }
+ }
+
+ $textArea.on("keyup", function() {
+ if ($textArea.val() !== current) {
+ sessionStorage.setItem(key, current = $textArea.val());
+ }
+ });
+ }());
+
+ // Preview for images.
+ (function() {
+ var $hoverElement = $("<div></div>");
+ var $hoverImage = $("<img />");
+
+ $hoverElement.addClass("attachment-preview");
+ $hoverElement.hide();
+
+ $hoverImage.addClass("attachment-preview-img");
+
+ $hoverElement.append($hoverImage);
+ $(document.body).append($hoverElement);
+
+ var over = function() {
+ var $this = $(this);
+
+ if ((/\.(png|jpg|jpeg|gif)$/i).test($this.text()) == false) {
+ return;
+ }
+
+ if ($hoverImage.attr("src") != $this.attr("href")) {
+ $hoverImage.attr("src", $this.attr("href"));
+ $hoverImage.load(function() {
+ var height = this.height;
+ var width = this.width;
+
+ if (height > 300) {
+ var factor = 300 / height;
+
+ height = factor * height;
+ width = factor * width;
+ }
+
+ $hoverImage.css({"height": height, "width": width});
+
+ var offset = $this.offset();
+ var left = offset.left, top = offset.top + $this.height() + 5;
+
+ $hoverElement.css({"top": top + "px", "left": left + "px"});
+ $hoverElement.css({"height": height + 16, "width": width + 16});
+ $hoverElement.show();
+ });
+ } else {
+ $hoverElement.show();
+ }
+ };
+
+ var out = function() {
+ $hoverElement.hide();
+ };
+
+ $(".issue-main .attachments .attachment").hover(over, out);
+ }());
+
+ // Upload.
+ (function() {
+ var $attachedList = $("#attached-list");
+ var $addButton = $("#attachments-button");
+ var files = [];
+ var fileInput = document.getElementById("attachments-input");
+
+ if (fileInput === null) {
+ return;
+ }
+
+ $attachedList.on("click", "span.attachment-remove", function(event) {
+ var $parent = $(this).parent();
+
+ files.splice($parent.data("index"), 1);
+ $parent.remove();
+ });
+
+ var clickedButton;
+
+ $('#issue-reply-btn,input[type="submit"]', fileInput.form).on('click', function() {
+ clickedButton = this;
+
+ var $button = $(this);
+
+ $button.removeClass("btn-success btn-default");
+ $button.addClass("btn-warning");
+
+ $button.text("Submitting&hellip;");
+ });
+
+ 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() {
+ console.log("Issue submit request failed. xhr.status: " + xhr.status);
+ });
+
+ xhr.addEventListener("load", function() {
+ var response = xhr.response;
+
+ 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 occurred!");
+
+ return;
+ }
+
+ if (!('sessionStorage' in window)) {
+ return;
+ }
+
+ var path = location.pathname.split("/");
+ var key = "issue-" + path[1] + "-" + path[2] + "-";
+
+ if (/\/issues\/\d+$/.test(location.pathname)) {
+ key = key + path[4];
+ } else {
+ key = key + "new";
+ }
+
+ sessionStorage.removeItem(key);
+ window.location.href = response.data;
+ });
+
+ xhr.open("POST", this.action, true);
+ xhr.send(data);
+
+ return false;
+ });
+
+ fileInput.addEventListener("change", function() {
+ 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.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(evt) {
+ fileInput.click();
+ evt.preventDefault();
+ });
+ }());
+
// issue edit mode
(function () {
$("#issue-edit-btn").on("click", function () {
@@ -529,7 +767,7 @@ function initIssue() {
$('.issue-edit-cancel').on("click", function () {
$('#issue h1.title,#issue .issue-main > .issue-content .content,#issue-edit-btn').toggleShow();
$('#issue-edit-title,.issue-edit-content,.issue-edit-cancel,.issue-edit-save').toggleHide();
- })
+ });
}());
// issue ajax update
@@ -744,11 +982,17 @@ function initIssue() {
$(item).addClass("no-checked");
$("#label-" + id, $labels).remove();
+
+ if ($labels.children(".label-item").length == 0) {
+ $labels.append("<p>None yet</p>");
+ }
} else {
$(item).prepend('<span class="check pull-left"><i class="fa fa-check"></i></span>');
$(item).removeClass("no-checked");
$(item).addClass("checked");
+
+ $("p:not([class])", $labels).remove();
var $l = $("<p></p>");
var c = $("span.color", item).css("background-color");