(self.webpackChunktimetrex=self.webpackChunktimetrex||[]).push([["ttgrid-TTGrid"],{2185:(__unused_webpack_module,__unused_webpack_exports,__webpack_require__)=>{eval("/* provided dependency */ var $ = __webpack_require__(9755);\n/**\n * @author: joshr@timetrex.com\n * @description wrapper class for jqgrid in timetrex.\n * Requires free-jqgrid 4.15.4+ and jquery 3.3.1+\n *\n * @param setup\n * @constructor\n */\nTTGrid = function( table_id, setup, column_info_array ) {\n\tthis.getGridId = function() {\n\t\treturn this.ui_id;\n\t};\n\n\tthis.setTableIDElement = function() {\n\t\tthis.table_id_element = $( '#' + this.ui_id );\n\t\treturn true;\n\t};\n\n\tthis.getTableIDElement = function() {\n\t\treturn this.table_id_element;\n\t};\n\n\tif ( !table_id || !setup || !column_info_array ) {\n\t\tDebug.Text( 'ERROR: constructor requires all 3 arguments', 'TTGrid.js', 'TTGrid', 'constructor', 10 );\n\t\treturn;\n\t}\n\n\tthis.ui_id = table_id;\n\n\t// Issue #2891 - Forcing GridUnload can cause grids inside a AComboBox to disappear after repeated opening. Check for container_selector is to mitigate that.\n\tif ( !setup.container_selector ) {\n\t\t// We are unloading grids with the same ID if they exist to help prevent: Uncaught TypeError: Failed to execute 'replaceChild' on 'Node': parameter 2 is not of type 'Node'.\n\t\t// Looping through array in reverse to make sure no index issues after splicing.\n\t\tfor ( var i = LocalCacheData.resizeable_grids.length - 1; i >= 0; i-- ) {\n\t\t\tif ( LocalCacheData.resizeable_grids[i] != null && LocalCacheData.resizeable_grids[i].grid != null && LocalCacheData.resizeable_grids[i].ui_id == this.ui_id ) {\n\t\t\t\tLocalCacheData.resizeable_grids[i].grid.jqGrid( 'GridUnload' );\n\t\t\t\tLocalCacheData.resizeable_grids.splice( i, 1 );\n\t\t\t} else if ( LocalCacheData.resizeable_grids[i] == null || LocalCacheData.resizeable_grids[i].grid == null ) {\n\t\t\t\t// LocalCacheData.resizeable_grids array gets full of null values from resize event and we are making sure to clear it out.\n\t\t\t\tLocalCacheData.resizeable_grids.splice( i, 1 );\n\t\t\t}\n\t\t}\n\t}\n\n\tvar max_height = null;\n\n\tthis.setTableIDElement();\n\tvar table_div = this.getTableIDElement();\n\n\tthis.grid = null;\n\n\tif ( table_div[0] == false ) {\n\t\tDebug.Text( 'ERROR: table_id not found in DOM', 'TTGrid.js', 'TTGrid', 'constructor', 10 );\n\t\treturn;\n\t}\n\n\t//Default grid settings.\n\tvar default_setup = {\n\t\tcontainer_selector: 'body',\n\t\tsub_grid_mode: false,\n\t\taltRows: true,\n\t\tdata: [],\n\t\tdatatype: 'local',\n\t\t//quickEmpty: 'true', //Default is 'quickest', might fix JS Exception: Uncaught TypeError: Failed to execute 'replaceChild' on 'Node': parameter 2 is not of type 'Node', but causes this instead: TTGrid.js?v=11.6.1-20191108:99 Uncaught TypeError: Cannot read property 'cells' of undefined\n\t\tsortable: false,\n\t\theight: table_div.parents( '.view' ).height(),\n\t\twidth: table_div.parent().width(),\n\t\trowNum: 10000,\n\t\tcolNames: [],\n\t\tcolModel: column_info_array,\n\t\tmultiselect: true,\n\t\tmultiselectWidth: 22,\n\t\tmultiboxonly: true,\n\t\tviewrecords: true,\n\t\tautoencode: true,\n\t\tscrollOffset: 0,\n\t\tverticalResize: true, //when the grid resizes do we reisize it vertically? needed for timesheet and subgrid views.\n\t\tresizeGrid: true,\n\t\twinMultiSelect: true\n\t\t// resizeStop: function(width, index){\n\t\t// \t//$this.setGridColumnsWidth(width, index);\n\t\t// }\n\t};\n\n\tif ( setup.max_height === true ) {\n\t\tsetup.max_height = max_height;\n\t}\n\n\tif ( setup ) {\n\t\tsetup = $.extend( {}, default_setup, setup );\n\t} else {\n\t\tsetup = default_setup;\n\t}\n\n\tthis.setup = setup;\n\n\ttable_div.empty(); //should unbind all events bound to the grid.\n\tthis.grid = table_div.jqGrid( setup );\n\n\tLocalCacheData.resizeable_grids.push( this );\n\n\tif ( setup.winMultiSelect === true ) {\n\t\tthis.grid.winMultiSelect();\n\t}\n\n\t//turn off grid resize event (for schedule grids that need to be rebuilt on every resize)\n\tthis.noResize = function() {\n\t\tthis.setup.onResizeGrid = false;\n\t};\n\n\t/**\n\t *\n\t * @param data\n\t */\n\tthis.setData = function( data, clear_grid ) {\n\t\tif ( this.grid ) {\n\t\t\t//Clear grid by default.\n\t\t\tclear_grid = ( clear_grid == null ) ? true : clear_grid;\n\t\t\tif ( clear_grid == true ) {\n\t\t\t\tthis.grid.clearGridData();\n\t\t\t}\n\n\t\t\t//ACombo might send data as \"true\" when the unselected grid is blank and \"Show All\" is clicked. Prevent anything but an array from being passed into setGridParam( 'data' ).\n\t\t\tif ( Array.isArray( data ) == false ) {\n\t\t\t\tdata = [];\n\t\t\t}\n\n\t\t\tthis.grid.setGridParam( { 'data': data } ).trigger( 'reloadGrid' );\n\t\t\t//this.setGridColumnsWidth();\n\t\t} else {\n\t\t\tthrow( 'ERROR: Grid is not ready yet.' );\n\t\t}\n\t};\n\tthis.getData = function() {\n\t\treturn this.getGridParam( 'data' );\n\t};\n\n\tthis.getSetup = function() {\n\t\treturn this.getGridParam( 'data' );\n\t};\n\n\tthis.getHeight = function() {\n\t\treturn $( this.grid ).height();\n\t};\n\tthis.getWidth = function() {\n\t\treturn $( this.grid ).width();\n\t};\n\n\t/**\n\t *\n\t * @param value\n\t */\n\tthis.deleteRow = function( value ) {\n\t\tthis.grid.jqGrid( 'delRowData', value );\n\t};\n\n\tthis.resetSelection = function() {\n\t\tthis.grid.resetSelection();\n\t};\n\n\tthis.setSelection = function( x1, y1, x2, y2, noScale ) {\n\t\tthis.grid.setSelection( x1, y1, x2, y2, noScale );\n\t};\n\n\tthis.getGridParam = function( parameter_name ) {\n\t\treturn this.grid.getGridParam( parameter_name );\n\t};\n\n\tthis.setGridParam = function( parameter_name, value ) {\n\t\treturn this.grid.setGridParam( parameter_name, value );\n\t};\n\n\tthis.unload = function() {\n\t\tif ( this.grid ) {\n\t\t\tthis.grid.jqGrid( 'GridUnload' );\n\t\t\tthis.grid = null;\n\t\t}\n\t\treturn true;\n\t};\n\n\tthis.clearGridData = function() {\n\t\tthis.grid.jqGrid( 'clearGridData', true );\n\t};\n\n\tthis.reloadGrid = function() {\n\t\tthis.grid.trigger( 'reloadGrid' );\n\t};\n\n\tthis.getRecordFromGridById = function( id ) {\n\t\tvar data = this.grid.getGridParam( 'data' );\n\t\tvar result = null;\n\t\t/* jshint ignore:start */\n\t\t//id could be string or number.\n\t\t$.each( data, function( index, value ) {\n\n\t\t\tif ( value['_id_'] == id ) {\n\t\t\t\tresult = Global.clone( value );\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t} );\n\t\t/* jshint ignore:end */\n\n\t\tif ( result ) {\n\t\t\tresult.id = result['_id_'];\n\t\t}\n\t\treturn result;\n\n\t};\n\n\tthis.getGridWidth = function() {\n\t\tif ( this.grid ) {\n\t\t\treturn this.grid.width();\n\t\t}\n\t\treturn 0;\n\t};\n\n\tthis.setGridWidth = function( w, inner_width ) {\n\t\tif ( this.grid ) {\n\t\t\tif ( inner_width > w ) {\n\t\t\t\tw = inner_width;\n\t\t\t}\n\t\t\tthis.grid.setGridWidth( w );\n\t\t}\n\t};\n\n\tthis.getGridHeight = function() {\n\t\tif ( this.grid ) {\n\t\t\treturn this.grid.height();\n\t\t}\n\t\treturn 0;\n\t};\n\tthis.setGridHeight = function( h ) {\n\t\tif ( this.setup.static_height ) {\n\t\t\th = this.setup.static_height;\n\t\t}\n\n\t\tif ( this.grid ) {\n\t\t\tthis.grid.setGridHeight( h );\n\t\t}\n\t};\n\n\tthis.setRowData = function( id, new_record ) {\n\t\tthis.grid.setRowData( id, new_record );\n\t};\n\n\tthis.getRowData = function( row_id ) {\n\t\tvar row = false;\n\n\t\tvar row_data = this.getData();\n\n\t\tfor ( var i in row_data ) {\n\t\t\tif ( row_data[i].id == row_id ) {\n\t\t\t\trow = row_data[i];\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn row;\n\t};\n\n\tthis.getColumnModel = function() {\n\t\treturn this.getGridParam( 'colModel' );\n\t};\n\n\tthis.setColumnModel = function( val ) {\n\t\tthis.getGridParam( 'colModel', val );\n\t};\n\n\tthis.grid2csv = function( filename ) {\n\t\t// TODO: Add in more robust quote escaping to handle data strings that have quotes. Currently we are just wrapping everything in double quotes.\n\n\t\tlet csv_data = [];\n\n\t\t// Get grid data for csv.\n\t\t// Column headers are in a different table. Seems to be a jqGrid thing?\n\t\t// Parsing column headers using aria-describedby on the first none blank (2nd) which links to the id of the header and from there gets the textContent.\n\t\tlet i = 1;\n\t\tlet headers = [];\n\t\tfor ( let tr of document.querySelectorAll( '#' + this.getGridId() + ' tr' ) ) {\n\t\t\tlet row = [];\n\t\t\tfor ( let td of tr.querySelectorAll( 'td' ) ) {\n\t\t\t\trow.push( '\"' + td.textContent.trim() + '\"' );\n\t\t\t\tif ( i === 2 ) {\n\t\t\t\t\t// Column headers sometimes contain HTML such as Claim
Dependents.\n\t\t\t\t\t// Using a temporary element to replace
with a space and then grabbing the textContent to strip the HTML.\n\t\t\t\t\tlet temp_element = document.createElement( 'div' );\n\t\t\t\t\ttemp_element.innerHTML = document.getElementById( td.getAttribute( 'aria-describedby' ) ).innerHTML.replace( '
', ' ' );\n\t\t\t\t\theaders.push( '\"' + temp_element.textContent.trim() + '\"' );\n\t\t\t\t}\n\t\t\t}\n\t\t\tcsv_data.push( row.join( ',' ) );\n\t\t\ti++;\n\t\t}\n\n\t\t// Replace blank row with table headers\n\t\tcsv_data[0] = headers.join( ',' );\n\n\t\tlet csv_content = csv_data.join( '\\r\\n' );\n\n\t\tGlobal.JSFileDownload( filename + '.csv', csv_content, 'text/csv;encoding:utf-8' );\n\n\t}\n\n\tthis.getRecordCount = function() {\n\t\tif ( !this.grid ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.grid.getGridParam( 'reccount' );\n\t};\n\n\t//Gets a single row\n\tthis.getSelectedRow = function() {\n\t\tif ( !this.grid ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tvar result = this.grid.getGridParam( 'selrow' );\n\n\t\tif ( !result ) {\n\t\t\tresult = false;\n\t\t}\n\n\t\treturn result;\n\t};\n\n\t//Gets an array of rows if multiple are selected.\n\tthis.getSelectedRows = function() {\n\t\tif ( !this.grid ) {\n\t\t\treturn []; //Return empty array so .length on the result doesn't fail with Cannot read property 'length' of undefined\n\t\t}\n\n\t\tvar result = this.grid.getGridParam( 'selarrrow' );\n\n\t\tif ( !result ) {\n\t\t\tresult = [];\n\t\t}\n\n\t\treturn result;\n\t};\n\n\tthis.getSelection = function() {\n\t\tvar tds = this.grid.find( 'td.ui-state-highlight' );\n\n\t\tvar selection = [];\n\t\tfor ( var x = 0; x < tds.length; x++ ) {\n\t\t\tselection.push( {\n\t\t\t\ttr: $( tds[x] ).parent( 'tr' ).index(),\n\t\t\t\ttd: $( tds[x] ).index()\n\t\t\t} );\n\t\t}\n\t\treturn selection;\n\t},\n\n\t\tthis.setTimesheetSelection = function( selection_obj ) {\n\t\t\t//This is currently broken, it highlights the cells, but they aren't actually considered \"selected\".\n\t\t\t// So if you go to Attendance -> TimeSheet, select two cells, Mass Edit them, click Save, the \"Mass Edit\" is no longer available to be clicked again.\n\t\t\t// As well if you hold in SHIFT to try and expand the selection (select more cells), that doesn't work either.\n\t\t\tvar trs = this.grid.find( 'tr' );\n\t\t\tfor ( var i = 0; i < selection_obj.length; i++ ) {\n\t\t\t\tfor ( var x = 0; x < trs.length; x++ ) {\n\t\t\t\t\tif ( $( trs[x] ).index() == selection_obj[i].tr ) {\n\t\t\t\t\t\tvar tds = $( trs[x] ).find( 'td' );\n\t\t\t\t\t\tfor ( var w = 0; w < tds.length; w++ ) {\n\t\t\t\t\t\t\tif ( $( tds[w] ).index() == selection_obj[i].td ) {\n\t\t\t\t\t\t\t\t$( tds[w] ).addClass( 'ui-state-highlight' );\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\tthis.setGridColumnsWidth = function( column_model, options ) {\n\t\t// this.grid.autoResizeAllColumns();\n\t\t// return;\n\t\tif ( this.setup.treeGrid || this.setup.tree_mode ) {\n\t\t\tthis.setGridWidth( $( this.setup.container_selector ).width() - 12 );\n\t\t\treturn;\n\t\t}\n\n\t\tif ( typeof options === 'undefined' ) {\n\t\t\toptions = {};\n\t\t}\n\n\t\tif ( this.setup.container_selector && ( !options.min_grid_width || options.min_grid_width == 0 ) ) {\n\t\t\tvar parent_container = this.grid.parents( this.setup.container_selector ).find( '.edit-view-tab' );\n\t\t\tif ( parent_container.length > 0 ) {\n\t\t\t\t//Sub-View grid, check if parent div is visible, and if not don't bother resizing grid.\n\t\t\t\tif ( parent_container.is( ':visible' ) === true ) {\n\t\t\t\t\toptions.min_grid_width = parent_container.innerWidth();\n\t\t\t\t} else {\n\t\t\t\t\tDebug.Text( ' Parent container of grid is not visible, skip setting column widths...', 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t//Main grid\n\t\t\t\tlet grid_parent = $( '#gbox_' + this.ui_id );\n\t\t\t\tif ( grid_parent.length !== 0 ) {\n\t\t\t\t\toptions.min_grid_width = grid_parent.parent().width();\n\t\t\t\t} else {\n\t\t\t\t\toptions.min_grid_width = this.grid.parents( this.setup.container_selector ).innerWidth();\n\t\t\t\t}\n\n\t\t\t}\n\t\t}\n\n\t\tif ( options.min_grid_width == 0 || options.min_grid_width == 'undefined' ) { //fallback width so it's never sized to zero when render timing collides\n\t\t\toptions.min_grid_width = $( 'body' ).innerWidth();\n\t\t}\n\n\t\t//Adjust for the vertical scrollbar offset that can occur when the items per page always exceeds the screen height.\n\t\tif ( Global.isVerticalScrollBarRequired( this.grid.parents( '.ui-jqgrid-bdiv' )[0] ) ) {\n\t\t\toptions.min_grid_width -= Global.getScrollbarWidth();\n\t\t}\n\n\t\tif ( !options.max_grid_width ) {\n\t\t\toptions.max_grid_width = null; //No maximum.\n\t\t}\n\n\t\tif ( options.max_grid_width && options.max_grid_width < options.min_grid_width ) {\n\t\t\toptions.min_grid_width = options.max_grid_width;\n\t\t}\n\n\t\tDebug.Text( 'Target Grid: ' + this.setup.container_selector + ' Target Div: ' + this.grid.parents( this.setup.container_selector ).id + ' Width: Min: ' + options.min_grid_width + ' Max: ' + options.max_grid_width + ' Scrollbar Offset: ' + Global.getScrollbarWidth() + ' Parent Width: ' + $( this.grid.parents( '.edit-view-tab, body' )[0] ).width(), 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\n\t\tif ( column_model ) {\n\t\t\tvar total_column_width = 0;\n\t\t\tfor ( var i = 0; i < column_model.length; i++ ) {\n\t\t\t\tvar field = column_model[i].name;\n\t\t\t\tvar width = column_model[i].width ? column_model[i].width : column_model.widthOrg;\n\t\t\t\ttotal_column_width += width;\n\n\t\t\t\t//Don't change the width of columns if they are already the same size. This may help avoid minor changes in the table caused by simple redraws.\n\t\t\t\tif ( this.grid.getColProp( field ).width != width ) {\n\t\t\t\t\tthis.grid.setColWidth( field, width );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn total_column_width;\n\t\t}\n\n\t\tvar column_model = this.getColumnModel();\n\n\t\t//Possible exception\n\t\t//Error: Uncaught TypeError: Cannot read property 'length' of undefined in /interface/html5/#!m=TimeSheet&date=20141102&user_id=53130 line 4288\n\t\tif ( !column_model ) {\n\t\t\tDebug.Text( 'ERROR: column_model is null or undefined', 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\treturn;\n\t\t}\n\n\t\tfunction longer( champ, contender ) {\n\t\t\treturn ( contender.length > champ.length ) ? contender : champ;\n\t\t}\n\n\t\tfunction longestWord( str ) {\n\t\t\tif ( str && typeof str === 'string' ) {\n\t\t\t\tvar words = str.split( ' ' );\n\t\t\t\treturn words.reduce( longer );\n\t\t\t} else {\n\t\t\t\treturn '';\n\t\t\t}\n\t\t}\n\n\t\tvar grid_data = this.getData();\n\t\tthis.grid_total_width = 0;\n\n\t\tvar cb_column_width = 0; //checkbox column width, usually 22, but only set once we know there is a checkbox column.\n\t\tvar cb_column_count_adjustment = 0; //If the checkbox column exists or not.\n\n\t\tvar longest_field_width = 0;\n\t\tvar last_column = null;\n\t\tvar column_widths = {};\n\n\t\tfor ( var i = 0; i < column_model.length; i++ ) {\n\t\t\tvar col = column_model[i];\n\t\t\tlast_column = col;\n\t\t\tvar field = col.name;\n\t\t\tvar longest_cell_content = longestWord( col.label ); // allow extra space for sort order UI hint\n\t\t\tvar header_is_longest = true;\n\n\t\t\tif ( field == 'cb' ) { //hard coded override on CB column, so we don't try to check the data in each row for it.\n\t\t\t\tcb_column_count_adjustment = 1;\n\t\t\t\tcb_column_width = 22;\n\t\t\t\twidth = cb_column_width;\n\t\t\t} else {\n\t\t\t\tif ( options.column_width_override && options.column_width_override[field] ) {\n\t\t\t\t\twidth = options.column_width_override[field];\n\t\t\t\t} else {\n\n\t\t\t\t\tfor ( var j = 0; j < grid_data.length; j++ ) {\n\t\t\t\t\t\tvar row_data = grid_data[j];\n\t\t\t\t\t\tif ( !row_data.hasOwnProperty( field ) ) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tvar current_cell_content = row_data[field];\n\t\t\t\t\t\tif ( !current_cell_content ) {\n\t\t\t\t\t\t\tcurrent_cell_content = '';\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif ( !longest_cell_content ) {\n\t\t\t\t\t\t\tlongest_cell_content = current_cell_content.toString();\n\t\t\t\t\t\t\theader_is_longest = false;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif ( current_cell_content && current_cell_content.toString().length > longest_cell_content.length ) {\n\t\t\t\t\t\t\t\tlongest_cell_content = current_cell_content.toString();\n\t\t\t\t\t\t\t\theader_is_longest = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tvar calculate_text_width_options;\n\t\t\t\t\tif ( longest_cell_content == field ) {\n\t\t\t\t\t\tcalculate_text_width_options = { fontSize: '11px', fontWeight: 'bolder' };\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcalculate_text_width_options = { fontSize: '11px', fontWeight: 'normal' };\n\t\t\t\t\t}\n\n\t\t\t\t\tvar width = Global.calculateTextWidth( longest_cell_content, calculate_text_width_options ); // + 40; // 8 is drag handle width +2 for borders +20 for sort order ui hint (17 for actual hint,13 for header padding on Firefox under windows\n\n\t\t\t\t\tif ( header_is_longest === true ) {\n\t\t\t\t\t\twidth += 40;\n\t\t\t\t\t} else {\n\t\t\t\t\t\twidth += 12;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( width > longest_field_width ) {\n\t\t\t\tlongest_field_width = width;\n\t\t\t}\n\n\t\t\t//Debug.Text( ' Column: '+ field +' Width: '+ width +' Content: \\''+ longest_cell_content +'\\' Longest Column Width: '+ longest_field_width +' Header is Longest: '+ header_is_longest, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\n\t\t\tcolumn_widths[field] = width;\n\t\t\tthis.grid_total_width += width;\n\t\t}\n\n\t\t//If the longest column width can be used for all columns, size them all equally so they don't change sizes between pages.\n\t\tif ( ( longest_field_width * column_model.length ) <= options.min_grid_width ) {\n\t\t\tvar equal_column_width = Math.floor( ( options.min_grid_width - cb_column_width ) / ( column_model.length - cb_column_count_adjustment ) );\n\t\t\tvar equal_column_width_remainder = ( ( options.min_grid_width - cb_column_width ) % ( column_model.length - cb_column_count_adjustment ) ); //Eliminate partial pixel adjustments.\n\t\t\tDebug.Text( ' Grid columns CAN fit with equal sizes... Grid Width: ' + options.min_grid_width + ' Optimal Grid Width: ' + this.grid_total_width + ' Equal Size Width: ' + equal_column_width + ' Remainder: ' + equal_column_width_remainder, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\n\t\t\tvar adjusted_grid_width = 0;\n\n\t\t\tvar x = 0;\n\t\t\tfor ( var tmp_column_name in column_widths ) {\n\t\t\t\tif ( tmp_column_name == 'cb' ) {\n\t\t\t\t\tthis.grid.setColWidth( 'cb', cb_column_width );\n\t\t\t\t\tadjusted_grid_width += cb_column_width;\n\t\t\t\t} else {\n\t\t\t\t\tvar tmp_column_width = equal_column_width;\n\n\t\t\t\t\tif ( x == 1 ) {\n\t\t\t\t\t\ttmp_column_width += equal_column_width_remainder;\n\t\t\t\t\t}\n\n\t\t\t\t\t//Debug.Text( ' Adjusted Column: '+ tmp_column_name +' Width: Old: '+ column_widths[tmp_column_name] +' New: '+ tmp_column_width, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t\tif ( this.grid.getColProp( tmp_column_name ).width != tmp_column_width ) {\n\t\t\t\t\t\tthis.grid.setColWidth( tmp_column_name, tmp_column_width );\n\t\t\t\t\t}\n\t\t\t\t\tadjusted_grid_width += tmp_column_width;\n\t\t\t\t}\n\n\t\t\t\tthis.grid.setColProp( tmp_column_name, 'fixed', true );\n\n\t\t\t\tx++;\n\t\t\t}\n\t\t\tDebug.Text( ' Adjusted Grid Width: ' + adjusted_grid_width + ' Adjusted Column Remainder: ' + equal_column_width_remainder, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\n\t\t\tthis.grid_total_width = options.min_grid_width;\n\t\t} else {\n\t\t\tDebug.Text( ' Optimal Grid Width: ' + this.grid_total_width + ' Equal Size Width: ' + ( longest_field_width * column_model.length ), 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\n\t\t\tvar body_width_difference = 0;\n\t\t\tvar column_width_adjustment = 0;\n\t\t\tvar columns_to_adjust_width = 0;\n\t\t\tvar column_width_adjustment_remainder = 0;\n\n\t\t\t//If the optimal column widths are wider than the max grid width, shrink them to fit.\n\t\t\tif ( ( options.max_grid_width > 0 && this.grid_total_width > options.max_grid_width ) || ( options.min_grid_width > 0 && this.grid_total_width < options.min_grid_width ) ) {\n\t\t\t\t//When columns are too small to fit on the screen and need to be stretched, ignore the overridden column.\n\t\t\t\tif ( ( options.max_grid_width > 0 && this.grid_total_width > options.max_grid_width ) ) {\n\t\t\t\t\tbody_width_difference = this.grid_total_width - options.max_grid_width; //Should be a negative difference to shrink columns to fit max width.\n\t\t\t\t\tthis.grid_total_width = options.max_grid_width;\n\t\t\t\t} else {\n\t\t\t\t\tbody_width_difference = options.min_grid_width - this.grid_total_width; //Should be a positive difference to grow columns to fit min width.\n\t\t\t\t\tthis.grid_total_width = options.min_grid_width;\n\t\t\t\t}\n\n\t\t\t\tif ( body_width_difference != 0 ) {\n\t\t\t\t\tif ( options.column_width_override ) {\n\t\t\t\t\t\tcolumns_to_adjust_width = ( column_model.length - options.column_width_override.length() );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tcolumns_to_adjust_width = ( column_model.length - cb_column_count_adjustment );\n\t\t\t\t\t}\n\t\t\t\t\tcolumn_width_adjustment = Math.floor( body_width_difference / columns_to_adjust_width );\n\t\t\t\t\tcolumn_width_adjustment_remainder = ( body_width_difference % columns_to_adjust_width ); //Eliminate partial pixel adjustments.\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvar adjusted_grid_width = 0;\n\n\t\t\tvar x = 0;\n\t\t\tfor ( var tmp_column_name in column_widths ) {\n\t\t\t\tif ( tmp_column_name == 'cb' ) {\n\t\t\t\t\tthis.grid.setColWidth( 'cb', cb_column_width );\n\t\t\t\t\tadjusted_grid_width += cb_column_width;\n\t\t\t\t} else {\n\t\t\t\t\tvar tmp_column_width;\n\t\t\t\t\tif ( options.column_width_override && options.column_width_override[n] ) {\n\t\t\t\t\t\ttmp_column_width = column_widths[tmp_column_name];\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttmp_column_width = column_widths[tmp_column_name] + column_width_adjustment;\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( x == 1 ) { //First column after the CB.\n\t\t\t\t\t\ttmp_column_width += column_width_adjustment_remainder;\n\t\t\t\t\t}\n\n\t\t\t\t\tDebug.Text( ' Adjusted Column: ' + tmp_column_name + ' Width: Old: ' + column_widths[tmp_column_name] + ' New: ' + tmp_column_width + ' Adjustment: ' + column_width_adjustment + ' Body Difference: ' + body_width_difference + ' Columns Adjusted: ' + columns_to_adjust_width, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t\tif ( this.grid.getColProp( tmp_column_name ).width != tmp_column_width ) {\n\t\t\t\t\t\tthis.grid.setColWidth( tmp_column_name, tmp_column_width );\n\t\t\t\t\t}\n\t\t\t\t\tadjusted_grid_width += tmp_column_width;\n\t\t\t\t}\n\t\t\t\tthis.grid.setColProp( tmp_column_name, 'fixed', true );\n\n\t\t\t\tx++;\n\t\t\t}\n\t\t\t//Debug.Text( ' Adjusted Grid Width: '+ adjusted_grid_width +' Adjusted Column Remainder: '+ column_width_adjustment_remainder, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t}\n\n\t\t//this.setGridWidth( this.grid_total_width, this.grid_total_width ); //Causes columns with to flucuate, specifically in schedule day mode.\n\t\tDebug.Text( ' FINAL Grid width: ' + this.grid_total_width + ' Body Width: ' + Global.bodyWidth() + ' Total Rows: ' + grid_data.length, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\treturn this.grid_total_width;\n\t};\n\n\t//resize event.\n\t$( window ).off( 'resize.grids' ).on( 'resize.grids', Global.debounce( ( e ) => this.TTGridResizeEvent( e ), 500 ) );\n\n\tthis.TTGridResizeEvent = function( e ) {\n\t\te.stopPropagation();\n\t\tDebug.Text( ' Window resize event hit by TTGrid. Target: ' + e.target, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\n\t\tif ( LocalCacheData.resizeable_grids.length > 0 ) {\n\n\t\t\t//remove the nulls\n\t\t\tvar grids = LocalCacheData.resizeable_grids.filter( function( t ) {\n\t\t\t\treturn t != null;\n\t\t\t} );\n\t\t\tLocalCacheData.resizeable_grids = grids;\n\n\t\t\tfor ( var i in LocalCacheData.resizeable_grids ) {\n\t\t\t\tvar ttgrid = LocalCacheData.resizeable_grids[i];\n\n\t\t\t\tif ( !ttgrid || ( typeof ttgrid.getTableIDElement === 'function' && ttgrid.getTableIDElement().length === 0 ) || !ttgrid.grid || ttgrid.setup.onResizeGrid === false ) {\n\t\t\t\t\tDebug.Arr( LocalCacheData.resizeable_grids, ' Grid ignored ' + i, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t\tLocalCacheData.resizeable_grids[i] = null;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t//Try to only resize visible grids. ie: Switch from Audit tab to primary tab, wait until resize event is triggered, then switch back, triggering \"flashing\" of scroll bars appearing/disappearing\n\t\t\t\t// Only happens on edit views with double row fields (ie: Note fields), like Edit Punch or Edit Schedule.\n\t\t\t\tif ( ttgrid.getTableIDElement().is( ':visible' ) ) {\n\t\t\t\t\tDebug.Text( ' Processing: ' + ttgrid.ui_id, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t\tif ( ttgrid.setup.onResizeGrid && typeof ttgrid.setup.onResizeGrid == 'function' ) {\n\t\t\t\t\t\tDebug.Text( ' TTGrid invoked setup defined onResizeGrid() for ' + ttgrid.ui_id, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t\t\tttgrid.setup.onResizeGrid();\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif ( ttgrid.grid.length == 1 ) {\n\t\t\t\t\t\t\tDebug.Text( ' TTGrid invoked TTgrid::setGridColumnsWidth() for ' + ttgrid.ui_id, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t\t\t\tttgrid.setGridColumnsWidth();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tDebug.Text( ' Skipping grid that is not visible: ' + ttgrid.ui_id, 'TTGrid.js', 'TTGrid', 'setGridColumnsWidth', 10 );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t//Usually we will want to make double sure that visible search grids resize.\n\t\t\t//Have to check for grid though because dashboard has no \"search grid\"\n\t\t\tif ( LocalCacheData.current_open_primary_controller && LocalCacheData.current_open_primary_controller.grid ) {\n\t\t\t\tLocalCacheData.current_open_primary_controller.setGridColumnsWidth(); //Be sure to call the setGridColumnsWidth() from current_open_primary_controller in case its overridden.\n\t\t\t\tLocalCacheData.current_open_primary_controller.setGridSize();\n\t\t\t}\n\n\t\t\t//Also resize grids inside Edit Views.\n\t\t\tif ( LocalCacheData.current_open_sub_controller && LocalCacheData.current_open_sub_controller.grid ) {\n\t\t\t\tLocalCacheData.current_open_sub_controller.setGridColumnsWidth(); //Be sure to call the setGridColumnsWidth() from current_open_sub_controller in case its overridden.\n\t\t\t\tLocalCacheData.current_open_sub_controller.setGridSize();\n\t\t\t}\n\t\t}\n\t}\n};//# sourceURL=[module]\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMjE4NS5qcyIsIm1hcHBpbmdzIjoiO0FBQUE7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBOztBQUVBO0FBQ0EsMEJBQTBCLENBQUM7QUFDM0I7QUFDQTs7QUFFQTtBQUNBO0FBQ0E7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7O0FBRUE7O0FBRUE7QUFDQTtBQUNBO0FBQ0E7QUFDQSw0REFBNEQsUUFBUTtBQUNwRTtBQUNBO0FBQ0E7QUFDQSxLQUFLO0FBQ0w7QUFDQTtBQUNBO0FBQ0E7QUFDQTs7QUFFQTs7QUFFQTtBQUNBOztBQUVBOztBQUVBO0FBQ0E7QUFDQTtBQUNBOztBQUVBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7QUFDQTtBQUNBO0FBQ0E7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