1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2026-03-18 00:19:50 +01:00

Started using es6

This commit is contained in:
Max Guglielmi 2014-11-16 01:34:32 +11:00
commit e8fba7cedd
27 changed files with 977 additions and 1844 deletions

View file

@ -1,98 +1,98 @@
define(['../dom'], function (dom) {
'use strict';
define(["exports", "../dom"], function (exports, _dom) {
"use strict";
/**
* Alternating rows color
* @param {Object} tf TableFilter instance
*/
function AlternateRows(tf) {
var f = tf.fObj;
//defines css class for even rows
this.evenCss = f.even_row_css_class || 'even';
//defines css class for odd rows
this.oddCss = f.odd_row_css_class || 'odd';
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
this.tf = tf;
}
var dom = _dom;
var AlternateRows = (function () {
var AlternateRows = function AlternateRows(tf) {
var f = tf.fObj;
//defines css class for even rows
this.evenCss = f.even_row_css_class || "even";
//defines css class for odd rows
this.oddCss = f.odd_row_css_class || "odd";
/**
* Sets alternating rows color
*/
AlternateRows.prototype.set = function() {
if(!this.tf.hasGrid && !this.tf.isFirstLoad){
this.tf = tf;
};
_classProps(AlternateRows, null, {
set: {
writable: true,
value: function () {
if (!this.tf.hasGrid && !this.tf.isFirstLoad) {
return;
}
var rows = this.tf.tbl.rows;
var noValidRowsIndex = this.tf.validRowsIndex===null;
//1st index
var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;
// nb indexes
var indexLen = noValidRowsIndex ?
this.tf.nbFilterableRows+beginIndex :
this.tf.validRowsIndex.length;
var idx = 0;
}
var rows = this.tf.tbl.rows;
var noValidRowsIndex = this.tf.validRowsIndex === null;
//1st index
var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;
// nb indexes
var indexLen = noValidRowsIndex ? this.tf.nbFilterableRows + beginIndex : this.tf.validRowsIndex.length;
var idx = 0;
//alternates bg color
for(var j=beginIndex; j<indexLen; j++){
//alternates bg color
for (var j = beginIndex; j < indexLen; j++) {
var rowIdx = noValidRowsIndex ? j : this.tf.validRowsIndex[j];
this.setRowBg(rowIdx, idx);
idx++;
}
}
};
/**
* Sets row background color
* @param {Number} rowIdx Row index
* @param {Number} idx Valid rows collection index needed to calculate bg
* color
*/
AlternateRows.prototype.setRowBg = function(rowIdx, idx) {
if(!this.tf.alternateBgs || isNaN(rowIdx)){
},
setRowBg: {
writable: true,
value: function (rowIdx, idx) {
if (!this.tf.alternateBgs || isNaN(rowIdx)) {
return;
}
var rows = this.tf.tbl.rows;
var i = !idx ? rowIdx : idx;
this.removeRowBg(rowIdx);
dom.addClass(rows[rowIdx], (i % 2) ? this.evenCss : this.oddCss);
}
var rows = this.tf.tbl.rows;
var i = !idx ? rowIdx : idx;
this.removeRowBg(rowIdx);
dom.addClass(
rows[rowIdx],
(i%2) ? this.evenCss : this.oddCss
);
};
/**
* Removes row background color
* @param {Number} idx Row index
*/
AlternateRows.prototype.removeRowBg = function(idx) {
if(isNaN(idx)){
},
removeRowBg: {
writable: true,
value: function (idx) {
if (isNaN(idx)) {
return;
}
var rows = this.tf.tbl.rows;
dom.removeClass(rows[idx], this.oddCss);
dom.removeClass(rows[idx], this.evenCss);
}
var rows = this.tf.tbl.rows;
dom.removeClass(rows[idx], this.oddCss);
dom.removeClass(rows[idx], this.evenCss);
};
/**
* Removes all row background color
*/
AlternateRows.prototype.remove = function() {
if(!this.tf.hasGrid){
},
remove: {
writable: true,
value: function () {
if (!this.tf.hasGrid) {
return;
}
var row = this.tf.tbl.rows;
for(var i=this.tf.refRow; i<this.tf.nbRows; i++){
}
var row = this.tf.tbl.rows;
for (var i = this.tf.refRow; i < this.tf.nbRows; i++) {
this.removeRowBg(i);
}
this.tf.isStartBgAlternate = true;
}
this.tf.isStartBgAlternate = true;
};
AlternateRows.prototype.enable = function() {
this.tf.alternateBgs = true;
};
AlternateRows.prototype.disable = function() {
this.tf.alternateBgs = false;
};
},
enable: {
writable: true,
value: function () {
this.tf.alternateBgs = true;
}
},
disable: {
writable: true,
value: function () {
this.tf.alternateBgs = false;
}
}
});
return AlternateRows;
});
})();
exports.AlternateRows = AlternateRows;
});

View file

@ -0,0 +1 @@
{"version":3,"sources":["src/es6-modules/alternateRows.js"],"names":[],"mappings":"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","file":"src/es6-modules/alternateRows.js","sourcesContent":["import * as dom from '../dom';\r\n\r\nexport class AlternateRows{\r\n\r\n /**\r\n * Alternating rows color\r\n * @param {Object} tf TableFilter instance\r\n */\r\n constructor(tf) {\r\n var f = tf.fObj;\r\n //defines css class for even rows\r\n this.evenCss = f.even_row_css_class || 'even';\r\n //defines css class for odd rows\r\n this.oddCss = f.odd_row_css_class || 'odd';\r\n\r\n this.tf = tf;\r\n }\r\n\r\n /**\r\n * Sets alternating rows color\r\n */\r\n set() {\r\n if(!this.tf.hasGrid && !this.tf.isFirstLoad){\r\n return;\r\n }\r\n var rows = this.tf.tbl.rows;\r\n var noValidRowsIndex = this.tf.validRowsIndex===null;\r\n //1st index\r\n var beginIndex = noValidRowsIndex ? this.tf.refRow : 0;\r\n // nb indexes\r\n var indexLen = noValidRowsIndex ?\r\n this.tf.nbFilterableRows+beginIndex :\r\n this.tf.validRowsIndex.length;\r\n var idx = 0;\r\n\r\n //alternates bg color\r\n for(var j=beginIndex; j<indexLen; j++){\r\n var rowIdx = noValidRowsIndex ? j : this.tf.validRowsIndex[j];\r\n this.setRowBg(rowIdx, idx);\r\n idx++;\r\n }\r\n }\r\n\r\n /**\r\n * Sets row background color\r\n * @param {Number} rowIdx Row index\r\n * @param {Number} idx Valid rows collection index needed to calculate bg\r\n * color\r\n */\r\n setRowBg(rowIdx, idx) {\r\n if(!this.tf.alternateBgs || isNaN(rowIdx)){\r\n return;\r\n }\r\n var rows = this.tf.tbl.rows;\r\n var i = !idx ? rowIdx : idx;\r\n this.removeRowBg(rowIdx);\r\n dom.addClass(\r\n rows[rowIdx],\r\n (i%2) ? this.evenCss : this.oddCss\r\n );\r\n }\r\n\r\n /**\r\n * Removes row background color\r\n * @param {Number} idx Row index\r\n */\r\n removeRowBg(idx) {\r\n if(isNaN(idx)){\r\n return;\r\n }\r\n var rows = this.tf.tbl.rows;\r\n dom.removeClass(rows[idx], this.oddCss);\r\n dom.removeClass(rows[idx], this.evenCss);\r\n }\r\n\r\n /**\r\n * Removes all row background color\r\n */\r\n remove() {\r\n if(!this.tf.hasGrid){\r\n return;\r\n }\r\n var row = this.tf.tbl.rows;\r\n for(var i=this.tf.refRow; i<this.tf.nbRows; i++){\r\n this.removeRowBg(i);\r\n }\r\n this.tf.isStartBgAlternate = true;\r\n }\r\n\r\n enable() {\r\n this.tf.alternateBgs = true;\r\n }\r\n\r\n disable() {\r\n this.tf.alternateBgs = false;\r\n }\r\n\r\n}\r\n\r\n"]}

View file

@ -1,300 +1,249 @@
define(['../dom', '../string'], function (dom, str) {
'use strict';
define(["exports", "../dom", "../string"], function (exports, _dom, _string) {
"use strict";
/**
* Column calculations
* @param {Object} tf TableFilter instance
*/
function ColOps(tf) {
var f = tf.fObj;
this.colOperation = f.col_operation;
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
this.tf = tf;
}
var dom = _dom;
var str = _string;
var ColOps = (function () {
var ColOps = function ColOps(tf) {
var f = tf.fObj;
this.colOperation = f.col_operation;
/**
* Calculates columns' values
* Configuration options are stored in 'colOperation' property
* - 'id' contains ids of elements showing result (array)
* - 'col' contains the columns' indexes (array)
* - 'operation' contains operation type (array, values: 'sum', 'mean',
* 'min', 'max', 'median', 'q1', 'q3')
* - 'write_method' array defines which method to use for displaying the
* result (innerHTML, setValue, createTextNode) - default: 'innerHTML'
* - 'tot_row_index' defines in which row results are displayed
* (integers array)
*
* - changes made by Nuovella:
* (1) optimized the routine (now it will only process each column once),
* (2) added calculations for the median, lower and upper quartile.
*/
ColOps.prototype.set = function() {
if(!this.tf.isFirstLoad && !this.tf.hasGrid){
return;
}
if(this.tf.onBeforeOperation){
this.tf.onBeforeOperation.call(null, this.tf);
}
var colOperation = this.colOperation,
labelId = colOperation.id,
colIndex = colOperation.col,
operation = colOperation.operation,
outputType = colOperation.write_method,
totRowIndex = colOperation.tot_row_index,
excludeRow = colOperation.exclude_row,
decimalPrecision = colOperation.decimal_precision !== undefined ?
colOperation.decimal_precision : 2;
//nuovella: determine unique list of columns to operate on
var ucolIndex = [],
ucolMax = 0;
ucolIndex[ucolMax] = colIndex[0];
for(var ii=1; ii<colIndex.length; ii++){
var saved = 0;
//see if colIndex[ii] is already in the list of unique indexes
for(var jj=0; jj<=ucolMax; jj++){
if(ucolIndex[jj] === colIndex[ii]){
saved = 1;
}
}
//if not saved then, save the index;
if (saved === 0){
ucolMax++;
ucolIndex[ucolMax] = colIndex[ii];
}
}
if(str.lower(typeof labelId)=='object' &&
str.lower(typeof colIndex)=='object' &&
str.lower(typeof operation)=='object'){
var row = this.tf.tbl.rows,
colvalues = [];
for(var ucol=0; ucol<=ucolMax; ucol++){
//this retrieves col values
//use ucolIndex because we only want to pass through this loop
//once for each column get the values in this unique column
colvalues.push(
this.tf.GetColValues(ucolIndex[ucol], true, excludeRow));
//next: calculate all operations for this column
var result,
nbvalues=0,
temp,
meanValue=0,
sumValue=0,
minValue=null,
maxValue=null,
q1Value=null,
medValue=null,
q3Value=null,
meanFlag=0,
sumFlag=0,
minFlag=0,
maxFlag=0,
q1Flag=0,
medFlag=0,
q3Flag=0,
theList=[],
opsThisCol=[],
decThisCol=[],
labThisCol=[],
oTypeThisCol=[],
mThisCol=-1;
for(var k=0; k<colIndex.length; k++){
if(colIndex[k] === ucolIndex[ucol]){
mThisCol++;
opsThisCol[mThisCol]=str.lower(operation[k]);
decThisCol[mThisCol]=decimalPrecision[k];
labThisCol[mThisCol]=labelId[k];
oTypeThisCol = outputType !== undefined &&
str.lower(typeof outputType)==='object' ?
outputType[k] : null;
switch(opsThisCol[mThisCol]){
case 'mean':
meanFlag=1;
break;
case 'sum':
sumFlag=1;
break;
case 'min':
minFlag=1;
break;
case 'max':
maxFlag=1;
break;
case 'median':
medFlag=1;
break;
case 'q1':
q1Flag=1;
break;
case 'q3':
q3Flag=1;
break;
}
}
}
for(var j=0; j<colvalues[ucol].length; j++){
//sort the list for calculation of median and quartiles
if((q1Flag==1)|| (q3Flag==1) || (medFlag==1)){
if (j<colvalues[ucol].length -1){
for(k=j+1; k<colvalues[ucol].length; k++) {
if(eval(colvalues[ucol][k]) <
eval(colvalues[ucol][j])){
temp = colvalues[ucol][j];
colvalues[ucol][j] = colvalues[ucol][k];
colvalues[ucol][k] = temp;
}
}
}
}
var cvalue = parseFloat(colvalues[ucol][j]);
theList[j] = parseFloat(cvalue);
if(!isNaN(cvalue)){
nbvalues++;
if(sumFlag===1 || meanFlag===1){
sumValue += parseFloat( cvalue );
}
if(minFlag===1){
if(minValue===null){
minValue = parseFloat( cvalue );
} else{
minValue = parseFloat( cvalue ) < minValue ?
parseFloat( cvalue ): minValue;
}
}
if(maxFlag===1){
if (maxValue===null){
maxValue = parseFloat( cvalue );
} else {
maxValue = parseFloat( cvalue ) > maxValue ?
parseFloat( cvalue ): maxValue;
}
}
}
}//for j
if(meanFlag===1){
meanValue = sumValue/nbvalues;
}
if(medFlag===1){
var aux = 0;
if(nbvalues%2 === 1){
aux = Math.floor(nbvalues/2);
medValue = theList[aux];
} else{
medValue =
(theList[nbvalues/2] + theList[((nbvalues/2)-1)])/2;
}
}
var posa;
if(q1Flag===1){
posa=0.0;
posa = Math.floor(nbvalues/4);
if(4*posa == nbvalues){
q1Value = (theList[posa-1] + theList[posa])/2;
} else {
q1Value = theList[posa];
}
}
if (q3Flag===1){
posa=0.0;
var posb=0.0;
posa = Math.floor(nbvalues/4);
if (4*posa === nbvalues){
posb = 3*posa;
q3Value = (theList[posb] + theList[posb-1])/2;
} else {
q3Value = theList[nbvalues-posa-1];
}
}
for(var i=0; i<=mThisCol; i++){
switch( opsThisCol[i] ){
case 'mean':
result=meanValue;
break;
case 'sum':
result=sumValue;
break;
case 'min':
result=minValue;
break;
case 'max':
result=maxValue;
break;
case 'median':
result=medValue;
break;
case 'q1':
result=q1Value;
break;
case 'q3':
result=q3Value;
break;
}
var precision = !isNaN(decThisCol[i]) ? decThisCol[i] : 2;
//if outputType is defined
if(oTypeThisCol && result){
result = result.toFixed( precision );
if(dom.id(labThisCol[i])){
switch( str.lower(oTypeThisCol) ){
case 'innerhtml':
if (isNaN(result) || !isFinite(result) ||
nbvalues===0){
dom.id(labThisCol[i]).innerHTML = '.';
} else{
dom.id(labThisCol[i]).innerHTML = result;
}
break;
case 'setvalue':
dom.id( labThisCol[i] ).value = result;
break;
case 'createtextnode':
var oldnode = dom.id(labThisCol[i])
.firstChild;
var txtnode = dom.text(result);
dom.id(labThisCol[i])
.replaceChild(txtnode, oldnode);
break;
}//switch
}
} else {
try{
if(isNaN(result) || !isFinite(result) ||
nbvalues===0){
dom.id(labThisCol[i]).innerHTML = '.';
} else {
dom.id(labThisCol[i]).innerHTML =
result.toFixed(precision);
}
} catch(e) {}//catch
}//else
}//for i
// row(s) with result are always visible
var totRow = totRowIndex && totRowIndex[ucol] ?
row[totRowIndex[ucol]] : null;
if(totRow){
totRow.style.display = '';
}
}//for ucol
}//if typeof
if(this.tf.onAfterOperation){
this.tf.onAfterOperation.call(null, this.tf);
}
this.tf = tf;
};
_classProps(ColOps, null, {
set: {
writable: true,
value: function () {
if (!this.tf.isFirstLoad && !this.tf.hasGrid) {
return;
}
if (this.tf.onBeforeOperation) {
this.tf.onBeforeOperation.call(null, this.tf);
}
var colOperation = this.colOperation, labelId = colOperation.id, colIndex = colOperation.col, operation = colOperation.operation, outputType = colOperation.write_method, totRowIndex = colOperation.tot_row_index, excludeRow = colOperation.exclude_row, decimalPrecision = colOperation.decimal_precision !== undefined ? colOperation.decimal_precision : 2;
//nuovella: determine unique list of columns to operate on
var ucolIndex = [], ucolMax = 0;
ucolIndex[ucolMax] = colIndex[0];
for (var ii = 1; ii < colIndex.length; ii++) {
var saved = 0;
//see if colIndex[ii] is already in the list of unique indexes
for (var jj = 0; jj <= ucolMax; jj++) {
if (ucolIndex[jj] === colIndex[ii]) {
saved = 1;
}
}
//if not saved then, save the index;
if (saved === 0) {
ucolMax++;
ucolIndex[ucolMax] = colIndex[ii];
}
}
if (str.lower(typeof labelId) == "object" && str.lower(typeof colIndex) == "object" && str.lower(typeof operation) == "object") {
var row = this.tf.tbl.rows, colvalues = [];
for (var ucol = 0; ucol <= ucolMax; ucol++) {
//this retrieves col values
//use ucolIndex because we only want to pass through this loop
//once for each column get the values in this unique column
colvalues.push(this.tf.GetColValues(ucolIndex[ucol], true, excludeRow));
//next: calculate all operations for this column
var result, nbvalues = 0, temp, meanValue = 0, sumValue = 0, minValue = null, maxValue = null, q1Value = null, medValue = null, q3Value = null, meanFlag = 0, sumFlag = 0, minFlag = 0, maxFlag = 0, q1Flag = 0, medFlag = 0, q3Flag = 0, theList = [], opsThisCol = [], decThisCol = [], labThisCol = [], oTypeThisCol = [], mThisCol = -1;
for (var k = 0; k < colIndex.length; k++) {
if (colIndex[k] === ucolIndex[ucol]) {
mThisCol++;
opsThisCol[mThisCol] = str.lower(operation[k]);
decThisCol[mThisCol] = decimalPrecision[k];
labThisCol[mThisCol] = labelId[k];
oTypeThisCol = outputType !== undefined && str.lower(typeof outputType) === "object" ? outputType[k] : null;
switch (opsThisCol[mThisCol]) {
case "mean":
meanFlag = 1;
break;
case "sum":
sumFlag = 1;
break;
case "min":
minFlag = 1;
break;
case "max":
maxFlag = 1;
break;
case "median":
medFlag = 1;
break;
case "q1":
q1Flag = 1;
break;
case "q3":
q3Flag = 1;
break;
}
}
}
for (var j = 0; j < colvalues[ucol].length; j++) {
//sort the list for calculation of median and quartiles
if ((q1Flag == 1) || (q3Flag == 1) || (medFlag == 1)) {
if (j < colvalues[ucol].length - 1) {
for (k = j + 1; k < colvalues[ucol].length; k++) {
if (eval(colvalues[ucol][k]) < eval(colvalues[ucol][j])) {
temp = colvalues[ucol][j];
colvalues[ucol][j] = colvalues[ucol][k];
colvalues[ucol][k] = temp;
}
}
}
}
var cvalue = parseFloat(colvalues[ucol][j]);
theList[j] = parseFloat(cvalue);
if (!isNaN(cvalue)) {
nbvalues++;
if (sumFlag === 1 || meanFlag === 1) {
sumValue += parseFloat(cvalue);
}
if (minFlag === 1) {
if (minValue === null) {
minValue = parseFloat(cvalue);
} else {
minValue = parseFloat(cvalue) < minValue ? parseFloat(cvalue) : minValue;
}
}
if (maxFlag === 1) {
if (maxValue === null) {
maxValue = parseFloat(cvalue);
} else {
maxValue = parseFloat(cvalue) > maxValue ? parseFloat(cvalue) : maxValue;
}
}
}
} //for j
if (meanFlag === 1) {
meanValue = sumValue / nbvalues;
}
if (medFlag === 1) {
var aux = 0;
if (nbvalues % 2 === 1) {
aux = Math.floor(nbvalues / 2);
medValue = theList[aux];
} else {
medValue = (theList[nbvalues / 2] + theList[((nbvalues / 2) - 1)]) / 2;
}
}
var posa;
if (q1Flag === 1) {
posa = 0;
posa = Math.floor(nbvalues / 4);
if (4 * posa == nbvalues) {
q1Value = (theList[posa - 1] + theList[posa]) / 2;
} else {
q1Value = theList[posa];
}
}
if (q3Flag === 1) {
posa = 0;
var posb = 0;
posa = Math.floor(nbvalues / 4);
if (4 * posa === nbvalues) {
posb = 3 * posa;
q3Value = (theList[posb] + theList[posb - 1]) / 2;
} else {
q3Value = theList[nbvalues - posa - 1];
}
}
for (var i = 0; i <= mThisCol; i++) {
switch (opsThisCol[i]) {
case "mean":
result = meanValue;
break;
case "sum":
result = sumValue;
break;
case "min":
result = minValue;
break;
case "max":
result = maxValue;
break;
case "median":
result = medValue;
break;
case "q1":
result = q1Value;
break;
case "q3":
result = q3Value;
break;
}
var precision = !isNaN(decThisCol[i]) ? decThisCol[i] : 2;
//if outputType is defined
if (oTypeThisCol && result) {
result = result.toFixed(precision);
if (dom.id(labThisCol[i])) {
switch (str.lower(oTypeThisCol)) {
case "innerhtml":
if (isNaN(result) || !isFinite(result) || nbvalues === 0) {
dom.id(labThisCol[i]).innerHTML = ".";
} else {
dom.id(labThisCol[i]).innerHTML = result;
}
break;
case "setvalue":
dom.id(labThisCol[i]).value = result;
break;
case "createtextnode":
var oldnode = dom.id(labThisCol[i]).firstChild;
var txtnode = dom.text(result);
dom.id(labThisCol[i]).replaceChild(txtnode, oldnode);
break;
} //switch
}
} else {
try {
if (isNaN(result) || !isFinite(result) || nbvalues === 0) {
dom.id(labThisCol[i]).innerHTML = ".";
} else {
dom.id(labThisCol[i]).innerHTML = result.toFixed(precision);
}
} catch (e) {} //catch
} //else
} //for i
// row(s) with result are always visible
var totRow = totRowIndex && totRowIndex[ucol] ? row[totRowIndex[ucol]] : null;
if (totRow) {
totRow.style.display = "";
}
} //for ucol
} //if typeof
if (this.tf.onAfterOperation) {
this.tf.onAfterOperation.call(null, this.tf);
}
}
}
});
return ColOps;
})();
exports.ColOps = ColOps;
});

File diff suppressed because one or more lines are too long

View file

@ -1,90 +1,98 @@
define(['../dom', '../types'], function (dom, types) {
'use strict';
define(["exports", "../dom", "../types"], function (exports, _dom, _types) {
"use strict";
var global = window;
var _classProps = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Loading message/spinner
* @param {Object} tf TableFilter instance
*/
function Loader(tf){
var dom = _dom;
var types = _types;
// TableFilter configuration
var f = tf.fObj;
//id of container element
tf.loaderTgtId = f.loader_target_id || null;
//div containing loader
tf.loaderDiv = null;
//defines loader text
tf.loaderText = f.loader_text || 'Loading...';
//defines loader innerHtml
tf.loaderHtml = f.loader_html || null;
//defines css class for loader div
tf.loaderCssClass = f.loader_css_class || 'loader';
//delay for hiding loader
tf.loaderCloseDelay = 200;
//callback function before loader is displayed
tf.onShowLoader = types.isFn(f.on_show_loader) ?
f.on_show_loader : null;
//callback function after loader is closed
tf.onHideLoader = types.isFn(f.on_hide_loader) ?
f.on_hide_loader : null;
this.tf = tf;
var global = window;
var containerDiv = dom.create('div', ['id', tf.prfxLoader+tf.id]);
containerDiv.className = tf.loaderCssClass;
var Loader = (function () {
var Loader = function Loader(tf) {
// TableFilter configuration
var f = tf.fObj;
//id of container element
tf.loaderTgtId = f.loader_target_id || null;
//div containing loader
tf.loaderDiv = null;
//defines loader text
tf.loaderText = f.loader_text || "Loading...";
//defines loader innerHtml
tf.loaderHtml = f.loader_html || null;
//defines css class for loader div
tf.loaderCssClass = f.loader_css_class || "loader";
//delay for hiding loader
tf.loaderCloseDelay = 200;
//callback function before loader is displayed
tf.onShowLoader = types.isFn(f.on_show_loader) ? f.on_show_loader : null;
//callback function after loader is closed
tf.onHideLoader = types.isFn(f.on_hide_loader) ? f.on_hide_loader : null;
var targetEl = !tf.loaderTgtId ?
(tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) :
dom.id(tf.loaderTgtId);
if(!tf.loaderTgtId){
targetEl.insertBefore(containerDiv, tf.tbl);
} else {
targetEl.appendChild(containerDiv);
}
tf.loaderDiv = dom.id(tf.prfxLoader+tf.id);
if(!tf.loaderHtml){
tf.loaderDiv.appendChild(dom.text(tf.loaderText));
} else {
tf.loaderDiv.innerHTML = tf.loaderHtml;
}
}
this.tf = tf;
Loader.prototype.show = function(p) {
if(!this.tf.loader || !this.tf.loaderDiv ||
this.tf.loaderDiv.style.display===p){
var containerDiv = dom.create("div", ["id", tf.prfxLoader + tf.id]);
containerDiv.className = tf.loaderCssClass;
var targetEl = !tf.loaderTgtId ? (tf.gridLayout ? tf.tblCont : tf.tbl.parentNode) : dom.id(tf.loaderTgtId);
if (!tf.loaderTgtId) {
targetEl.insertBefore(containerDiv, tf.tbl);
} else {
targetEl.appendChild(containerDiv);
}
tf.loaderDiv = dom.id(tf.prfxLoader + tf.id);
if (!tf.loaderHtml) {
tf.loaderDiv.appendChild(dom.text(tf.loaderText));
} else {
tf.loaderDiv.innerHTML = tf.loaderHtml;
}
};
_classProps(Loader, null, {
show: {
writable: true,
value: function (p) {
if (!this.tf.loader || !this.tf.loaderDiv || this.tf.loaderDiv.style.display === p) {
return;
}
var o = this.tf;
}
var o = this.tf;
function displayLoader(){
if(!o.loaderDiv){
return;
function displayLoader() {
if (!o.loaderDiv) {
return;
}
if(o.onShowLoader && p!=='none'){
o.onShowLoader.call(null, o);
if (o.onShowLoader && p !== "none") {
o.onShowLoader.call(null, o);
}
o.loaderDiv.style.display = p;
if(o.onHideLoader && p==='none'){
o.onHideLoader.call(null, o);
if (o.onHideLoader && p === "none") {
o.onHideLoader.call(null, o);
}
}
var t = p === "none" ? this.tf.loaderCloseDelay : 1;
global.setTimeout(displayLoader, t);
}
var t = p==='none' ? this.tf.loaderCloseDelay : 1;
global.setTimeout(displayLoader, t);
};
Loader.prototype.remove = function() {
if(!this.tf.loaderDiv){
},
remove: {
writable: true,
value: function () {
if (!this.tf.loaderDiv) {
return;
}
var targetEl = !this.tf.loaderTgtId ? (this.tf.gridLayout ? this.tf.tblCont : this.tf.tbl.parentNode) : dom.id(this.tf.loaderTgtId);
targetEl.removeChild(this.tf.loaderDiv);
this.tf.loaderDiv = null;
}
var targetEl = !this.tf.loaderTgtId ?
(this.tf.gridLayout ? this.tf.tblCont : this.tf.tbl.parentNode) :
dom.id(this.tf.loaderTgtId);
targetEl.removeChild(this.tf.loaderDiv);
this.tf.loaderDiv = null;
};
}
});
return Loader;
return Loader;
})();
exports.Loader = Loader;
});

File diff suppressed because one or more lines are too long