1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-03 06:22:34 +02:00
TableFilter/src-es6/extensions/colsVisibility/colsVisibility.js

159 lines
6.7 KiB
JavaScript
Raw Normal View History

2015-04-15 09:09:20 +02:00
import {Dom} from 'dom';
import {Types} from 'types';
2015-04-12 10:32:24 +02:00
export class ColsVisibility{
/**
2015-04-12 12:24:32 +02:00
* Columns Visibility extension
2015-04-12 10:32:24 +02:00
* @param {Object} tf TableFilter instance
*/
constructor(tf, ext){
// Configuration object
var f = tf.config();
this.colsVisibility = f.cols_visibility;
this.showHideColsExtLoaded = false;
this.showHideColsExtName = ext.name;
this.showHideColsExtDesc = ext.description;
//show/hide cols span element
this.showHideColsSpanEl = null;
//show/hide cols button element
this.btnShowHideColsEl = null;
//show/hide cols container div element
this.showHideColsContEl = null;
2015-04-12 12:24:32 +02:00
//tick to hide or show column
2015-04-15 09:09:20 +02:00
this.showHideColsTickToHide = Boolean(f.colvis_tick_to_hide || true);
2015-04-12 12:24:32 +02:00
//enables/disables cols manager generation
2015-04-15 09:09:20 +02:00
this.showHideColsManager = Boolean(f.colvis_manager || true);
2015-04-12 12:24:32 +02:00
//only if external headers
2015-04-15 09:09:20 +02:00
this.showHideColsHeadersTbl = f.colvis_headers_table || null;
2015-04-12 12:24:32 +02:00
//only if external headers
2015-04-15 09:09:20 +02:00
this.showHideColsHeadersIndex = f.colvis_headers_index || 1;
2015-04-12 12:24:32 +02:00
//id of container element
2015-04-15 09:09:20 +02:00
this.showHideColsContElTgtId = f.colvis_container_target_id || null;
2015-04-12 12:24:32 +02:00
//alternative headers text
2015-04-15 09:09:20 +02:00
this.showHideColsHeadersText = f.colvis_headers_text || null;
2015-04-12 12:24:32 +02:00
//id of button container element
2015-04-15 09:09:20 +02:00
this.btnShowHideColsTgtId = f.btn_colvis_target_id || null;
2015-04-12 12:24:32 +02:00
//defines show/hide cols text
2015-04-15 09:09:20 +02:00
this.btnShowHideColsText = f.btn_colvis_text ||
2015-04-12 12:24:32 +02:00
'Display columns▼';
//defines show/hide cols button innerHtml
2015-04-15 09:09:20 +02:00
this.btnShowHideColsHtml = f.btn_colvis_html || null;
2015-04-12 12:24:32 +02:00
//defines css class for show/hide cols button
2015-04-15 09:09:20 +02:00
this.btnShowHideColsCssClass = f.btn_colvis_css_class || 'showHideCols';
2015-04-12 12:24:32 +02:00
//defines close link text
2015-04-15 09:09:20 +02:00
this.btnShowHideColsCloseText = f.btn_colvis_close_text || 'Close';
2015-04-12 12:24:32 +02:00
//defines close button innerHtml
2015-04-15 09:09:20 +02:00
this.btnShowHideColsCloseHtml = f.btn_colvis_close_html || null;
2015-04-12 12:24:32 +02:00
//defines css class for close button
this.btnShowHideColsCloseCssClass =
2015-04-15 09:09:20 +02:00
f.btn_colvis_close_css_class || this.btnShowHideColsCssClass;
this.showHideColsExtPath = ext.path || 'TFExt_ColsVisibility/';
this.showHideColsStylesheet = 'TFExt_ColsVisibility.css';
//span containing show/hide cols button
this.prfxShowHideColsSpan = 'showHideCols_';
//defines css class span containing show/hide cols
this.showHideColsSpanCss = f.colvis_span_css_class ||
'showHideColsSpan';
this.prfxShowHideColsCont = 'showHideColsCont_';
//defines css class div containing show/hide cols
this.showHideColsContCss = f.colvis_cont_css_class ||
'showHideColsCont';
//defines css class for cols list (ul)
this.showHideColsListCss = f.colvis_list_css_class ||'cols_checklist';
//defines css class for list item (li)
this.showHideColsListItemCssClass = f.checklist_item_css_class ||
'cols_checklist_item';
//defines css class for selected list item (li)
this.showHideColsListSlcItemCssClass =
f.checklist_selected_item_css_class || 'cols_checklist_slc_item';
//text preceding columns list
this.showHideColsText = f.colvis_text || 'Hide columns: ';
this.showHideColsAtStart = f.colvis_at_start || null;
this.showHideColsEnableHover = Boolean(f.colvis_enable_hover) || false;
//enables select all option
this.showHideEnableTickAll = Boolean(f.colvis_enable_tick_all) ||
false;
//text preceding columns list
this.showHideTickAllText = f.colvis_tick_all_text || 'Select all:';
this.showHideColsIsOpen = false;
//array containing hidden columns indexes
this.showHideHiddenCols = [];
this.tblHasColTag = (Dom.tag(tf.tbl,'col').length > 0);
//callback invoked just after cols manager is loaded
this.onColsManagerLoaded = Types.isFn(f.on_cols_manager_loaded) ?
f.on_cols_manager_loaded : null;
//calls function before cols manager is opened
this.onBeforeOpenColsManager =
Types.isFn(f.on_before_open_cols_manager) ?
f.on_before_open_cols_manager : null;
//calls function after cols manager is opened
this.onAfterOpenColsManager = Types.isFn(f.on_after_open_cols_manager) ?
f.on_after_open_cols_manager : null;
//calls function before cols manager is closed
this.onBeforeCloseColsManager =
Types.isFn(f.on_before_close_cols_manager) ?
f.on_before_close_cols_manager : null;
//calls function after cols manager is closed
this.onAfterCloseColsManager =
Types.isFn(f.on_after_close_cols_manager) ?
f.on_after_close_cols_manager : null;
//calls function before col is hidden
this.onBeforeColIsHidden = Types.isFn(f.on_before_col_is_hidden) ?
f.on_before_col_is_hidden : null;
//calls function after col is hidden
this.onAfterColIsHidden = Types.isFn(f.on_after_col_is_hidden) ?
f.on_after_col_is_hidden : null;
//calls function before col is displayed
this.onBeforeColIsDisplayed = Types.isFn(f.on_before_col_is_displayed) ?
f.on_before_col_is_displayed : null;
//calls function after col is displayed
this.onAfterColIsDisplayed = Types.isFn(f.on_after_col_is_displayed) ?
f.on_after_col_is_displayed : null;
//Grid layout compatibility
if(tf.gridLayout){
this.showHideColsHeadersTbl = tf.headTbl; //headers table
this.showHideColsHeadersIndex = 0; //headers index
this.onAfterColIsDisplayed = function(){};
this.onAfterColIsHidden = function(){};
}
//Extension event definition
//event name for TF event manager
tf.Evt.name.colsvisibility = 'ShowColsVisibility';
//event status message
tf.msgShowColsVisibility = 'Show/Hide columns';
tf.Evt._ShowColsVisibility = function(){ o.ShowColsVisibility(); };
//event name for TF event manager
tf.Evt.name.checkitem = 'CheckItem';
//event status message
tf.msgCheckItem = 'Showing/hiding columns';
tf.Evt._CheckItem = function(li){ o.CheckItem(li); };
//Loads extension stylesheet
tf.includeFile(
ext.name+'Style',
this.showHideColsExtPath + this.showHideColsStylesheet,
null,
'link'
);
//Sets button
// if(this.showHideColsManager) o.SetShowHideColsBtn();
this.init();
this.showHideColsExtLoaded = true;
}
init(){
2015-04-12 10:32:24 +02:00
}
}