diff options
author | Dzial Techniczny WMW Projekt s.c <techniczna@wmwprojekt.pl> | 2019-12-10 11:34:53 +0100 |
---|---|---|
committer | Dzial Techniczny WMW Projekt s.c <techniczna@wmwprojekt.pl> | 2019-12-10 11:34:53 +0100 |
commit | b8fa0246803dab40cf57d40b45984c53046f2d55 (patch) | |
tree | dc92b167c7542137c385614a1d558e57669a4339 /plugins/Bigboard/Asset | |
parent | 2a43146236fd8fb16f84398d85720ad84aa0a0b1 (diff) |
Plugins directory and local modifications
Diffstat (limited to 'plugins/Bigboard/Asset')
-rw-r--r-- | plugins/Bigboard/Asset/js/BoardDragAndDrop.js | 124 | ||||
-rw-r--r-- | plugins/Bigboard/Asset/js/BoardPolling.js | 43 |
2 files changed, 167 insertions, 0 deletions
diff --git a/plugins/Bigboard/Asset/js/BoardDragAndDrop.js b/plugins/Bigboard/Asset/js/BoardDragAndDrop.js new file mode 100644 index 00000000..b6b7b8c3 --- /dev/null +++ b/plugins/Bigboard/Asset/js/BoardDragAndDrop.js @@ -0,0 +1,124 @@ +Kanboard.BoardDragAndDrop = function(app) { + this.app = app; + this.savingInProgress = false; +}; + +Kanboard.BoardDragAndDrop.prototype.execute = function() { + if (this.app.hasId("board")) { + this.executeListeners(); + this.dragAndDrop(); + } +}; + +Kanboard.BoardDragAndDrop.prototype.dragAndDrop = function() { + var self = this; + var dropzone = $(".board-task-list"); + + // Run for every Board List, connecting the Items within the same project id + dropzone.each(function() { + // Set dropzone height to the height of the table cell + $(this).css("min-height", $(this).parent().height()); + + var project_id = $(this).closest("table[id=board]").attr("data-project-id"); + + var params = { + forcePlaceholderSize: true, + tolerance: "pointer", + connectWith: ".sortable-column[data-project-id=" + project_id + "]", + placeholder: "draggable-placeholder", + items: ".draggable-item[data-project-id=" + project_id + "]", + stop: function(event, ui) { + var task = ui.item; + var taskId = task.attr('data-task-id'); + var taskPosition = task.attr('data-position'); + var taskColumnId = task.attr('data-column-id'); + var taskSwimlaneId = task.attr('data-swimlane-id'); + + var newColumnId = task.parent().attr("data-column-id"); + var newSwimlaneId = task.parent().attr('data-swimlane-id'); + var newPosition = task.index() + 1; + + var boardId = task.closest("table").attr("data-project-id"); + var saveURL = task.closest("table").attr("data-save-url"); + + task.removeClass("draggable-item-selected"); + + if (newColumnId != taskColumnId || newSwimlaneId != taskSwimlaneId || newPosition != taskPosition) { + self.changeTaskState(taskId); + self.save(saveURL, boardId, taskId, taskColumnId, newColumnId, newPosition, newSwimlaneId); + } + }, + start: function(event, ui) { + ui.item.addClass("draggable-item-selected"); + ui.placeholder.height(ui.item.height()); + } + }; + + if (isMobile.any) { + $(".task-board-sort-handle").css("display", "inline"); + params.handle = ".task-board-sort-handle"; + } + + $(this).sortable(params); + }); +}; + +Kanboard.BoardDragAndDrop.prototype.changeTaskState = function(taskId) { + var task = $("div[data-task-id=" + taskId + "]"); + task.addClass('task-board-saving-state'); + task.find('.task-board-saving-icon').show(); +}; + +Kanboard.BoardDragAndDrop.prototype.save = function(saveURL, boardId, taskId, srcColumnId, dstColumnId, position, swimlaneId) { + var self = this; + self.app.showLoadingIcon(); + self.savingInProgress = true; + + $.ajax({ + cache: false, + url: saveURL, + contentType: "application/json", + type: "POST", + processData: false, + data: JSON.stringify({ + "task_id": taskId, + "src_column_id": srcColumnId, + "dst_column_id": dstColumnId, + "swimlane_id": swimlaneId, + "position": position + }), + success: function(data) { + self.refresh(boardId,data); + self.savingInProgress = false; + }, + error: function() { + self.app.hideLoadingIcon(); + self.savingInProgress = false; + }, + statusCode: { + 403: function(data) { + window.alert(data.responseJSON.message); + document.location.reload(true); + } + } + }); +}; + +Kanboard.BoardDragAndDrop.prototype.refresh = function(boardId, data) { + + $("div[id=board-container][data-project-id=" + boardId + "]").replaceWith(data); + + this.app.hideLoadingIcon(); + this.executeListeners(); + this.dragAndDrop(); +}; + +Kanboard.BoardDragAndDrop.prototype.executeListeners = function() { + for (var className in this.app.controllers) { + var controller = this.app.get(className); + + if (typeof controller.onBoardRendered === "function") { + controller.onBoardRendered(); + } + } +}; diff --git a/plugins/Bigboard/Asset/js/BoardPolling.js b/plugins/Bigboard/Asset/js/BoardPolling.js new file mode 100644 index 00000000..6d5499fd --- /dev/null +++ b/plugins/Bigboard/Asset/js/BoardPolling.js @@ -0,0 +1,43 @@ +Kanboard.BoardPolling = function(app) { + this.app = app; +}; + +Kanboard.BoardPolling.prototype.execute = function() { + if (this.app.hasId("board")) { + var interval = parseInt($("#board").attr("data-check-interval")); + + if (interval > 0) { + window.setInterval(this.check.bind(this), interval * 1000); + } + } +}; + +Kanboard.BoardPolling.prototype.check = function() { + if (KB.utils.isVisible() && !this.app.get("BoardDragAndDrop").savingInProgress) { + var self = this; + if (!$("#app-loading-icon").length) this.app.showLoadingIcon(); + var pollsinprogress=0; + + $("table.board-project").each(function() { + var boardId = $(this).attr("data-project-id") + var url = $(this).attr("data-check-url"); + pollsinprogress++; + $.ajax({ + cache: false, + url: url, + statusCode: { + 200: function(data) { + pollsinprogress--; + if (pollsinprogress <= 0) self.app.hideLoadingIcon(); + self.app.get("BoardDragAndDrop").refresh(boardId, data); + }, + 304: function () { + pollsinprogress--; + if (pollsinprogress <= 0) self.app.hideLoadingIcon(); + } + } + }); + }); + if (pollsinprogress <= 0) self.app.hideLoadingIcon(); + } +}; |