mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-05 07:22:33 +02:00
Converted checklist into es6 module
This commit is contained in:
parent
d9eb8370e7
commit
718b3cc1b0
2
dist/filtergrid.css
vendored
2
dist/filtergrid.css
vendored
|
@ -1,6 +1,6 @@
|
||||||
/*------------------------------------------------------------------------
|
/*------------------------------------------------------------------------
|
||||||
- TableFilter stylesheet by Max Guglielmi
|
- TableFilter stylesheet by Max Guglielmi
|
||||||
- (build date: Mon Jan 26 2015 20:27:42)
|
- (build date: Sun Feb 01 2015 19:22:55)
|
||||||
- Edit below for your projects' needs
|
- Edit below for your projects' needs
|
||||||
------------------------------------------------------------------------*/
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
10
dist/tablefilter.js
vendored
10
dist/tablefilter.js
vendored
File diff suppressed because one or more lines are too long
412
src-es6/modules/checkList.js
Normal file
412
src-es6/modules/checkList.js
Normal file
|
@ -0,0 +1,412 @@
|
||||||
|
import {Dom} from '../dom';
|
||||||
|
import {Arr as array} from '../array';
|
||||||
|
import {Str} from '../string';
|
||||||
|
import {Sort} from '../sort';
|
||||||
|
import {Event} from '../event';
|
||||||
|
|
||||||
|
export class CheckList{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checklist UI component
|
||||||
|
* @param {Object} tf TableFilter instance
|
||||||
|
*/
|
||||||
|
constructor(tf){
|
||||||
|
// Configuration object
|
||||||
|
var f = tf.fObj;
|
||||||
|
|
||||||
|
this.checkListDiv = []; //checklist container div
|
||||||
|
//defines css class for div containing checklist filter
|
||||||
|
this.checkListDivCssClass = f.div_checklist_css_class ||
|
||||||
|
'div_checklist';
|
||||||
|
//defines css class for checklist filters
|
||||||
|
this.checkListCssClass = f.checklist_css_class || 'flt_checklist';
|
||||||
|
//defines css class for checklist item (li)
|
||||||
|
this.checkListItemCssClass = f.checklist_item_css_class ||
|
||||||
|
'flt_checklist_item';
|
||||||
|
//defines css class for selected checklist item (li)
|
||||||
|
this.checkListSlcItemCssClass = f.checklist_selected_item_css_class ||
|
||||||
|
'flt_checklist_slc_item';
|
||||||
|
//Load on demand text
|
||||||
|
this.activateCheckListTxt = f.activate_checklist_text ||
|
||||||
|
'Click to load filter data';
|
||||||
|
//defines css class for checklist filters
|
||||||
|
this.checkListItemDisabledCssClass =
|
||||||
|
f.checklist_item_disabled_css_class ||
|
||||||
|
'flt_checklist_item_disabled';
|
||||||
|
this.enableCheckListResetFilter =
|
||||||
|
f.enable_checklist_reset_filter===false ? false : true;
|
||||||
|
|
||||||
|
this.isCustom = null;
|
||||||
|
this.opts = [];
|
||||||
|
this.optsTxt = [];
|
||||||
|
|
||||||
|
this.tf = tf;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add _OnSlcChange event here
|
||||||
|
onChange(evt){
|
||||||
|
this.tf.Evt._OnSlcChange(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
optionClick(evt){
|
||||||
|
this.setCheckListValues(evt.target);
|
||||||
|
this.onChange(evt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build checklist UI asynchronously
|
||||||
|
* @param {Number} colIndex Column index
|
||||||
|
* @param {Boolean} isExternal Render in external container
|
||||||
|
* @param {String} extFltId External container id
|
||||||
|
*/
|
||||||
|
build(colIndex, isExternal, extFltId){
|
||||||
|
var tf = this.tf;
|
||||||
|
tf.EvtManager(
|
||||||
|
tf.Evt.name.checklist,
|
||||||
|
{ slcIndex:colIndex, slcExternal:isExternal, slcId:extFltId }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build checklist UI
|
||||||
|
* @param {Number} colIndex Column index
|
||||||
|
* @param {Boolean} isExternal Render in external container
|
||||||
|
* @param {String} extFltId External container id
|
||||||
|
*/
|
||||||
|
_build(colIndex, isExternal=false, extFltId=null){
|
||||||
|
var tf = this.tf;
|
||||||
|
colIndex = parseInt(colIndex, 10);
|
||||||
|
|
||||||
|
var divFltId = tf.prfxCheckListDiv+colIndex+'_'+tf.id;
|
||||||
|
if((!Dom.id(divFltId) && !isExternal) ||
|
||||||
|
(!Dom.id(extFltId) && isExternal)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var flt = !isExternal ? this.checkListDiv[colIndex] : Dom.id(extFltId);
|
||||||
|
var ul = Dom.create(
|
||||||
|
'ul', ['id', tf.fltIds[colIndex]], ['colIndex', colIndex]);
|
||||||
|
ul.className = this.checkListCssClass;
|
||||||
|
Event.add(ul, 'change', (evt) => { this.onChange(evt); });
|
||||||
|
|
||||||
|
var rows = tf.tbl.rows;
|
||||||
|
this.isCustom = (tf.hasCustomSlcOptions &&
|
||||||
|
array.has(tf.customSlcOptions.cols, colIndex));
|
||||||
|
|
||||||
|
var activeFlt;
|
||||||
|
if(tf.refreshFilters && tf.activeFilterId){
|
||||||
|
activeFlt = tf.activeFilterId.split('_')[0];
|
||||||
|
activeFlt = activeFlt.split(tf.prfxFlt)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
var excludedOpts,
|
||||||
|
filteredDataCol = [];
|
||||||
|
if(tf.refreshFilters && tf.disableExcludedOptions){
|
||||||
|
excludedOpts = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var k=tf.refRow; k<tf.nbRows; k++){
|
||||||
|
// always visible rows don't need to appear on selects as always
|
||||||
|
// valid
|
||||||
|
if(tf.hasVisibleRows && array.has(tf.visibleRows, k) && !tf.paging){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cells = rows[k].cells;
|
||||||
|
var ncells = cells.length;
|
||||||
|
|
||||||
|
// checks if row has exact cell #
|
||||||
|
if(ncells === tf.nbCells && !this.isCustom){
|
||||||
|
// this loop retrieves cell data
|
||||||
|
for(var j=0; j<ncells; j++){
|
||||||
|
if((colIndex===j && (!tf.refreshFilters ||
|
||||||
|
(tf.refreshFilters && tf.disableExcludedOptions)))||
|
||||||
|
(colIndex===j && tf.refreshFilters &&
|
||||||
|
((rows[k].style.display === '' && !tf.paging) ||
|
||||||
|
(tf.paging && ((!activeFlt || activeFlt===colIndex )||
|
||||||
|
(activeFlt!=colIndex &&
|
||||||
|
array.has(tf.validRowsIndex, k))) )))){
|
||||||
|
var cell_data = tf.GetCellData(j, cells[j]);
|
||||||
|
//Vary Peter's patch
|
||||||
|
var cell_string = Str.matchCase(
|
||||||
|
cell_data, tf.matchCase);
|
||||||
|
// checks if celldata is already in array
|
||||||
|
if(!array.has(this.opts, cell_string, tf.matchCase)){
|
||||||
|
this.opts.push(cell_data);
|
||||||
|
}
|
||||||
|
var filteredCol = filteredDataCol[j];
|
||||||
|
if(tf.refreshFilters && tf.disableExcludedOptions){
|
||||||
|
if(!filteredCol){
|
||||||
|
filteredDataCol[j] = tf.GetFilteredDataCol(j);
|
||||||
|
}
|
||||||
|
if(!array.has(filteredCol,
|
||||||
|
cell_string, tf.matchCase) &&
|
||||||
|
!array.has(excludedOpts,
|
||||||
|
cell_string, tf.matchCase) &&
|
||||||
|
!tf.isFirstLoad){
|
||||||
|
excludedOpts.push(cell_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Retrieves custom values
|
||||||
|
if(this.isCustom){
|
||||||
|
var customValues = tf.__getCustomValues(colIndex);
|
||||||
|
this.opts = customValues[0];
|
||||||
|
this.optsTxt = customValues[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tf.sortSlc && !this.isCustom){
|
||||||
|
if (!tf.matchCase){
|
||||||
|
this.opts.sort(Sort.ignoreCase);
|
||||||
|
if(excludedOpts){
|
||||||
|
excludedOpts.sort(Sort.ignoreCase);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.opts.sort();
|
||||||
|
if(excludedOpts){
|
||||||
|
excludedOpts.sort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//asc sort
|
||||||
|
if(tf.sortNumAsc && array.has(tf.sortNumAsc, colIndex)){
|
||||||
|
try{
|
||||||
|
this.opts.sort(numSortAsc);
|
||||||
|
if(excludedOpts){
|
||||||
|
excludedOpts.sort(numSortAsc);
|
||||||
|
}
|
||||||
|
if(this.isCustom){
|
||||||
|
this.optsTxt.sort(numSortAsc);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
this.opts.sort();
|
||||||
|
if(excludedOpts){
|
||||||
|
excludedOpts.sort();
|
||||||
|
}
|
||||||
|
if(this.isCustom){
|
||||||
|
this.optsTxt.sort();
|
||||||
|
}
|
||||||
|
}//in case there are alphanumeric values
|
||||||
|
}
|
||||||
|
//desc sort
|
||||||
|
if(tf.sortNumDesc && array.has(tf.sortNumDesc, colIndex)){
|
||||||
|
try{
|
||||||
|
this.opts.sort(numSortDesc);
|
||||||
|
if(excludedOpts){
|
||||||
|
excludedOpts.sort(numSortDesc);
|
||||||
|
}
|
||||||
|
if(this.isCustom){
|
||||||
|
this.optsTxt.sort(numSortDesc);
|
||||||
|
}
|
||||||
|
} catch(e) {
|
||||||
|
this.opts.sort();
|
||||||
|
if(excludedOpts){
|
||||||
|
excludedOpts.sort(); }
|
||||||
|
if(this.isCustom){
|
||||||
|
this.optsTxt.sort();
|
||||||
|
}
|
||||||
|
}//in case there are alphanumeric values
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addChecks(colIndex, ul, tf.separator);
|
||||||
|
|
||||||
|
if(tf.fillSlcOnDemand){
|
||||||
|
flt.innerHTML = '';
|
||||||
|
}
|
||||||
|
flt.appendChild(ul);
|
||||||
|
flt.setAttribute('filled', '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add checklist options
|
||||||
|
* @param {Number} colIndex Column index
|
||||||
|
* @param {Object} ul Ul element
|
||||||
|
* @param {String} separator Data separator
|
||||||
|
*/
|
||||||
|
addChecks(colIndex, ul, separator){
|
||||||
|
var tf = this.tf;
|
||||||
|
var chkCt = this.addTChecks(colIndex, ul);
|
||||||
|
var flts_values = [], fltArr = []; //remember grid values
|
||||||
|
var store = tf.Cpt.store;
|
||||||
|
var tmpVal = store ?
|
||||||
|
store.getFilterValues(tf.fltsValuesCookie)[colIndex] : null;
|
||||||
|
if(tmpVal && Str.trim(tmpVal).length > 0){
|
||||||
|
if(tf.hasCustomSlcOptions &&
|
||||||
|
array.has(tf.customSlcOptions.cols, colIndex)){
|
||||||
|
fltArr.push(tmpVal);
|
||||||
|
} else {
|
||||||
|
fltArr = tmpVal.split(' '+tf.orOperator+' ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var y=0; y<this.opts.length; y++){
|
||||||
|
var val = this.opts[y]; //item value
|
||||||
|
var lbl = this.isCustom ? this.optsTxt[y] : val; //item text
|
||||||
|
var li = Dom.createCheckItem(
|
||||||
|
tf.fltIds[colIndex]+'_'+(y+chkCt), val, lbl);
|
||||||
|
li.className = this.checkListItemCssClass;
|
||||||
|
if(tf.refreshFilters && tf.disableExcludedOptions &&
|
||||||
|
array.has(excludedOpts,
|
||||||
|
Str.matchCase(val, tf.matchCase), tf.matchCase)){
|
||||||
|
Dom.addClass(li, this.checkListItemDisabledCssClass);
|
||||||
|
li.check.disabled = true;
|
||||||
|
li.disabled = true;
|
||||||
|
} else{
|
||||||
|
Event.add(li.check, 'click',
|
||||||
|
(evt) => { this.optionClick(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ul.appendChild(li);
|
||||||
|
|
||||||
|
if(val===''){
|
||||||
|
//item is hidden
|
||||||
|
li.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** remember grid values ***/
|
||||||
|
if(tf.rememberGridValues){
|
||||||
|
if((tf.hasCustomSlcOptions &&
|
||||||
|
array.has(tf.customSlcOptions.cols, colIndex) &&
|
||||||
|
fltArr.toString().indexOf(val)!= -1) ||
|
||||||
|
array.has(fltArr,
|
||||||
|
Str.matchCase(val, tf.matchCase), tf.matchCase)){
|
||||||
|
li.check.checked = true;
|
||||||
|
this.setCheckListValues(li.check);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add checklist header option
|
||||||
|
* @param {Number} colIndex Column index
|
||||||
|
* @param {Object} ul Ul element
|
||||||
|
*/
|
||||||
|
addTChecks(colIndex, ul){
|
||||||
|
var tf = this.tf;
|
||||||
|
var chkCt = 1;
|
||||||
|
var li0 = Dom.createCheckItem(
|
||||||
|
tf.fltIds[colIndex]+'_0', '', tf.displayAllText);
|
||||||
|
li0.className = this.checkListItemCssClass;
|
||||||
|
ul.appendChild(li0);
|
||||||
|
|
||||||
|
Event.add(li0.check, 'click', (evt) => {
|
||||||
|
this.optionClick(evt);
|
||||||
|
});
|
||||||
|
|
||||||
|
if(!this.enableCheckListResetFilter){
|
||||||
|
li0.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tf.enableEmptyOption){
|
||||||
|
var li1 = Dom.createCheckItem(
|
||||||
|
tf.fltIds[colIndex]+'_1', tf.emOperator, tf.emptyText);
|
||||||
|
li1.className = this.checkListItemCssClass;
|
||||||
|
ul.appendChild(li1);
|
||||||
|
Event.add(li1.check, 'click', (evt) => {
|
||||||
|
this.optionClick(evt);
|
||||||
|
});
|
||||||
|
chkCt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(tf.enableNonEmptyOption){
|
||||||
|
var li2 = Dom.createCheckItem(
|
||||||
|
tf.fltIds[colIndex]+'_2',
|
||||||
|
tf.nmOperator,
|
||||||
|
tf.nonEmptyText
|
||||||
|
);
|
||||||
|
li2.className = this.checkListItemCssClass;
|
||||||
|
ul.appendChild(li2);
|
||||||
|
Event.add(li2.check, 'click', (evt) => {
|
||||||
|
this.optionClick(evt);
|
||||||
|
});
|
||||||
|
chkCt++;
|
||||||
|
}
|
||||||
|
return chkCt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store checked options in DOM element attribute
|
||||||
|
* @param {Object} o checklist option DOM element
|
||||||
|
*/
|
||||||
|
setCheckListValues(o){
|
||||||
|
if(!o){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var tf = this.tf;
|
||||||
|
var chkValue = o.value; //checked item value
|
||||||
|
var chkIndex = parseInt(o.id.split('_')[2], 10);
|
||||||
|
var filterTag = 'ul', itemTag = 'li';
|
||||||
|
var n = o;
|
||||||
|
|
||||||
|
//ul tag search
|
||||||
|
while(Str.lower(n.nodeName)!==filterTag){
|
||||||
|
n = n.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
var li = n.childNodes[chkIndex];
|
||||||
|
var colIndex = n.getAttribute('colIndex');
|
||||||
|
var fltValue = n.getAttribute('value'); //filter value (ul tag)
|
||||||
|
var fltIndexes = n.getAttribute('indexes'); //selected items (ul tag)
|
||||||
|
|
||||||
|
if(o.checked){
|
||||||
|
//show all item
|
||||||
|
if(chkValue===''){
|
||||||
|
if((fltIndexes && fltIndexes!=='')){
|
||||||
|
//items indexes
|
||||||
|
var indSplit = fltIndexes.split(tf.separator);
|
||||||
|
//checked items loop
|
||||||
|
for(var u=0; u<indSplit.length; u++){
|
||||||
|
//checked item
|
||||||
|
var cChk = Dom.id(tf.fltIds[colIndex]+'_'+indSplit[u]);
|
||||||
|
if(cChk){
|
||||||
|
cChk.checked = false;
|
||||||
|
Dom.removeClass(
|
||||||
|
n.childNodes[indSplit[u]],
|
||||||
|
this.checkListSlcItemCssClass
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n.setAttribute('value', '');
|
||||||
|
n.setAttribute('indexes', '');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fltValue = (fltValue) ? fltValue : '';
|
||||||
|
chkValue = Str.trim(
|
||||||
|
fltValue+' '+chkValue+' '+tf.orOperator);
|
||||||
|
chkIndex = fltIndexes + chkIndex + tf.separator;
|
||||||
|
n.setAttribute('value', chkValue );
|
||||||
|
n.setAttribute('indexes', chkIndex);
|
||||||
|
//1st option unchecked
|
||||||
|
if(Dom.id(tf.fltIds[colIndex]+'_0')){
|
||||||
|
Dom.id(tf.fltIds[colIndex]+'_0').checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(Str.lower(li.nodeName) === itemTag){
|
||||||
|
Dom.removeClass(
|
||||||
|
n.childNodes[0], this.checkListSlcItemCssClass);
|
||||||
|
Dom.addClass(li, this.checkListSlcItemCssClass);
|
||||||
|
}
|
||||||
|
} else { //removes values and indexes
|
||||||
|
if(chkValue!==''){
|
||||||
|
var replaceValue = new RegExp(
|
||||||
|
Str.rgxEsc(chkValue+' '+tf.orOperator));
|
||||||
|
fltValue = fltValue.replace(replaceValue,'');
|
||||||
|
n.setAttribute('value', Str.trim(fltValue));
|
||||||
|
|
||||||
|
var replaceIndex = new RegExp(
|
||||||
|
Str.rgxEsc(chkIndex + tf.separator));
|
||||||
|
fltIndexes = fltIndexes.replace(replaceIndex, '');
|
||||||
|
n.setAttribute('indexes', fltIndexes);
|
||||||
|
}
|
||||||
|
if(Str.lower(li.nodeName)===itemTag){
|
||||||
|
Dom.removeClass(li, this.checkListSlcItemCssClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -433,7 +433,7 @@ export class Paging{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show page based param value (string or number):
|
* Show page based on passed param value (string or number):
|
||||||
* @param {String} or {Number} cmd possible string values: 'next',
|
* @param {String} or {Number} cmd possible string values: 'next',
|
||||||
* 'previous', 'last', 'first' or page number as per param
|
* 'previous', 'last', 'first' or page number as per param
|
||||||
*/
|
*/
|
||||||
|
@ -463,13 +463,13 @@ export class Paging{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(cmdtype==='number'){
|
else if(cmdtype==='number'){
|
||||||
this.changePage(cmd-1);
|
this.changePage(cmd-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates UI elements of the number of results per page drop-down
|
* Generates UI elements for the number of results per page drop-down
|
||||||
*/
|
*/
|
||||||
setResultsPerPage(){
|
setResultsPerPage(){
|
||||||
var tf = this.tf;
|
var tf = this.tf;
|
||||||
|
|
15
src-es6/sort.js
Normal file
15
src-es6/sort.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/**
|
||||||
|
* Sort helpers
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {Str} from 'string';
|
||||||
|
|
||||||
|
var Sort = {
|
||||||
|
ignoreCase(a, b){
|
||||||
|
var x = Str.lower(a);
|
||||||
|
var y = Str.lower(b);
|
||||||
|
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.Sort = Sort;
|
493
src/core.js
493
src/core.js
|
@ -22,6 +22,7 @@ var global = this,
|
||||||
dateHelper = require('date').DateHelper,
|
dateHelper = require('date').DateHelper,
|
||||||
isValidDate = dateHelper.isValid,
|
isValidDate = dateHelper.isValid,
|
||||||
formatDate = dateHelper.format,
|
formatDate = dateHelper.format,
|
||||||
|
Sort = require('sort').Sort,
|
||||||
doc = global.document;
|
doc = global.document;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -322,29 +323,6 @@ function TableFilter(id) {
|
||||||
this.onAfterOperation = types.isFn(f.on_after_operation) ?
|
this.onAfterOperation = types.isFn(f.on_after_operation) ?
|
||||||
f.on_after_operation : null;
|
f.on_after_operation : null;
|
||||||
|
|
||||||
/*** checklist customisation and behaviours ***/
|
|
||||||
this.checkListDiv = []; //checklist container div
|
|
||||||
//defines css class for div containing checklist filter
|
|
||||||
this.checkListDivCssClass = f.div_checklist_css_class ||
|
|
||||||
'div_checklist';
|
|
||||||
//defines css class for checklist filters
|
|
||||||
this.checkListCssClass = f.checklist_css_class || 'flt_checklist';
|
|
||||||
//defines css class for checklist item (li)
|
|
||||||
this.checkListItemCssClass = f.checklist_item_css_class ||
|
|
||||||
'flt_checklist_item';
|
|
||||||
//defines css class for selected checklist item (li)
|
|
||||||
this.checkListSlcItemCssClass = f.checklist_selected_item_css_class ||
|
|
||||||
'flt_checklist_slc_item';
|
|
||||||
//Load on demand text
|
|
||||||
this.activateCheckListTxt = f.activate_checklist_text ||
|
|
||||||
'Click to load filter data';
|
|
||||||
//defines css class for checklist filters
|
|
||||||
this.checkListItemDisabledCssClass =
|
|
||||||
f.checklist_item_disabled_css_class ||
|
|
||||||
'flt_checklist_item_disabled';
|
|
||||||
this.enableCheckListResetFilter =
|
|
||||||
f.enable_checklist_reset_filter===false ? false : true;
|
|
||||||
|
|
||||||
/*** Filter operators ***/
|
/*** Filter operators ***/
|
||||||
this.rgxOperator = f.regexp_operator || 'rgx:';
|
this.rgxOperator = f.regexp_operator || 'rgx:';
|
||||||
this.emOperator = f.empty_operator || '[empty]';
|
this.emOperator = f.empty_operator || '[empty]';
|
||||||
|
@ -655,7 +633,8 @@ function TableFilter(id) {
|
||||||
gridLayout: null,
|
gridLayout: null,
|
||||||
store: null,
|
store: null,
|
||||||
highlightKeywords: null,
|
highlightKeywords: null,
|
||||||
paging: null
|
paging: null,
|
||||||
|
checkList: null
|
||||||
};
|
};
|
||||||
|
|
||||||
/*** TF events ***/
|
/*** TF events ***/
|
||||||
|
@ -664,7 +643,7 @@ function TableFilter(id) {
|
||||||
name: {
|
name: {
|
||||||
filter: 'Filter',
|
filter: 'Filter',
|
||||||
populateselect: 'Populate',
|
populateselect: 'Populate',
|
||||||
populatechecklist: 'PopulateCheckList',
|
checklist: 'checkList',
|
||||||
changepage: 'changePage',
|
changepage: 'changePage',
|
||||||
clear: 'Clear',
|
clear: 'Clear',
|
||||||
changeresultsperpage: 'changeResults',
|
changeresultsperpage: 'changeResults',
|
||||||
|
@ -817,9 +796,9 @@ function TableFilter(id) {
|
||||||
if(!o.activeFlt){ return; }
|
if(!o.activeFlt){ return; }
|
||||||
var colIndex = o.activeFlt.getAttribute('colIndex');
|
var colIndex = o.activeFlt.getAttribute('colIndex');
|
||||||
//Checks filter is a checklist and caller is not null
|
//Checks filter is a checklist and caller is not null
|
||||||
if(o.activeFlt && colIndex &&
|
// if(o.activeFlt && colIndex &&
|
||||||
o['col'+colIndex]===o.fltTypeCheckList &&
|
// o['col'+colIndex]===o.fltTypeCheckList &&
|
||||||
!o.Evt._OnSlcChange.caller){ return; }
|
// !o.Evt._OnSlcChange.caller){ return; }
|
||||||
var _evt = e || global.event;
|
var _evt = e || global.event;
|
||||||
if(o.popUpFilters){ evt.stop(_evt); }
|
if(o.popUpFilters){ evt.stop(_evt); }
|
||||||
if(o.onSlcChange){ o.Filter(); }
|
if(o.onSlcChange){ o.Filter(); }
|
||||||
|
@ -828,23 +807,16 @@ function TableFilter(id) {
|
||||||
- onblur event for select filters
|
- onblur event for select filters
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
_OnSlcBlur: function(e) {},
|
_OnSlcBlur: function(e) {},
|
||||||
/*====================================================
|
|
||||||
- onchange event for checklist filters
|
|
||||||
=====================================================*/
|
|
||||||
_OnCheckListChange: function(e) {
|
|
||||||
//Checks caller is not null
|
|
||||||
if(!o.Evt._OnCheckListChange.caller){ return; }
|
|
||||||
o.Evt._OnSlcChange(e);
|
|
||||||
},
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- onclick event for checklist filters
|
- onclick event for checklist filters
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
_OnCheckListClick: function() {
|
_OnCheckListClick: function() {
|
||||||
if(o.fillSlcOnDemand && this.getAttribute('filled') === '0'){
|
if(o.fillSlcOnDemand && this.getAttribute('filled') === '0'){
|
||||||
var ct = this.getAttribute('ct');
|
var ct = this.getAttribute('ct');
|
||||||
o.PopulateCheckList(ct);
|
// o.PopulateCheckList(ct);
|
||||||
o.checkListDiv[ct].onclick = null;
|
o.Cpt.checkList._build(ct);
|
||||||
o.checkListDiv[ct].title = '';
|
o.Cpt.checkList.checkListDiv[ct].onclick = null;
|
||||||
|
o.Cpt.checkList.checkListDiv[ct].title = '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/*====================================================
|
/*====================================================
|
||||||
|
@ -1069,10 +1041,14 @@ TableFilter.prototype = {
|
||||||
}
|
}
|
||||||
// checklist
|
// checklist
|
||||||
else if(col===this.fltTypeCheckList){
|
else if(col===this.fltTypeCheckList){
|
||||||
|
var CheckList = require('modules/checkList').CheckList;
|
||||||
|
this.Cpt.checkList = new CheckList(this);
|
||||||
|
|
||||||
var divCont = dom.create('div',
|
var divCont = dom.create('div',
|
||||||
['id',this.prfxCheckListDiv+i+'_'+this.id],
|
['id',this.prfxCheckListDiv+i+'_'+this.id],
|
||||||
['ct',i],['filled','0']);
|
['ct',i],['filled','0']);
|
||||||
divCont.className = this.checkListDivCssClass;
|
divCont.className =
|
||||||
|
this.Cpt.checkList.checkListDivCssClass;
|
||||||
|
|
||||||
//filter is appended in desired element
|
//filter is appended in desired element
|
||||||
if(externalFltTgtId){
|
if(externalFltTgtId){
|
||||||
|
@ -1082,19 +1058,25 @@ TableFilter.prototype = {
|
||||||
fltcell.appendChild(divCont);
|
fltcell.appendChild(divCont);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.checkListDiv[i] = divCont;
|
// this.checkListDiv[i] = divCont;
|
||||||
|
this.Cpt.checkList.checkListDiv[i] = divCont;
|
||||||
this.fltIds.push(this.prfxFlt+i+'_'+this.id);
|
this.fltIds.push(this.prfxFlt+i+'_'+this.id);
|
||||||
if(!this.fillSlcOnDemand){
|
if(!this.fillSlcOnDemand){
|
||||||
this._PopulateCheckList(i);
|
// this._PopulateCheckList(i);
|
||||||
|
this.Cpt.checkList._build(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
divCont.onclick = this.Evt._OnCheckListFocus;
|
|
||||||
|
|
||||||
if(this.fillSlcOnDemand){
|
if(this.fillSlcOnDemand){
|
||||||
divCont.onclick = this.Evt._OnCheckListClick;
|
//divCont.onclick = this.Evt._OnCheckListClick;
|
||||||
|
evt.add(
|
||||||
|
divCont, 'click', this.Evt._OnCheckListClick);
|
||||||
divCont.appendChild(
|
divCont.appendChild(
|
||||||
dom.text(this.activateCheckListTxt));
|
dom.text(
|
||||||
|
this.Cpt.checkList.activateCheckListTxt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//divCont.onclick = this.Evt._OnCheckListFocus;
|
||||||
|
evt.add(divCont, 'click', this.Evt._OnCheckListFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
|
@ -1262,11 +1244,10 @@ TableFilter.prototype = {
|
||||||
o._PopulateSelect(slcIndex, false, slcExternal, slcId);
|
o._PopulateSelect(slcIndex, false, slcExternal, slcId);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.populatechecklist:
|
case o.Evt.name.checklist:
|
||||||
o._PopulateCheckList(slcIndex, slcExternal, slcId);
|
o.Cpt.checkList._build(slcIndex, slcExternal, slcId);
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.changepage:
|
case o.Evt.name.changepage:
|
||||||
// o._ChangePage(pgIndex);
|
|
||||||
o.Cpt.paging._changePage(pgIndex);
|
o.Cpt.paging._changePage(pgIndex);
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.clear:
|
case o.Evt.name.clear:
|
||||||
|
@ -1274,7 +1255,6 @@ TableFilter.prototype = {
|
||||||
o._Filter();
|
o._Filter();
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.changeresultsperpage:
|
case o.Evt.name.changeresultsperpage:
|
||||||
// o._ChangeResultsPerPage();
|
|
||||||
o.Cpt.paging._changeResultsPerPage();
|
o.Cpt.paging._changeResultsPerPage();
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.resetvalues:
|
case o.Evt.name.resetvalues:
|
||||||
|
@ -1282,11 +1262,9 @@ TableFilter.prototype = {
|
||||||
o._Filter();
|
o._Filter();
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.resetpage:
|
case o.Evt.name.resetpage:
|
||||||
// o._ResetPage(o.pgNbCookie);
|
|
||||||
o.Cpt.paging._resetPage(o.pgNbCookie);
|
o.Cpt.paging._resetPage(o.pgNbCookie);
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.resetpagelength:
|
case o.Evt.name.resetpagelength:
|
||||||
// o._ResetPageLength(o.pgLenCookie);
|
|
||||||
o.Cpt.paging._resetPageLength(o.pgLenCookie);
|
o.Cpt.paging._resetPageLength(o.pgLenCookie);
|
||||||
break;
|
break;
|
||||||
case o.Evt.name.sort:
|
case o.Evt.name.sort:
|
||||||
|
@ -2283,9 +2261,9 @@ TableFilter.prototype = {
|
||||||
|
|
||||||
if(this.sortSlc && !isCustomSlc){
|
if(this.sortSlc && !isCustomSlc){
|
||||||
if (!matchCase){
|
if (!matchCase){
|
||||||
optArray.sort(ignoreCaseSort);
|
optArray.sort(Sort.ignoreCase);
|
||||||
if(excludedOpts){
|
if(excludedOpts){
|
||||||
excludedOpts.sort(ignoreCaseSort);
|
excludedOpts.sort(Sort.ignoreCase);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
optArray.sort();
|
optArray.sort();
|
||||||
|
@ -2494,356 +2472,6 @@ TableFilter.prototype = {
|
||||||
return [optArray,optTxt];
|
return [optArray,optTxt];
|
||||||
},
|
},
|
||||||
|
|
||||||
PopulateCheckList: function(colIndex, isExternal, extFltId){
|
|
||||||
this.EvtManager(
|
|
||||||
this.Evt.name.populatechecklist,
|
|
||||||
{ slcIndex:colIndex, slcExternal:isExternal, slcId:extFltId }
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
/*====================================================
|
|
||||||
- populates checklist filters
|
|
||||||
=====================================================*/
|
|
||||||
_PopulateCheckList: function(colIndex, isExternal, extFltId){
|
|
||||||
isExternal = !isExternal ? false : isExternal;
|
|
||||||
var divFltId = this.prfxCheckListDiv+colIndex+'_'+this.id;
|
|
||||||
if(!dom.id(divFltId) && !isExternal){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!dom.id(extFltId) && isExternal){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var flt = !isExternal ? this.checkListDiv[colIndex] : dom.id(extFltId);
|
|
||||||
var ul = dom.create('ul',
|
|
||||||
['id',this.fltIds[colIndex]], ['colIndex',colIndex]);
|
|
||||||
ul.className = this.checkListCssClass;
|
|
||||||
ul.onchange = this.Evt._OnCheckListChange;
|
|
||||||
var o = this, row = this.tbl.rows;
|
|
||||||
var optArray = [];
|
|
||||||
//custom select test
|
|
||||||
var isCustomSlc = (this.hasCustomSlcOptions &&
|
|
||||||
array.has(this.customSlcOptions.cols, colIndex));
|
|
||||||
//custom selects text
|
|
||||||
var optTxt = [],
|
|
||||||
activeFlt;
|
|
||||||
if(this.refreshFilters && this.activeFilterId){
|
|
||||||
activeFlt = this.activeFilterId.split('_')[0];
|
|
||||||
activeFlt = activeFlt.split(this.prfxFlt)[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
var excludedOpts,
|
|
||||||
filteredDataCol = [];
|
|
||||||
if(this.refreshFilters && this.disableExcludedOptions){
|
|
||||||
excludedOpts = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var k=this.refRow; k<this.nbRows; k++){
|
|
||||||
// always visible rows don't need to appear on selects as always
|
|
||||||
// valid
|
|
||||||
if(this.hasVisibleRows && array.has(this.visibleRows, k) &&
|
|
||||||
!this.paging){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var cells = row[k].cells;
|
|
||||||
var ncells = cells.length;
|
|
||||||
|
|
||||||
// checks if row has exact cell #
|
|
||||||
if(ncells == this.nbCells && !isCustomSlc){
|
|
||||||
// this loop retrieves cell data
|
|
||||||
for(var j=0; j<ncells; j++){
|
|
||||||
if((colIndex===j && (!this.refreshFilters ||
|
|
||||||
(this.refreshFilters && this.disableExcludedOptions)))||
|
|
||||||
(colIndex===j && this.refreshFilters &&
|
|
||||||
((row[k].style.display === '' && !this.paging) ||
|
|
||||||
(this.paging && ((!activeFlt || activeFlt===colIndex )||
|
|
||||||
(activeFlt!=colIndex &&
|
|
||||||
array.has(this.validRowsIndex, k))) )))){
|
|
||||||
var cell_data = this.GetCellData(j, cells[j]);
|
|
||||||
//Vary Peter's patch
|
|
||||||
var cell_string =
|
|
||||||
str.matchCase(cell_data, this.matchCase);
|
|
||||||
// checks if celldata is already in array
|
|
||||||
if(!array.has(optArray, cell_string, this.matchCase)){
|
|
||||||
optArray.push(cell_data);
|
|
||||||
}
|
|
||||||
var filteredCol = filteredDataCol[j];
|
|
||||||
if(this.refreshFilters && this.disableExcludedOptions){
|
|
||||||
if(!filteredCol){
|
|
||||||
filteredDataCol[j] = this.GetFilteredDataCol(j);
|
|
||||||
}
|
|
||||||
if(!array.has(filteredCol,
|
|
||||||
cell_string,this.matchCase) &&
|
|
||||||
!array.has(excludedOpts,
|
|
||||||
cell_string,this.matchCase) &&
|
|
||||||
!this.isFirstLoad){
|
|
||||||
excludedOpts.push(cell_data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Retrieves custom values
|
|
||||||
if(isCustomSlc){
|
|
||||||
var customValues = this.__getCustomValues(colIndex);
|
|
||||||
optArray = customValues[0];
|
|
||||||
optTxt = customValues[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.sortSlc && !isCustomSlc){
|
|
||||||
if (!this.matchCase){
|
|
||||||
optArray.sort(ignoreCaseSort);
|
|
||||||
if(excludedOpts){
|
|
||||||
excludedOpts.sort(ignoreCaseSort);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
optArray.sort();
|
|
||||||
if(excludedOpts){ excludedOpts.sort(); }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//asc sort
|
|
||||||
if(this.sortNumAsc && array.has(this.sortNumAsc, colIndex)){
|
|
||||||
try{
|
|
||||||
optArray.sort( numSortAsc );
|
|
||||||
if(excludedOpts){
|
|
||||||
excludedOpts.sort( numSortAsc );
|
|
||||||
}
|
|
||||||
if(isCustomSlc){
|
|
||||||
optTxt.sort( numSortAsc );
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
optArray.sort(); if(excludedOpts){ excludedOpts.sort(); }
|
|
||||||
if(isCustomSlc){
|
|
||||||
optTxt.sort();
|
|
||||||
}
|
|
||||||
}//in case there are alphanumeric values
|
|
||||||
}
|
|
||||||
//desc sort
|
|
||||||
if(this.sortNumDesc && array.has(this.sortNumDesc, colIndex)){
|
|
||||||
try{
|
|
||||||
optArray.sort( numSortDesc );
|
|
||||||
if(excludedOpts){
|
|
||||||
excludedOpts.sort( numSortDesc );
|
|
||||||
}
|
|
||||||
if(isCustomSlc){
|
|
||||||
optTxt.sort( numSortDesc );
|
|
||||||
}
|
|
||||||
} catch(e) {
|
|
||||||
optArray.sort(); if(excludedOpts){ excludedOpts.sort(); }
|
|
||||||
if(isCustomSlc){
|
|
||||||
optTxt.sort();
|
|
||||||
}
|
|
||||||
}//in case there are alphanumeric values
|
|
||||||
}
|
|
||||||
|
|
||||||
AddChecks(this.separator);
|
|
||||||
|
|
||||||
// adds 1st option
|
|
||||||
function AddTChecks(){
|
|
||||||
var chkCt = 1;
|
|
||||||
var li0 = dom.createCheckItem(
|
|
||||||
o.fltIds[colIndex]+'_0', '', o.displayAllText);
|
|
||||||
li0.className = o.checkListItemCssClass;
|
|
||||||
ul.appendChild(li0);
|
|
||||||
li0.check.onclick = function(e){
|
|
||||||
o.__setCheckListValues(this);
|
|
||||||
ul.onchange.call(null, e);
|
|
||||||
};
|
|
||||||
if(!o.enableCheckListResetFilter){
|
|
||||||
li0.style.display = 'none';
|
|
||||||
}
|
|
||||||
//IE: label looses check capability
|
|
||||||
// if(hlp.isIE()){
|
|
||||||
// li0.label.onclick = function(){ li0.check.click(); };
|
|
||||||
// }
|
|
||||||
|
|
||||||
if(o.enableEmptyOption){
|
|
||||||
var li1 = dom.createCheckItem(
|
|
||||||
o.fltIds[colIndex]+'_1', o.emOperator, o.emptyText);
|
|
||||||
li1.className = o.checkListItemCssClass;
|
|
||||||
ul.appendChild(li1);
|
|
||||||
li1.check.onclick = function(e){
|
|
||||||
o.__setCheckListValues(this);
|
|
||||||
ul.onchange.call(null, e);
|
|
||||||
};
|
|
||||||
//IE: label looses check capability
|
|
||||||
// if(hlp.isIE()){
|
|
||||||
// li1.label.onclick = function(){ li1.check.click(); };
|
|
||||||
// }
|
|
||||||
chkCt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(o.enableNonEmptyOption){
|
|
||||||
var li2 = dom.createCheckItem(
|
|
||||||
o.fltIds[colIndex]+'_2',
|
|
||||||
o.nmOperator,
|
|
||||||
o.nonEmptyText
|
|
||||||
);
|
|
||||||
li2.className = o.checkListItemCssClass;
|
|
||||||
ul.appendChild(li2);
|
|
||||||
li2.check.onclick = function(e){
|
|
||||||
o.__setCheckListValues(this);
|
|
||||||
ul.onchange.call(null, e);
|
|
||||||
};
|
|
||||||
//IE: label looses check capability
|
|
||||||
// if(hlp.isIE())
|
|
||||||
// {
|
|
||||||
// li2.label.onclick = function(){ li2.check.click(); };
|
|
||||||
// }
|
|
||||||
chkCt++;
|
|
||||||
}
|
|
||||||
return chkCt;
|
|
||||||
}
|
|
||||||
|
|
||||||
function AddChecks(separator){
|
|
||||||
var chkCt = AddTChecks();
|
|
||||||
|
|
||||||
var flts_values = [], fltArr = []; //remember grid values
|
|
||||||
var tmpVal = cookie.getValueByIndex(
|
|
||||||
o.fltsValuesCookie, colIndex, separator);
|
|
||||||
if(tmpVal && str.trim(tmpVal).length > 0){
|
|
||||||
if(o.hasCustomSlcOptions &&
|
|
||||||
array.has(o.customSlcOptions.cols, colIndex)){
|
|
||||||
fltArr.push(tmpVal);
|
|
||||||
} else {
|
|
||||||
fltArr = tmpVal.split(' '+o.orOperator+' ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function optionClick(evt){
|
|
||||||
o.__setCheckListValues(this);
|
|
||||||
ul.onchange.call(null, evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(var y=0; y<optArray.length; y++){
|
|
||||||
var val = optArray[y]; //item value
|
|
||||||
var lbl = isCustomSlc ? optTxt[y] : val; //item text
|
|
||||||
var li = dom.createCheckItem(
|
|
||||||
o.fltIds[colIndex]+'_'+(y+chkCt), val, lbl);
|
|
||||||
li.className = o.checkListItemCssClass;
|
|
||||||
if(o.refreshFilters && o.disableExcludedOptions &&
|
|
||||||
array.has(excludedOpts,
|
|
||||||
str.matchCase(val, o.matchCase), o.matchCase)){
|
|
||||||
dom.addClass(li, o.checkListItemDisabledCssClass);
|
|
||||||
li.check.disabled = true;
|
|
||||||
li.disabled = true;
|
|
||||||
} else{
|
|
||||||
li.check.onclick = optionClick;
|
|
||||||
}
|
|
||||||
ul.appendChild(li);
|
|
||||||
|
|
||||||
if(val===''){
|
|
||||||
//item is hidden
|
|
||||||
li.style.display = 'none';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*** remember grid values ***/
|
|
||||||
if(o.rememberGridValues){
|
|
||||||
if((o.hasCustomSlcOptions &&
|
|
||||||
array.has(o.customSlcOptions.cols, colIndex) &&
|
|
||||||
fltArr.toString().indexOf(val)!= -1) ||
|
|
||||||
array.has(fltArr,
|
|
||||||
str.matchCase(val, o.matchCase), o.matchCase)){
|
|
||||||
li.check.checked = true;
|
|
||||||
o.__setCheckListValues(li.check);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function labelClick(){
|
|
||||||
this.firstChild.click();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(this.fillSlcOnDemand){
|
|
||||||
flt.innerHTML = '';
|
|
||||||
}
|
|
||||||
flt.appendChild(ul);
|
|
||||||
flt.setAttribute('filled','1');
|
|
||||||
},
|
|
||||||
|
|
||||||
/*====================================================
|
|
||||||
- Sets checked items information of a checklist
|
|
||||||
=====================================================*/
|
|
||||||
__setCheckListValues: function(o){
|
|
||||||
if(!o){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var chkValue = o.value; //checked item value
|
|
||||||
var chkIndex = parseInt(o.id.split('_')[2], 10);
|
|
||||||
var filterTag = 'ul', itemTag = 'li';
|
|
||||||
var n = o;
|
|
||||||
|
|
||||||
//ul tag search
|
|
||||||
while(str.lower(n.nodeName)!==filterTag){
|
|
||||||
n = n.parentNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
var li = n.childNodes[chkIndex];
|
|
||||||
var colIndex = n.getAttribute('colIndex');
|
|
||||||
var fltValue = n.getAttribute('value'); //filter value (ul tag)
|
|
||||||
var fltIndexes = n.getAttribute('indexes'); //selected items (ul tag)
|
|
||||||
|
|
||||||
if(o.checked){
|
|
||||||
//show all item
|
|
||||||
if(chkValue===''){
|
|
||||||
if((fltIndexes && fltIndexes!=='')){
|
|
||||||
//items indexes
|
|
||||||
var indSplit = fltIndexes.split(this.separator);
|
|
||||||
//checked items loop
|
|
||||||
for(var u=0; u<indSplit.length; u++){
|
|
||||||
//checked item
|
|
||||||
var cChk = dom.id(
|
|
||||||
this.fltIds[colIndex]+'_'+indSplit[u]);
|
|
||||||
if(cChk){
|
|
||||||
cChk.checked = false;
|
|
||||||
dom.removeClass(
|
|
||||||
n.childNodes[indSplit[u]],
|
|
||||||
this.checkListSlcItemCssClass
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
n.setAttribute('value', '');
|
|
||||||
n.setAttribute('indexes', '');
|
|
||||||
|
|
||||||
} else {
|
|
||||||
fltValue = (fltValue) ? fltValue : '';
|
|
||||||
chkValue = str.trim(
|
|
||||||
fltValue+' '+chkValue+' '+this.orOperator);
|
|
||||||
chkIndex = fltIndexes + chkIndex + this.separator;
|
|
||||||
n.setAttribute('value', chkValue );
|
|
||||||
n.setAttribute('indexes', chkIndex);
|
|
||||||
//1st option unchecked
|
|
||||||
if(dom.id(this.fltIds[colIndex]+'_0')){
|
|
||||||
dom.id(this.fltIds[colIndex]+'_0').checked = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(str.lower(li.nodeName) === itemTag){
|
|
||||||
dom.removeClass(
|
|
||||||
n.childNodes[0],this.checkListSlcItemCssClass);
|
|
||||||
dom.addClass(li,this.checkListSlcItemCssClass);
|
|
||||||
}
|
|
||||||
} else { //removes values and indexes
|
|
||||||
if(chkValue!==''){
|
|
||||||
var replaceValue = new RegExp(
|
|
||||||
str.rgxEsc(chkValue+' '+this.orOperator));
|
|
||||||
fltValue = fltValue.replace(replaceValue,'');
|
|
||||||
n.setAttribute('value', str.trim(fltValue));
|
|
||||||
|
|
||||||
var replaceIndex = new RegExp(
|
|
||||||
str.rgxEsc(chkIndex + this.separator));
|
|
||||||
fltIndexes = fltIndexes.replace(replaceIndex,'');
|
|
||||||
n.setAttribute('indexes', fltIndexes);
|
|
||||||
}
|
|
||||||
if(str.lower(li.nodeName)===itemTag){
|
|
||||||
dom.removeClass(li,this.checkListSlcItemCssClass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/*====================================================
|
/*====================================================
|
||||||
- Generates reset button
|
- Generates reset button
|
||||||
=====================================================*/
|
=====================================================*/
|
||||||
|
@ -3281,14 +2909,14 @@ TableFilter.prototype = {
|
||||||
if(!this.fillSlcOnDemand){
|
if(!this.fillSlcOnDemand){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var flts_values = this.Cpt.store.getFilterValues(name),
|
var fltsValues = this.Cpt.store.getFilterValues(name),
|
||||||
slcFltsIndex = this.GetFiltersByType(this.fltTypeSlc, true),
|
slcFltsIndex = this.GetFiltersByType(this.fltTypeSlc, true),
|
||||||
multiFltsIndex = this.GetFiltersByType(this.fltTypeMulti, true);
|
multiFltsIndex = this.GetFiltersByType(this.fltTypeMulti, true);
|
||||||
|
|
||||||
//if the number of columns is the same as before page reload
|
//if the number of columns is the same as before page reload
|
||||||
if(flts_values[(flts_values.length-1)] === this.fltIds.length){
|
if(Number(fltsValues[(fltsValues.length-1)]) === this.fltIds.length){
|
||||||
for(var i=0; i<(flts_values.length - 1); i++){
|
for(var i=0; i<(fltsValues.length - 1); i++){
|
||||||
if(flts_values[i]===' '){
|
if(fltsValues[i]===' '){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var s, opt;
|
var s, opt;
|
||||||
|
@ -3301,13 +2929,13 @@ TableFilter.prototype = {
|
||||||
|
|
||||||
//selects
|
//selects
|
||||||
if(array.has(slcFltsIndex, i)){
|
if(array.has(slcFltsIndex, i)){
|
||||||
opt = dom.createOpt(flts_values[i],flts_values[i],true);
|
opt = dom.createOpt(fltsValues[i],fltsValues[i],true);
|
||||||
slc.appendChild(opt);
|
slc.appendChild(opt);
|
||||||
this.hasStoredValues = true;
|
this.hasStoredValues = true;
|
||||||
}
|
}
|
||||||
//multiple select
|
//multiple select
|
||||||
if(array.has(multiFltsIndex, i)){
|
if(array.has(multiFltsIndex, i)){
|
||||||
s = flts_values[i].split(' '+this.orOperator+' ');
|
s = fltsValues[i].split(' '+this.orOperator+' ');
|
||||||
for(j=0; j<s.length; j++){
|
for(j=0; j<s.length; j++){
|
||||||
if(s[j]===''){
|
if(s[j]===''){
|
||||||
continue;
|
continue;
|
||||||
|
@ -3325,39 +2953,39 @@ TableFilter.prototype = {
|
||||||
}// if multiFltsIndex
|
}// if multiFltsIndex
|
||||||
}
|
}
|
||||||
else if(this['col'+i]==this.fltTypeCheckList){
|
else if(this['col'+i]==this.fltTypeCheckList){
|
||||||
var divChk = this.checkListDiv[i];
|
var checkList = this.Cpt.checkList;
|
||||||
|
var divChk = checkList.checkListDiv[i];
|
||||||
divChk.title = divChk.innerHTML;
|
divChk.title = divChk.innerHTML;
|
||||||
divChk.innerHTML = '';
|
divChk.innerHTML = '';
|
||||||
|
|
||||||
var ul = dom.create(
|
var ul = dom.create(
|
||||||
'ul',['id',this.fltIds[i]],['colIndex',i]);
|
'ul',['id',this.fltIds[i]],['colIndex',i]);
|
||||||
ul.className = this.checkListCssClass;
|
ul.className = checkList.checkListCssClass;
|
||||||
|
|
||||||
var li0 = dom.createCheckItem(
|
var li0 = dom.createCheckItem(
|
||||||
this.fltIds[i]+'_0', '', this.displayAllText);
|
this.fltIds[i]+'_0', '', this.displayAllText);
|
||||||
li0.className = this.checkListItemCssClass;
|
li0.className = checkList.checkListItemCssClass;
|
||||||
ul.appendChild(li0);
|
ul.appendChild(li0);
|
||||||
|
|
||||||
divChk.appendChild(ul);
|
divChk.appendChild(ul);
|
||||||
|
|
||||||
flts_values[i].split(' '+this.orOperator+' ');
|
s = fltsValues[i].split(' '+this.orOperator+' ');
|
||||||
for(j=0; j<s.length; j++){
|
for(j=0; j<s.length; j++){
|
||||||
if(s[j]===''){
|
if(s[j]===''){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var li = dom.createCheckItem(
|
var li = dom.createCheckItem(
|
||||||
this.fltIds[i]+'_'+(j+1), s[j], s[j]);
|
this.fltIds[i]+'_'+(j+1), s[j], s[j]);
|
||||||
li.className = this.checkListItemCssClass;
|
li.className = checkList.checkListItemCssClass;
|
||||||
ul.appendChild(li);
|
ul.appendChild(li);
|
||||||
li.check.checked = true;
|
li.check.checked = true;
|
||||||
this.__setCheckListValues(li.check);
|
checkList.setCheckListValues(li.check);
|
||||||
this.hasStoredValues = true;
|
this.hasStoredValues = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}//end for
|
}//end for
|
||||||
|
|
||||||
if(!this.hasStoredValues && this.paging){
|
if(!this.hasStoredValues && this.paging){
|
||||||
// this.SetPagingInfo();
|
|
||||||
this.Cpt.paging.setPagingInfo();
|
this.Cpt.paging.setPagingInfo();
|
||||||
}
|
}
|
||||||
}//end if
|
}//end if
|
||||||
|
@ -3395,7 +3023,6 @@ TableFilter.prototype = {
|
||||||
|
|
||||||
// removes keyword highlighting
|
// removes keyword highlighting
|
||||||
if(this.highlightKeywords){
|
if(this.highlightKeywords){
|
||||||
// this.UnhighlightAll();
|
|
||||||
this.Cpt.highlightKeyword.unhighlightAll();
|
this.Cpt.highlightKeyword.unhighlightAll();
|
||||||
}
|
}
|
||||||
//removes popup filters active icons
|
//removes popup filters active icons
|
||||||
|
@ -4191,11 +3818,11 @@ TableFilter.prototype = {
|
||||||
dom.getText(lbl), this.matchCase);
|
dom.getText(lbl), this.matchCase);
|
||||||
if(lblTxt!=='' && array.has(sarg, lblTxt, true)){
|
if(lblTxt!=='' && array.has(sarg, lblTxt, true)){
|
||||||
chk.checked = true;
|
chk.checked = true;
|
||||||
this.__setCheckListValues(chk);
|
this.Cpt.checkList.setCheckListValues(chk);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
chk.checked = false;
|
chk.checked = false;
|
||||||
this.__setCheckListValues(chk);
|
this.Cpt.checkList.setCheckListValues(chk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4291,10 +3918,10 @@ TableFilter.prototype = {
|
||||||
}
|
}
|
||||||
this.nbRows = this.GetRowsNb(); //in case table is refreshed
|
this.nbRows = this.GetRowsNb(); //in case table is refreshed
|
||||||
this.RemoveGrid();
|
this.RemoveGrid();
|
||||||
window['tf_'+this.id] = new TF(this.id, this.startRow, configObj);
|
window['tf_'+this.id] = new TableFilter(this.id, this.startRow, configObj);
|
||||||
this.isFirstLoad = true;
|
this.isFirstLoad = true;
|
||||||
this.fltIds = [];
|
this.fltIds = [];
|
||||||
this._AddGrid();
|
this.init();
|
||||||
//New tbody content needs to be referenced in sortabletable script with
|
//New tbody content needs to be referenced in sortabletable script with
|
||||||
//setTBody() method
|
//setTBody() method
|
||||||
if(hasSort){
|
if(hasSort){
|
||||||
|
@ -4333,7 +3960,9 @@ TableFilter.prototype = {
|
||||||
slcSelectedValue === this.displayAllText ){
|
slcSelectedValue === this.displayAllText ){
|
||||||
|
|
||||||
if(array.has(slcA3, slcIndex[i])){
|
if(array.has(slcA3, slcIndex[i])){
|
||||||
this.checkListDiv[slcIndex[i]].innerHTML = '';
|
// this.checkListDiv[slcIndex[i]].innerHTML = '';
|
||||||
|
this.Cpt.checkList.checkListDiv[
|
||||||
|
slcIndex[i]].innerHTML = '';
|
||||||
} else {
|
} else {
|
||||||
curSlc.innerHTML = '';
|
curSlc.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
@ -4347,9 +3976,10 @@ TableFilter.prototype = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(array.has(slcA3, slcIndex[i])){
|
if(array.has(slcA3, slcIndex[i])){
|
||||||
this._PopulateCheckList(slcIndex[i]);
|
// this._PopulateCheckList(slcIndex[i]);
|
||||||
|
this.Cpt.checkList._build(slcIndex[i]);
|
||||||
} else {
|
} else {
|
||||||
this._PopulateSelect(slcIndex[i],true);
|
this._PopulateSelect(slcIndex[i], true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.SetFilterValue(slcIndex[i],slcSelectedValue);
|
this.SetFilterValue(slcIndex[i],slcSelectedValue);
|
||||||
|
@ -4396,7 +4026,8 @@ TableFilter.prototype = {
|
||||||
this.PopulateSelect(ct);
|
this.PopulateSelect(ct);
|
||||||
}
|
}
|
||||||
if(colFltType === this.fltTypeCheckList){
|
if(colFltType === this.fltTypeCheckList){
|
||||||
this.PopulateCheckList(ct);
|
// this.PopulateCheckList(ct);
|
||||||
|
this.Cpt.checkList.build(ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4640,11 +4271,11 @@ function numSortAsc(a, b){ return (a-b); }
|
||||||
|
|
||||||
function numSortDesc(a, b){ return (b-a); }
|
function numSortDesc(a, b){ return (b-a); }
|
||||||
|
|
||||||
function ignoreCaseSort(a, b){
|
// function ignoreCaseSort(a, b){
|
||||||
var x = str.lower(a);
|
// var x = str.lower(a);
|
||||||
var y = str.lower(b);
|
// var y = str.lower(b);
|
||||||
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
// return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
||||||
}
|
// }
|
||||||
|
|
||||||
function removeNbFormat(data, format){
|
function removeNbFormat(data, format){
|
||||||
if(!data){
|
if(!data){
|
||||||
|
|
|
@ -96,9 +96,10 @@
|
||||||
paging_length: 2,
|
paging_length: 2,
|
||||||
// page_selector_type: 'input',
|
// page_selector_type: 'input',
|
||||||
results_per_page: ['Results per page', [2,4,6]],
|
results_per_page: ['Results per page', [2,4,6]],
|
||||||
// remember_grid_values: true,
|
remember_grid_values: true,
|
||||||
// remember_page_number: true,
|
// remember_page_number: true,
|
||||||
// remember_page_length: true,
|
// remember_page_length: true,
|
||||||
|
fill_slc_on_demand: true,
|
||||||
alternate_rows: true,
|
alternate_rows: true,
|
||||||
highlight_keywords: true,
|
highlight_keywords: true,
|
||||||
match_case: false,
|
match_case: false,
|
||||||
|
|
369
src/modules/checkList.js
Normal file
369
src/modules/checkList.js
Normal file
|
@ -0,0 +1,369 @@
|
||||||
|
define(["exports", "../dom", "../array", "../string", "../sort", "../event"], function (exports, _dom, _array, _string, _sort, _event) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var _classProps = function (child, staticProps, instanceProps) {
|
||||||
|
if (staticProps) Object.defineProperties(child, staticProps);
|
||||||
|
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
|
||||||
|
};
|
||||||
|
|
||||||
|
var Dom = _dom.Dom;
|
||||||
|
var array = _array.Arr;
|
||||||
|
var Str = _string.Str;
|
||||||
|
var Sort = _sort.Sort;
|
||||||
|
var Event = _event.Event;
|
||||||
|
var CheckList = (function () {
|
||||||
|
var CheckList = function CheckList(tf) {
|
||||||
|
// Configuration object
|
||||||
|
var f = tf.fObj;
|
||||||
|
|
||||||
|
this.checkListDiv = []; //checklist container div
|
||||||
|
//defines css class for div containing checklist filter
|
||||||
|
this.checkListDivCssClass = f.div_checklist_css_class || "div_checklist";
|
||||||
|
//defines css class for checklist filters
|
||||||
|
this.checkListCssClass = f.checklist_css_class || "flt_checklist";
|
||||||
|
//defines css class for checklist item (li)
|
||||||
|
this.checkListItemCssClass = f.checklist_item_css_class || "flt_checklist_item";
|
||||||
|
//defines css class for selected checklist item (li)
|
||||||
|
this.checkListSlcItemCssClass = f.checklist_selected_item_css_class || "flt_checklist_slc_item";
|
||||||
|
//Load on demand text
|
||||||
|
this.activateCheckListTxt = f.activate_checklist_text || "Click to load filter data";
|
||||||
|
//defines css class for checklist filters
|
||||||
|
this.checkListItemDisabledCssClass = f.checklist_item_disabled_css_class || "flt_checklist_item_disabled";
|
||||||
|
this.enableCheckListResetFilter = f.enable_checklist_reset_filter === false ? false : true;
|
||||||
|
|
||||||
|
this.isCustom = null;
|
||||||
|
this.opts = [];
|
||||||
|
this.optsTxt = [];
|
||||||
|
|
||||||
|
this.tf = tf;
|
||||||
|
};
|
||||||
|
|
||||||
|
_classProps(CheckList, null, {
|
||||||
|
onChange: {
|
||||||
|
writable: true,
|
||||||
|
value: function (evt) {
|
||||||
|
this.tf.Evt._OnSlcChange(evt);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
optionClick: {
|
||||||
|
writable: true,
|
||||||
|
value: function (evt) {
|
||||||
|
this.setCheckListValues(evt.target);
|
||||||
|
this.onChange(evt);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
build: {
|
||||||
|
writable: true,
|
||||||
|
value: function (colIndex, isExternal, extFltId) {
|
||||||
|
var tf = this.tf;
|
||||||
|
tf.EvtManager(tf.Evt.name.checklist, { slcIndex: colIndex, slcExternal: isExternal, slcId: extFltId });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_build: {
|
||||||
|
writable: true,
|
||||||
|
value: function (colIndex, isExternal, extFltId) {
|
||||||
|
var _this = this;
|
||||||
|
if (extFltId === undefined) extFltId = null;
|
||||||
|
if (isExternal === undefined) isExternal = false;
|
||||||
|
var tf = this.tf;
|
||||||
|
colIndex = parseInt(colIndex, 10);
|
||||||
|
|
||||||
|
var divFltId = tf.prfxCheckListDiv + colIndex + "_" + tf.id;
|
||||||
|
if ((!Dom.id(divFltId) && !isExternal) || (!Dom.id(extFltId) && isExternal)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var flt = !isExternal ? this.checkListDiv[colIndex] : Dom.id(extFltId);
|
||||||
|
var ul = Dom.create("ul", ["id", tf.fltIds[colIndex]], ["colIndex", colIndex]);
|
||||||
|
ul.className = this.checkListCssClass;
|
||||||
|
Event.add(ul, "change", function (evt) {
|
||||||
|
_this.onChange(evt);
|
||||||
|
});
|
||||||
|
|
||||||
|
var rows = tf.tbl.rows;
|
||||||
|
this.isCustom = (tf.hasCustomSlcOptions && array.has(tf.customSlcOptions.cols, colIndex));
|
||||||
|
|
||||||
|
var activeFlt;
|
||||||
|
if (tf.refreshFilters && tf.activeFilterId) {
|
||||||
|
activeFlt = tf.activeFilterId.split("_")[0];
|
||||||
|
activeFlt = activeFlt.split(tf.prfxFlt)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
var excludedOpts, filteredDataCol = [];
|
||||||
|
if (tf.refreshFilters && tf.disableExcludedOptions) {
|
||||||
|
excludedOpts = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var k = tf.refRow; k < tf.nbRows; k++) {
|
||||||
|
// always visible rows don't need to appear on selects as always
|
||||||
|
// valid
|
||||||
|
if (tf.hasVisibleRows && array.has(tf.visibleRows, k) && !tf.paging) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var cells = rows[k].cells;
|
||||||
|
var ncells = cells.length;
|
||||||
|
|
||||||
|
// checks if row has exact cell #
|
||||||
|
if (ncells === tf.nbCells && !this.isCustom) {
|
||||||
|
// this loop retrieves cell data
|
||||||
|
for (var j = 0; j < ncells; j++) {
|
||||||
|
if ((colIndex === j && (!tf.refreshFilters || (tf.refreshFilters && tf.disableExcludedOptions))) || (colIndex === j && tf.refreshFilters && ((rows[k].style.display === "" && !tf.paging) || (tf.paging && ((!activeFlt || activeFlt === colIndex) || (activeFlt != colIndex && array.has(tf.validRowsIndex, k))))))) {
|
||||||
|
var cell_data = tf.GetCellData(j, cells[j]);
|
||||||
|
//Vary Peter's patch
|
||||||
|
var cell_string = Str.matchCase(cell_data, tf.matchCase);
|
||||||
|
// checks if celldata is already in array
|
||||||
|
if (!array.has(this.opts, cell_string, tf.matchCase)) {
|
||||||
|
this.opts.push(cell_data);
|
||||||
|
}
|
||||||
|
var filteredCol = filteredDataCol[j];
|
||||||
|
if (tf.refreshFilters && tf.disableExcludedOptions) {
|
||||||
|
if (!filteredCol) {
|
||||||
|
filteredDataCol[j] = tf.GetFilteredDataCol(j);
|
||||||
|
}
|
||||||
|
if (!array.has(filteredCol, cell_string, tf.matchCase) && !array.has(excludedOpts, cell_string, tf.matchCase) && !tf.isFirstLoad) {
|
||||||
|
excludedOpts.push(cell_data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Retrieves custom values
|
||||||
|
if (this.isCustom) {
|
||||||
|
var customValues = tf.__getCustomValues(colIndex);
|
||||||
|
this.opts = customValues[0];
|
||||||
|
this.optsTxt = customValues[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tf.sortSlc && !this.isCustom) {
|
||||||
|
if (!tf.matchCase) {
|
||||||
|
this.opts.sort(Sort.ignoreCase);
|
||||||
|
if (excludedOpts) {
|
||||||
|
excludedOpts.sort(Sort.ignoreCase);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.opts.sort();
|
||||||
|
if (excludedOpts) {
|
||||||
|
excludedOpts.sort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//asc sort
|
||||||
|
if (tf.sortNumAsc && array.has(tf.sortNumAsc, colIndex)) {
|
||||||
|
try {
|
||||||
|
this.opts.sort(numSortAsc);
|
||||||
|
if (excludedOpts) {
|
||||||
|
excludedOpts.sort(numSortAsc);
|
||||||
|
}
|
||||||
|
if (this.isCustom) {
|
||||||
|
this.optsTxt.sort(numSortAsc);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.opts.sort();
|
||||||
|
if (excludedOpts) {
|
||||||
|
excludedOpts.sort();
|
||||||
|
}
|
||||||
|
if (this.isCustom) {
|
||||||
|
this.optsTxt.sort();
|
||||||
|
}
|
||||||
|
} //in case there are alphanumeric values
|
||||||
|
}
|
||||||
|
//desc sort
|
||||||
|
if (tf.sortNumDesc && array.has(tf.sortNumDesc, colIndex)) {
|
||||||
|
try {
|
||||||
|
this.opts.sort(numSortDesc);
|
||||||
|
if (excludedOpts) {
|
||||||
|
excludedOpts.sort(numSortDesc);
|
||||||
|
}
|
||||||
|
if (this.isCustom) {
|
||||||
|
this.optsTxt.sort(numSortDesc);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
this.opts.sort();
|
||||||
|
if (excludedOpts) {
|
||||||
|
excludedOpts.sort();
|
||||||
|
}
|
||||||
|
if (this.isCustom) {
|
||||||
|
this.optsTxt.sort();
|
||||||
|
}
|
||||||
|
} //in case there are alphanumeric values
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addChecks(colIndex, ul, tf.separator);
|
||||||
|
|
||||||
|
if (tf.fillSlcOnDemand) {
|
||||||
|
flt.innerHTML = "";
|
||||||
|
}
|
||||||
|
flt.appendChild(ul);
|
||||||
|
flt.setAttribute("filled", "1");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addChecks: {
|
||||||
|
writable: true,
|
||||||
|
value: function (colIndex, ul, separator) {
|
||||||
|
var _this2 = this;
|
||||||
|
var tf = this.tf;
|
||||||
|
var chkCt = this.addTChecks(colIndex, ul);
|
||||||
|
var flts_values = [], fltArr = []; //remember grid values
|
||||||
|
var store = tf.Cpt.store;
|
||||||
|
var tmpVal = store ? store.getFilterValues(tf.fltsValuesCookie)[colIndex] : null;
|
||||||
|
if (tmpVal && Str.trim(tmpVal).length > 0) {
|
||||||
|
if (tf.hasCustomSlcOptions && array.has(tf.customSlcOptions.cols, colIndex)) {
|
||||||
|
fltArr.push(tmpVal);
|
||||||
|
} else {
|
||||||
|
fltArr = tmpVal.split(" " + tf.orOperator + " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var y = 0; y < this.opts.length; y++) {
|
||||||
|
var val = this.opts[y]; //item value
|
||||||
|
var lbl = this.isCustom ? this.optsTxt[y] : val; //item text
|
||||||
|
var li = Dom.createCheckItem(tf.fltIds[colIndex] + "_" + (y + chkCt), val, lbl);
|
||||||
|
li.className = this.checkListItemCssClass;
|
||||||
|
if (tf.refreshFilters && tf.disableExcludedOptions && array.has(excludedOpts, Str.matchCase(val, tf.matchCase), tf.matchCase)) {
|
||||||
|
Dom.addClass(li, this.checkListItemDisabledCssClass);
|
||||||
|
li.check.disabled = true;
|
||||||
|
li.disabled = true;
|
||||||
|
} else {
|
||||||
|
Event.add(li.check, "click", function (evt) {
|
||||||
|
_this2.optionClick(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ul.appendChild(li);
|
||||||
|
|
||||||
|
if (val === "") {
|
||||||
|
//item is hidden
|
||||||
|
li.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*** remember grid values ***/
|
||||||
|
if (tf.rememberGridValues) {
|
||||||
|
if ((tf.hasCustomSlcOptions && array.has(tf.customSlcOptions.cols, colIndex) && fltArr.toString().indexOf(val) != -1) || array.has(fltArr, Str.matchCase(val, tf.matchCase), tf.matchCase)) {
|
||||||
|
li.check.checked = true;
|
||||||
|
this.setCheckListValues(li.check);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
addTChecks: {
|
||||||
|
writable: true,
|
||||||
|
value: function (colIndex, ul) {
|
||||||
|
var _this3 = this;
|
||||||
|
var tf = this.tf;
|
||||||
|
var chkCt = 1;
|
||||||
|
var li0 = Dom.createCheckItem(tf.fltIds[colIndex] + "_0", "", tf.displayAllText);
|
||||||
|
li0.className = this.checkListItemCssClass;
|
||||||
|
ul.appendChild(li0);
|
||||||
|
|
||||||
|
Event.add(li0.check, "click", function (evt) {
|
||||||
|
_this3.optionClick(evt);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!this.enableCheckListResetFilter) {
|
||||||
|
li0.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tf.enableEmptyOption) {
|
||||||
|
var li1 = Dom.createCheckItem(tf.fltIds[colIndex] + "_1", tf.emOperator, tf.emptyText);
|
||||||
|
li1.className = this.checkListItemCssClass;
|
||||||
|
ul.appendChild(li1);
|
||||||
|
Event.add(li1.check, "click", function (evt) {
|
||||||
|
_this3.optionClick(evt);
|
||||||
|
});
|
||||||
|
chkCt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tf.enableNonEmptyOption) {
|
||||||
|
var li2 = Dom.createCheckItem(tf.fltIds[colIndex] + "_2", tf.nmOperator, tf.nonEmptyText);
|
||||||
|
li2.className = this.checkListItemCssClass;
|
||||||
|
ul.appendChild(li2);
|
||||||
|
Event.add(li2.check, "click", function (evt) {
|
||||||
|
_this3.optionClick(evt);
|
||||||
|
});
|
||||||
|
chkCt++;
|
||||||
|
}
|
||||||
|
return chkCt;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setCheckListValues: {
|
||||||
|
writable: true,
|
||||||
|
value: function (o) {
|
||||||
|
if (!o) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var tf = this.tf;
|
||||||
|
var chkValue = o.value; //checked item value
|
||||||
|
var chkIndex = parseInt(o.id.split("_")[2], 10);
|
||||||
|
var filterTag = "ul", itemTag = "li";
|
||||||
|
var n = o;
|
||||||
|
|
||||||
|
//ul tag search
|
||||||
|
while (Str.lower(n.nodeName) !== filterTag) {
|
||||||
|
n = n.parentNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
var li = n.childNodes[chkIndex];
|
||||||
|
var colIndex = n.getAttribute("colIndex");
|
||||||
|
var fltValue = n.getAttribute("value"); //filter value (ul tag)
|
||||||
|
var fltIndexes = n.getAttribute("indexes"); //selected items (ul tag)
|
||||||
|
|
||||||
|
if (o.checked) {
|
||||||
|
//show all item
|
||||||
|
if (chkValue === "") {
|
||||||
|
if ((fltIndexes && fltIndexes !== "")) {
|
||||||
|
//items indexes
|
||||||
|
var indSplit = fltIndexes.split(tf.separator);
|
||||||
|
//checked items loop
|
||||||
|
for (var u = 0; u < indSplit.length; u++) {
|
||||||
|
//checked item
|
||||||
|
var cChk = Dom.id(tf.fltIds[colIndex] + "_" + indSplit[u]);
|
||||||
|
if (cChk) {
|
||||||
|
cChk.checked = false;
|
||||||
|
Dom.removeClass(n.childNodes[indSplit[u]], this.checkListSlcItemCssClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
n.setAttribute("value", "");
|
||||||
|
n.setAttribute("indexes", "");
|
||||||
|
} else {
|
||||||
|
fltValue = (fltValue) ? fltValue : "";
|
||||||
|
chkValue = Str.trim(fltValue + " " + chkValue + " " + tf.orOperator);
|
||||||
|
chkIndex = fltIndexes + chkIndex + tf.separator;
|
||||||
|
n.setAttribute("value", chkValue);
|
||||||
|
n.setAttribute("indexes", chkIndex);
|
||||||
|
//1st option unchecked
|
||||||
|
if (Dom.id(tf.fltIds[colIndex] + "_0")) {
|
||||||
|
Dom.id(tf.fltIds[colIndex] + "_0").checked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Str.lower(li.nodeName) === itemTag) {
|
||||||
|
Dom.removeClass(n.childNodes[0], this.checkListSlcItemCssClass);
|
||||||
|
Dom.addClass(li, this.checkListSlcItemCssClass);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//removes values and indexes
|
||||||
|
if (chkValue !== "") {
|
||||||
|
var replaceValue = new RegExp(Str.rgxEsc(chkValue + " " + tf.orOperator));
|
||||||
|
fltValue = fltValue.replace(replaceValue, "");
|
||||||
|
n.setAttribute("value", Str.trim(fltValue));
|
||||||
|
|
||||||
|
var replaceIndex = new RegExp(Str.rgxEsc(chkIndex + tf.separator));
|
||||||
|
fltIndexes = fltIndexes.replace(replaceIndex, "");
|
||||||
|
n.setAttribute("indexes", fltIndexes);
|
||||||
|
}
|
||||||
|
if (Str.lower(li.nodeName) === itemTag) {
|
||||||
|
Dom.removeClass(li, this.checkListSlcItemCssClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return CheckList;
|
||||||
|
})();
|
||||||
|
|
||||||
|
exports.CheckList = CheckList;
|
||||||
|
});
|
1
src/modules/checkList.js.map
Normal file
1
src/modules/checkList.js.map
Normal file
File diff suppressed because one or more lines are too long
|
@ -392,8 +392,7 @@ define(["exports", "../dom", "../types", "../string", "../helpers", "../event"],
|
||||||
btnEvt.next();
|
btnEvt.next();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
} else if (cmdtype === "number") {
|
||||||
if (cmdtype === "number") {
|
|
||||||
this.changePage(cmd - 1);
|
this.changePage(cmd - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
16
src/sort.js
Normal file
16
src/sort.js
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
define(["exports", "string"], function (exports, _string) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var Str = _string.Str;
|
||||||
|
|
||||||
|
|
||||||
|
var Sort = {
|
||||||
|
ignoreCase: function (a, b) {
|
||||||
|
var x = Str.lower(a);
|
||||||
|
var y = Str.lower(b);
|
||||||
|
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.Sort = Sort;
|
||||||
|
});
|
1
src/sort.js.map
Normal file
1
src/sort.js.map
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"version":3,"sources":["src-es6/sort.js"],"names":[],"mappings":";;;MAIQ,GAAG,WAAH,GAAG;;;MAEP,IAAI,GAAG;AACR,cAAU,EAAA,UAAC,CAAC,EAAE,CAAC,EAAC;AACX,UAAI,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACrB,UAAI,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACrB,aAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;;GAEjD,CAAC;;SAEK,CAAC,IAAI,GAAG,IAAI,CAAC","file":"src-es6/sort.js","sourcesContent":["/**\r\n * Sort helpers\r\n */\r\n\r\nimport {Str} from 'string';\r\n\r\nvar Sort = {\r\n ignoreCase(a, b){\r\n var x = Str.lower(a);\r\n var y = Str.lower(b);\r\n return ((x < y) ? -1 : ((x > y) ? 1 : 0));\r\n }\r\n};\r\n\r\nexports.Sort = Sort;"]}
|
82
test/test-checklist.html
Normal file
82
test/test-checklist.html
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>TableFilter checklist</title>
|
||||||
|
<link rel="stylesheet" href="libs/qunit/qunit.css">
|
||||||
|
<link rel="stylesheet" href="../dist/filtergrid.css">
|
||||||
|
<script src="libs/qunit/qunit.js"></script>
|
||||||
|
<script>
|
||||||
|
// Defer Qunit so RequireJS can work its magic and resolve all modules.
|
||||||
|
QUnit.config.autostart = false;
|
||||||
|
QUnit.config.autoload = false;
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table id="demo" cellpadding="0" cellspacing="0">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>From</th>
|
||||||
|
<th>Destination</th>
|
||||||
|
<th>Road Distance (km)</th>
|
||||||
|
<th>By Air (hrs)</th>
|
||||||
|
<th>By Rail (hrs)</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Sydney</strong></td>
|
||||||
|
<td>Adelaide</td>
|
||||||
|
<td>1412</td>
|
||||||
|
<td>1.4</td>
|
||||||
|
<td>25.3</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Sydney</strong></td>
|
||||||
|
<td>Brisbane</td>
|
||||||
|
<td>982</td>
|
||||||
|
<td>1.5</td>
|
||||||
|
<td>16</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Sydney</strong></td>
|
||||||
|
<td>Canberra</td>
|
||||||
|
<td>286</td>
|
||||||
|
<td>.6</td>
|
||||||
|
<td>4.3</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Sydney</strong></td>
|
||||||
|
<td>Melbourne</td>
|
||||||
|
<td>872</td>
|
||||||
|
<td>1.1</td>
|
||||||
|
<td>10.5</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Adelaide</strong></td>
|
||||||
|
<td>Perth</td>
|
||||||
|
<td>2781</td>
|
||||||
|
<td>3.1</td>
|
||||||
|
<td>38</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Adelaide</strong></td>
|
||||||
|
<td>Alice Springs</td>
|
||||||
|
<td>1533</td>
|
||||||
|
<td>2</td>
|
||||||
|
<td>20.25</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Adelaide</strong></td>
|
||||||
|
<td>Brisbane</td>
|
||||||
|
<td>2045</td>
|
||||||
|
<td>2.15</td>
|
||||||
|
<td>40</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<script data-main="test-checklist" src="../libs/requirejs/require.js"></script>
|
||||||
|
|
||||||
|
<div id="qunit"></div>
|
||||||
|
<div id="qunit-fixture"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
37
test/test-checklist.js
Normal file
37
test/test-checklist.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
requirejs(['test-config', '../src/core'], function(config, TableFilter){
|
||||||
|
|
||||||
|
QUnit.start();
|
||||||
|
|
||||||
|
var CheckList = require('modules/checkList').CheckList,
|
||||||
|
types = require('types').Types,
|
||||||
|
dom = require('dom').Dom;
|
||||||
|
|
||||||
|
var tf = new TableFilter('demo', {
|
||||||
|
col_3: 'checklist',
|
||||||
|
fill_slc_on_demand: false
|
||||||
|
});
|
||||||
|
tf.init();
|
||||||
|
|
||||||
|
var checkList = tf.Cpt.checkList;
|
||||||
|
module('Sanity checks');
|
||||||
|
test('CheckList component', function() {
|
||||||
|
deepEqual(checkList instanceof CheckList, true, 'CheckList type');
|
||||||
|
notEqual(checkList, null, 'CheckList instanciated');
|
||||||
|
deepEqual(types.isArray(checkList.checkListDiv), true, 'Type of checkListDiv property');
|
||||||
|
});
|
||||||
|
|
||||||
|
module('UI elements');
|
||||||
|
test('CheckList UI elements', function() {
|
||||||
|
var flt = dom.id(tf.fltIds[3]);
|
||||||
|
notEqual(flt, null, 'CheckList UL element');
|
||||||
|
deepEqual(flt.firstChild.nodeName, 'LI', 'First CheckList option element name');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('TableFilter removed', function() {
|
||||||
|
tf.RemoveGrid();
|
||||||
|
deepEqual(dom.id(tf.fltIds[3]), null, 'CheckList UL element');
|
||||||
|
});
|
||||||
|
|
||||||
|
// tf.fObj.fill_slc_on_demand = false;
|
||||||
|
// tf.RefreshGrid(tf.fObj);
|
||||||
|
});
|
|
@ -2,7 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>TableFilter store</title>
|
<title>TableFilter paging</title>
|
||||||
<link rel="stylesheet" href="libs/qunit/qunit.css">
|
<link rel="stylesheet" href="libs/qunit/qunit.css">
|
||||||
<link rel="stylesheet" href="../dist/filtergrid.css">
|
<link rel="stylesheet" href="../dist/filtergrid.css">
|
||||||
<script src="libs/qunit/qunit.js"></script>
|
<script src="libs/qunit/qunit.js"></script>
|
||||||
|
|
Loading…
Reference in a new issue