(function(){"use strict";BX.namespace("BX.Kanban");BX.Kanban.Grid=function(t){if(!BX.type.isPlainObject(t)){throw new Error("BX.Kanban.Grid: 'options' is not an object.")}this.options=t;if(!BX.type.isDomNode(t.renderTo)){throw new Error("BX.Kanban.Grid: 'renderTo' is not a DOMNode.")}this.renderTo=t.renderTo;this.rendered=false;this.layout={outerContainer:null,innerContainer:null,gridContainer:null,earLeft:null,earRight:null,emptyStub:null,loader:null,leftShadow:null,rightShadow:null};this.emptyStubItems=t.emptyStubItems;this.itemType=this.getItemType(t.itemType);this.columnType=this.getColumnType(t.columnType);this.messages=BX.type.isPlainObject(t.messages)?t.messages:Object.create(null);this.columns=Object.create(null);this.columnsOrder=[];this.items=Object.create(null);this.data=BX.type.isPlainObject(t.data)?t.data:Object.create(null);this.bgColor=BX.Kanban.Utils.isValidColor(t.bgColor)||t.bgColor==="transparent"?t.bgColor:"ffffff";this.earTimer=null;this.firstRenderComplete=null;this.dragMode=BX.Kanban.DragMode.NONE;this.multiSelect=t.multiSelect;this.ahaMode=null;this.selectedItems=[];this.addItemTitleText=t.addItemTitleText;this.addDraftItemInfo=t.addDraftItemInfo;this.columnsRevert=t.columnsRevert;this.canAddColumn=false;this.canEditColumn=false;this.canSortColumn=false;this.canRemoveColumn=false;this.canAddItem=false;this.canSortItem=false;this.dropZoneArea=new BX.Kanban.DropZoneArea(this,{dropZoneType:t.dropZoneType,dropZoneTimeout:t.dropZoneTimeout});this.data=Object.create(null);this.setData(t.data);this.loadData(t);if(t.events){for(var e in t.events){if(t.events.hasOwnProperty(e)){BX.addCustomEvent(this,e,t.events[e])}}}this.bindEvents();BX.addCustomEvent(this,"Kanban.Grid:onItemDragStart",BX.delegate(this.onItemDragStart,this));BX.addCustomEvent(this,"Kanban.Grid:onItemsDragStart",BX.delegate(this.onItemDragStart,this));BX.addCustomEvent(this,"Kanban.Grid:onItemDragStop",BX.delegate(this.onItemDragStop,this));BX.addCustomEvent(this,"Kanban.Grid:onColumnDragStart",BX.delegate(this.onColumnDragStart,this));BX.addCustomEvent(this,"Kanban.Grid:onColumnDragStop",BX.delegate(this.onColumnDragStop,this));if(this.multiSelect){BX.addCustomEvent(this,"Kanban.Item:select",this.addSelectedItem.bind(this));BX.addCustomEvent(this,"Kanban.Item:select",this.adjustMultiSelectMode.bind(this));BX.addCustomEvent(this,"Kanban.Item:unSelect",this.removeSelectedItem.bind(this));BX.addCustomEvent(this,"Kanban.Item:unSelect",this.adjustMultiSelectMode.bind(this));window.addEventListener("keydown",function(t){if(BX.Kanban.Utils.getKeyDownName(t.keyCode)==="Escape"&&this.getSelectedItems().length>0){this.cleanSelectedItems();this.adjustMultiSelectMode();BX.PreventDefault(t)}}.bind(this));window.addEventListener("click",function(t){if(BX.findParent(t.target,{attr:{"data-element":"kanban-element"}})||t.target.getAttribute("data-element")==="kanban-element"){return}this.cleanSelectedItems();this.adjustMultiSelectMode()}.bind(this))}};BX.Kanban.DragMode={NONE:0,ITEM:1,COLUMN:2};BX.Kanban.Grid.prototype={addColumn:function(t){t=t||{};if(this.getColumn(t.id)!==null){return null}var e=this.getColumnType(t.type);var n=new e(t);if(!(n instanceof BX.Kanban.Column)){throw new Error("Column type must be an instance of BX.Kanban.Column")}n.setGrid(this);this.columns[n.getId()]=n;var i=this.getColumn(t.targetId);var a=BX.util.array_search(i,this.columnsOrder);if(a>=0){this.columnsOrder.splice(a,0,n)}else{this.columnsOrder.push(n)}if(this.isRendered()){if(i){this.getGridContainer().insertBefore(n.render(),i.getContainer())}else{this.getGridContainer().appendChild(n.render())}}return n},getAddItemTitleText:function(){return this.addItemTitleText},getAddDraftItemInfo:function(){return this.addDraftItemInfo},isAhaMode:function(){return this.ahaMode},onAhaMode:function(){this.getGridContainer().classList.add("main-kanban-aha");this.ahaMode=true},offAhaMode:function(){this.getGridContainer().classList.remove("main-kanban-aha");this.ahaMode=false},removeColumn:function(t){t=this.getColumn(t);if(!t){return false}this.removeColumnItems(t);this.columnsOrder=this.columnsOrder.filter((function(e){return t!==e}));delete this.columns[t.getId()];BX.remove(t.getContainer());return true},bindEvents:function(){},updateColumn:function(t,e){t=this.getColumn(t);if(!t){return false}t.setOptions(e);t.render();return true},getNextColumnSibling:function(t){var e=this.getColumnIndex(t);var n=this.getColumns();return e!==-1&&n[e+1]?n[e+1]:null},getPreviousColumnSibling:function(t){var e=this.getColumnIndex(t);var n=this.getColumns();return e>0&&n[e-1]?n[e-1]:null},adjustMultiSelectMode:function(){if(this.selectedItems.length>0){this.onMultiSelect()}else{this.offMultiSelect()}},addSelectedItem:function(t){if(!(t instanceof BX.Kanban.Item)){throw new Error("Item type must be an instance of BX.Kanban.Item")}this.selectedItems.push(t)},removeSelectedItem:function(t){if(!(t instanceof BX.Kanban.Item)){throw new Error("Item type must be an instance of BX.Kanban.Item")}if(this.selectedItems.indexOf(t)>=0){this.selectedItems.splice(this.selectedItems.indexOf(t),1)}},addItem:function(t){t=t||{};var e=this.getColumn(t.columnId);if(!e){return null}var n=this.getItemType(t.type);var i=new n(t);if(!(i instanceof BX.Kanban.Item)){throw new Error("Item type must be an instance of BX.Kanban.Item")}if(this.items[i.getId()]){return null}i.setGrid(this);this.items[i.getId()]=i;var a=this.getItem(t.targetId);e.addItem(i,a);t.type==="BX.Kanban.DraftItem"?BX.onCustomEvent(this,"Kanban.Grid:addDraftItem",[i]):BX.onCustomEvent(this,"Kanban.Grid:addItem",[i]);return i},removeItem:function(t){var e=this.getItem(t);if(e){var n=e.getColumn();delete this.items[e.getId()];n.removeItem(e);e.dispose()}return e},removeColumnItems:function(t){t=this.getColumn(t);var e=t.getItems();t.removeItems();e.forEach((function(t){this.removeItem(t)}),this)},removeItems:function(){this.getColumns().forEach((function(t){this.removeColumnItems(t)}),this)},updateItem:function(t,e){t=this.getItem(t);if(!t){return false}if(BX.Kanban.Utils.isValidId(e.columnId)&&e.columnId!==t.getColumn().getId()){this.moveItem(t,this.getColumn(e.columnId),this.getItem(e.targetId))}var n=["UPDATE",{task:t,options:e}];BX.onCustomEvent(window,"tasksTaskEvent",n);t.setOptions(e);t.render();return true},hideItem:function(t){t=this.getItem(t);if(!t||!t.isVisible()){return false}t.setOptions({visible:false});if(t.isCountable()){t.getColumn().decrementTotal()}t.getColumn().render();return true},unhideItem:function(t){t=this.getItem(t);if(!t||t.isVisible()){return false}t.setOptions({visible:true});if(t.isCountable()){t.getColumn().incrementTotal()}t.getColumn().render();return true},getSelectedItems:function(){return this.selectedItems},cleanSelectedItems:function(){for(var t=0;t'+''+""});return this.layout.loader},adjustLayout:function(){this.adjustWidth();this.adjustHeight();this.adjustEars()},adjustEars:function(){var t=this.getGridContainer();var e=t.scrollLeft;var n=e>0;var i=t.scrollWidth>Math.round(e+t.offsetWidth);this.getOuterContainer().classList[n?"add":"remove"]("main-kanban-left-ear-shown");this.getOuterContainer().classList[i?"add":"remove"]("main-kanban-right-ear-shown")},adjustWidth:function(){this.getOuterContainer().style.width=this.renderTo.offsetWidth+"px"},adjustHeight:function(){var t=this.getOuterContainer();var e=this.getInnerContainer();if(t.getBoundingClientRect().top>=15){var n=document.documentElement.clientHeight-e.getBoundingClientRect().top;e.style.height=n+"px";if(e.classList.contains("main-kanban-fixed")){BX.onCustomEvent(this,"Kanban.Grid:onFixedModeEnd",[this])}t.style.minHeight=document.documentElement.clientHeight+"px";e.style.removeProperty("top");e.style.removeProperty("left");e.style.removeProperty("width");e.classList.remove("main-kanban-fixed")}else{if(!e.classList.contains("main-kanban-fixed")){BX.onCustomEvent(this,"Kanban.Grid:onFixedModeStart",[this])}var i=this.renderTo.getBoundingClientRect();e.style.left=i.left+"px";e.style.width=i.width+"px";e.style.removeProperty("height");e.classList.add("main-kanban-fixed")}},adjustEmptyStub:function(){var t=true;var e=this.getItems();for(var n in e){var i=e[n];if(i.isVisible()){t=false;break}}this.getInnerContainer().classList[t?"add":"remove"]("main-kanban-no-data-mode")},moveSelectedItems:function(t,e){t=this.getColumn(t);e=this.getItem(e);if(this.selectedItems.length>0||!t||!e){return false}t.addSelectedItems(this.selectedItems,e)},moveItem:function(t,e,n){t=this.getItem(t);e=this.getColumn(e);n=this.getItem(n);if(!t||!e||t===n){return false}var i=t.getColumn();i.removeItem(t);e.addItem(t,n);return true},moveItems:function(t,e,n){var i=[];for(var a in t){var s=this.getColumn(t[a].columnId);if(i.indexOf(s)===-1){i.push(s)}}for(var r in i){var o=[];for(var l in t){if(i[r].getId()===t[l].getColumnId()){o.push(t[l])}}i[r].removeSelectedItems(o)}e.addItems(t,n);return true},moveColumn:function(t,e){t=this.getColumn(t);e=this.getColumn(e);if(!t||t===e){return false}var n=BX.util.array_search(t,this.columnsOrder);this.columnsOrder.splice(n,1);var i=BX.util.array_search(e,this.columnsOrder);if(i>=0){this.columnsOrder.splice(i,0,t);if(this.isRendered()){t.getContainer().parentNode.insertBefore(t.getContainer(),e.getContainer())}}else{this.columnsOrder.push(t);if(this.isRendered()){t.getContainer().parentNode.appendChild(t.getContainer())}}return true},canAddColumns:function(){return this.canAddColumn},canEditColumns:function(){return this.canEditColumn},canSortColumns:function(){return this.canSortColumn},canRemoveColumns:function(){return this.canRemoveColumn},canAddItems:function(){return this.canAddItem},canSortItems:function(){return this.canSortItem},scrollToRight:function(){this.earTimer=setInterval(function(){this.getGridContainer().scrollLeft+=10}.bind(this),20)},scrollToLeft:function(){this.earTimer=setInterval(function(){this.getGridContainer().scrollLeft-=10}.bind(this),20)},stopAutoScroll:function(){clearInterval(this.earTimer);jsDD.refreshDestArea()},getDragMode:function(){return this.dragMode},getDragModeCode:function(t){for(var e in BX.Kanban.DragMode){if(BX.Kanban.DragMode[e]===t){return e}}return null},setDragMode:function(t){var e=this.getDragModeCode(t);if(e!==null){this.getOuterContainer().classList.add("main-kanban-drag-mode-"+e.toLowerCase());this.dragMode=t}},resetDragMode:function(){var t=this.getDragModeCode(this.getDragMode());if(t!==null){this.getOuterContainer().classList.remove("main-kanban-drag-mode-"+t.toLowerCase())}this.dragMode=BX.Kanban.DragMode.NONE},onItemDragStart:function(t){if(this.multiSelect&&this.selectedItems.length>0){for(var t in this.selectedItems){this.selectedItems[t].disabledItem()}}this.setDragMode(BX.Kanban.DragMode.ITEM);var e=this.getItems();for(var n in e){e[n].enableDropping()}this.getColumns().forEach((function(t){t.enableDropping()}));this.getDropZoneArea().emptyAll();this.getDropZoneArea().show()},onItemDragStop:function(t){if(this.multiSelect&&this.selectedItems.length>0){for(var t in this.selectedItems){this.selectedItems[t].unDisabledItem()}}this.resetDragMode();this.getDropZoneArea().hide()},onColumnDragStart:function(t){this.setDragMode(BX.Kanban.DragMode.COLUMN)},onColumnDragStop:function(t){this.resetDragMode()},getEventPromise:function(t,e,n,i){var a=[];e=BX.type.isArray(e)?e:[];BX.onCustomEvent(this,t,[a].concat(e));var s=new BX.Promise;var r=s;for(var o=0;o