1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-25 00:40:32 +02:00
TableFilter/src/core.js

3051 lines
114 KiB
JavaScript
Raw Normal View History

2015-02-22 12:46:05 +01:00
define(["exports", "event", "dom", "string", "cookie", "types", "array", "helpers", "date", "sort", "modules/store", "modules/gridLayoutf"], function (exports, _event, _dom, _string, _cookie, _types, _array, _helpers, _date, _sort, _modulesStore, _modulesGridLayoutf) {
"use strict";
2015-02-22 12:46:05 +01:00
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
var evt = _event.Event;
var dom = _dom.Dom;
var str = _string.Str;
var cookie = _cookie.Cookie;
var types = _types.Types;
var array = _array.Arr;
var hlp = _helpers.Helpers;
var dateHelper = _date.DateHelper;
var Sort = _sort.Sort;
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
var global = window, isValidDate = dateHelper.isValid, formatDate = dateHelper.format, doc = global.document;
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
var TableFilter = (function () {
var TableFilter = function TableFilter(id) {
if (arguments.length === 0) {
return;
}
this.id = id;
this.version = "3.0";
this.year = new Date().getFullYear();
this.tbl = 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 || str.lower(this.tbl.nodeName) !== "table" || this.getRowsNb() === 0) {
throw new Error("Could not instantiate TF object: 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 (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 : "";
/*** 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];
2014-10-18 14:00:34 +02:00
var col = !cfgCol ? this.fltTypeInp : str.lower(cfgCol);
2014-09-20 15:56:35 +02:00
this.fltCol.push(col);
2015-02-22 12:46:05 +01:00
this["col" + j] = col;
}
2014-09-20 06:57:49 +02:00
2015-02-22 12:46:05 +01:00
/*** Developer's additional methods ***/
this.publicMethods = f.public_methods !== undefined ? f.public_methods : false;
2015-02-22 12:46:05 +01:00
/*** filters' grid properties ***/
2014-09-20 06:57:49 +02:00
2015-02-22 12:46:05 +01:00
//enables/disables filter grid
this.fltGrid = f.grid === false ? false : true;
2014-09-20 06:57:49 +02:00
2015-02-22 12:46:05 +01:00
/*** Grid layout ***/
//enables/disables grid layout (fixed headers)
this.gridLayout = f.grid_layout ? true : false;
this.sourceTblHtml = null;
if (this.gridLayout) {
2014-09-20 15:56:35 +02:00
//Firefox does not support outerHTML property...
2015-02-22 12:46:05 +01:00
if (this.tbl.outerHTML === undefined) {
setOuterHtml();
}
2014-09-20 15:56:35 +02:00
this.sourceTblHtml = this.tbl.outerHTML;
2015-02-22 12:46:05 +01:00
}
/*** ***/
2014-09-20 06:57:49 +02:00
2015-02-22 12:46:05 +01:00
this.filtersRowIndex = f.filters_row_index || 0;
this.headersRow = f.headers_row_index || (this.filtersRowIndex === 0 ? 1 : 0);
2014-09-20 10:09:23 +02:00
2015-02-22 12:46:05 +01:00
if (this.gridLayout) {
if (this.headersRow > 1) {
this.filtersRowIndex = this.headersRow + 1;
2014-09-20 15:56:35 +02:00
} else {
2015-02-22 12:46:05 +01:00
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.isFn(f.on_before_filter) ? f.on_before_filter : null;
//calls function after filtering
this.onAfterFilter = 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.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.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.isFn(f.custom_cell_data) ? f.custom_cell_data : null;
//input watermark text array
this.watermark = f.watermark || "";
this.isWatermarkArray = 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.isFn(f.on_before_active_column) ? f.on_before_active_column : null;
//calls function after active column header is marked
this.onAfterActiveColumn = 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.isObj(f.custom_slc_options) ? true : false;
this.customSlcOptions = 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 || "^[\u00a5\u00a3\u20ac$]";
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.isFn(f.on_before_reset) ? f.on_before_reset : null;
//callback function after filters are cleared
this.onAfterReset = 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;
//indicates if tables was sorted
this.sorted = 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.basePath + "sortabletable.js";
this.sortConfig.adapterSrc = this.sortConfig["adapter_src"] !== undefined ? f.sort_config.adapter_src : this.basePath + "tfAdapter.sortabletable.js";
this.sortConfig.initialize = this.sortConfig["initialize"] !== undefined ? f.sort_config.initialize : function (o) {
if (o.SetSortTable) {
o.SetSortTable();
}
};
this.sortConfig.sortTypes = 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.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.basePath + "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.basePath + "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.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.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_";
//table container if fixed headers enabled
this.prfxContentDiv = "cont_";
//checklist filter container div
this.prfxCheckListDiv = "chkdiv_";
//pages select
this.prfxSlcPages = "slcPages_";
//results per page select
this.prfxSlcResults = "slcResults_";
//label preciding results per page select
this.prfxSlcResultsTxt = "slcResultsTxt_";
//span containing next page button
this.prfxBtnNextSpan = "btnNextSpan_";
//span containing previous page button
this.prfxBtnPrevSpan = "btnPrevSpan_";
//span containing last page button
this.prfxBtnLastSpan = "btnLastSpan_";
//span containing first page button
this.prfxBtnFirstSpan = "btnFirstSpan_";
//next button
this.prfxBtnNext = "btnNext_";
//previous button
this.prfxBtnPrev = "btnPrev_";
//last button
this.prfxBtnLast = "btnLast_";
//first button
this.prfxBtnFirst = "btnFirst_";
//span for tot nb pages
this.prfxPgSpan = "pgspan_";
//span preceding pages select (contains 'Page')
this.prfxPgBeforeSpan = "pgbeforespan_";
//span following pages select (contains ' of ')
this.prfxPgAfterSpan = "pgafterspan_";
//rows counter div
this.prfxCounter = "counter_";
//nb displayed rows label
this.prfxTotRows = "totrows_span_";
//label preceding nb rows label
this.prfxTotRowsTxt = "totRowsTextSpan_";
//span containing reset button
this.prfxResetSpan = "resetspan_";
//loader div
this.prfxLoader = "load_";
//status bar div
this.prfxStatus = "status_";
//status bar label
this.prfxStatusSpan = "statusSpan_";
//text preceding status bar label
this.prfxStatusTxt = "statusText_";
//filter values cookie
this.prfxCookieFltsValues = "tf_flts_";
//page nb cookie
this.prfxCookiePageNb = "tf_pgnb_";
//page length cookie
this.prfxCookiePageLen = "tf_pglen_";
//div containing grid elements if grid_layout true
this.prfxMainTblCont = "gridCont_";
//div containing table if grid_layout true
this.prfxTblCont = "tblCont_";
//div containing headers table if grid_layout true
this.prfxHeadTblCont = "tblHeadCont_";
//headers' table if grid_layout true
this.prfxHeadTbl = "tblHead_";
//id of td containing the filter if grid_layout true
this.prfxGridFltTd = "_td_";
//id of th containing column header if grid_layout true
this.prfxGridTh = "tblHeadTh_";
//id prefix for help elements
this.prfxHelpSpan = "helpSpan_";
//id prefix for help elements
this.prfxHelpDiv = "helpDiv_";
//id prefix for pop-up filter span
this.prfxPopUpSpan = "popUpSpan_";
//id prefix for pop-up div containing filter
this.prfxPopUpDiv = "popUpDiv_";
/*** 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;
/*** themes ***/
this.enableDefaultTheme = f.enable_default_theme === true ? true : false;
//imports themes
this.hasThemes = (f.enable_default_theme || (f.themes && types.isObj(f.themes))) ? true : false;
this.themes = this.hasThemes ? f.themes : null;
//themes path
this.themesPath = f.themes_path || this.basePath + "TF_Themes/";
// Components
this.Cpt = {
2014-11-09 09:31:15 +01:00
loader: null,
2014-11-15 09:39:10 +01:00
alternateRows: null,
2014-11-16 01:29:07 +01:00
colOps: null,
2014-11-22 15:01:29 +01:00
rowsCounter: null,
gridLayout: null,
store: null,
2015-01-11 11:22:52 +01:00
highlightKeywords: null,
2015-02-01 09:26:48 +01:00
paging: null,
2015-02-15 04:25:22 +01:00
checkList: null,
2015-02-15 09:55:23 +01:00
dropdown: null,
2015-02-19 05:40:46 +01:00
popupFilter: null,
2015-02-20 05:03:57 +01:00
clearButton: null,
2015-02-20 14:46:57 +01:00
help: null,
statusBar: null
2015-02-22 12:46:05 +01:00
};
2015-02-22 12:46:05 +01:00
/*** TF events ***/
var o = this;
this.Evt = {
2014-09-20 15:56:35 +02:00
name: {
2015-02-22 12:46:05 +01:00
filter: "Filter",
dropdown: "dropdown",
checklist: "checkList",
changepage: "changePage",
clear: "Clear",
changeresultsperpage: "changeResults",
resetvalues: "ResetValues",
resetpage: "resetPage",
resetpagelength: "resetPageLength",
sort: "Sort",
loadextensions: "LoadExtensions",
loadthemes: "LoadThemes"
2014-09-20 15:56:35 +02:00
},
2015-02-22 12:46:05 +01:00
getKeyCode: function (evt) {
return evt.charCode ? evt.charCode : (evt.keyCode ? evt.keyCode : (evt.which ? evt.which : 0));
2014-09-20 15:56:35 +02:00
},
/*====================================================
- Detects <enter> key for a given element
=====================================================*/
2015-02-22 12:46:05 +01:00
_DetectKey: function (e) {
if (!o.enterKey) {
return;
}
var _evt = e || global.event;
if (_evt) {
var key = o.Evt.getKeyCode(_evt);
if (key === 13) {
o._filter();
evt.cancel(_evt);
evt.stop(_evt);
} else {
o.isUserTyping = true;
global.clearInterval(o.onKeyUpTimer);
o.onKeyUpTimer = undefined;
}
} //if evt
2014-09-20 15:56:35 +02:00
},
/*====================================================
- onkeyup event for text filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnKeyUp: function (e) {
if (!o.onKeyUp) {
return;
}
var _evt = e || global.event;
var key = o.Evt.getKeyCode(_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;
}
2014-09-20 15:56:35 +02:00
},
/*====================================================
- onkeydown event for input filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnKeyDown: function (e) {
if (!o.onKeyUp) {
return;
}
o.isUserTyping = true;
2014-09-20 15:56:35 +02:00
},
/*====================================================
- onblur event for input filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnInpBlur: function (e) {
if (o.onKeyUp) {
o.isUserTyping = false;
global.clearInterval(o.onKeyUpTimer);
}
if (o.ezEditTable) {
if (o.editable) {
o.ezEditTable.Editable.Set();
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
if (o.selectable) {
o.ezEditTable.Selection.Set();
}
}
2014-09-20 15:56:35 +02:00
},
/*====================================================
- onfocus event for input filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnInpFocus: function (e) {
var _evt = e || global.event;
o.activeFilterId = this.getAttribute("id");
o.activeFlt = dom.id(o.activeFilterId);
if (o.popUpFilters) {
evt.cancel(_evt);
evt.stop(_evt);
}
if (o.ezEditTable) {
if (o.editable) {
o.ezEditTable.Editable.Remove();
}
if (o.selectable) {
o.ezEditTable.Selection.Remove();
}
}
2014-09-20 15:56:35 +02:00
},
/*====================================================
2014-09-20 15:56:35 +02:00
- onfocus event for select filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnSlcFocus: function (e) {
var _evt = e || global.event;
o.activeFilterId = this.getAttribute("id");
o.activeFlt = 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) {
evt.cancel(_evt);
evt.stop(_evt);
}
2014-09-20 15:56:35 +02:00
},
/*====================================================
- onchange event for select filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnSlcChange: function (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) {
evt.stop(_evt);
}
if (o.onSlcChange) {
o.filter();
}
2014-09-20 15:56:35 +02:00
},
/*====================================================
- onblur event for select filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnSlcBlur: function (e) {},
2014-09-20 15:56:35 +02:00
/*====================================================
- onclick event for checklist filters
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnCheckListClick: function () {
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 = "";
}
2014-09-20 15:56:35 +02:00
},
/*====================================================
- onclick event for checklist filter container
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnCheckListFocus: function (e) {
o.activeFilterId = this.firstChild.getAttribute("id");
o.activeFlt = dom.id(o.activeFilterId);
2014-09-20 15:56:35 +02:00
},
2015-02-22 12:46:05 +01:00
_OnCheckListBlur: function (e) {},
2014-09-20 15:56:35 +02:00
/*====================================================
- onclick event for validation button
(btn property)
=====================================================*/
2015-02-22 12:46:05 +01:00
_OnBtnClick: function () {
o.filter();
2014-09-20 15:56:35 +02:00
},
_OnSlcPagesChangeEvt: null, //used by sort adapter
/*====================================================
- onclick event slc parent node (enables filters)
IE only
=====================================================*/
2015-02-22 12:46:05 +01:00
_EnableSlc: function () {
this.firstChild.disabled = false;
this.firstChild.focus();
this.onclick = null;
2014-09-20 15:56:35 +02:00
},
2015-02-20 05:14:47 +01:00
2014-09-20 15:56:35 +02:00
_Paging: { //used by sort adapter
2015-02-22 12:46:05 +01:00
nextEvt: null,
prevEvt: null,
lastEvt: null,
firstEvt: null
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
};
2014-09-20 15:56:35 +02:00
};
2015-02-22 12:46:05 +01:00
_classProps(TableFilter, null, {
init: {
writable: true,
value: function () {
if (this._hasGrid) {
2014-11-15 15:34:32 +01:00
return;
2015-02-22 12:46:05 +01:00
}
if (!this.tbl) {
this.tbl = dom.id(this.id);
2015-02-22 12:46:05 +01:00
}
if (this.gridLayout) {
this.refRow = this.startRow === null ? 0 : this.startRow;
}
if (this.popUpFilters && ((this.filtersRowIndex === 0 && this.headersRow === 1) || this.gridLayout)) {
2014-09-20 15:56:35 +02:00
this.headersRow = 0;
2015-02-22 12:46:05 +01:00
}
var f = this.cfg, n = this.singleSearchFlt ? 1 : this.nbCells, inpclass;
2015-02-22 12:46:05 +01:00
if (window["tf_" + this.id] === undefined) {
window["tf_" + this.id] = this;
}
2015-02-22 12:46:05 +01:00
//loads stylesheet if not imported
//Issues with browsers != IE, IE rules in this case
this.includeFile(this.stylesheetId, this.stylesheet, null, "link");
2015-02-22 12:46:05 +01:00
//loads theme
if (this.hasThemes) {
this._LoadThemes();
}
2015-02-22 12:46:05 +01:00
if (this.rememberGridValues || this.rememberPageNb || this.rememberPageLen) {
var Store = _modulesStore.Store;
this.Cpt.store = new Store(this);
2015-02-22 12:46:05 +01:00
}
2014-12-05 02:10:00 +01:00
2015-02-22 12:46:05 +01:00
if (this.gridLayout) {
var GridLayout = _modulesGridLayoutf.GridLayout;
2014-11-22 15:01:29 +01:00
this.Cpt.gridLayout = new GridLayout(this);
this.Cpt.gridLayout.init();
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
if (this.loader) {
if (!this.Cpt.loader) {
var Loader = require("modules/loader").Loader;
this.Cpt.loader = new Loader(this);
2015-02-15 09:55:23 +01:00
}
2015-02-22 12:46:05 +01:00
}
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
if (this.highlightKeywords) {
var Highlight = require("modules/highlightKeywords").HighlightKeyword;
this.Cpt.highlightKeyword = new Highlight(this);
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
if (this.popUpFilters) {
if (!this.Cpt.popupFilter) {
var PopupFilter = require("modules/popupFilter").PopupFilter;
this.Cpt.popupFilter = new PopupFilter(this);
2015-02-15 09:55:23 +01:00
}
this.Cpt.popupFilter.init();
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
//filters grid is not generated
if (!this.fltGrid) {
this.refRow = this.refRow - 1;
if (this.gridLayout) {
this.refRow = 0;
2014-09-20 15:56:35 +02:00
}
this.nbFilterableRows = this.getRowsNb();
2014-09-20 15:56:35 +02:00
this.nbVisibleRows = this.nbFilterableRows;
this.nbRows = this.nbFilterableRows + this.refRow;
2015-02-22 12:46:05 +01:00
} else {
if (this.isFirstLoad) {
var fltrow;
if (!this.gridLayout) {
var thead = dom.tag(this.tbl, "thead");
if (thead.length > 0) {
fltrow = thead[0].insertRow(this.filtersRowIndex);
} else {
fltrow = this.tbl.insertRow(this.filtersRowIndex);
}
2015-02-22 12:46:05 +01:00
if (this.headersRow > 1 && this.filtersRowIndex <= this.headersRow && !this.popUpFilters) {
this.headersRow++;
}
if (this.popUpFilters) {
this.headersRow++;
}
2015-02-22 12:46:05 +01:00
fltrow.className = this.fltsRowCssClass;
//Disable for grid_layout
if (this.isExternalFlt && (!this.gridLayout || this.popUpFilters)) {
fltrow.style.display = "none";
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
this.nbFilterableRows = this.getRowsNb();
this.nbVisibleRows = this.nbFilterableRows;
this.nbRows = this.tbl.rows.length;
2015-02-22 12:46:05 +01:00
for (var i = 0; i < n; i++) {
// this loop adds filters
2015-02-15 09:55:23 +01:00
2015-02-22 12:46:05 +01:00
if (this.popUpFilters) {
this.Cpt.popupFilter.build(i);
}
2015-02-15 09:55:23 +01:00
2015-02-22 12:46:05 +01:00
var fltcell = dom.create(this.fltCellTag), col = this["col" + i], externalFltTgtId = this.isExternalFlt && this.externalFltTgtIds ? this.externalFltTgtIds[i] : null;
2015-02-22 12:46:05 +01:00
if (this.singleSearchFlt) {
fltcell.colSpan = this.nbCells;
}
if (!this.gridLayout) {
fltrow.appendChild(fltcell);
}
inpclass = (i == n - 1 && this.displayBtn) ? this.fltSmallCssClass : this.fltCssClass;
2015-02-22 12:46:05 +01:00
if (col === undefined) {
col = f["col_" + i] === undefined ? this.fltTypeInp : str.lower(f["col_" + i]);
}
2015-02-22 12:46:05 +01:00
//only 1 input for single search
if (this.singleSearchFlt) {
col = this.fltTypeInp;
inpclass = this.singleFltCssClass;
}
2015-02-22 12:46:05 +01:00
//drop-down filters
if (col === this.fltTypeSlc || col === this.fltTypeMulti) {
if (!this.Cpt.dropdown) {
var Dropdown = require("modules/dropdown").Dropdown;
this.Cpt.dropdown = new Dropdown(this);
}
var dropdown = this.Cpt.dropdown;
2015-02-22 12:46:05 +01:00
var slc = dom.create(this.fltTypeSlc, ["id", this.prfxFlt + i + "_" + this.id], ["ct", i], ["filled", "0"]);
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
if (col === this.fltTypeMulti) {
slc.multiple = this.fltTypeMulti;
slc.title = dropdown.multipleSlcTooltip;
}
slc.className = str.lower(col) === this.fltTypeSlc ? inpclass : this.fltMultiCssClass; // for ie<=6
2015-02-22 12:46:05 +01:00
//filter is appended in desired external element
if (externalFltTgtId) {
dom.id(externalFltTgtId).appendChild(slc);
this.externalFltEls.push(slc);
} else {
fltcell.appendChild(slc);
}
2015-02-22 12:46:05 +01:00
this.fltIds.push(this.prfxFlt + i + "_" + this.id);
2015-02-22 12:46:05 +01:00
if (!this.fillSlcOnDemand) {
dropdown._build(i);
}
evt.add(slc, "keypress", this.Evt._DetectKey);
evt.add(slc, "change", this.Evt._OnSlcChange);
evt.add(slc, "focus", this.Evt._OnSlcFocus);
evt.add(slc, "blur", this.Evt._OnSlcBlur);
2015-02-22 12:46:05 +01:00
//1st option is created here since dropdown.build isn't
//invoked
if (this.fillSlcOnDemand) {
var opt0 = dom.createOpt(this.displayAllText, "");
slc.appendChild(opt0);
}
}
// checklist
else if (col === this.fltTypeCheckList) {
if (!this.Cpt.checkList) {
var CheckList = require("modules/checkList").CheckList;
this.Cpt.checkList = new CheckList(this);
}
var divCont = dom.create("div", ["id", this.prfxCheckListDiv + i + "_" + this.id], ["ct", i], ["filled", "0"]);
divCont.className = this.Cpt.checkList.checkListDivCssClass;
//filter is appended in desired element
if (externalFltTgtId) {
dom.id(externalFltTgtId).appendChild(divCont);
this.externalFltEls.push(divCont);
} else {
fltcell.appendChild(divCont);
}
this.Cpt.checkList.checkListDiv[i] = divCont;
this.fltIds.push(this.prfxFlt + i + "_" + this.id);
if (!this.fillSlcOnDemand) {
this.Cpt.checkList._build(i);
}
2015-02-22 12:46:05 +01:00
if (this.fillSlcOnDemand) {
evt.add(divCont, "click", this.Evt._OnCheckListClick);
divCont.appendChild(dom.text(this.Cpt.checkList.activateCheckListTxt));
}
evt.add(divCont, "click", this.Evt._OnCheckListFocus);
} else {
//show/hide input
var inptype = col === this.fltTypeInp ? "text" : "hidden";
var inp = 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.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.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.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;
2014-11-16 01:29:07 +01:00
this.Cpt.rowsCounter = new RowsCounter(this);
this.Cpt.rowsCounter.init();
2015-02-22 12:46:05 +01:00
}
if (this.statusBar) {
2015-02-20 14:46:57 +01:00
// this.SetStatusBar();
2015-02-22 12:46:05 +01:00
var StatusBar = require("modules/statusBar").StatusBar;
2015-02-20 14:46:57 +01:00
this.Cpt.statusBar = new StatusBar(this);
this.Cpt.statusBar.init();
2015-02-22 12:46:05 +01:00
}
if (this.paging) {
var Paging = require("modules/paging").Paging;
2015-01-11 11:22:52 +01:00
this.Cpt.paging = new Paging(this);
this.Cpt.paging.init();
2015-02-22 12:46:05 +01:00
}
if (this.btnReset) {
var ClearButton = require("modules/clearButton").ClearButton;
2015-02-19 05:40:46 +01:00
this.Cpt.clearButton = new ClearButton(this);
this.Cpt.clearButton.init();
2015-02-22 12:46:05 +01:00
}
if (this.helpInstructions) {
var Help = require("modules/help").Help;
2015-02-20 05:03:57 +01:00
this.Cpt.help = new Help(this);
this.Cpt.help.init();
2015-02-22 12:46:05 +01:00
}
if (this.hasColWidth && !this.gridLayout) {
this.setColWidths();
2015-02-22 12:46:05 +01:00
}
if (this.alternateBgs) {
2014-09-20 15:56:35 +02:00
//1st time only if no paging and rememberGridValues
2015-02-22 12:46:05 +01:00
var AlternateRows = require("modules/alternateRows").AlternateRows;
2014-11-09 09:31:15 +01:00
this.Cpt.alternateRows = new AlternateRows(this);
2014-11-16 01:29:07 +01:00
this.Cpt.alternateRows.init();
2015-02-22 12:46:05 +01:00
}
if (this.hasColOperation) {
var ColOps = require("modules/colOps").ColOps;
2014-11-15 09:39:10 +01:00
this.Cpt.colOps = new ColOps(this);
2014-11-16 01:29:07 +01:00
this.Cpt.colOps.calc();
2015-02-22 12:46:05 +01:00
}
if (this.sort || this.gridLayout) {
2014-09-20 15:56:35 +02:00
this.SetSort();
2015-02-22 12:46:05 +01:00
}
if (this.selectable || this.editable) {
2014-09-20 15:56:35 +02:00
this.SetEditable();
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
this.isFirstLoad = false;
this._hasGrid = true;
2015-02-22 12:46:05 +01:00
if (this.rememberGridValues || this.rememberPageLen || this.rememberPageNb) {
this.resetValues();
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
//TF css class is added to table
if (!this.gridLayout) {
2014-10-18 14:00:34 +02:00
dom.addClass(this.tbl, this.prfxTf);
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
if (this.loader) {
this.Cpt.loader.show("none");
}
2015-02-22 12:46:05 +01:00
/* Loads extensions */
if (this.hasExtensions) {
2014-09-20 15:56:35 +02:00
this.LoadExtensions();
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
if (this.onFiltersLoaded) {
this.onFiltersLoaded.call(null, this);
2015-02-22 12:46:05 +01:00
}
}
},
EvtManager: {
writable: true,
value: function (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();
}
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.dropdown:
if (o.linkedFilters) {
o.Cpt.dropdown._build(slcIndex, true);
} else {
o.Cpt.dropdown._build(slcIndex, false, slcExternal, slcId);
}
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.checklist:
o.Cpt.checkList._build(slcIndex, slcExternal, slcId);
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.changepage:
o.Cpt.paging._changePage(pgIndex);
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.clear:
o._clearFilters();
o._filter();
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.changeresultsperpage:
o.Cpt.paging._changeResultsPerPage();
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.resetvalues:
o._resetValues();
o._filter();
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.resetpage:
o.Cpt.paging._resetPage(o.pgNbCookie);
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.resetpagelength:
o.Cpt.paging._resetPageLength(o.pgLenCookie);
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.sort:
void (0);
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.loadextensions:
o._LoadExtensions();
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
case o.Evt.name.loadthemes:
o._LoadThemes();
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
default: //to be used by extensions events when needed
o["_" + evt].call(null, o, s);
2014-09-20 15:56:35 +02:00
break;
}
2015-02-22 12:46:05 +01:00
if (o.statusBar) {
o.Cpt.statusBar.message("");
}
2015-02-22 12:46:05 +01:00
if (o.loader) {
o.Cpt.loader.show("none");
}
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
if (this.loader || this.statusBar) {
try {
this.Cpt.loader.show("");
// this.StatusMsg(o['msg'+evt]);
this.Cpt.statusBar.message(this["msg" + evt]);
} catch (e) {}
2014-11-09 06:12:03 +01:00
global.setTimeout(efx, this.execDelay);
2015-02-22 12:46:05 +01:00
} else {
2014-09-20 15:56:35 +02:00
efx();
2015-02-22 12:46:05 +01:00
}
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
},
ImportModule: {
writable: true,
value: function (module) {
if (!module.path || !module.name) {
2014-09-21 14:52:12 +02:00
return;
2015-02-22 12:46:05 +01:00
}
this.includeFile(module.name, module.path, module.init);
}
},
LoadExtensions: {
writable: true,
value: function () {
if (!this.Ext) {
2014-11-22 15:01:29 +01:00
/*** TF extensions ***/
var o = this;
this.Ext = {
2015-02-22 12:46:05 +01:00
list: {},
add: function (extName, extDesc, extPath, extCallBack) {
var file = extPath.split("/")[extPath.split("/").length - 1], re = new RegExp(file), path = extPath.replace(re, "");
o.Ext.list[extName] = {
name: extName,
description: extDesc,
file: file,
path: path,
callback: extCallBack
};
}
2014-11-22 15:01:29 +01:00
};
2015-02-22 12:46:05 +01:00
}
this.EvtManager(this.Evt.name.loadextensions);
}
},
_LoadExtensions: {
writable: true,
value: function () {
if (!this.hasExtensions || !types.isArray(this.extensions.name) || !types.isArray(this.extensions.src)) {
2014-11-22 15:01:29 +01:00
return;
2015-02-22 12:46:05 +01:00
}
var ext = this.extensions;
for (var e = 0; e < ext.name.length; e++) {
var extPath = ext.src[e], extName = ext.name[e], extInit = (ext.initialize && ext.initialize[e]) ? ext.initialize[e] : null, extDesc = (ext.description && ext.description[e]) ? ext.description[e] : null;
2014-11-22 15:01:29 +01:00
//Registers extension
this.Ext.add(extName, extDesc, extPath, extInit);
2015-02-22 12:46:05 +01:00
if (this.isImported(extPath)) {
extInit.call(null, this);
2014-11-22 15:01:29 +01:00
} else {
2015-02-22 12:46:05 +01:00
this.includeFile(extName, extPath, extInit);
2014-11-22 15:01:29 +01:00
}
2015-02-22 12:46:05 +01:00
}
2014-11-22 15:01:29 +01:00
}
2015-02-22 12:46:05 +01:00
},
LoadThemes: {
writable: true,
value: function () {
this.EvtManager(this.Evt.name.loadthemes);
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
},
_LoadThemes: {
writable: true,
value: function () {
if (!this.hasThemes) {
return;
}
if (!this.Thm) {
2014-09-20 15:56:35 +02:00
/*** TF themes ***/
var o = this;
this.Thm = {
2015-02-22 12:46:05 +01:00
list: {},
add: function (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
};
}
2014-09-20 15:56:35 +02:00
};
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
//Default theme config
if (this.enableDefaultTheme) {
2014-09-20 15:56:35 +02:00
this.themes = {
2015-02-22 12:46:05 +01:00
name: ["DefaultTheme"],
src: [this.themesPath + "Default/TF_Default.css"],
description: ["Default Theme"]
2014-09-20 15:56:35 +02:00
};
2015-02-22 12:46:05 +01:00
this.Thm.add("DefaultTheme", this.themesPath + "Default/TF_Default.css", "Default Theme");
}
if (types.isArray(this.themes.name) && types.isArray(this.themes.src)) {
2014-09-20 15:56:35 +02:00
var thm = this.themes;
2015-02-22 12:46:05 +01:00
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.isFn(thmInit)) {
thmInit.call(null, this);
}
}
}
//Some elements need to be overriden for theme
//Reset button
this.btnResetText = null;
this.btnResetHtml = "<input type=\"button\" value=\"\" class=\"" + this.btnResetCssClass + "\" title=\"Clear filters\" />";
//Paging buttons
this.btnPrevPageHtml = "<input type=\"button\" value=\"\" class=\"" + this.btnPageCssClass + " previousPage\" title=\"Previous page\" />";
this.btnNextPageHtml = "<input type=\"button\" value=\"\" class=\"" + this.btnPageCssClass + " nextPage\" title=\"Next page\" />";
this.btnFirstPageHtml = "<input type=\"button\" value=\"\" class=\"" + this.btnPageCssClass + " firstPage\" title=\"First page\" />";
this.btnLastPageHtml = "<input type=\"button\" value=\"\" class=\"" + this.btnPageCssClass + " lastPage\" title=\"Last page\" />";
//Loader
this.loader = true;
this.loaderHtml = "<div class=\"defaultLoader\"></div>";
this.loaderText = null;
}
},
remove: {
writable: true,
value: function () {
if (this.fltGrid && this._hasGrid) {
2014-09-20 15:56:35 +02:00
var rows = this.tbl.rows;
2015-02-22 12:46:05 +01:00
if (this.paging) {
this.Cpt.paging.destroy();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.statusBar) {
// this.RemoveStatusBar();
this.Cpt.statusBar.destroy();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.rowsCounter) {
this.Cpt.rowsCounter.destroy();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.btnReset) {
// this.RemoveResetBtn();
this.Cpt.clearButton.destroy();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.helpInstructions /*|| !this.helpInstructions*/) {
this.Cpt.help.destroy();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.isExternalFlt && !this.popUpFilters) {
this.RemoveExternalFlts();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.infDiv) {
this.removeToolbar();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.highlightKeywords) {
this.Cpt.highlightKeyword.unhighlightAll();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.sort) {
this.RemoveSort();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.loader) {
this.Cpt.loader.remove();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.popUpFilters) {
this.Cpt.popupFilter.destroy();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.markActiveColumns) {
this.clearActiveColumns();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (this.editable || this.selectable) {
this.RemoveEditable();
2014-09-21 14:52:12 +02:00
}
//this loop shows all rows and removes validRow attribute
2015-02-22 12:46:05 +01:00
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 (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();
2014-09-21 14:52:12 +02:00
}
2014-10-18 14:00:34 +02:00
dom.removeClass(this.tbl, this.prfxTf);
2014-09-20 15:56:35 +02:00
this.activeFlt = null;
this.isStartBgAlternate = true;
this._hasGrid = false;
this.tbl = null;
2015-02-22 12:46:05 +01:00
} //if this.fltGrid
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
},
setToolbar: {
writable: true,
value: function () {
if (this.infDiv !== null) {
return;
}
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
/*** container div ***/
var infdiv = dom.create("div", ["id", this.prfxInfDiv + this.id]);
infdiv.className = this.infDivCssClass;
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
//custom container
if (this.toolBarTgtId) {
dom.id(this.toolBarTgtId).appendChild(infdiv);
2015-02-22 12:46:05 +01:00
}
//grid-layout
else if (this.gridLayout) {
2014-11-22 15:01:29 +01:00
this.Cpt.gridLayout.tblMainCont.appendChild(infdiv);
2014-09-20 15:56:35 +02:00
infdiv.className = this.gridInfDivCssClass;
2015-02-22 12:46:05 +01:00
}
//default location: just above the table
else {
2014-09-20 15:56:35 +02:00
this.tbl.parentNode.insertBefore(infdiv, this.tbl);
2015-02-22 12:46:05 +01:00
}
this.infDiv = dom.id(this.prfxInfDiv + this.id);
/*** left div containing rows # displayer ***/
var ldiv = dom.create("div", ["id", this.prfxLDiv + this.id]);
ldiv.className = this.lDivCssClass;
infdiv.appendChild(ldiv);
this.lDiv = dom.id(this.prfxLDiv + this.id);
/*** right div containing reset button
+ nb results per page select ***/
var rdiv = dom.create("div", ["id", this.prfxRDiv + this.id]);
rdiv.className = this.rDivCssClass;
infdiv.appendChild(rdiv);
this.rDiv = dom.id(this.prfxRDiv + this.id);
/*** mid div containing paging elements ***/
var mdiv = dom.create("div", ["id", this.prfxMDiv + this.id]);
mdiv.className = this.mDivCssClass;
infdiv.appendChild(mdiv);
this.mDiv = 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;
this.Cpt.help = new Help(this);
2015-02-20 05:03:57 +01:00
}
this.Cpt.help.init();
2015-02-22 12:46:05 +01:00
}
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
},
removeToolbar: {
writable: true,
value: function () {
if (!this.infDiv) {
2014-09-21 14:52:12 +02:00
return;
2015-02-22 12:46:05 +01:00
}
this.infDiv.parentNode.removeChild(this.infDiv);
this.infDiv = null;
}
},
RemoveExternalFlts: {
writable: true,
value: function () {
if (!this.isExternalFlt && !this.externalFltTgtIds) {
2014-09-21 14:52:12 +02:00
return;
2015-02-22 12:46:05 +01:00
}
for (var ct = 0; ct < this.externalFltTgtIds.length; ct++) {
var externalFltTgtId = this.externalFltTgtIds[ct], externalFlt = dom.id(externalFltTgtId);
if (externalFlt) {
externalFlt.innerHTML = "";
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
}
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
},
SetSort: {
writable: true,
value: function () {
var fn = this.Evt._EnableSort, sortConfig = this.sortConfig;
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
if (!types.isFn(fn)) {
2014-09-20 15:56:35 +02:00
var o = this;
/*====================================================
- enables table sorting
=====================================================*/
2015-02-22 12:46:05 +01:00
this.Evt._EnableSort = function () {
//gridLayout needs sort to be re-enabled
if (o.isSortEnabled && !o.gridLayout) {
return;
}
if (this.isImported(sortConfig.adapterSrc)) {
sortConfig.initialize.call(null, o);
} else {
o.includeFile(sortConfig.name + "_adapter", sortConfig.adapterSrc, function () {
sortConfig.initialize.call(null, o);
});
}
2014-09-21 14:52:12 +02:00
};
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
if (this.isImported(this.sortConfig.src)) {
2014-09-20 15:56:35 +02:00
this.Evt._EnableSort();
2015-02-22 12:46:05 +01:00
} else {
this.includeFile(sortConfig.name, sortConfig.src, this.Evt._EnableSort);
}
}
},
RemoveSort: {
writable: true,
value: function () {
this.sort = false;
}
},
Sort: {
writable: true,
value: function () {
this.EvtManager(this.Evt.name.sort);
}
},
SetEditable: {
writable: true,
value: function () {
var ezEditConfig = this.ezEditTableConfig;
if (this.isImported(ezEditConfig.src)) {
2014-09-20 15:56:35 +02:00
this._EnableEditable();
2015-02-22 12:46:05 +01:00
} 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");
}
}
},
RemoveEditable: {
writable: true,
value: function () {
var ezEditTable = this.ezEditTable;
if (ezEditTable) {
if (this.selectable) {
ezEditTable.Selection.ClearSelections();
ezEditTable.Selection.Remove();
}
if (this.editable) {
ezEditTable.Editable.Remove();
}
}
}
},
ResetEditable: {
writable: true,
value: function () {
var ezEditTable = this.ezEditTable;
if (ezEditTable) {
if (this.selectable) {
ezEditTable.Selection.Set();
}
if (this.editable) {
ezEditTable.Editable.Set();
}
}
}
},
_EnableEditable: {
writable: true,
value: function (o) {
if (!o) {
2014-09-21 14:52:12 +02:00
o = this;
2015-02-22 12:46:05 +01:00
}
2014-09-21 14:52:12 +02:00
2015-02-22 12:46:05 +01:00
//start row for EditTable constructor needs to be calculated
var startRow, ezEditConfig = o.ezEditTableConfig, thead = dom.tag(o.tbl, "thead");
2014-09-21 14:52:12 +02:00
2015-02-22 12:46:05 +01:00
//if thead exists and startRow not specified, startRow is calculated
//automatically by EditTable
if (thead.length > 0 && !ezEditConfig.startRow) {
2014-09-21 14:52:12 +02:00
startRow = undefined;
2015-02-22 12:46:05 +01:00
}
//otherwise startRow config property if any or TableFilter refRow
else {
2014-09-21 14:52:12 +02:00
startRow = ezEditConfig.startRow || o.refRow;
2015-02-22 12:46:05 +01:00
}
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
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;
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
if (o.selectable) {
ezEditConfig.default_selection = ezEditConfig.default_selection || "row";
}
//CSS Styles
ezEditConfig.active_cell_css = ezEditConfig.active_cell_css || "ezETSelectedCell";
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
o._lastValidRowIndex = 0;
o._lastRowIndex = 0;
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
if (o.selectable) {
2014-09-21 14:52:12 +02:00
//Row navigation needs to be calculated according to TableFilter's
//validRowsIndex array
2015-02-22 12:46:05 +01:00
var onAfterSelection = function (et, selectedElm, e) {
//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.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];
}
2015-02-22 12:46:05 +01:00
}
2014-09-21 14:52:12 +02:00
} else {
2015-02-22 12:46:05 +01:00
//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;
DoSelection(nextRowIndex);
} else {
//If filtered row is valid, special calculation for
//pgup/pgdown keys
if (keyCode !== 34 && keyCode !== 33) {
o._lastValidRowIndex = array.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];
2014-09-20 15:56:35 +02:00
} else {
2015-02-22 12:46:05 +01:00
nextRowIndex = validIndexes[o._lastValidRowIndex - d];
}
2015-02-22 12:46:05 +01:00
}
o._lastRowIndex = nextRowIndex;
o._lastValidRowIndex = array.indexByValue(validIndexes, nextRowIndex);
DoSelection(nextRowIndex);
}
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
//Next valid filtered row needs to be selected
var DoSelection = function (nextRowIndex) {
if (et.defaultSelection === "row") {
et.Selection.SelectRowByIndex(nextRowIndex);
} else {
et.ClearSelections();
var cellIndex = selectedElm.cellIndex, row = o.tbl.rows[nextRowIndex];
if (et.defaultSelection === "both") {
et.Selection.SelectRowByIndex(nextRowIndex);
}
if (row) {
et.Selection.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;
2014-09-20 15:56:35 +02:00
} else {
2015-02-22 12:46:05 +01:00
cell.scrollIntoView(false);
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
}
}
};
2014-09-21 14:52:12 +02:00
};
2014-09-21 14:52:12 +02:00
//Page navigation has to be enforced whenever selected row is out of
//the current page range
2015-02-22 12:46:05 +01:00
var onBeforeSelection = function (et, selectedElm, e) {
var row = et.defaultSelection !== "row" ? selectedElm.parentNode : selectedElm;
if (o.paging) {
if (o.nbPages > 1) {
//page length is re-assigned in case it has changed
et.nbRowsPerPage = o.pagingLength;
var validIndexes = o.validRowsIndex, validIdxLen = validIndexes.length, pagingEndRow = parseInt(o.startPagingRow, 10) + parseInt(o.pagingLength, 10);
var rowIndex = row.rowIndex;
if ((rowIndex === validIndexes[validIdxLen - 1]) && o.currentPageNb != o.nbPages) {
// o.SetPage('last');
o.Cpt.paging.setPage("last");
} else if ((rowIndex == validIndexes[0]) && o.currentPageNb !== 1) {
// o.SetPage('first');
o.Cpt.paging.setPage("first");
} else if (rowIndex > validIndexes[pagingEndRow - 1] && rowIndex < validIndexes[validIdxLen - 1]) {
// o.SetPage('next');
o.Cpt.paging.setPage("next");
} else if (rowIndex < validIndexes[o.startPagingRow] && rowIndex > validIndexes[0]) {
// o.SetPage('previous');
o.Cpt.paging.setPage("previous");
}
}
}
2014-09-21 14:52:12 +02:00
};
2014-09-20 15:56:35 +02:00
//Selected row needs to be visible when paging is activated
2015-02-22 12:46:05 +01:00
if (o.paging) {
o.onAfterChangePage = function (tf, i) {
var et = tf.ezEditTable;
var row = et.Selection.GetActiveRow();
if (row) {
row.scrollIntoView(false);
}
var cell = et.Selection.GetActiveCell();
if (cell) {
cell.scrollIntoView(false);
}
};
}
2014-09-20 15:56:35 +02:00
2014-09-21 14:52:12 +02:00
//Rows navigation when rows are filtered is performed with the
//EditTable row selection callback events
2015-02-22 12:46:05 +01:00
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]);
}
};
2014-09-20 15:56:35 +02:00
} else {
2015-02-22 12:46:05 +01:00
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) {
2014-09-20 15:56:35 +02:00
//Added or removed rows, TF rows number needs to be re-calculated
2014-09-21 14:52:12 +02:00
var fnE = ezEditConfig.on_added_dom_row;
2015-02-22 12:46:05 +01:00
ezEditConfig.on_added_dom_row = function () {
o.nbFilterableRows++;
if (!o.paging) {
o.Cpt.rowsCounter.refresh();
} else {
o.nbRows++;
o.nbVisibleRows++;
2014-09-20 15:56:35 +02:00
o.nbFilterableRows++;
2015-02-22 12:46:05 +01:00
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();
2014-11-16 01:29:07 +01:00
} else {
2015-02-22 12:46:05 +01:00
o.nbRows--;
o.nbVisibleRows--;
o.nbFilterableRows--;
o.paging = false;
o.Cpt.paging.destroy();
o.Cpt.paging.addPaging(false);
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (o.alternateBgs) {
o.Cpt.alternateRows.init();
2014-09-21 14:52:12 +02:00
}
2015-02-22 12:46:05 +01:00
if (fnF) {
fnF.call(null, arguments[0], arguments[1]);
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
};
}
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
try {
2014-09-21 14:52:12 +02:00
o.ezEditTable = new EditTable(o.id, ezEditConfig, startRow);
2014-09-20 15:56:35 +02:00
o.ezEditTable.Init();
2015-02-22 12:46:05 +01:00
} catch (e) {
console.log(ezEditConfig.err);
}
}
},
resetValues: {
writable: true,
value: function () {
this.EvtManager(this.Evt.name.resetvalues);
}
},
_resetValues: {
writable: true,
value: function () {
//only fillSlcOnDemand
if (this.rememberGridValues && this.fillSlcOnDemand) {
this.resetGridValues(this.fltsValuesCookie);
2015-02-22 12:46:05 +01:00
}
if (this.rememberPageLen) {
2015-01-11 11:22:52 +01:00
// this.ResetPageLength(this.pgLenCookie);
this.Cpt.paging.resetPageLength(this.pgLenCookie);
2015-02-22 12:46:05 +01:00
}
if (this.rememberPageNb) {
2015-01-11 11:22:52 +01:00
// this.ResetPage(this.pgNbCookie);
this.Cpt.paging.resetPage(this.pgNbCookie);
2015-02-22 12:46:05 +01:00
}
2014-09-30 11:19:12 +02:00
}
2015-02-22 12:46:05 +01:00
},
resetGridValues: {
writable: true,
value: function (name) {
if (!this.fillSlcOnDemand) {
2014-09-30 11:19:12 +02:00
return;
2015-02-22 12:46:05 +01:00
}
var fltsValues = this.Cpt.store.getFilterValues(name), slcFltsIndex = this.getFiltersByType(this.fltTypeSlc, true), multiFltsIndex = this.getFiltersByType(this.fltTypeMulti, true);
2014-09-30 11:19:12 +02:00
2015-02-22 12:46:05 +01:00
//if the number of columns is the same as before page reload
if (Number(fltsValues[(fltsValues.length - 1)]) === this.fltIds.length) {
for (var i = 0; i < (fltsValues.length - 1); i++) {
if (fltsValues[i] === " ") {
continue;
}
var s, opt;
// if fillSlcOnDemand, drop-down needs to contain stored
// value(s) for filtering
if (this["col" + i] === this.fltTypeSlc || this["col" + i] === this.fltTypeMulti) {
var slc = dom.id(this.fltIds[i]);
slc.options[0].selected = false;
//selects
if (array.has(slcFltsIndex, i)) {
opt = dom.createOpt(fltsValues[i], fltsValues[i], true);
slc.appendChild(opt);
this.hasStoredValues = true;
}
//multiple select
if (array.has(multiFltsIndex, i)) {
s = fltsValues[i].split(" " + this.orOperator + " ");
for (j = 0; j < s.length; j++) {
if (s[j] === "") {
continue;
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
opt = dom.createOpt(s[j], s[j], true);
slc.appendChild(opt);
this.hasStoredValues = true;
// IE multiple selection work-around
// if(hlp.isIE()){
// this.__deferMultipleSelection(slc,j,false);
// hasStoredValues = false;
// }
}
} // if multiFltsIndex
} else if (this["col" + i] == this.fltTypeCheckList) {
var checkList = this.Cpt.checkList;
var divChk = checkList.checkListDiv[i];
divChk.title = divChk.innerHTML;
divChk.innerHTML = "";
var ul = dom.create("ul", ["id", this.fltIds[i]], ["colIndex", i]);
ul.className = checkList.checkListCssClass;
var li0 = dom.createCheckItem(this.fltIds[i] + "_0", "", this.displayAllText);
li0.className = checkList.checkListItemCssClass;
ul.appendChild(li0);
divChk.appendChild(ul);
s = fltsValues[i].split(" " + this.orOperator + " ");
for (j = 0; j < s.length; j++) {
if (s[j] === "") {
continue;
}
var li = dom.createCheckItem(this.fltIds[i] + "_" + (j + 1), s[j], s[j]);
li.className = checkList.checkListItemCssClass;
ul.appendChild(li);
li.check.checked = true;
checkList.setCheckListValues(li.check);
this.hasStoredValues = true;
}
}
} //end for
if (!this.hasStoredValues && this.paging) {
this.Cpt.paging.setPagingInfo();
}
} //end if
}
},
filter: {
writable: true,
value: function () {
this.EvtManager(this.Evt.name.filter);
}
},
_filter: {
writable: true,
value: function () {
if (!this.fltGrid || (!this._hasGrid && !this.isFirstLoad)) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
//invokes onbefore callback
if (this.onBeforeFilter) {
2014-10-04 16:38:42 +02:00
this.onBeforeFilter.call(null, this);
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
var row = this.tbl.rows, f = this.cfg, hiddenrows = 0;
this.validRowsIndex = [];
var o = this;
2015-02-22 12:46:05 +01:00
// removes keyword highlighting
if (this.highlightKeywords) {
this.Cpt.highlightKeyword.unhighlightAll();
2015-02-22 12:46:05 +01:00
}
//removes popup filters active icons
if (this.popUpFilters) {
2015-02-15 09:55:23 +01:00
this.Cpt.popupFilter.buildIcons();
2015-02-22 12:46:05 +01:00
}
//removes active column header class
if (this.markActiveColumns) {
this.clearActiveColumns();
2015-02-22 12:46:05 +01:00
}
// search args re-init
this.searchArgs = this.getFiltersValue();
var num_cell_data, nbFormat;
var re_le = new RegExp(this.leOperator), re_ge = new RegExp(this.geOperator), re_l = new RegExp(this.lwOperator), re_g = new RegExp(this.grOperator), re_d = new RegExp(this.dfOperator), re_lk = new RegExp(str.rgxEsc(this.lkOperator)), re_eq = new RegExp(this.eqOperator), re_st = new RegExp(this.stOperator), re_en = new RegExp(this.enOperator), re_an = new RegExp(this.anOperator), re_cr = new RegExp(this.curExp), re_em = this.emOperator, re_nm = this.nmOperator, re_re = new RegExp(str.rgxEsc(this.rgxOperator));
//keyword highlighting
function highlight(str, ok, cell) {
if (o.highlightKeywords && ok) {
str = str.replace(re_lk, "");
str = str.replace(re_eq, "");
str = str.replace(re_st, "");
str = str.replace(re_en, "");
var w = str;
if (re_le.test(str) || re_ge.test(str) || re_l.test(str) || re_g.test(str) || re_d.test(str)) {
w = dom.getText(cell);
}
if (w !== "") {
o.Cpt.highlightKeyword.highlight(cell, w, o.Cpt.highlightKeyword.highlightCssClass);
}
}
}
//looks for search argument in current row
function hasArg(sA, cell_data, j) {
2014-09-20 15:56:35 +02:00
var occurence;
//Search arg operator tests
2015-02-22 12:46:05 +01:00
var hasLO = re_l.test(sA), hasLE = re_le.test(sA), hasGR = re_g.test(sA), hasGE = re_ge.test(sA), hasDF = re_d.test(sA), hasEQ = re_eq.test(sA), hasLK = re_lk.test(sA), hasAN = re_an.test(sA), hasST = re_st.test(sA), hasEN = re_en.test(sA), hasEM = (re_em === sA), hasNM = (re_nm === sA), hasRE = re_re.test(sA);
2014-09-20 15:56:35 +02:00
//Search arg dates tests
2015-02-22 12:46:05 +01:00
var isLDate = hasLO && isValidDate(sA.replace(re_l, ""), dtType);
var isLEDate = hasLE && isValidDate(sA.replace(re_le, ""), dtType);
var isGDate = hasGR && isValidDate(sA.replace(re_g, ""), dtType);
var isGEDate = hasGE && isValidDate(sA.replace(re_ge, ""), dtType);
var isDFDate = hasDF && isValidDate(sA.replace(re_d, ""), dtType);
var isEQDate = hasEQ && isValidDate(sA.replace(re_eq, ""), dtType);
2014-10-04 16:38:42 +02:00
var dte1, dte2;
//dates
2015-02-22 12:46:05 +01:00
if (isValidDate(cell_data, dtType)) {
dte1 = formatDate(cell_data, dtType);
// lower date
if (isLDate) {
dte2 = formatDate(sA.replace(re_l, ""), dtType);
occurence = dte1 < dte2;
}
// lower equal date
else if (isLEDate) {
dte2 = formatDate(sA.replace(re_le, ""), dtType);
occurence = dte1 <= dte2;
}
// greater equal date
else if (isGEDate) {
dte2 = formatDate(sA.replace(re_ge, ""), dtType);
occurence = dte1 >= dte2;
}
// greater date
else if (isGDate) {
dte2 = formatDate(sA.replace(re_g, ""), dtType);
occurence = dte1 > dte2;
}
// different date
else if (isDFDate) {
dte2 = formatDate(sA.replace(re_d, ""), dtType);
occurence = dte1.toString() != dte2.toString();
}
// equal date
else if (isEQDate) {
dte2 = formatDate(sA.replace(re_eq, ""), dtType);
occurence = dte1.toString() == dte2.toString();
}
// searched keyword with * operator doesn't have to be a date
else if (re_lk.test(sA)) {
// like date
occurence = o._containsStr(sA.replace(re_lk, ""), cell_data, null, false);
} else if (isValidDate(sA, dtType)) {
dte2 = formatDate(sA, dtType);
occurence = dte1.toString() == dte2.toString();
}
//empty
else if (hasEM) {
occurence = str.isEmpty(cell_data);
}
//non-empty
else if (hasNM) {
occurence = !str.isEmpty(cell_data);
}
} else {
//first numbers need to be formated
if (o.hasColNbFormat && o.colNbFormat[j]) {
num_cell_data = removeNbFormat(cell_data, o.colNbFormat[j]);
nbFormat = o.colNbFormat[j];
} else {
if (o.thousandsSeparator === "," && o.decimalSeparator === ".") {
num_cell_data = removeNbFormat(cell_data, "us");
nbFormat = "us";
2014-09-20 15:56:35 +02:00
} else {
2015-02-22 12:46:05 +01:00
num_cell_data = removeNbFormat(cell_data, "eu");
nbFormat = "eu";
}
}
// first checks if there is any operator (<,>,<=,>=,!,*,=,{,},
// rgx:)
// lower equal
if (hasLE) {
occurence = num_cell_data <= removeNbFormat(sA.replace(re_le, ""), nbFormat);
}
//greater equal
else if (hasGE) {
occurence = num_cell_data >= removeNbFormat(sA.replace(re_ge, ""), nbFormat);
}
//lower
else if (hasLO) {
occurence = num_cell_data < removeNbFormat(sA.replace(re_l, ""), nbFormat);
}
//greater
else if (hasGR) {
occurence = num_cell_data > removeNbFormat(sA.replace(re_g, ""), nbFormat);
}
//different
else if (hasDF) {
occurence = o._containsStr(sA.replace(re_d, ""), cell_data) ? false : true;
}
//like
else if (hasLK) {
occurence = o._containsStr(sA.replace(re_lk, ""), cell_data, null, false);
}
//equal
else if (hasEQ) {
occurence = o._containsStr(sA.replace(re_eq, ""), cell_data, null, true);
}
//starts with
else if (hasST) {
occurence = cell_data.indexOf(sA.replace(re_st, "")) === 0 ? true : false;
}
//ends with
else if (hasEN) {
var searchArg = sA.replace(re_en, "");
occurence = cell_data.lastIndexOf(searchArg, cell_data.length - 1) === (cell_data.length - 1) - (searchArg.length - 1) && cell_data.lastIndexOf(searchArg, cell_data.length - 1) > -1 ? true : false;
}
//empty
else if (hasEM) {
occurence = str.isEmpty(cell_data);
}
//non-empty
else if (hasNM) {
occurence = !str.isEmpty(cell_data);
}
//regexp
else if (hasRE) {
//in case regexp fires an exception
try {
//operator is removed
var srchArg = sA.replace(re_re, "");
var rgx = new RegExp(srchArg);
occurence = rgx.test(cell_data);
} catch (e) {
occurence = false;
}
} else {
var fCol = f["col_" + j];
occurence = o._containsStr(sA, cell_data, !fCol ? this.fltTypeInp : fCol);
}
} //else
2014-09-20 15:56:35 +02:00
return occurence;
2015-02-22 12:46:05 +01:00
} //fn
2015-02-22 12:46:05 +01:00
for (var k = this.refRow; k < this.nbRows; k++) {
2014-09-20 15:56:35 +02:00
/*** if table already filtered some rows are not visible ***/
2015-02-22 12:46:05 +01:00
if (row[k].style.display === "none") {
row[k].style.display = "";
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
var cell = row[k].cells, nchilds = cell.length;
2014-09-20 15:56:35 +02:00
// checks if row has exact cell #
2015-02-22 12:46:05 +01:00
if (nchilds !== this.nbCells) {
continue;
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
var occurence = [], isRowValid = this.searchType === "include" ? true : false,
//only for single filter search
singleFltRowValid = false;
2014-10-04 16:38:42 +02:00
// this loop retrieves cell data
2015-02-22 12:46:05 +01:00
for (var j = 0; j < nchilds; j++) {
//searched keyword
var sA = this.searchArgs[this.singleSearchFlt ? 0 : j], dtType = this.hasColDateType ? this.colDateType[j] : this.defaultDateType;
if (sA === "") {
continue;
}
var cell_data = str.matchCase(this.getCellData(j, cell[j]), this.matchCase);
//multiple search parameter operator ||
var sAOrSplit = sA.split(this.orOperator),
//multiple search || parameter boolean
hasMultiOrSA = (sAOrSplit.length > 1) ? true : false,
//multiple search parameter operator &&
sAAndSplit = sA.split(this.anOperator),
//multiple search && parameter boolean
hasMultiAndSA = sAAndSplit.length > 1 ? true : false;
//multiple sarch parameters
if (hasMultiOrSA || hasMultiAndSA) {
var cS, occur = false, s = hasMultiOrSA ? sAOrSplit : sAAndSplit;
for (var w = 0; w < s.length; w++) {
cS = str.trim(s[w]);
occur = hasArg(cS, cell_data, j);
highlight(cS, occur, cell[j]);
if (hasMultiOrSA && occur) {
break;
}
if (hasMultiAndSA && !occur) {
break;
}
}
occurence[j] = occur;
}
//single search parameter
else {
occurence[j] = hasArg(str.trim(sA), cell_data, j);
highlight(sA, occurence[j], cell[j]);
} //else single param
if (!occurence[j]) {
isRowValid = this.searchType === "include" ? false : true;
}
if (this.singleSearchFlt && occurence[j]) {
singleFltRowValid = true;
}
if (this.popUpFilters) {
this.Cpt.popupFilter.buildIcon(j, true);
}
if (this.markActiveColumns) {
if (k === this.refRow) {
if (this.onBeforeActiveColumn) {
this.onBeforeActiveColumn.call(null, this, j);
}
dom.addClass(this.getHeaderElement(j), this.activeColumnsCssClass);
if (this.onAfterActiveColumn) {
this.onAfterActiveColumn.call(null, this, j);
}
}
}
} //for j
if (this.singleSearchFlt && singleFltRowValid) {
isRowValid = true;
}
if (!isRowValid) {
this.validateRow(k, false);
// always visible rows need to be counted as valid
if (this.hasVisibleRows && array.has(this.visibleRows, k) && !this.paging) {
2014-09-20 15:56:35 +02:00
this.validRowsIndex.push(k);
2015-02-22 12:46:05 +01:00
} else {
hiddenrows++;
}
} else {
this.validateRow(k, true);
this.validRowsIndex.push(k);
if (this.alternateBgs) {
this.Cpt.alternateRows.setRowBg(k, this.validRowsIndex.length);
}
if (this.onRowValidated) {
this.onRowValidated.call(null, this, k);
}
}
} // for k
this.nbVisibleRows = this.validRowsIndex.length;
this.nbHiddenRows = hiddenrows;
this.isStartBgAlternate = false;
if (this.rememberGridValues) {
this.Cpt.store.saveFilterValues(this.fltsValuesCookie);
2015-02-22 12:46:05 +01:00
}
//applies filter props after filtering process
if (!this.paging) {
this.applyGridProps();
2015-02-22 12:46:05 +01:00
} else {
2014-09-20 15:56:35 +02:00
this.startPagingRow = 0;
this.currentPageNb = 1;
2015-01-11 11:22:52 +01:00
this.Cpt.paging.setPagingInfo(this.validRowsIndex);
2015-02-22 12:46:05 +01:00
} //starts paging process
//invokes onafter callback
if (this.onAfterFilter) {
this.onAfterFilter.call(null, this);
}
}
},
applyGridProps: {
writable: true,
value: function () {
// blurs active filter (IE)
if (this.activeFlt && str.lower(this.activeFlt.nodeName) === this.fltTypeSlc && !this.popUpFilters) {
2014-09-20 15:56:35 +02:00
this.activeFlt.blur();
2015-02-22 12:46:05 +01:00
if (this.activeFlt.parentNode) {
this.activeFlt.parentNode.focus();
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
//shows rows always visible
if (this.visibleRows) {
this.enforceVisibility();
2015-02-22 12:46:05 +01:00
}
//makes operation on a col
if (this.hasColOperation) {
2014-11-16 01:29:07 +01:00
this.Cpt.colOps.calc();
2015-02-22 12:46:05 +01:00
}
//re-populates drop-down filters
if (this.linkedFilters) {
this.linkFilters();
2015-02-22 12:46:05 +01:00
}
var nr = !this.paging && this.hasVisibleRows ? this.nbVisibleRows - this.visibleRows.length : this.nbVisibleRows;
//refreshes rows counter
if (this.rowsCounter) {
2014-11-16 01:29:07 +01:00
this.Cpt.rowsCounter.refresh(nr);
2015-02-22 12:46:05 +01:00
}
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
if (this.popUpFilters) {
2015-02-15 09:55:23 +01:00
this.Cpt.popupFilter.closeAll();
2015-02-22 12:46:05 +01:00
}
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
},
getColValues: {
writable: true,
value: function (colindex, num, exclude) {
if (!this.fltGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
var row = this.tbl.rows, colValues = [];
2015-02-22 12:46:05 +01:00
for (var i = this.refRow; i < this.nbRows; i++) {
2014-09-20 15:56:35 +02:00
var isExludedRow = false;
2014-10-04 16:38:42 +02:00
// checks if current row index appears in exclude array
2015-02-22 12:46:05 +01:00
if (exclude && types.isArray(exclude)) {
isExludedRow = array.has(exclude, i); //boolean
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
var cell = row[i].cells, nchilds = cell.length;
2014-10-04 16:38:42 +02:00
// checks if row has exact cell # and is not excluded
2015-02-22 12:46:05 +01:00
if (nchilds == this.nbCells && !isExludedRow) {
// this loop retrieves cell data
for (var j = 0; j < nchilds; j++) {
if (j === colindex && row[i].style.display === "") {
var cell_data = str.lower(this.getCellData(j, cell[j])), nbFormat = this.colNbFormat ? this.colNbFormat[colindex] : null, data = num ? removeNbFormat(cell_data, nbFormat) : cell_data;
colValues.push(data);
}
}
}
} //for i
return colValues;
}
},
getFilterValue: {
writable: true,
value: function (index) {
if (!this.fltGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
var fltValue, flt = this.getFilterElement(index);
if (!flt) {
return "";
}
var fltColType = this.fltCol[index];
if (fltColType !== this.fltTypeMulti && fltColType !== this.fltTypeCheckList) {
2014-09-20 15:56:35 +02:00
fltValue = flt.value;
2015-02-22 12:46:05 +01:00
}
//mutiple select
else if (fltColType === this.fltTypeMulti) {
fltValue = "";
for (var j = 0; j < flt.options.length; j++) {
if (flt.options[j].selected) {
fltValue = fltValue.concat(flt.options[j].value + " " + this.orOperator + " ");
}
2014-10-04 16:38:42 +02:00
}
2014-09-20 15:56:35 +02:00
//removes last operator ||
2015-02-22 12:46:05 +01:00
fltValue = fltValue.substr(0, fltValue.length - 4);
}
//checklist
else if (fltColType === this.fltTypeCheckList) {
if (flt.getAttribute("value") !== null) {
fltValue = flt.getAttribute("value");
//removes last operator ||
fltValue = fltValue.substr(0, fltValue.length - 3);
} else {
fltValue = "";
}
}
return fltValue;
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
},
getFiltersValue: {
writable: true,
value: function () {
if (!this.fltGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
var searchArgs = [];
for (var i = 0; i < this.fltIds.length; i++) {
searchArgs.push(str.trim(str.matchCase(this.getFilterValue(i), this.matchCase)));
}
return searchArgs;
}
},
getFilterId: {
writable: true,
value: function (index) {
if (!this.fltGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
return this.fltIds[i];
}
},
getFiltersByType: {
writable: true,
value: function (type, bool) {
if (!this.fltGrid) {
return;
}
var arr = [];
for (var i = 0; i < this.fltIds.length; i++) {
var fltType = this["col" + i];
if (fltType === str.lower(type)) {
var a = (bool) ? i : this.fltIds[i];
arr.push(a);
}
}
return arr;
}
},
getFilterElement: {
writable: true,
value: function (index) {
if (!this.fltGrid) {
2014-10-04 16:38:42 +02:00
return null;
2015-02-22 12:46:05 +01:00
}
return dom.id(this.fltIds[index]);
}
},
getCellsNb: {
writable: true,
value: function (rowIndex) {
var tr = !rowIndex ? this.tbl.rows[0] : this.tbl.rows[rowIndex];
return tr.cells.length;
}
},
getRowsNb: {
writable: true,
value: function (includeHeaders) {
var s = !this.refRow ? 0 : this.refRow, ntrs = this.tbl.rows.length;
if (includeHeaders) {
s = 0;
}
return parseInt(ntrs - s, 10);
}
},
getCellData: {
writable: true,
value: function (i, cell) {
if (i === undefined || !cell) {
return "";
}
//First checks for customCellData event
if (this.customCellData && array.has(this.customCellDataCols, i)) {
return this.customCellData.call(null, this, cell, i);
} else {
2014-10-18 14:00:34 +02:00
return dom.getText(cell);
2015-02-22 12:46:05 +01:00
}
}
},
getTableData: {
writable: true,
value: function () {
var row = this.tbl.rows;
for (var k = this.refRow; k < this.nbRows; k++) {
var rowData = [k, []];
2014-09-20 15:56:35 +02:00
var cells = row[k].cells;
2014-10-04 16:38:42 +02:00
// this loop retrieves cell data
2015-02-22 12:46:05 +01:00
for (var j = 0; j < cells.length; j++) {
var cell_data = this.getCellData(j, cells[j]);
rowData[1].push(cell_data);
}
2014-10-04 16:38:42 +02:00
this.tblData.push(rowData);
2015-02-22 12:46:05 +01:00
}
return this.tblData;
}
},
getFilteredData: {
writable: true,
value: function (includeHeaders) {
if (!this.validRowsIndex) {
2014-10-04 16:38:42 +02:00
return [];
2015-02-22 12:46:05 +01:00
}
var row = this.tbl.rows, filteredData = [];
if (includeHeaders) {
var table = this.gridLayout ? this.headTbl : this.tbl, r = table.rows[this.headersRow], rowData = [r.rowIndex, []];
for (var j = 0; j < this.nbCells; j++) {
var headerText = this.getCellData(j, r.cells[j]);
rowData[1].push(headerText);
}
2014-09-20 15:56:35 +02:00
filteredData.push(rowData);
2015-02-22 12:46:05 +01:00
}
2014-10-04 16:38:42 +02:00
2015-02-22 12:46:05 +01:00
var validRows = this.getValidRowsIndex(true);
for (var i = 0; i < validRows.length; i++) {
var rData = [this.validRowsIndex[i], []], cells = row[this.validRowsIndex[i]].cells;
for (var k = 0; k < cells.length; k++) {
var cell_data = this.getCellData(k, cells[k]);
rData[1].push(cell_data);
}
2014-10-04 16:38:42 +02:00
filteredData.push(rData);
2015-02-22 12:46:05 +01:00
}
return filteredData;
}
},
getFilteredDataCol: {
writable: true,
value: function (colIndex) {
if (colIndex === undefined) {
2014-10-04 16:38:42 +02:00
return [];
2015-02-22 12:46:05 +01:00
}
var data = this.getFilteredData(), colData = [];
for (var i = 0; i < data.length; i++) {
2014-10-04 16:38:42 +02:00
var r = data[i],
2015-02-22 12:46:05 +01:00
//cols values of current row
d = r[1],
//data of searched column
c = d[colIndex];
2014-09-20 15:56:35 +02:00
colData.push(c);
2015-02-22 12:46:05 +01:00
}
return colData;
}
},
getRowDisplay: {
writable: true,
value: function (row) {
if (!this.fltGrid && !types.isObj(row)) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
return row.style.display;
}
},
validateRow: {
writable: true,
value: function (rowIndex, isValid) {
var row = this.tbl.rows[rowIndex];
if (!row || str.lower(typeof isValid) !== "boolean") {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
// always visible rows are valid
if (this.hasVisibleRows && array.has(this.visibleRows, rowIndex) && !this.paging) {
2014-09-20 15:56:35 +02:00
isValid = true;
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
var displayFlag = isValid ? "" : "none", validFlag = isValid ? "true" : "false";
row.style.display = displayFlag;
2015-02-22 12:46:05 +01:00
if (this.paging) {
row.setAttribute("validRow", validFlag);
}
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
},
validateAllRows: {
writable: true,
value: function () {
if (!this._hasGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
this.validRowsIndex = [];
for (var k = this.refRow; k < this.nbFilterableRows; k++) {
this.validateRow(k, true);
2014-09-20 15:56:35 +02:00
this.validRowsIndex.push(k);
2015-02-22 12:46:05 +01:00
}
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
},
setFilterValue: {
writable: true,
value: function (index, searcharg, doFilter) {
if ((!this.fltGrid && !this.isFirstLoad) || !this.getFilterElement(index)) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
var slc = this.getFilterElement(index), execFilter = doFilter === undefined ? true : doFilter, fltColType = this["col" + index];
searcharg = searcharg === undefined ? "" : searcharg;
2014-10-04 16:38:42 +02:00
2015-02-22 12:46:05 +01:00
if (fltColType !== this.fltTypeMulti && fltColType != this.fltTypeCheckList) {
2014-09-20 15:56:35 +02:00
slc.value = searcharg;
2015-02-22 12:46:05 +01:00
}
//multiple selects
else if (fltColType === this.fltTypeMulti) {
var s = searcharg.split(" " + this.orOperator + " "), ct = 0; //keywords counter
for (var j = 0; j < slc.options.length; j++) {
if (s === "" || s[0] === "") {
slc.options[j].selected = false;
}
if (slc.options[j].value === "") {
slc.options[j].selected = false;
}
if (slc.options[j].value !== "" && array.has(s, slc.options[j].value, true)) {
// IE multiple selection work-around
// if(hlp.isIE()){
// //when last value reached filtering can be executed
// var filter = ct==(s.length-1) && execFilter ?
// true : false;
// this.__deferMultipleSelection(slc,j,filter);
// ct++;
// }
// else{
// slc.options[j].selected = true;
// }
slc.options[j].selected = true;
} //if
} //for j
}
//checklist
else if (fltColType === this.fltTypeCheckList) {
2014-10-18 14:00:34 +02:00
searcharg = str.matchCase(searcharg, this.matchCase);
2015-02-22 12:46:05 +01:00
var sarg = searcharg.split(" " + this.orOperator + " "), fltValue = slc.setAttribute("value", ""), fltIndex = slc.setAttribute("indexes", "");
for (var k = 0; k < dom.tag(slc, "li").length; k++) {
var li = dom.tag(slc, "li")[k], lbl = dom.tag(li, "label")[0], chk = dom.tag(li, "input")[0], lblTxt = str.matchCase(dom.getText(lbl), this.matchCase);
if (lblTxt !== "" && array.has(sarg, lblTxt, true)) {
chk.checked = true;
this.Cpt.checkList.setCheckListValues(chk);
} else {
chk.checked = false;
this.Cpt.checkList.setCheckListValues(chk);
}
}
}
}
},
setColWidths: {
writable: true,
value: function (rowIndex) {
if (!this.fltGrid || !this.hasColWidth) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
var o = this, rIndex;
if (rowIndex === undefined) {
rIndex = this.tbl.rows[0].style.display != "none" ? 0 : 1;
} else {
2014-10-04 16:38:42 +02:00
rIndex = rowIndex;
2015-02-22 12:46:05 +01:00
}
setWidths(this.tbl.rows[rIndex]);
function setWidths(row) {
if (!o && (o.nbCells != o.colWidth.length)) {
return;
}
if (o.nbCells == row.cells.length) {
for (var k = 0; k < o.nbCells; k++) {
row.cells[k].style.width = o.colWidth[k];
}
}
}
}
},
enforceVisibility: {
writable: true,
value: function () {
if (this._hasGrid && this.hasVisibleRows && !this.paging) {
for (var i = 0; i < this.visibleRows.length; i++) {
//row index cannot be > nrows
if (this.visibleRows[i] <= this.nbRows) {
this.validateRow(this.visibleRows[i], true);
}
}
}
}
},
clearFilters: {
writable: true,
value: function () {
this.EvtManager(this.Evt.name.clear);
}
},
_clearFilters: {
writable: true,
value: function () {
if (!this.fltGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
if (this.onBeforeReset) {
this.onBeforeReset.call(null, this, this.getFiltersValue());
2015-02-22 12:46:05 +01:00
}
for (var i = 0; i < this.fltIds.length; i++) {
this.setFilterValue(i, "");
}
if (this.linkedFilters) {
this.activeFilterId = "";
this.linkFilters();
2015-02-22 12:46:05 +01:00
}
if (this.rememberPageLen) {
cookie.remove(this.pgLenCookie);
}
if (this.rememberPageNb) {
cookie.remove(this.pgNbCookie);
}
if (this.onAfterReset) {
this.onAfterReset.call(null, this);
}
}
},
clearActiveColumns: {
writable: true,
value: function () {
for (var i = 0; i < this.fltIds.length; i++) {
dom.removeClass(this.getHeaderElement(i), this.activeColumnsCssClass);
}
}
},
refresh: {
writable: true,
value: function (config) {
var configObj = !config ? this.cfg : config;
var hasSort = this.sort;
//sort property is set to false in order to avoid sort object
//re-instanciation
if (hasSort) {
2014-10-04 16:38:42 +02:00
this.sort = false;
2015-02-22 12:46:05 +01:00
}
this.nbRows = this.getRowsNb(); //in case table is refreshed
this.remove();
window["tf_" + this.id] = new TableFilter(this.id, this.startRow, configObj);
this.isFirstLoad = true;
this.fltIds = [];
this.init();
//New tbody content needs to be referenced in sortabletable script with
//setTBody() method
if (hasSort) {
2014-09-20 15:56:35 +02:00
//this.st = SortableTable object
2014-10-04 16:38:42 +02:00
//Note this is a method of the Sortable Table 1.12 script
//(Erik Arvidsson)
this.st.setTBody(this.tbl.tBodies[0]);
//finally sort property is enabled again
this.sort = true;
2015-02-22 12:46:05 +01:00
}
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
},
linkFilters: {
writable: true,
value: function () {
var slcA1 = this.getFiltersByType(this.fltTypeSlc, true), slcA2 = this.getFiltersByType(this.fltTypeMulti, true), slcA3 = this.getFiltersByType(this.fltTypeCheckList, true), slcIndex = slcA1.concat(slcA2);
slcIndex = slcIndex.concat(slcA3);
if (this.activeFilterId) {
var activeFlt = this.activeFilterId.split("_")[0];
2014-09-20 15:56:35 +02:00
activeFlt = activeFlt.split(this.prfxFlt)[1];
var slcSelectedValue;
2015-02-22 12:46:05 +01:00
for (var i = 0; i < slcIndex.length; i++) {
var curSlc = dom.id(this.fltIds[slcIndex[i]]);
slcSelectedValue = this.getFilterValue(slcIndex[i]);
if (activeFlt !== slcIndex[i] || (this.paging && array.has(slcA1, slcIndex[i]) && activeFlt === slcIndex[i]) || (!this.paging && (array.has(slcA3, slcIndex[i]) || array.has(slcA2, slcIndex[i]))) || slcSelectedValue === this.displayAllText) {
if (array.has(slcA3, slcIndex[i])) {
this.Cpt.checkList.checkListDiv[slcIndex[i]].innerHTML = "";
} else {
curSlc.innerHTML = "";
2014-09-20 15:56:35 +02:00
}
2015-02-22 12:46:05 +01:00
//1st option needs to be inserted
if (this.fillSlcOnDemand) {
var opt0 = dom.createOpt(this.displayAllText, "");
if (curSlc) {
curSlc.appendChild(opt0);
}
}
2015-02-22 12:46:05 +01:00
if (array.has(slcA3, slcIndex[i])) {
this.Cpt.checkList._build(slcIndex[i]);
} else {
this.Cpt.dropdown._build(slcIndex[i], true);
}
2015-02-22 12:46:05 +01:00
this.setFilterValue(slcIndex[i], slcSelectedValue);
}
} // for i
}
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
},
_resetGrid: {
writable: true,
value: function () {
if (this.isFirstLoad) {
return;
}
// grid was removed, grid row element is stored in fltGridEl property
if (!this.gridLayout) {
this.tbl.rows[this.filtersRowIndex].parentNode.insertBefore(this.fltGridEl, this.tbl.rows[this.filtersRowIndex]);
}
// filters are appended in external placeholders elements
if (this.isExternalFlt) {
for (var ct = 0; ct < this.externalFltTgtIds.length; ct++) {
var extFlt = dom.id(this.externalFltTgtIds[ct]);
if (extFlt) {
extFlt.appendChild(this.externalFltEls[ct]);
var colFltType = this["col" + ct];
//IE special treatment for gridLayout, appended filters are
//empty
if (this.gridLayout && this.externalFltEls[ct].innerHTML === "" && colFltType !== this.fltTypeInp) {
if (colFltType === this.fltTypeSlc || colFltType === this.fltTypeMulti) {
this.Cpt.dropdown.build(ct);
}
if (colFltType === this.fltTypeCheckList) {
this.Cpt.checkList.build(ct);
}
}
}
}
}
this.nbFilterableRows = this.getRowsNb();
this.nbVisibleRows = this.nbFilterableRows;
this.nbRows = this.tbl.rows.length;
if (this.isSortEnabled) {
this.sort = true;
}
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
if (this.tbl.rows[this.filtersRowIndex].innerHTML === "") {
2014-09-20 15:56:35 +02:00
refreshFilters(this);
2015-02-22 12:46:05 +01:00
} else {
if (this.popUpFilters) {
this.headersRow++;
this.Cpt.popupFilter.buildAll();
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
}
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
/*** ie bug work-around, filters need to be re-generated since row
is empty; insertBefore method doesn't seem to work properly
with previously generated DOM nodes modified by innerHTML ***/
function refreshFilters(o) {
2014-09-20 15:56:35 +02:00
o.tbl.deleteRow(o.filtersRowIndex);
o.remove();
2014-09-20 15:56:35 +02:00
o.fltIds = [];
o.isFirstLoad = true;
2015-02-22 12:46:05 +01:00
if (o.popUpFilters) {
// o.RemovePopupFilters();
o.Cpt.popupFilter.destroy();
2014-10-04 16:38:42 +02:00
}
2014-09-20 15:56:35 +02:00
o._AddGrid();
2015-02-22 12:46:05 +01:00
}
2015-02-22 12:46:05 +01:00
if (!this.gridLayout) {
2014-10-18 14:00:34 +02:00
dom.addClass(this.tbl, this.prfxTf);
2015-02-22 12:46:05 +01:00
}
this._hasGrid = true;
}
},
_containsStr: {
writable: true,
value: function (arg, data, fltType, forceMatch) {
// Improved by Cedric Wartel (cwl)
// automatic exact match for selects and special characters are now
// filtered
var regexp, modifier = (this.matchCase) ? "g" : "gi", exactMatch = !forceMatch ? this.exactMatch : forceMatch;
if (exactMatch || (fltType !== this.fltTypeInp && fltType)) {
regexp = new RegExp("(^\\s*)" + str.rgxEsc(arg) + "(\\s*$)", modifier);
} else {
2014-10-18 14:00:34 +02:00
regexp = new RegExp(str.rgxEsc(arg), modifier);
2015-02-22 12:46:05 +01:00
}
return regexp.test(data);
}
},
includeFile: {
writable: true,
value: function (fileId, filePath, callback, type) {
var ftype = !type ? "script" : type, imported = this.isImported(filePath, ftype);
if (imported) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
var o = this, isLoaded = false, file, head = dom.tag(doc, "head")[0];
if (str.lower(ftype) === "link") {
file = dom.create("link", ["id", fileId], ["type", "text/css"], ["rel", "stylesheet"], ["href", filePath]);
} else {
file = dom.create("script", ["id", fileId], ["type", "text/javascript"], ["src", filePath]);
}
//Browser <> IE onload event works only for scripts, not for stylesheets
file.onload = file.onreadystatechange = function () {
if (!isLoaded && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete")) {
isLoaded = true;
if (typeof callback === "function") {
callback.call(null, o);
}
}
};
file.onerror = function () {
throw new Error("TF script could not load:\n" + this.src);
};
head.appendChild(file);
}
},
hasGrid: {
writable: true,
value: function () {
return this._hasGrid;
}
},
getFiltersId: {
writable: true,
value: function () {
if (!this._hasGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
return this.fltIds;
}
},
getValidRowsIndex: {
writable: true,
value: function (reCalc) {
if (!this._hasGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
if (!reCalc) {
2014-10-04 16:38:42 +02:00
return this.validRowsIndex;
2015-02-22 12:46:05 +01:00
}
2014-10-04 16:38:42 +02:00
2015-02-22 12:46:05 +01:00
this.validRowsIndex = [];
for (var k = this.refRow; k < this.getRowsNb(true); k++) {
2014-09-20 15:56:35 +02:00
var r = this.tbl.rows[k];
2015-02-22 12:46:05 +01:00
if (!this.paging) {
if (this.getRowDisplay(r) !== "none") {
this.validRowsIndex.push(r.rowIndex);
}
2014-09-20 15:56:35 +02:00
} else {
2015-02-22 12:46:05 +01:00
if (r.getAttribute("validRow") === "true" || r.getAttribute("validRow") === null) {
this.validRowsIndex.push(r.rowIndex);
}
}
}
return this.validRowsIndex;
}
},
getFiltersRowIndex: {
writable: true,
value: function () {
if (!this._hasGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
return this.filtersRowIndex;
}
},
getHeadersRowIndex: {
writable: true,
value: function () {
if (!this._hasGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
return this.headersRow;
}
},
getStartRowIndex: {
writable: true,
value: function () {
if (!this._hasGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
return this.refRow;
}
},
getLastRowIndex: {
writable: true,
value: function () {
if (!this._hasGrid) {
2014-10-04 16:38:42 +02:00
return;
2015-02-22 12:46:05 +01:00
}
return (this.nbRows - 1);
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
},
getHeaderElement: {
writable: true,
value: function (colIndex) {
var table = this.gridLayout ? this.headTbl : this.tbl;
var header, tHead = dom.tag(this.tbl, "thead");
for (var i = 0; i < this.nbCells; i++) {
if (i !== colIndex) {
continue;
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
if (tHead.length === 0) {
header = table.rows[this.headersRow].cells[i];
2014-10-04 16:38:42 +02:00
}
2015-02-22 12:46:05 +01:00
if (tHead.length === 1) {
header = tHead[0].rows[this.headersRow].cells[i];
2014-10-04 16:38:42 +02:00
}
2014-09-20 15:56:35 +02:00
break;
2015-02-22 12:46:05 +01:00
}
return header;
}
},
config: {
writable: true,
value: function () {
return this.cfg;
}
},
getFilterableRowsNb: {
writable: true,
value: function () {
return this.getRowsNb(false);
}
},
numSortAsc: {
writable: true,
value: function (a, b) {
return (a - b);
}
},
numSortDesc: {
writable: true,
value: function (a, b) {
return (b - a);
}
},
removeNbFormat: {
writable: true,
value: function (data, format) {
if (!data) {
return;
}
if (!format) {
format = "us";
}
var n = data;
if (str.lower(format) === "us") {
n = +n.replace(/[^\d\.-]/g, "");
} else {
n = +n.replace(/[^\d\,-]/g, "").replace(",", ".");
}
return n;
}
},
isImported: {
writable: true,
value: function (filePath, type) {
var imported = false, importType = !type ? "script" : type, attr = importType == "script" ? "src" : "href", files = dom.tag(doc, importType);
for (var i = 0; i < files.length; i++) {
if (files[i][attr] === undefined) {
continue;
}
if (files[i][attr].match(filePath)) {
imported = true;
break;
}
}
return imported;
}
},
setOuterHtml: {
writable: true,
value: function () {
if (doc.body.__defineGetter__) {
if (HTMLElement) {
var element = HTMLElement.prototype;
if (element.__defineGetter__) {
element.__defineGetter__("outerHTML", function () {
var parent = this.parentNode;
var el = dom.create(parent.tagName);
el.appendChild(this);
var shtml = el.innerHTML;
parent.appendChild(this);
return shtml;
});
}
if (element.__defineSetter__) {
HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
var r = this.ownerDocument.createRange();
r.setStartBefore(this);
var df = r.createContextualFragment(sHTML);
this.parentNode.replaceChild(df, this);
return sHTML;
});
}
}
}
}
2015-02-22 12:46:05 +01:00
// return TableFilter;
2014-09-20 15:56:35 +02:00
2015-02-22 12:46:05 +01:00
// });
2015-02-22 12:46:05 +01:00
}
});
2015-02-22 12:46:05 +01:00
return TableFilter;
})();
2015-02-22 12:46:05 +01:00
exports.TableFilter = TableFilter;
});