From 81ab528e839beb6ef10e66aa34a02c9b37c217a1 Mon Sep 17 00:00:00 2001 From: Max Guglielmi Date: Sun, 12 Apr 2015 18:32:24 +1000 Subject: [PATCH] Started columns visibility extension --- .../TFExt_ColsVisibility.css | 47 ++ .../TFExt_ColsVisibility.js | 498 ++++++++++++++++++ .../colsVisibility/colsVisibility.js | 25 + 3 files changed, 570 insertions(+) create mode 100644 libs/TFExt_ColsVisibility/TFExt_ColsVisibility.css create mode 100644 libs/TFExt_ColsVisibility/TFExt_ColsVisibility.js create mode 100644 src-es6/extensions/colsVisibility/colsVisibility.js diff --git a/libs/TFExt_ColsVisibility/TFExt_ColsVisibility.css b/libs/TFExt_ColsVisibility/TFExt_ColsVisibility.css new file mode 100644 index 00000000..c7036e57 --- /dev/null +++ b/libs/TFExt_ColsVisibility/TFExt_ColsVisibility.css @@ -0,0 +1,47 @@ +/*==================================================== + - HTML Table Filter Generator + - Columns Visibility Manager Extension + - do not hesitate to edit classes below to + change extension appearance +=====================================================*/ + +span.showHideColsSpan{ text-align:left; } + +span.showHideColsSpan a.showHideCols{ + /* Link */ + margin:0 5px 0 5px; +} +div.showHideColsCont{ + /* Container div */ + position:absolute; + display:none; + border:1px solid #ccc; + height:auto; width:250px; + background:#fff; + margin:18px 0 0 0; z-index:10000; + padding:10px 10px 10px 10px; + text-align:left; font-size:12px; + border-radius:4px; + -moz-border-radius:4px; + -webkit-border-radius:4px; + box-shadow:3px 3px 2px #888; + -moz-box-shadow:3px 3px 2px #888; + -webkit-box-shadow:3px 3px 2px #888; +} +div.showHideColsCont p{ margin:6px auto 6px auto; } + +ul.cols_checklist{ padding:0; margin:0; list-style: none; } +li.cols_checklist_item{ /*check list item*/ + padding:1px; margin:0; font-size:11px; + border-bottom:1px solid #ccc; +} +li.cols_checklist_item:hover{ + background-color:#335EA8; + color:#fff; +} +.cols_checklist_slc_item{ /*selected check list item*/ + background-color:#335EA8; + color:#fff; +} +ul.cols_checklist label{ display:block; } +ul.cols_checklist input{ vertical-align:middle; margin:2px 5px 2px 1px; } \ No newline at end of file diff --git a/libs/TFExt_ColsVisibility/TFExt_ColsVisibility.js b/libs/TFExt_ColsVisibility/TFExt_ColsVisibility.js new file mode 100644 index 00000000..7222368c --- /dev/null +++ b/libs/TFExt_ColsVisibility/TFExt_ColsVisibility.js @@ -0,0 +1,498 @@ +/*------------------------------------------------------------------------ + - HTML Table Filter Generator + - Columns Visibility Manager Extension v1.4 + - By Max Guglielmi (tablefilter.free.fr) + - Licensed under the MIT License +-------------------------------------------------------------------------- +Copyright (c) 2009-2012 Max Guglielmi + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +------------------------------------------------------------------------ + - Special credit to: + Salman A. Kagzi for active contribution and/or inspiration +------------------------------------------------------------------------*/ + +TF.prototype.SetColsVisibility = function(extName) +{ + var o = this, f = o.fObj, ext = (extName) ? o.Ext.list[extName] : o.Ext.list['ColsVisibility']; + o.colsVisibility = (f.cols_visibility==undefined) ? true : f.cols_visibility; + if(!o.colsVisibility || o.showHideColsExtLoaded) return; + + o.showHideColsExtLoaded = false; + o.showHideColsExtName = ext.name; + o.showHideColsExtDesc = ext.description; + + o.showHideColsSpanEl = null; //show/hide cols span element + o.btnShowHideColsEl = null; //show/hide cols button element + o.showHideColsContEl = null; //show/hide cols container div element + + o.showHideColsTickToHide = f.showHide_cols_tick_to_hide!=undefined //tick to hide or show column + ? f.showHide_cols_tick_to_hide : true; + o.showHideColsManager = f.showHide_cols_manager!=undefined //enables/disables cols manager generation + ? f.showHide_cols_manager : true; + o.showHideColsHeadersTbl = f.showHide_cols_headers_table!=undefined //only if external headers + ? f.showHide_cols_headers_table : null; + o.showHideColsHeadersIndex = f.showHide_cols_headers_index!=undefined //only if external headers + ? f.showHide_cols_headers_index : 1; + o.showHideColsContElTgtId = f.showHide_cols_container_target_id!=undefined //id of container element + ? f.showHide_cols_container_target_id : null; + o.showHideColsHeadersText = f.showHide_cols_headers_text!=undefined //alternative headers text + ? f.showHide_cols_headers_text : null; + o.btnShowHideColsTgtId = f.btn_showHide_cols_target_id!=undefined //id of button container element + ? f.btn_showHide_cols_target_id : null; + o.btnShowHideColsText = f.btn_showHide_cols_text!=undefined + ? f.btn_showHide_cols_text : 'Display columns▼'; //defines show/hide cols text + o.btnShowHideColsHtml = f.btn_showHide_cols_html!=undefined + ? f.btn_showHide_cols_html : null; //defines show/hide cols button innerHtml + o.btnShowHideColsCssClass = f.btn_showHide_cols_css_class!=undefined //defines css class for show/hide cols button + ? f.btn_showHide_cols_css_class :'showHideCols'; + o.btnShowHideColsCloseText = f.btn_showHide_cols_close_text!=undefined + ? f.btn_showHide_cols_close_text : 'Close'; //defines close link text + o.btnShowHideColsCloseHtml = f.btn_showHide_cols_close_html!=undefined + ? f.btn_showHide_cols_close_html : null; //defines close button innerHtml + o.btnShowHideColsCloseCssClass = f.btn_showHide_cols_close_css_class!=undefined //defines css class for close button + ? f.btn_showHide_cols_close_css_class :o.btnShowHideColsCssClass; + + o.showHideColsExtPath = (ext.path == undefined) ? 'TFExt_ColsVisibility/' : ext.path; + o.showHideColsStylesheet = 'TFExt_ColsVisibility.css'; + o.prfxShowHideColsSpan = 'showHideCols_'; //span containing show/hide cols button + o.showHideColsSpanCss = f.showHide_cols_span_css_class!=undefined //defines css class span containing show/hide cols + ? f.showHide_cols_span_css_class : 'showHideColsSpan'; + o.prfxShowHideColsCont = 'showHideColsCont_'; + o.showHideColsContCss = f.showHide_cols_cont_css_class!=undefined //defines css class div containing show/hide cols + ? f.showHide_cols_cont_css_class : 'showHideColsCont'; + o.showHideColsListCss = f.showHide_cols_list_css_class!=undefined //defines css class for cols list (ul) + ? f.showHide_cols_list_css_class : 'cols_checklist'; + o.showHideColsListItemCssClass = f.checklist_item_css_class!=undefined //defines css class for list item (li) + ? f.checklist_item_css_class : 'cols_checklist_item'; + o.showHideColsListSlcItemCssClass = f.checklist_selected_item_css_class!=undefined //defines css class for selected list item (li) + ? f.checklist_selected_item_css_class : 'cols_checklist_slc_item'; + o.showHideColsText = f.showHide_cols_text!=undefined //text preceding columns list + ? f.showHide_cols_text : 'Hide columns: '; + o.showHideColsAtStart = f.showHide_cols_at_start!=undefined + ? f.showHide_cols_at_start : null; + o.showHideColsEnableHover = f.showHide_cols_enable_hover!=undefined + ? f.showHide_cols_enable_hover : false; + o.showHideEnableTickAll = f.showHide_enable_tick_all!=undefined //enables select all option + ? f.showHide_enable_tick_all : false; + o.showHideTickAllText = f.showHide_tick_all_text!=undefined //text preceding columns list + ? f.showHide_tick_all_text : 'Select all:'; + o.showHideColsIsOpen = false; + o.showHideHiddenCols = []; //array containing hidden columns indexes + o.tblHasColTag = (tf_Tag(o.tbl,'col').length > 0) ? true : false; + + /*** Extension events ***/ + //callback invoked just after cols manager is loaded + o.onColsManagerLoaded = tf_IsFn(f.on_cols_manager_loaded) ? f.on_cols_manager_loaded : null; + //calls function before cols manager is opened + o.onBeforeOpenColsManager = tf_IsFn(f.on_before_open_cols_manager) ? f.on_before_open_cols_manager : null; + //calls function after cols manager is opened + o.onAfterOpenColsManager = tf_IsFn(f.on_after_open_cols_manager) ? f.on_after_open_cols_manager : null; + //calls function before cols manager is closed + o.onBeforeCloseColsManager = tf_IsFn(f.on_before_close_cols_manager) ? f.on_before_close_cols_manager : null; + //calls function after cols manager is closed + o.onAfterCloseColsManager = tf_IsFn(f.on_after_close_cols_manager) ? f.on_after_close_cols_manager : null; + + //calls function before col is hidden + o.onBeforeColIsHidden = tf_IsFn(f.on_before_col_is_hidden) ? f.on_before_col_is_hidden : null; + //calls function after col is hidden + o.onAfterColIsHidden = tf_IsFn(f.on_after_col_is_hidden) ? f.on_after_col_is_hidden : null; + //calls function before col is displayed + o.onBeforeColIsDisplayed = tf_IsFn(f.on_before_col_is_displayed) ? f.on_before_col_is_displayed : null; + //calls function after col is displayed + o.onAfterColIsDisplayed = tf_IsFn(f.on_after_col_is_displayed) ? f.on_after_col_is_displayed : null; + /*** ***/ + + //Grid layout compatibility + if(o.gridLayout){ + o.showHideColsHeadersTbl = o.headTbl; //headers table + o.showHideColsHeadersIndex = 0; //headers index + o.onAfterColIsDisplayed = function(){}; + o.onAfterColIsHidden = function(){}; + } + + //Extension event definition + o.Evt.name.colsvisibility = 'ShowColsVisibility'; //event name for TF event manager + o.msgShowColsVisibility = 'Show/Hide columns'; //event status message + o.Evt._ShowColsVisibility = function(){ o.ShowColsVisibility(); }; //event + o.Evt.name.checkitem = 'CheckItem'; //event name for TF event manager + o.msgCheckItem = 'Showing/hiding columns'; //event status message + o.Evt._CheckItem = function(li){ o.CheckItem(li); }; //event + + //Loads extension stylesheet + o.IncludeFile(ext.name+'Style', o.showHideColsExtPath + o.showHideColsStylesheet, null, 'link'); + + //Sets button + if(o.showHideColsManager) o.SetShowHideColsBtn(); + o.showHideColsExtLoaded = true; +} + +TF.prototype.SetShowHideColsBtn = function() +/*==================================================== + - Generates show/hide cols button +=====================================================*/ +{ + if(!this.hasGrid && !this.isFirstLoad) return; + if( this.btnShowHideColsEl!=null ) return; + var showHideColsSpan = tf_CreateElm('span',['id',this.prfxShowHideColsSpan+this.id]); + showHideColsSpan.className = this.showHideColsSpanCss; + + //Container element (rdiv or custom element) + if(this.btnShowHideColsTgtId==null) this.SetTopDiv(); + var targetEl = ( this.btnShowHideColsTgtId==null ) ? this.rDiv : tf_Id( this.btnShowHideColsTgtId ); + + if(this.btnShowHideColsTgtId==null) + targetEl.firstChild.parentNode.insertBefore(showHideColsSpan,targetEl.firstChild); + else + targetEl.appendChild(showHideColsSpan); + + if(this.btnShowHideColsHtml==null) + { //Default link + var btn = tf_CreateElm( 'a', ['href','javascript:;'] ); + btn.className = this.btnShowHideColsCssClass; + btn.title = this.showHideColsExtDesc; + + btn.innerHTML = this.btnShowHideColsText; + showHideColsSpan.appendChild(btn); + if(!this.showHideColsEnableHover) + btn.onclick = this.Evt._ShowColsVisibility; + else{ + var o = this; + btn.onmouseover = this.Evt._ShowColsVisibility; + } + } else { //Custom html + showHideColsSpan.innerHTML = this.btnShowHideColsHtml; + var showHideColsEl = showHideColsSpan.firstChild; + if(!this.showHideColsEnableHover) + showHideColsEl.onclick = this.Evt._ShowColsVisibility; + else + showHideColsEl.onmouseover = this.Evt._ShowColsVisibility; + } + + this.showHideColsSpanEl = showHideColsSpan; + this.btnShowHideColsEl = this.showHideColsSpanEl.firstChild; + + this.SetColsVisibilityManager(); + + if(this.onColsManagerLoaded) this.onColsManagerLoaded.call(null, this); +} + +TF.prototype.SetColsVisibilityManager = function() +/*==================================================== + - Generates show/hide cols manager +=====================================================*/ +{ + if(!this.hasGrid && !this.isFirstLoad) return; + + var container = (!this.showHideColsContElTgtId) + ? tf_CreateElm('div',['id',this.prfxShowHideColsCont+this.id]) + : tf_Id(this.showHideColsContElTgtId); + container.className = this.showHideColsContCss; + + //Extension description + var extNameLabel = tf_CreateElm('p'); + extNameLabel.innerHTML = this.showHideColsText; + container.appendChild(extNameLabel); + + //Headers list + var ul = tf_CreateElm('ul',['id','ul'+this.showHideColsExtName+'_'+this.id]); + ul.className = this.showHideColsListCss; + + var o = this; + var tbl = (o.showHideColsHeadersTbl) ? o.showHideColsHeadersTbl : o.tbl; + var headerIndex = (o.showHideColsHeadersTbl) + ? o.showHideColsHeadersIndex : o.GetHeadersRowIndex(); + var headerRow = tbl.rows[headerIndex]; + + //Tick all option + if(o.showHideEnableTickAll){ + var li = tf_CreateCheckItem('col__'+o.id, o.showHideTickAllText, o.showHideTickAllText); + tf_AddClass(li,this.showHideColsListItemCssClass); + ul.appendChild(li); + var isAllTicked = false; + li.check.onclick = function(){ + for(var h=0; h