define(['exports', './event', './dom', './string', './cookie', './types', './array', './helpers', './date', './sort', './modules/store', './modules/gridLayout', './modules/loader', './modules/highlightKeywords', './modules/popupFilter', './modules/dropdown', './modules/checkList', './modules/rowsCounter', './modules/statusBar', './modules/paging', './modules/clearButton', './modules/help', './modules/alternateRows', './modules/colOps'], function (exports, _event, _dom, _string, _cookie, _types, _array, _helpers, _date, _sort, _modulesStore, _modulesGridLayout, _modulesLoader, _modulesHighlightKeywords, _modulesPopupFilter, _modulesDropdown, _modulesCheckList, _modulesRowsCounter, _modulesStatusBar, _modulesPaging, _modulesClearButton, _modulesHelp, _modulesAlternateRows, _modulesColOps) { 'use strict'; var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); Object.defineProperty(exports, '__esModule', { value: true }); var global = window, isValidDate = _date.DateHelper.isValid, formatDate = _date.DateHelper.format, doc = global.document; var TableFilter = (function () { /** * TF object constructor * @param {String} id Table id * @param {Number} row index indicating the 1st row * @param {Object} configuration object */ function TableFilter(id) { _classCallCheck(this, TableFilter); if (arguments.length === 0) { return; } this.id = id; this.version = '3.0'; this.year = new Date().getFullYear(); this.tbl = _dom.Dom.id(id); this.startRow = null; this.refRow = null; this.headersRow = null; this.cfg = {}; this.nbFilterableRows = null; this.nbRows = null; this.nbCells = null; this._hasGrid = false; this.enableModules = false; if (!this.tbl || _string.Str.lower(this.tbl.nodeName) !== 'table' || this.getRowsNb() === 0) { throw new Error('Could not instantiate TableFilter class: ' + 'HTML table not found.'); } if (arguments.length > 1) { for (var i = 0; i < arguments.length; i++) { var arg = arguments[i]; var argtype = typeof arg; switch (_string.Str.lower(argtype)) { case 'number': this.startRow = arg; break; case 'object': this.cfg = arg; break; } } } // configuration object var f = this.cfg; //Start row et cols nb this.refRow = this.startRow === null ? 2 : this.startRow + 1; try { this.nbCells = this.getCellsNb(this.refRow); } catch (e) { this.nbCells = this.getCellsNb(0); } //default script base path this.basePath = f.base_path !== undefined ? f.base_path : ''; this.extensionsPath = f.extensions_path || this.basePath + 'extensions/'; /*** filter types ***/ this.fltTypeInp = 'input'; this.fltTypeSlc = 'select'; this.fltTypeMulti = 'multiple'; this.fltTypeCheckList = 'checklist'; this.fltTypeNone = 'none'; this.fltCol = []; //filter type of each column for (var j = 0; j < this.nbCells; j++) { var cfgCol = f['col_' + j]; var col = !cfgCol ? this.fltTypeInp : _string.Str.lower(cfgCol); this.fltCol.push(col); this['col' + j] = col; } /*** Developer's additional methods ***/ this.publicMethods = f.public_methods !== undefined ? f.public_methods : false; /*** filters' grid properties ***/ //enables/disables filter grid this.fltGrid = f.grid === false ? false : true; /*** Grid layout ***/ //enables/disables grid layout (fixed headers) this.gridLayout = f.grid_layout ? true : false; this.sourceTblHtml = null; if (this.gridLayout) { //Firefox does not support outerHTML property... if (this.tbl.outerHTML === undefined) { setOuterHtml(); } this.sourceTblHtml = this.tbl.outerHTML; } /*** ***/ this.filtersRowIndex = f.filters_row_index || 0; this.headersRow = f.headers_row_index || (this.filtersRowIndex === 0 ? 1 : 0); if (this.gridLayout) { if (this.headersRow > 1) { this.filtersRowIndex = this.headersRow + 1; } else { this.filtersRowIndex = 1; this.headersRow = 0; } } //defines tag of the cells containing filters (td/th) this.fltCellTag = f.filters_cell_tag !== 'th' || f.filters_cell_tag !== 'td' ? 'td' : f.filters_cell_tag; //stores filters ids this.fltIds = []; //stores filters DOM elements this.fltElms = []; //stores filters values this.searchArgs = null; //stores table data this.tblData = []; //stores valid rows indexes (rows visible upon filtering) this.validRowsIndex = null; //stores filters row element this.fltGridEl = null; //is first load boolean this.isFirstLoad = true; //container div for paging elements, reset btn etc. this.infDiv = null; //div for rows counter this.lDiv = null; //div for reset button and results per page select this.rDiv = null; //div for paging elements this.mDiv = null; //table container div for fixed headers (IE only) this.contDiv = null; //defines css class for div containing paging elements, rows counter etc. this.infDivCssClass = f.inf_div_css_class || 'inf'; //defines css class for left div this.lDivCssClass = f.left_div_css_class || 'ldiv'; //defines css class for right div this.rDivCssClass = f.right_div_css_class || 'rdiv'; //defines css class for mid div this.mDivCssClass = f.middle_div_css_class || 'mdiv'; //table container div css class this.contDivCssClass = f.content_div_css_class || 'cont'; /*** filters' grid appearance ***/ //stylesheet file this.stylesheet = f.stylesheet || this.basePath + 'filtergrid.css'; this.stylesheetId = this.id + '_style'; //defines css class for filters row this.fltsRowCssClass = f.flts_row_css_class || 'fltrow'; //enables/disables icons (paging, reset button) this.enableIcons = f.enable_icons === false ? false : true; //enables/disbles rows alternating bg colors this.alternateBgs = f.alternate_rows === true ? true : false; //defines widths of columns this.hasColWidth = f.col_width === true ? true : false; this.colWidth = this.hasColWidth ? f.col_width : null; //enables/disables fixed headers this.fixedHeaders = f.fixed_headers === true ? true : false; //tbody height if fixed headers enabled this.tBodyH = !isNaN(f.tbody_height) ? f.tbody_height : 200; //defines css class for filters this.fltCssClass = f.flt_css_class || 'flt'; //defines css class for multiple selects filters this.fltMultiCssClass = f.flt_multi_css_class || 'flt_multi'; //defines css class for filters this.fltSmallCssClass = f.flt_small_css_class || 'flt_s'; //defines css class for single-filter this.singleFltCssClass = f.single_flt_css_class || 'single_flt'; this.isStartBgAlternate = true; /*** filters' grid behaviours ***/ //enables/disables enter key this.enterKey = f.enter_key === false ? false : true; //enables/disables alternative fn call this.isModFilterFn = f.mod_filter_fn === true ? true : false; // used by tf_DetectKey fn this.modFilterFn = this.isModFilterFn ? f.mod_filter_fn : null; //calls function before filtering starts this.onBeforeFilter = _types.Types.isFn(f.on_before_filter) ? f.on_before_filter : null; //calls function after filtering this.onAfterFilter = _types.Types.isFn(f.on_after_filter) ? f.on_after_filter : null; //enables/disables case sensitivity this.matchCase = f.match_case === true ? true : false; //enables/disbles exact match for search this.exactMatch = f.exact_match === true ? true : false; //refreshes drop-down lists upon validation this.linkedFilters = f.linked_filters === true ? true : false; //wheter excluded options are disabled this.disableExcludedOptions = f.disable_excluded_options === true ? true : false; //stores active filter element this.activeFlt = null; //id of active filter this.activeFilterId = null; //enables/disbles column operation(sum,mean) this.hasColOperation = f.col_operation ? true : false; this.colOperation = null; //enables always visible rows this.hasVisibleRows = f.rows_always_visible ? true : false; //array containing always visible rows this.visibleRows = this.hasVisibleRows ? f.rows_always_visible : []; //defines search type: include or exclude this.searchType = f.search_type || 'include'; //enables/disables external filters generation this.isExternalFlt = f.external_flt_grid === true ? true : false; //array containing ids of external elements containing filters this.externalFltTgtIds = f.external_flt_grid_ids || null; //stores filters elements if isExternalFlt is true this.externalFltEls = []; //delays any filtering process if loader true this.execDelay = !isNaN(f.exec_delay) ? parseInt(f.exec_delay, 10) : 100; //calls function when filters grid loaded this.onFiltersLoaded = _types.Types.isFn(f.on_filters_loaded) ? f.on_filters_loaded : null; //enables/disables single filter search this.singleSearchFlt = f.single_search_filter === true ? true : false; //calls function after row is validated this.onRowValidated = _types.Types.isFn(f.on_row_validated) ? f.on_row_validated : null; //array defining columns for customCellData event this.customCellDataCols = f.custom_cell_data_cols ? f.custom_cell_data_cols : []; //calls custom function for retrieving cell data this.customCellData = _types.Types.isFn(f.custom_cell_data) ? f.custom_cell_data : null; //input watermark text array this.watermark = f.watermark || ''; this.isWatermarkArray = _types.Types.isArray(this.watermark); //id of toolbar container element this.toolBarTgtId = f.toolbar_target_id || null; //enables/disables help div this.helpInstructions = f.help_instructions || false; //popup filters this.popUpFilters = f.popup_filters === true ? true : false; //active columns color this.markActiveColumns = f.mark_active_columns === true ? true : false; //defines css class for active column header this.activeColumnsCssClass = f.active_columns_css_class || 'activeHeader'; //calls function before active column header is marked this.onBeforeActiveColumn = _types.Types.isFn(f.on_before_active_column) ? f.on_before_active_column : null; //calls function after active column header is marked this.onAfterActiveColumn = _types.Types.isFn(f.on_after_active_column) ? f.on_after_active_column : null; /*** select filter's customisation and behaviours ***/ //defines 1st option text this.displayAllText = f.display_all_text || ''; //enables/disables empty option in combo-box filters this.enableEmptyOption = f.enable_empty_option === true ? true : false; //defines empty option text this.emptyText = f.empty_text || '(Empty)'; //enables/disables non empty option in combo-box filters this.enableNonEmptyOption = f.enable_non_empty_option === true ? true : false; //defines empty option text this.nonEmptyText = f.non_empty_text || '(Non empty)'; //enables/disables onChange event on combo-box this.onSlcChange = f.on_change === false ? false : true; //enables/disables select options sorting this.sortSlc = f.sort_select === false ? false : true; //enables/disables ascending numeric options sorting this.isSortNumAsc = f.sort_num_asc === true ? true : false; this.sortNumAsc = this.isSortNumAsc ? f.sort_num_asc : null; //enables/disables descending numeric options sorting this.isSortNumDesc = f.sort_num_desc === true ? true : false; this.sortNumDesc = this.isSortNumDesc ? f.sort_num_desc : null; //enabled selects are populated on demand this.fillSlcOnDemand = f.fill_slc_on_demand === true ? true : false; this.hasCustomSlcOptions = _types.Types.isObj(f.custom_slc_options) ? true : false; this.customSlcOptions = _types.Types.isArray(f.custom_slc_options) ? f.custom_slc_options : null; /*** Filter operators ***/ this.rgxOperator = f.regexp_operator || 'rgx:'; this.emOperator = f.empty_operator || '[empty]'; this.nmOperator = f.nonempty_operator || '[nonempty]'; this.orOperator = f.or_operator || '||'; this.anOperator = f.and_operator || '&&'; this.grOperator = f.greater_operator || '>'; this.lwOperator = f.lower_operator || '<'; this.leOperator = f.lower_equal_operator || '<='; this.geOperator = f.greater_equal_operator || '>='; this.dfOperator = f.different_operator || '!'; this.lkOperator = f.like_operator || '*'; this.eqOperator = f.equal_operator || '='; this.stOperator = f.start_with_operator || '{'; this.enOperator = f.end_with_operator || '}'; this.curExp = f.cur_exp || '^[¥£€$]'; this.separator = f.separator || ','; /*** rows counter ***/ //show/hides rows counter this.rowsCounter = f.rows_counter === true ? true : false; /*** status bar ***/ //show/hides status bar this.statusBar = f.status_bar === true ? true : false; /*** loader ***/ //enables/disables loader/spinner indicator this.loader = f.loader === true ? true : false; /*** validation - reset buttons/links ***/ //show/hides filter's validation button this.displayBtn = f.btn === true ? true : false; //defines validation button text this.btnText = f.btn_text || (!this.enableIcons ? 'Go' : ''); //defines css class for validation button this.btnCssClass = f.btn_css_class || (!this.enableIcons ? 'btnflt' : 'btnflt_icon'); //show/hides reset link this.btnReset = f.btn_reset === true ? true : false; //defines css class for reset button this.btnResetCssClass = f.btn_reset_css_class || 'reset'; //callback function before filters are cleared this.onBeforeReset = _types.Types.isFn(f.on_before_reset) ? f.on_before_reset : null; //callback function after filters are cleared this.onAfterReset = _types.Types.isFn(f.on_after_reset) ? f.on_after_reset : null; /*** paging ***/ //enables/disables table paging this.paging = f.paging === true ? true : false; this.nbVisibleRows = 0; //nb visible rows this.nbHiddenRows = 0; //nb hidden rows /*** webfx sort adapter ***/ //enables/disables default table sorting this.sort = f.sort === true ? true : false; //indicates if sort is set (used in tfAdapter.sortabletable.js) this.isSortEnabled = false; this.sortConfig = f.sort_config || {}; this.sortConfig.name = this.sortConfig.name !== undefined ? f.sort_config.name : 'sortabletable'; this.sortConfig.src = this.sortConfig.src !== undefined ? f.sort_config.src : this.extensionsPath + 'sortabletable/' + 'sortabletable.js'; this.sortConfig.adapterSrc = this.sortConfig.adapter_src !== undefined ? f.sort_config.adapter_src : this.extensionsPath + 'sortabletable/adapterSortabletable.js'; this.sortConfig.initialize = this.sortConfig.initialize !== undefined ? f.sort_config.initialize : function (o) {}; this.sortConfig.sortTypes = _types.Types.isArray(this.sortConfig.sort_types) ? f.sort_config.sort_types : []; this.sortConfig.sortCol = this.sortConfig.sort_col !== undefined ? f.sort_config.sort_col : null; this.sortConfig.asyncSort = this.sortConfig.async_sort === true ? true : false; this.sortConfig.triggerIds = _types.Types.isArray(this.sortConfig.sort_trigger_ids) ? f.sort_config.sort_trigger_ids : []; /*** ezEditTable extension ***/ //enables/disables table selection feature this.selectable = f.selectable === true ? true : false; //enables/disables editable table feature this.editable = f.editable === true ? true : false; this.ezEditTableConfig = f.ezEditTable_config || {}; this.ezEditTableConfig.name = this.ezEditTableConfig.name !== undefined ? f.ezEditTable_config.name : 'ezedittable'; this.ezEditTableConfig.src = this.ezEditTableConfig.src !== undefined ? f.ezEditTable_config.src : this.extensionsPath + 'ezEditTable/ezEditTable.js'; //ezEditTable stylesheet not imported by default as filtergrid.css //applies this.ezEditTableConfig.loadStylesheet = this.ezEditTableConfig.loadStylesheet === true ? true : false; this.ezEditTableConfig.stylesheet = this.ezEditTableConfig.stylesheet || this.extensionsPath + 'ezEditTable/ezEditTable.css'; this.ezEditTableConfig.stylesheetName = this.ezEditTableConfig.stylesheetName !== undefined ? f.ezEditTable_config.stylesheetName : 'ezEditTableCss'; this.ezEditTableConfig.err = 'Failed to instantiate EditTable ' + 'object.\n"ezEditTable" module may not be available.'; /*** onkeyup event ***/ //enables/disables onkeyup event, table is filtered when user stops //typing this.onKeyUp = f.on_keyup === true ? true : false; //onkeyup delay timer (msecs) this.onKeyUpDelay = !isNaN(f.on_keyup_delay) ? f.on_keyup_delay : 900; this.isUserTyping = null; //typing indicator this.onKeyUpTimer = undefined; /*** keyword highlighting ***/ //enables/disables keyword highlighting this.highlightKeywords = f.highlight_keywords === true ? true : false; /*** data types ***/ //defines default date type (european DMY) this.defaultDateType = f.default_date_type || 'DMY'; //defines default thousands separator //US = ',' EU = '.' this.thousandsSeparator = f.thousands_separator || ','; //defines default decimal separator //US & javascript = '.' EU = ',' this.decimalSeparator = f.decimal_separator || '.'; //enables number format per column this.hasColNbFormat = f.col_number_format === true ? true : false; //array containing columns nb formats this.colNbFormat = _types.Types.isArray(this.hasColNbFormat) ? f.col_number_format : null; //enables date type per column this.hasColDateType = f.col_date_type === true ? true : false; //array containing columns date type this.colDateType = _types.Types.isArray(this.hasColDateType) ? f.col_date_type : null; /*** status messages ***/ //filtering this.msgFilter = f.msg_filter || 'Filtering data...'; //populating drop-downs this.msgPopulate = f.msg_populate || 'Populating filter...'; //populating drop-downs this.msgPopulateCheckList = f.msg_populate_checklist || 'Populating list...'; //changing paging page this.msgChangePage = f.msg_change_page || 'Collecting paging data...'; //clearing filters this.msgClear = f.msg_clear || 'Clearing filters...'; //changing nb results/page this.msgChangeResults = f.msg_change_results || 'Changing results per page...'; //re-setting grid values this.msgResetValues = f.msg_reset_grid_values || 'Re-setting filters values...'; //re-setting page this.msgResetPage = f.msg_reset_page || 'Re-setting page...'; //re-setting page length this.msgResetPageLength = f.msg_reset_page_length || 'Re-setting page length...'; //table sorting this.msgSort = f.msg_sort || 'Sorting data...'; //extensions loading this.msgLoadExtensions = f.msg_load_extensions || 'Loading extensions...'; //themes loading this.msgLoadThemes = f.msg_load_themes || 'Loading theme(s)...'; /*** ids prefixes ***/ //css class name added to table this.prfxTf = 'TF'; //filters (inputs - selects) this.prfxFlt = 'flt'; //validation button this.prfxValButton = 'btn'; //container div for paging elements, rows counter etc. this.prfxInfDiv = 'inf_'; //left div this.prfxLDiv = 'ldiv_'; //right div this.prfxRDiv = 'rdiv_'; //middle div this.prfxMDiv = 'mdiv_'; //filter values cookie this.prfxCookieFltsValues = 'tf_flts_'; //page nb cookie this.prfxCookiePageNb = 'tf_pgnb_'; //page length cookie this.prfxCookiePageLen = 'tf_pglen_'; /*** cookies ***/ this.hasStoredValues = false; //remembers filters values on page load this.rememberGridValues = f.remember_grid_values === true ? true : false; //cookie storing filter values this.fltsValuesCookie = this.prfxCookieFltsValues + this.id; //remembers page nb on page load this.rememberPageNb = this.paging && f.remember_page_number ? true : false; //cookie storing page nb this.pgNbCookie = this.prfxCookiePageNb + this.id; //remembers page length on page load this.rememberPageLen = this.paging && f.remember_page_length ? true : false; //cookie storing page length this.pgLenCookie = this.prfxCookiePageLen + this.id; /*** extensions ***/ //imports external script // this.hasExtensions = f.extensions===true ? true : false; // this.extensions = this.hasExtensions ? f.extensions : null; this.extensions = f.extensions; this.hasExtensions = _types.Types.isArray(this.extensions); /*** themes ***/ this.enableDefaultTheme = f.enable_default_theme === true ? true : false; //imports themes this.hasThemes = f.enable_default_theme || f.themes && _types.Types.isObj(f.themes) ? true : false; this.themes = this.hasThemes ? f.themes : null; //themes path this.themesPath = f.themes_path || this.basePath + 'TF_Themes/'; // Features registry this.Cpt = { loader: null, alternateRows: null, colOps: null, rowsCounter: null, gridLayout: null, store: null, highlightKeywords: null, paging: null, checkList: null, dropdown: null, popupFilter: null, clearButton: null, help: null, statusBar: null }; // Extensions registry this.ExtRegistry = { sort: null, ezEditTable: null }; /*** TF events ***/ var o = this; this.Evt = { name: { filter: 'Filter', dropdown: 'dropdown', checklist: 'checkList', changepage: 'changePage', clear: 'Clear', changeresultsperpage: 'changeResults', resetvalues: 'ResetValues', resetpage: 'resetPage', resetpagelength: 'resetPageLength', sort: 'Sort', loadextensions: 'LoadExtensions', loadthemes: 'loadThemes' }, /*==================================================== - Detects key for a given element =====================================================*/ detectKey: function detectKey(e) { if (!o.enterKey) { return; } var _evt = e || global.event; if (_evt) { var key = _event.Event.keyCode(_evt); if (key === 13) { o._filter(); _event.Event.cancel(_evt); _event.Event.stop(_evt); } else { o.isUserTyping = true; global.clearInterval(o.onKeyUpTimer); o.onKeyUpTimer = undefined; } } //if evt }, /*==================================================== - onkeyup event for text filters =====================================================*/ onKeyUp: function onKeyUp(e) { if (!o.onKeyUp) { return; } var _evt = e || global.event; var key = _event.Event.keyCode(_evt); o.isUserTyping = false; function filter() { global.clearInterval(o.onKeyUpTimer); o.onKeyUpTimer = undefined; if (!o.isUserTyping) { o.filter(); o.isUserTyping = null; } } if (key !== 13 && key !== 9 && key !== 27 && key !== 38 && key !== 40) { if (o.onKeyUpTimer === undefined) { o.onKeyUpTimer = global.setInterval(filter, o.onKeyUpDelay); } } else { global.clearInterval(o.onKeyUpTimer); o.onKeyUpTimer = undefined; } }, /*==================================================== - onkeydown event for input filters =====================================================*/ onKeyDown: function onKeyDown(e) { if (!o.onKeyUp) { return; } o.isUserTyping = true; }, /*==================================================== - onblur event for input filters =====================================================*/ onInpBlur: function onInpBlur(e) { if (o.onKeyUp) { o.isUserTyping = false; global.clearInterval(o.onKeyUpTimer); } if (o.ezEditTable) { if (o.editable) { o.ezEditTable.Editable.Set(); } if (o.selectable) { o.ezEditTable.Selection.Set(); } } }, /*==================================================== - onfocus event for input filters =====================================================*/ onInpFocus: function onInpFocus(e) { var _evt = e || global.event; o.activeFilterId = this.getAttribute('id'); o.activeFlt = _dom.Dom.id(o.activeFilterId); if (o.popUpFilters) { _event.Event.cancel(_evt); _event.Event.stop(_evt); } if (o.ezEditTable) { if (o.editable) { o.ezEditTable.Editable.Remove(); } if (o.selectable) { o.ezEditTable.Selection.Remove(); } } }, /*==================================================== - onfocus event for select filters =====================================================*/ onSlcFocus: function onSlcFocus(e) { var _evt = e || global.event; o.activeFilterId = this.getAttribute('id'); o.activeFlt = _dom.Dom.id(o.activeFilterId); // select is populated when element has focus if (o.fillSlcOnDemand && this.getAttribute('filled') === '0') { var ct = this.getAttribute('ct'); o.Cpt.dropdown._build(ct); } if (o.popUpFilters) { _event.Event.cancel(_evt); _event.Event.stop(_evt); } }, /*==================================================== - onchange event for select filters =====================================================*/ onSlcChange: function onSlcChange(e) { if (!o.activeFlt) { return; } var colIndex = o.activeFlt.getAttribute('colIndex'); //Checks filter is a checklist and caller is not null // if(o.activeFlt && colIndex && // o['col'+colIndex]===o.fltTypeCheckList && // !o.Evt.onSlcChange.caller){ return; } var _evt = e || global.event; if (o.popUpFilters) { _event.Event.stop(_evt); } if (o.onSlcChange) { o.filter(); } }, /*==================================================== - onblur event for select filters =====================================================*/ // _OnSlcBlur: function(e) {}, /*==================================================== - onclick event for checklist filters =====================================================*/ onCheckListClick: function onCheckListClick() { if (o.fillSlcOnDemand && this.getAttribute('filled') === '0') { var ct = this.getAttribute('ct'); o.Cpt.checkList._build(ct); o.Cpt.checkList.checkListDiv[ct].onclick = null; o.Cpt.checkList.checkListDiv[ct].title = ''; } }, /*==================================================== - onclick event for checklist filter container =====================================================*/ onCheckListFocus: function onCheckListFocus(e) { o.activeFilterId = this.firstChild.getAttribute('id'); o.activeFlt = _dom.Dom.id(o.activeFilterId); }, /*==================================================== - onclick event for validation button (btn property) =====================================================*/ onBtnClick: function onBtnClick() { o.filter(); } // , // _OnSlcPagesChangeEvt: null, //used by sort adapter /*==================================================== - onclick event slc parent node (enables filters) IE only =====================================================*/ // _EnableSlc: function() { // this.firstChild.disabled = false; // this.firstChild.focus(); // this.onclick = null; // }, // _Paging: { //used by sort adapter // nextEvt: null, // prevEvt: null, // lastEvt: null, // firstEvt: null // } }; } _createClass(TableFilter, [{ key: 'init', /*==================================================== - initialises filtering grid bar behaviours and layout =====================================================*/ value: function init() { if (this._hasGrid) { return; } if (!this.tbl) { this.tbl = _dom.Dom.id(this.id); } if (this.gridLayout) { this.refRow = this.startRow === null ? 0 : this.startRow; } if (this.popUpFilters && (this.filtersRowIndex === 0 && this.headersRow === 1 || this.gridLayout)) { this.headersRow = 0; } var f = this.cfg, n = this.singleSearchFlt ? 1 : this.nbCells, inpclass; if (window['tf_' + this.id] === undefined) { window['tf_' + this.id] = this; } //loads stylesheet if not imported //Issues with browsers != IE, IE rules in this case this.includeFile(this.stylesheetId, this.stylesheet, null, 'link'); //loads theme if (this.hasThemes) { this._loadThemes(); } if (this.rememberGridValues || this.rememberPageNb || this.rememberPageLen) { //var Store = require('modules/store').Store; // import {Store} from 'modules/store'; this.Cpt.store = new _modulesStore.Store(this); } if (this.gridLayout) { // var GridLayout = require('modules/gridLayout').GridLayout; // import {GridLayout} from 'modules/gridLayout'; this.Cpt.gridLayout = new _modulesGridLayout.GridLayout(this); this.Cpt.gridLayout.init(); } if (this.loader) { if (!this.Cpt.loader) { // var Loader = require('modules/loader').Loader; // import {Loader} from 'modules/loader'; this.Cpt.loader = new _modulesLoader.Loader(this); } } if (this.highlightKeywords) { // var Highlight = // require('modules/highlightKeywords').HighlightKeyword; // import {HighlightKeyword} from 'modules/highlightKeywords'; this.Cpt.highlightKeyword = new _modulesHighlightKeywords.HighlightKeyword(this); } if (this.popUpFilters) { if (!this.Cpt.popupFilter) { // var PopupFilter = require('modules/popupFilter').PopupFilter; // import {PopupFilter} from 'modules/popupFilter'; this.Cpt.popupFilter = new _modulesPopupFilter.PopupFilter(this); } this.Cpt.popupFilter.init(); } //filters grid is not generated if (!this.fltGrid) { this.refRow = this.refRow - 1; if (this.gridLayout) { this.refRow = 0; } this.nbFilterableRows = this.getRowsNb(); this.nbVisibleRows = this.nbFilterableRows; this.nbRows = this.nbFilterableRows + this.refRow; } else { if (this.isFirstLoad) { var fltrow; if (!this.gridLayout) { var thead = _dom.Dom.tag(this.tbl, 'thead'); if (thead.length > 0) { fltrow = thead[0].insertRow(this.filtersRowIndex); } else { fltrow = this.tbl.insertRow(this.filtersRowIndex); } if (this.headersRow > 1 && this.filtersRowIndex <= this.headersRow && !this.popUpFilters) { this.headersRow++; } if (this.popUpFilters) { this.headersRow++; } fltrow.className = this.fltsRowCssClass; //Disable for grid_layout if (this.isExternalFlt && (!this.gridLayout || this.popUpFilters)) { fltrow.style.display = 'none'; } } this.nbFilterableRows = this.getRowsNb(); this.nbVisibleRows = this.nbFilterableRows; this.nbRows = this.tbl.rows.length; for (var i = 0; i < n; i++) { // this loop adds filters if (this.popUpFilters) { this.Cpt.popupFilter.build(i); } var fltcell = _dom.Dom.create(this.fltCellTag), col = this['col' + i], externalFltTgtId = this.isExternalFlt && this.externalFltTgtIds ? this.externalFltTgtIds[i] : null; if (this.singleSearchFlt) { fltcell.colSpan = this.nbCells; } if (!this.gridLayout) { fltrow.appendChild(fltcell); } inpclass = i == n - 1 && this.displayBtn ? this.fltSmallCssClass : this.fltCssClass; if (col === undefined) { col = f['col_' + i] === undefined ? this.fltTypeInp : _string.Str.lower(f['col_' + i]); } //only 1 input for single search if (this.singleSearchFlt) { col = this.fltTypeInp; inpclass = this.singleFltCssClass; } //drop-down filters if (col === this.fltTypeSlc || col === this.fltTypeMulti) { if (!this.Cpt.dropdown) { // var Dropdown = require('modules/dropdown').Dropdown; // import {Dropdown} from 'modules/dropdown'; this.Cpt.dropdown = new _modulesDropdown.Dropdown(this); } var dropdown = this.Cpt.dropdown; var slc = _dom.Dom.create(this.fltTypeSlc, ['id', this.prfxFlt + i + '_' + this.id], ['ct', i], ['filled', '0']); if (col === this.fltTypeMulti) { slc.multiple = this.fltTypeMulti; slc.title = dropdown.multipleSlcTooltip; } slc.className = _string.Str.lower(col) === this.fltTypeSlc ? inpclass : this.fltMultiCssClass; // for ie<=6 //filter is appended in desired external element if (externalFltTgtId) { _dom.Dom.id(externalFltTgtId).appendChild(slc); this.externalFltEls.push(slc); } else { fltcell.appendChild(slc); } this.fltIds.push(this.prfxFlt + i + '_' + this.id); if (!this.fillSlcOnDemand) { dropdown._build(i); } _event.Event.add(slc, 'keypress', this.Evt.detectKey); _event.Event.add(slc, 'change', this.Evt.onSlcChange); _event.Event.add(slc, 'focus', this.Evt.onSlcFocus); // evt.add(slc, 'blur', this.Evt._OnSlcBlur); //1st option is created here since dropdown.build isn't //invoked if (this.fillSlcOnDemand) { var opt0 = _dom.Dom.createOpt(this.displayAllText, ''); slc.appendChild(opt0); } } // checklist else if (col === this.fltTypeCheckList) { var checkList; if (!this.Cpt.checkList) { // var CheckList = // require('modules/checkList').CheckList; // import {CheckList} from 'modules/checkList'; this.Cpt.checkList = new _modulesCheckList.CheckList(this); checkList = this.Cpt.checkList; } var divCont = _dom.Dom.create('div', ['id', checkList.prfxCheckListDiv + i + '_' + this.id], ['ct', i], ['filled', '0']); divCont.className = checkList.checkListDivCssClass; //filter is appended in desired element if (externalFltTgtId) { _dom.Dom.id(externalFltTgtId).appendChild(divCont); this.externalFltEls.push(divCont); } else { fltcell.appendChild(divCont); } checkList.checkListDiv[i] = divCont; this.fltIds.push(this.prfxFlt + i + '_' + this.id); if (!this.fillSlcOnDemand) { checkList._build(i); } if (this.fillSlcOnDemand) { _event.Event.add(divCont, 'click', this.Evt.onCheckListClick); divCont.appendChild(_dom.Dom.text(checkList.activateCheckListTxt)); } _event.Event.add(divCont, 'click', this.Evt.onCheckListFocus); } else { //show/hide input var inptype = col === this.fltTypeInp ? 'text' : 'hidden'; var inp = _dom.Dom.create(this.fltTypeInp, ['id', this.prfxFlt + i + '_' + this.id], ['type', inptype], ['ct', i]); if (inptype !== 'hidden' && this.watermark) { inp.setAttribute('placeholder', this.isWatermarkArray ? this.watermark[i] || '' : this.watermark); } inp.className = inpclass; inp.onfocus = this.Evt.onInpFocus; //filter is appended in desired element if (externalFltTgtId) { _dom.Dom.id(externalFltTgtId).appendChild(inp); this.externalFltEls.push(inp); } else { fltcell.appendChild(inp); } this.fltIds.push(this.prfxFlt + i + '_' + this.id); inp.onkeypress = this.Evt.detectKey; inp.onkeydown = this.Evt.onKeyDown; inp.onkeyup = this.Evt.onKeyUp; inp.onblur = this.Evt.onInpBlur; if (this.rememberGridValues) { var flts_values = this.Cpt.store.getFilterValues(this.fltsValuesCookie); if (flts_values[i] != ' ') { this.setFilterValue(i, flts_values[i], false); } } } // this adds submit button if (i == n - 1 && this.displayBtn) { var btn = _dom.Dom.create(this.fltTypeInp, ['id', this.prfxValButton + i + '_' + this.id], ['type', 'button'], ['value', this.btnText]); btn.className = this.btnCssClass; //filter is appended in desired element if (externalFltTgtId) { _dom.Dom.id(externalFltTgtId).appendChild(btn); } else { fltcell.appendChild(btn); } btn.onclick = this.Evt.onBtnClick; } //if } // for i } else { this._resetGrid(); } //if isFirstLoad } //if this.fltGrid /* Filter behaviours */ if (this.rowsCounter) { // var RowsCounter = require('modules/rowsCounter').RowsCounter; // import {RowsCounter} from 'modules/rowsCounter'; this.Cpt.rowsCounter = new _modulesRowsCounter.RowsCounter(this); this.Cpt.rowsCounter.init(); } if (this.statusBar) { // var StatusBar = require('modules/statusBar').StatusBar; // import {StatusBar} from 'modules/statusBar'; this.Cpt.statusBar = new _modulesStatusBar.StatusBar(this); this.Cpt.statusBar.init(); } if (this.paging || this.Cpt.paging && this.Cpt.paging.isPagingRemoved) { // var Paging = require('modules/paging').Paging; // import {Paging} from 'modules/paging'; // if(!this.Cpt.paging){ this.Cpt.paging = new _modulesPaging.Paging(this); // } this.Cpt.paging.init(); } if (this.btnReset) { // var ClearButton = require('modules/clearButton').ClearButton; // import {ClearButton} from 'modules/clearButton'; this.Cpt.clearButton = new _modulesClearButton.ClearButton(this); this.Cpt.clearButton.init(); } if (this.helpInstructions) { // var Help = require('modules/help').Help; // import {Help} from 'modules/help'; this.Cpt.help = new _modulesHelp.Help(this); this.Cpt.help.init(); } if (this.hasColWidth && !this.gridLayout) { this.setColWidths(); } if (this.alternateBgs) { //1st time only if no paging and rememberGridValues // var AlternateRows = require('modules/alternateRows').AlternateRows; // import {AlternateRows} from 'modules/alternateRows'; this.Cpt.alternateRows = new _modulesAlternateRows.AlternateRows(this); this.Cpt.alternateRows.init(); } if (this.hasColOperation) { // var ColOps = require('modules/colOps').ColOps; // import {ColOps} from 'modules/colOps'; this.Cpt.colOps = new _modulesColOps.ColOps(this); this.Cpt.colOps.calc(); } if (this.sort /*|| this.gridLayout*/) { this.setSort(); } if (this.selectable || this.editable) { this.setEditable(); } this.isFirstLoad = false; this._hasGrid = true; if (this.rememberGridValues || this.rememberPageLen || this.rememberPageNb) { this.resetValues(); } //TF css class is added to table if (!this.gridLayout) { _dom.Dom.addClass(this.tbl, this.prfxTf); } if (this.loader) { this.Cpt.loader.show('none'); } /* Loads extensions */ if (this.hasExtensions) { // this.loadExtensions(); // this.registerExtensions(); this.initExtensions(); } if (this.onFiltersLoaded) { this.onFiltersLoaded.call(null, this); } } }, { key: 'EvtManager', /*==================================================== - TF events manager - Params: - event name (string) - config object (optional literal object) =====================================================*/ value: function EvtManager(evt, s) { var o = this; var slcIndex = s && s.slcIndex !== undefined ? s.slcIndex : null; var slcExternal = s && s.slcExternal !== undefined ? s.slcExternal : false; var slcId = s && s.slcId !== undefined ? s.slcId : null; var pgIndex = s && s.pgIndex !== undefined ? s.pgIndex : null; function efx() { if (!evt) { return; } switch (evt) { case o.Evt.name.filter: if (o.isModFilterFn) { o.modFilterFn.call(null, o); } else { o._filter(); } break; case o.Evt.name.dropdown: if (o.linkedFilters) { o.Cpt.dropdown._build(slcIndex, true); } else { o.Cpt.dropdown._build(slcIndex, false, slcExternal, slcId); } break; case o.Evt.name.checklist: o.Cpt.checkList._build(slcIndex, slcExternal, slcId); break; case o.Evt.name.changepage: o.Cpt.paging._changePage(pgIndex); break; case o.Evt.name.clear: o._clearFilters(); o._filter(); break; case o.Evt.name.changeresultsperpage: o.Cpt.paging._changeResultsPerPage(); break; case o.Evt.name.resetvalues: o._resetValues(); o._filter(); break; case o.Evt.name.resetpage: o.Cpt.paging._resetPage(o.pgNbCookie); break; case o.Evt.name.resetpagelength: o.Cpt.paging._resetPageLength(o.pgLenCookie); break; case o.Evt.name.sort: void 0; break; case o.Evt.name.loadextensions: o._loadExtensions(); break; case o.Evt.name.loadthemes: o._loadThemes(); break; default: //to be used by extensions events when needed o['_' + evt].call(null, o, s); break; } if (o.statusBar) { o.Cpt.statusBar.message(''); } if (o.loader) { o.Cpt.loader.show('none'); } } if (this.loader || this.statusBar) { try { this.Cpt.loader.show(''); this.Cpt.statusBar.message(this['msg' + evt]); } catch (e) {} global.setTimeout(efx, this.execDelay); } else { efx(); } } }, { key: 'initExtensions', value: function initExtensions() { var exts = this.extensions; for (var i = 0; i < exts.length; i++) { var ext = exts[i]; if (_types.Types.isUndef(this.ExtRegistry[ext.name])) { this.loadExtension(ext); } } } }, { key: 'loadExtension', value: function loadExtension(ext) { var _this = this; if (!ext || !ext.name) { return; } var name = ext.name; var path = ext.path; var modulePath; if (name && path) { modulePath = ext.path + '/' + name; } else { name = name.replace('.js', ''); modulePath = './extensions/{}/{}'.replace(/{}/g, name); } require([modulePath], function (mod) { var inst = new mod(_this, ext); inst.init(); _this.ExtRegistry[name] = inst; }); } }, { key: 'loadThemes', value: function loadThemes() { this.EvtManager(this.Evt.name.loadthemes); } }, { key: '_loadThemes', /*==================================================== - loads TF themes =====================================================*/ value: function _loadThemes() { if (!this.hasThemes) { return; } if (!this.Thm) { /*** TF themes ***/ var o = this; this.Thm = { list: {}, add: function add(thmName, thmDesc, thmPath, thmCallBack) { var file = thmPath.split('/')[thmPath.split('/').length - 1], re = new RegExp(file), path = thmPath.replace(re, ''); o.Thm.list[thmName] = { name: thmName, description: thmDesc, file: file, path: path, callback: thmCallBack }; } }; } //Default theme config if (this.enableDefaultTheme) { this.themes = { name: ['DefaultTheme'], src: [this.themesPath + 'Default/TF_Default.css'], description: ['Default Theme'] }; this.Thm.add('DefaultTheme', this.themesPath + 'Default/TF_Default.css', 'Default Theme'); } if (_types.Types.isArray(this.themes.name) && _types.Types.isArray(this.themes.src)) { var thm = this.themes; for (var i = 0; i < thm.name.length; i++) { var thmPath = thm.src[i], thmName = thm.name[i], thmInit = thm.initialize && thm.initialize[i] ? thm.initialize[i] : null, thmDesc = thm.description && thm.description[i] ? thm.description[i] : null; //Registers theme this.Thm.add(thmName, thmDesc, thmPath, thmInit); if (!this.isImported(thmPath, 'link')) { this.includeFile(thmName, thmPath, null, 'link'); } if (_types.Types.isFn(thmInit)) { thmInit.call(null, this); } } } //Some elements need to be overriden for theme //Reset button this.btnResetText = null; this.btnResetHtml = ''; //Paging buttons this.btnPrevPageHtml = ''; this.btnNextPageHtml = ''; this.btnFirstPageHtml = ''; this.btnLastPageHtml = ''; //Loader this.loader = true; this.loaderHtml = '
'; this.loaderText = null; } }, { key: 'remove', /*==================================================== - removes a filter grid =====================================================*/ value: function remove() { if (this.fltGrid && this._hasGrid) { var rows = this.tbl.rows; if (this.paging) { this.Cpt.paging.destroy(); } if (this.statusBar) { this.Cpt.statusBar.destroy(); } if (this.rowsCounter) { this.Cpt.rowsCounter.destroy(); } if (this.btnReset) { this.Cpt.clearButton.destroy(); } if (this.helpInstructions) { this.Cpt.help.destroy(); } if (this.isExternalFlt && !this.popUpFilters) { this.removeExternalFlts(); } if (this.infDiv) { this.removeToolbar(); } if (this.highlightKeywords) { this.Cpt.highlightKeyword.unhighlightAll(); } if (this.sort) { // this.RemoveSort(); this.ExtRegistry.sort.destroy(); } if (this.loader) { this.Cpt.loader.remove(); } if (this.popUpFilters) { this.Cpt.popupFilter.destroy(); } if (this.markActiveColumns) { this.clearActiveColumns(); } if (this.editable || this.selectable) { this.removeEditable(); } //this loop shows all rows and removes validRow attribute for (var j = this.refRow; j < this.nbRows; j++) { rows[j].style.display = ''; try { if (rows[j].hasAttribute('validRow')) { rows[j].removeAttribute('validRow'); } } catch (e) { //ie<=6 doesn't support hasAttribute method var row = rows[j]; var attribs = row.attributes; for (var x = 0; x < attribs.length; x++) { if (_string.Str.lower(attribs.nodeName) === 'validrow') { row.removeAttribute('validRow'); } } } //removes alternating colors if (this.alternateBgs) { this.Cpt.alternateRows.removeRowBg(j); } } //for j if (this.fltGrid && !this.gridLayout) { this.fltGridEl = rows[this.filtersRowIndex]; this.tbl.deleteRow(this.filtersRowIndex); } if (this.gridLayout) { this.Cpt.gridLayout.destroy(); } _dom.Dom.removeClass(this.tbl, this.prfxTf); this.activeFlt = null; this.isStartBgAlternate = true; this._hasGrid = false; this.tbl = null; } //if this.fltGrid } }, { key: 'setToolbar', /*==================================================== - Generates div above table where paging, reset button, rows counter label etc. are placed =====================================================*/ value: function setToolbar() { if (this.infDiv !== null) { return; } /*** container div ***/ var infdiv = _dom.Dom.create('div', ['id', this.prfxInfDiv + this.id]); infdiv.className = this.infDivCssClass; //custom container if (this.toolBarTgtId) { _dom.Dom.id(this.toolBarTgtId).appendChild(infdiv); } //grid-layout else if (this.gridLayout) { var gridLayout = this.Cpt.gridLayout; gridLayout.tblMainCont.appendChild(infdiv); infdiv.className = gridLayout.gridInfDivCssClass; } //default location: just above the table else { this.tbl.parentNode.insertBefore(infdiv, this.tbl); } this.infDiv = _dom.Dom.id(this.prfxInfDiv + this.id); /*** left div containing rows # displayer ***/ var ldiv = _dom.Dom.create('div', ['id', this.prfxLDiv + this.id]); ldiv.className = this.lDivCssClass; infdiv.appendChild(ldiv); this.lDiv = _dom.Dom.id(this.prfxLDiv + this.id); /*** right div containing reset button + nb results per page select ***/ var rdiv = _dom.Dom.create('div', ['id', this.prfxRDiv + this.id]); rdiv.className = this.rDivCssClass; infdiv.appendChild(rdiv); this.rDiv = _dom.Dom.id(this.prfxRDiv + this.id); /*** mid div containing paging elements ***/ var mdiv = _dom.Dom.create('div', ['id', this.prfxMDiv + this.id]); mdiv.className = this.mDivCssClass; infdiv.appendChild(mdiv); this.mDiv = _dom.Dom.id(this.prfxMDiv + this.id); // Enable help instructions by default is topbar is generated if (!this.helpInstructions) { if (!this.Cpt.help) { // var Help = require('modules/help').Help; // import {Help} from 'modules/help'; this.Cpt.help = new _modulesHelp.Help(this); } this.Cpt.help.init(); } } }, { key: 'removeToolbar', /*==================================================== - Removes div above table where paging, reset button, rows counter label etc. are placed =====================================================*/ value: function removeToolbar() { if (!this.infDiv) { return; } this.infDiv.parentNode.removeChild(this.infDiv); this.infDiv = null; } }, { key: 'removeExternalFlts', /*==================================================== - removes external filters =====================================================*/ value: function removeExternalFlts() { if (!this.isExternalFlt && !this.externalFltTgtIds) { return; } for (var ct = 0; ct < this.externalFltTgtIds.length; ct++) { var externalFltTgtId = this.externalFltTgtIds[ct], externalFlt = _dom.Dom.id(externalFltTgtId); if (externalFlt) { externalFlt.innerHTML = ''; } } } }, { key: 'setSort', /*==================================================== - Sets sorting feature by loading WebFX Sortable Table 1.12 plugin by Erik Arvidsson and TF adapter by Max Guglielmi =====================================================*/ value: function setSort() { // require(['adapterSortabletable'], (m)=> { // var adapterSortabletable = new m.AdapterSortableTable(this); // this.ExtRegistry.sort = adapterSortabletable; // adapterSortabletable.init(); // }); this.loadExtension({ name: 'adapterSortabletable.js', path: './extensions/sortabletable' }); } }, { key: 'performSort', value: function performSort() { this.EvtManager(this.Evt.name.sort); } }, { key: 'setEditable', /*==================================================== - Sets selection or edition features by loading ezEditTable script by Max Guglielmi =====================================================*/ value: function setEditable() { var ezEditConfig = this.ezEditTableConfig; if (this.isImported(ezEditConfig.src)) { this._enableEditable(); } else { this.includeFile(ezEditConfig.name, ezEditConfig.src, this._enableEditable); } if (ezEditConfig.loadStylesheet && !this.isImported(ezEditConfig.stylesheet, 'link')) { this.includeFile(ezEditConfig.stylesheetName, ezEditConfig.stylesheet, null, 'link'); } } }, { key: 'removeEditable', /*==================================================== - Removes selection or edition features =====================================================*/ value: function removeEditable() { var ezEditTable = this.ezEditTable; if (ezEditTable) { if (this.selectable) { ezEditTable.Selection.ClearSelections(); ezEditTable.Selection.Remove(); } if (this.editable) { ezEditTable.Editable.Remove(); } } } }, { key: 'resetEditable', /*==================================================== - Resets selection or edition features after removal =====================================================*/ value: function resetEditable() { var ezEditTable = this.ezEditTable; if (ezEditTable) { if (this.selectable) { ezEditTable.Selection.Set(); } if (this.editable) { ezEditTable.Editable.Set(); } } } }, { key: '_enableEditable', value: function _enableEditable(o) { if (!o) { o = this; } //start row for EditTable constructor needs to be calculated var startRow, ezEditConfig = o.ezEditTableConfig, thead = _dom.Dom.tag(o.tbl, 'thead'); //if thead exists and startRow not specified, startRow is calculated //automatically by EditTable if (thead.length > 0 && !ezEditConfig.startRow) { startRow = undefined; } //otherwise startRow config property if any or TableFilter refRow else { startRow = ezEditConfig.startRow || o.refRow; } ezEditConfig.scroll_into_view = ezEditConfig.scroll_into_view === false ? false : true; ezEditConfig.base_path = ezEditConfig.base_path || o.basePath + 'ezEditTable/'; ezEditConfig.editable = o.editable = o.cfg.editable; ezEditConfig.selection = o.selectable = o.cfg.selectable; if (o.selectable) { ezEditConfig.default_selection = ezEditConfig.default_selection || 'row'; } //CSS Styles ezEditConfig.active_cell_css = ezEditConfig.active_cell_css || 'ezETSelectedCell'; o._lastValidRowIndex = 0; o._lastRowIndex = 0; if (o.selectable) { //Row navigation needs to be calculated according to TableFilter's //validRowsIndex array var onAfterSelection = function onAfterSelection(et, selectedElm, e) { var slc = et.Selection; //Next valid filtered row needs to be selected var doSelect = function doSelect(nextRowIndex) { if (et.defaultSelection === 'row') { slc.SelectRowByIndex(nextRowIndex); } else { et.ClearSelections(); var cellIndex = selectedElm.cellIndex, row = o.tbl.rows[nextRowIndex]; if (et.defaultSelection === 'both') { slc.SelectRowByIndex(nextRowIndex); } if (row) { slc.SelectCell(row.cells[cellIndex]); } } //Table is filtered if (o.validRowsIndex.length !== o.getRowsNb()) { var r = o.tbl.rows[nextRowIndex]; if (r) { r.scrollIntoView(false); } if (cell) { if (cell.cellIndex === o.getCellsNb() - 1 && o.gridLayout) { o.tblCont.scrollLeft = 100000000; } else if (cell.cellIndex === 0 && o.gridLayout) { o.tblCont.scrollLeft = 0; } else { cell.scrollIntoView(false); } } } }; //table is not filtered if (!o.validRowsIndex) { return; } var validIndexes = o.validRowsIndex, validIdxLen = validIndexes.length, row = et.defaultSelection !== 'row' ? selectedElm.parentNode : selectedElm, //cell for default_selection = 'both' or 'cell' cell = selectedElm.nodeName === 'TD' ? selectedElm : null, keyCode = e !== undefined ? et.Event.GetKey(e) : 0, isRowValid = _array.Arr.has(validIndexes, row.rowIndex), nextRowIndex, //pgup/pgdown keys d = keyCode === 34 || keyCode === 33 ? o.pagingLength || et.nbRowsPerPage : 1; //If next row is not valid, next valid filtered row needs to be //calculated if (!isRowValid) { //Selection direction up/down if (row.rowIndex > o._lastRowIndex) { //last row if (row.rowIndex >= validIndexes[validIdxLen - 1]) { nextRowIndex = validIndexes[validIdxLen - 1]; } else { var calcRowIndex = o._lastValidRowIndex + d; if (calcRowIndex > validIdxLen - 1) { nextRowIndex = validIndexes[validIdxLen - 1]; } else { nextRowIndex = validIndexes[calcRowIndex]; } } } else { //first row if (row.rowIndex <= validIndexes[0]) { nextRowIndex = validIndexes[0]; } else { var v = validIndexes[o._lastValidRowIndex - d]; nextRowIndex = v ? v : validIndexes[0]; } } o._lastRowIndex = row.rowIndex; doSelect(nextRowIndex); } else { //If filtered row is valid, special calculation for //pgup/pgdown keys if (keyCode !== 34 && keyCode !== 33) { o._lastValidRowIndex = _array.Arr.indexByValue(validIndexes, row.rowIndex); o._lastRowIndex = row.rowIndex; } else { if (keyCode === 34) { //pgdown //last row if (o._lastValidRowIndex + d <= validIdxLen - 1) { nextRowIndex = validIndexes[o._lastValidRowIndex + d]; } else { nextRowIndex = [validIdxLen - 1]; } } else { //pgup //first row if (o._lastValidRowIndex - d <= validIndexes[0]) { nextRowIndex = validIndexes[0]; } else { nextRowIndex = validIndexes[o._lastValidRowIndex - d]; } } o._lastRowIndex = nextRowIndex; o._lastValidRowIndex = _array.Arr.indexByValue(validIndexes, nextRowIndex); doSelect(nextRowIndex); } } }; //Page navigation has to be enforced whenever selected row is out of //the current page range var onBeforeSelection = function onBeforeSelection(et, selectedElm, e) { var row = et.defaultSelection !== 'row' ? selectedElm.parentNode : selectedElm; if (o.paging) { if (o.Cpt.paging.nbPages > 1) { var paging = o.Cpt.paging; //page length is re-assigned in case it has changed et.nbRowsPerPage = paging.pagingLength; var validIndexes = o.validRowsIndex, validIdxLen = validIndexes.length, pagingEndRow = parseInt(paging.startPagingRow, 10) + parseInt(paging.pagingLength, 10); var rowIndex = row.rowIndex; if (rowIndex === validIndexes[validIdxLen - 1] && paging.currentPageNb !== paging.nbPages) { paging.setPage('last'); } else if (rowIndex == validIndexes[0] && paging.currentPageNb !== 1) { paging.setPage('first'); } else if (rowIndex > validIndexes[pagingEndRow - 1] && rowIndex < validIndexes[validIdxLen - 1]) { paging.setPage('next'); } else if (rowIndex < validIndexes[paging.startPagingRow] && rowIndex > validIndexes[0]) { paging.setPage('previous'); } } } }; //Selected row needs to be visible when paging is activated if (o.paging) { o.onAfterChangePage = function (tf, i) { var et = tf.ExtRegistry.ezEditTable; var slc = et.Selection; var row = slc.GetActiveRow(); if (row) { row.scrollIntoView(false); } var cell = slc.GetActiveCell(); if (cell) { cell.scrollIntoView(false); } }; } //Rows navigation when rows are filtered is performed with the //EditTable row selection callback events if (ezEditConfig.default_selection === 'row') { var fnB = ezEditConfig.on_before_selected_row; ezEditConfig.on_before_selected_row = function () { onBeforeSelection(arguments[0], arguments[1], arguments[2]); if (fnB) { fnB.call(null, arguments[0], arguments[1], arguments[2]); } }; var fnA = ezEditConfig.on_after_selected_row; ezEditConfig.on_after_selected_row = function () { onAfterSelection(arguments[0], arguments[1], arguments[2]); if (fnA) { fnA.call(null, arguments[0], arguments[1], arguments[2]); } }; } else { var fnD = ezEditConfig.on_before_selected_cell; ezEditConfig.on_before_selected_cell = function () { onBeforeSelection(arguments[0], arguments[1], arguments[2]); if (fnD) { fnD.call(null, arguments[0], arguments[1], arguments[2]); } }; var fnC = ezEditConfig.on_after_selected_cell; ezEditConfig.on_after_selected_cell = function () { onAfterSelection(arguments[0], arguments[1], arguments[2]); if (fnC) { fnC.call(null, arguments[0], arguments[1], arguments[2]); } }; } } if (o.editable) { //Added or removed rows, TF rows number needs to be re-calculated var fnE = ezEditConfig.on_added_dom_row; ezEditConfig.on_added_dom_row = function () { o.nbFilterableRows++; if (!o.paging) { o.Cpt.rowsCounter.refresh(); } else { o.nbRows++; o.nbVisibleRows++; o.nbFilterableRows++; o.paging = false; o.Cpt.paging.destroy(); o.Cpt.paging.addPaging(); } if (o.alternateBgs) { o.Cpt.alternateRows.init(); } if (fnE) { fnE.call(null, arguments[0], arguments[1], arguments[2]); } }; if (ezEditConfig.actions && ezEditConfig.actions['delete']) { var fnF = ezEditConfig.actions['delete'].on_after_submit; ezEditConfig.actions['delete'].on_after_submit = function () { o.nbFilterableRows--; if (!o.paging) { o.Cpt.rowsCounter.refresh(); } else { o.nbRows--; o.nbVisibleRows--; o.nbFilterableRows--; o.paging = false; o.Cpt.paging.destroy(); o.Cpt.paging.addPaging(false); } if (o.alternateBgs) { o.Cpt.alternateRows.init(); } if (fnF) { fnF.call(null, arguments[0], arguments[1]); } }; } } try { o.ExtRegistry.ezEditTable = new EditTable(o.id, ezEditConfig, startRow); o.ExtRegistry.ezEditTable.Init(); } catch (e) { console.log(ezEditConfig.err); } } }, { key: 'resetValues', /*==================================================== - IE bug: it seems there is no way to make multiple selections programatically, only last selection is kept (multiple select previously populated via DOM) - Work-around: defer selection with a setTimeout If you find a more elegant solution to this let me know ;-) - For the moment only this solution seems to work! - Params: - slc = select object (select obj) - index to be selected (integer) - execute filtering (boolean) =====================================================*/ // __deferMultipleSelection: function(slc,index,filter){ // if(str.lower(slc.nodeName)!=='select'){ // return; // } // var doFilter = filter===undefined ? false : filter; // var o = this; // global.setTimeout(function(){ // slc.options[0].selected = false; // if(slc.options[index].value===''){ // slc.options[index].selected = false; // } // else{ // slc.options[index].selected = true; // if(doFilter){ // o.filter(); // } // } // }, 0.1); // }, /*==================================================== - Returns an array [[values],[texts]] with custom values for a given filter - Param: column index (integer) =====================================================*/ // _getCustomValues: function(colIndex){ // if(!colIndex){ // return; // } // //custom select test // var isCustomSlc = this.hasCustomSlcOptions && // array.has(this.customSlcOptions.cols, colIndex); // if(!isCustomSlc){ // return; // } // var optTxt = [], optArray = []; // var index = array.indexByValue(this.customSlcOptions.cols, colIndex); // var slcValues = this.customSlcOptions.values[index]; // var slcTexts = this.customSlcOptions.texts[index]; // var slcSort = this.customSlcOptions.sorts[index]; // for(var r=0; r