From be4e90e319cf65b368bb866165abc8d1fd4e074f Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 1 Feb 2015 11:05:07 -0500 Subject: Add collapsible swimlanes (merge and improve pull-request #565) --- assets/js/src/swimlane.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 assets/js/src/swimlane.js (limited to 'assets/js/src') diff --git a/assets/js/src/swimlane.js b/assets/js/src/swimlane.js new file mode 100644 index 00000000..77f45907 --- /dev/null +++ b/assets/js/src/swimlane.js @@ -0,0 +1,90 @@ +Kanboard.Swimlane = (function() { + + // Expand a Swimlane via display attributes + function expand(swimlaneId) + { + $('.swimlane-row-' + swimlaneId).css('display', 'table-row'); + $('.show-icon-swimlane-' + swimlaneId).css('display', 'none'); + $('.hide-icon-swimlane-' + swimlaneId).css('display', 'inline'); + } + + // Collapse a Swimlane via display attributes + function collapse(swimlaneId) + { + $('.swimlane-row-' + swimlaneId).css('display', 'none'); + $('.show-icon-swimlane-' + swimlaneId).css('display', 'inline'); + $('.hide-icon-swimlane-' + swimlaneId).css('display', 'none'); + } + + // Add swimlane Id to the hidden list and stores the list to localStorage + function hide(id) + { + var storageKey = "hidden_swimlanes_" + $("#board").data("project-id"); + var hiddenSwimlaneIds = JSON.parse(Kanboard.GetStorageItem(storageKey)) || []; + + hiddenSwimlaneIds.push(id); + + Kanboard.SetStorageItem(storageKey, JSON.stringify(hiddenSwimlaneIds)); + } + + // Remove swimlane Id from the hidden list and stores the list to + // localStorage + function unhide(id) + { + var storageKey = "hidden_swimlanes_" + $("#board").data("project-id"); + var hiddenSwimlaneIds = JSON.parse(Kanboard.GetStorageItem(storageKey)) || []; + var index = hiddenSwimlaneIds.indexOf(id); + + if (index > -1) { + hiddenSwimlaneIds.splice(index, 1); + } + + Kanboard.SetStorageItem(storageKey, JSON.stringify(hiddenSwimlaneIds)); + } + + // Check if swimlane Id is hidden. Anything > -1 means hidden. + function isHidden(id) + { + return getAllHidden().indexOf(id) > -1; + } + + // Gets all swimlane Ids that are hidden + function getAllHidden() + { + var storageKey = "hidden_swimlanes_" + $("#board").data("project-id"); + return JSON.parse(Kanboard.GetStorageItem(storageKey)) || []; + } + + // Reload the swimlane states (shown/hidden) after an ajax call + jQuery(document).ajaxComplete(function() { + + getAllHidden().map(function(swimlaneId) { + collapse(swimlaneId); + }); + }); + + // Reload the swimlane states (shown/hidden) after page refresh + jQuery(document).ready(function() { + + getAllHidden().map(function(swimlaneId) { + collapse(swimlaneId); + }); + }); + + // Clicking on Show/Hide icon fires this. + jQuery(document).on('click', ".board-swimlane-toggle", function(e) { + e.preventDefault(); + + var swimlaneId = $(this).data('swimlane-id'); + + if (isHidden(swimlaneId)) { + unhide(swimlaneId); + expand(swimlaneId); + } + else { + hide(swimlaneId); + collapse(swimlaneId); + } + }); + +})(); -- cgit v1.2.3