;(function($,_,undefined){"use strict";ips.controller.register('lego.admin.clubs.lugTable',{initialize:function(){this.on('scroll',this.scrollTableWrap);this.on(document,'contentChange',this.checkContentChange);this.on(document,'click','[data-action="expandTable"]',this.expandTable);this.on(document,'menuOpened',this.menuOpened);this.on(document,'openDialog',this.dialogOpened);this.on(document,'submit','#dateForm',this.submitDateForm);this.on(window,'resize',this.windowResize);this.on(document,'click','.legoLugTable_dummyColumn',this.clickCell);this.setup();},setup:function(){this._expanded=false;this._table=this.scope.find('#legoLugTable');this._dummyColumns=this.scope.parent().find('#legoLugInfoColumns');this._headerHeight=this._table.find('th').first().outerHeight();this.setUpTableColumns();},checkContentChange:function(e,data){this.setUpTableColumns();},windowResize:function(){this.setUpTableColumns();},submitDateForm:function(e){e.preventDefault();var startDate=$('[name="dateFrom"]').val();var endDate=$('[name="dateTo"]').val();var baseUrl=$('#filterDate').attr('data-baseUrl');if(!startDate||!endDate){alert("You must provide both start and end dates");return;}
var newUrl=baseUrl+'&dateFrom='+startDate+'&dateTo='+endDate;window.location=newUrl;},clickCell:function(e){Debug.log('here');var cell=$(e.currentTarget);if(cell.attr('data-link')){window.location=cell.attr('data-link');}},setUpTableColumns:function(){var self=this;var firstCells=this._table.find('tr td:first-child');var header=this._table.find('tr th:first-child');var currentWidth=firstCells.first().outerWidth();var dummyCells=[];var copyCell=function(cell){var id=cell.identify().attr('id');var height=cell.outerHeight();var existingDummy=self.scope.find(id+'_dummy');var viewLink=cell.closest('tr').find('[data-controlstrip-action="open"]').attr('href');if(existingDummy.length){existingDummy.css({height:height+'px',width:currentWidth+'px'});dummyCells.push(existingDummy);}else{var copy=$('<div />').css({height:height+'px',width:currentWidth+'px'}).addClass('legoLugTable_dummyColumn').append($('<div />').html(cell.html())).attr('id',id+'_dummy').attr('data-link',viewLink);dummyCells.push(copy);}};copyCell(header);firstCells.each(function(){copyCell($(this))});this._dummyColumns.empty().append(dummyCells);},scrollTableWrap:function(e){var scrollLeftOffset=$(e.currentTarget).scrollLeft();var scrollTopOffset=$(e.currentTarget).scrollTop();if(scrollLeftOffset>0){this._dummyColumns.show();}else if(scrollLeftOffset==0){this._dummyColumns.hide();}
if(scrollTopOffset>0){this._dummyColumns.css({top:(scrollTopOffset*-1)+'px'});}else{this._dummyColumns.css({top:0});}},expandTable:function(e){e.preventDefault();if(!this._expanded){$('#legoMainTable').addClass('fullscreen');$('#acpMainLayout').css({zIndex:10000});$(e.currentTarget).removeClass('ipsButton_veryLight').addClass('ipsButton_primary');this._expanded=true;}else{$('#legoMainTable').removeClass('fullscreen');$('#acpMainLayout').css({zIndex:1500});$(e.currentTarget).removeClass('ipsButton_primary').addClass('ipsButton_veryLight');this._expanded=false;}},menuOpened:function(e,data){if(this._expanded){data.menu.css({zIndex:parseInt(data.menu.css('zIndex'))+5000});}},dialogOpened:function(e,data){if(this._expanded){$('.ipsModal').css({zIndex:parseInt($('.ipsModal').css('zIndex'))+5000});data.dialog.css({zIndex:parseInt(data.dialog.css('zIndex'))+5000});}}});}(jQuery,_));;