diff options
Diffstat (limited to 'assets/js/src/swimlane.js')
-rw-r--r-- | assets/js/src/swimlane.js | 111 |
1 files changed, 44 insertions, 67 deletions
diff --git a/assets/js/src/swimlane.js b/assets/js/src/swimlane.js index 212d6d36..ce18dbfa 100644 --- a/assets/js/src/swimlane.js +++ b/assets/js/src/swimlane.js @@ -1,90 +1,67 @@ -(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');
- }
+function Swimlane() {
+}
- // 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)) || [];
+Swimlane.prototype.getStorageKey = function() {
+ return "hidden_swimlanes_" + $("#board").data("project-id");
+};
- hiddenSwimlaneIds.push(id);
+Swimlane.prototype.expand = function(swimlaneId) {
+ var swimlaneIds = this.getAllCollapsed();
+ var index = swimlaneIds.indexOf(swimlaneId);
- Kanboard.SetStorageItem(storageKey, JSON.stringify(hiddenSwimlaneIds));
+ if (index > -1) {
+ swimlaneIds.splice(index, 1);
}
- // 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);
+ localStorage.setItem(this.getStorageKey(), JSON.stringify(swimlaneIds));
- if (index > -1) {
- hiddenSwimlaneIds.splice(index, 1);
- }
+ $('.swimlane-row-' + swimlaneId).css('display', 'table-row');
+ $('.show-icon-swimlane-' + swimlaneId).css('display', 'none');
+ $('.hide-icon-swimlane-' + swimlaneId).css('display', 'inline');
+};
- Kanboard.SetStorageItem(storageKey, JSON.stringify(hiddenSwimlaneIds));
- }
+Swimlane.prototype.collapse = function(swimlaneId) {
+ var swimlaneIds = this.getAllCollapsed();
- // Check if swimlane Id is hidden. Anything > -1 means hidden.
- function isHidden(id)
- {
- return getAllHidden().indexOf(id) > -1;
+ if (swimlaneIds.indexOf(swimlaneId) < 0) {
+ swimlaneIds.push(swimlaneId);
+ localStorage.setItem(this.getStorageKey(), JSON.stringify(swimlaneIds));
}
- // Gets all swimlane Ids that are hidden
- function getAllHidden()
- {
- var storageKey = "hidden_swimlanes_" + $("#board").data("project-id");
- return JSON.parse(Kanboard.GetStorageItem(storageKey)) || [];
- }
+ $('.swimlane-row-' + swimlaneId).css('display', 'none');
+ $('.show-icon-swimlane-' + swimlaneId).css('display', 'inline');
+ $('.hide-icon-swimlane-' + swimlaneId).css('display', 'none');
+};
- // Reload the swimlane states (shown/hidden) after an ajax call
- jQuery(document).ajaxComplete(function() {
+Swimlane.prototype.isCollapsed = function(swimlaneId) {
+ return this.getAllCollapsed().indexOf(swimlaneId) > -1;
+};
- getAllHidden().map(function(swimlaneId) {
- collapse(swimlaneId);
- });
- });
+Swimlane.prototype.getAllCollapsed = function() {
+ return JSON.parse(localStorage.getItem(this.getStorageKey())) || [];
+};
- // Reload the swimlane states (shown/hidden) after page refresh
- jQuery(document).ready(function() {
+Swimlane.prototype.refresh = function() {
+ var swimlaneIds = this.getAllCollapsed();
- getAllHidden().map(function(swimlaneId) {
- collapse(swimlaneId);
- });
- });
+ for (var i = 0; i < swimlaneIds.length; i++) {
+ this.collapse(swimlaneIds[i]);
+ }
+};
- // Clicking on Show/Hide icon fires this.
- jQuery(document).on('click', ".board-swimlane-toggle", function(e) {
+Swimlane.prototype.listen = function() {
+ var self = this;
+
+ $(document).on('click', ".board-swimlane-toggle", function(e) {
e.preventDefault();
var swimlaneId = $(this).data('swimlane-id');
- if (isHidden(swimlaneId)) {
- unhide(swimlaneId);
- expand(swimlaneId);
+ if (self.isCollapsed(swimlaneId)) {
+ self.expand(swimlaneId);
}
else {
- hide(swimlaneId);
- collapse(swimlaneId);
+ self.collapse(swimlaneId);
}
});
-
-})();
+};
|