summaryrefslogtreecommitdiff
path: root/assets/js/src
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-02-01 11:05:07 -0500
committerFrederic Guillot <fred@kanboard.net>2015-02-01 11:05:07 -0500
commitbe4e90e319cf65b368bb866165abc8d1fd4e074f (patch)
treed7170a150abf37644654b2c35910dee54663eb7b /assets/js/src
parent9a98013736f1acebbb62c5fce6a10c02e32b516f (diff)
Add collapsible swimlanes (merge and improve pull-request #565)
Diffstat (limited to 'assets/js/src')
-rw-r--r--assets/js/src/swimlane.js90
1 files changed, 90 insertions, 0 deletions
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);
+ }
+ });
+
+})();