mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-06-15 20:25:07 +02:00
Merged master in, added doco comments to dateType
This commit is contained in:
commit
8fa502b2c4
2
dist/tablefilter/style/colsVisibility.css
vendored
2
dist/tablefilter/style/colsVisibility.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-12T09:16:33.045Z
|
||||
* build date: 2016-09-20T13:30:11.327Z
|
||||
* MIT License
|
||||
*/
|
||||
span.colVisSpan{text-align:left;}span.colVisSpan a.colVis{display:inline-block;padding:7px 5px 0;font-size:inherit;font-weight:inherit;vertical-align:top}div.colVisCont{position:relative;background:#fff;-webkit-box-shadow:3px 3px 2px #888;-moz-box-shadow:3px 3px 2px #888;box-shadow:3px 3px 2px #888;position:absolute;display:none;border:1px solid #ccc;height:auto;width:250px;background-color:#fff;margin:35px 0 0 -100px;z-index:10000;padding:10px 10px 10px 10px;text-align:left;font-size:12px;}div.colVisCont:after,div.colVisCont:before{bottom:100%;left:50%;border:solid transparent;content:" ";height:0;width:0;position:absolute;pointer-events:none}div.colVisCont:after{border-color:rgba(255,255,255,0);border-bottom-color:#fff;border-width:10px;margin-left:-10px}div.colVisCont:before{border-color:rgba(255,255,255,0);border-bottom-color:#ccc;border-width:12px;margin-left:-12px}div.colVisCont p{margin:6px auto 6px auto}div.colVisCont a.colVis{display:initial;font-weight:inherit}ul.cols_checklist{padding:0;margin:0;list-style:none;}ul.cols_checklist label{display:block}ul.cols_checklist input{vertical-align:middle;margin:2px 5px 2px 1px}li.cols_checklist_item{padding:4px;margin:0;}li.cols_checklist_item:hover{background-color:#335ea8;color:#fff}.cols_checklist_slc_item{background-color:#335ea8;color:#fff}
|
2
dist/tablefilter/style/filtersVisibility.css
vendored
2
dist/tablefilter/style/filtersVisibility.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-12T09:16:33.045Z
|
||||
* build date: 2016-09-20T13:30:11.327Z
|
||||
* MIT License
|
||||
*/
|
||||
span.expClpFlt a.btnExpClpFlt{width:35px;height:35px;display:inline-block;}span.expClpFlt a.btnExpClpFlt:hover{background-color:#f4f4f4}span.expClpFlt img{padding:8px 11px 11px 11px}
|
2
dist/tablefilter/style/tablefilter.css
vendored
2
dist/tablefilter/style/tablefilter.css
vendored
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-12T09:16:33.045Z
|
||||
* build date: 2016-09-20T13:30:11.327Z
|
||||
* MIT License
|
||||
*/
|
||||
.activeHeader{background-color:#66afe9 !important;color:#fff !important}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-12T09:16:33.045Z
|
||||
* build date: 2016-09-20T13:30:11.327Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{border-left:1px solid #ccc;border-top:none;border-right:none;border-bottom:none;}table.TF th{background:#ebecee url("images/bg_th.jpg") left top repeat-x;border-bottom:1px solid #d0d0d0;border-right:1px solid #d0d0d0;border-left:1px solid #fff;border-top:1px solid #fff;color:#333}table.TF td{border-bottom:1px dotted #999;padding:5px}.fltrow{background-color:#ebecee !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #666 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #999 !important}input.flt{width:99% !important}.inf{height:$min-height;background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important}input.reset{background:transparent url("images/btn_eraser.gif") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;}.nextPage:hover{background:transparent url("images/btn_over_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important;}.previousPage:hover{background:transparent url("images/btn_over_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;}.firstPage:hover{background:transparent url("images/btn_over_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;}.lastPage:hover{background:transparent url("images/btn_over_last_page.gif") center center no-repeat !important}div.grd_Cont{background-color:#ebecee !important;border:1px solid #ccc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#d5d5d5}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important;}div.grd_headTblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#ebecee url("images/bg_th.jpg") left top repeat-x !important;border-bottom:1px solid #d0d0d0 !important;border-right:1px solid #d0d0d0 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #999 !important}.grd_inf{background:#d7d7d7 url("images/bg_infDiv.jpg") 0 0 repeat-x !important;border-top:1px solid #d0d0d0 !important}.loader{border:1px solid #999}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#fff}.odd{background-color:#d5d5d5}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#999 !important}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-12T09:16:33.045Z
|
||||
* build date: 2016-09-20T13:30:11.327Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{border-left:1px dotted #81963b;border-top:none;border-right:0;border-bottom:none;}table.TF th{background:#39424b url("images/bg_headers.jpg") left top repeat-x;border-bottom:0;border-right:1px dotted #d0d0d0;border-left:0;border-top:0;color:#fff}table.TF td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b;padding:5px}.fltrow{background-color:#81963b !important;}.fltrow th,.fltrow td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #687830 !important}input.flt{width:99% !important}.inf{background:#d8d8d8;height:$min-height}input.reset{width:53px;background:transparent url("images/btn_filter.png") center center no-repeat !important}.helpBtn:hover{background-color:transparent}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important}.previousPage{background:transparent url("images/btn_previous_page.gif") center center no-repeat !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important}div.grd_Cont{background:#81963b url("images/bg_headers.jpg") left top repeat-x !important;border:1px solid #ccc !important;padding:0 1px 1px 1px !important;}div.grd_Cont .even{background-color:#bccd83}div.grd_Cont .odd{background-color:#fff}div.grd_headTblCont{background-color:#ebecee !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important;}div.grd_tblCont table td{border-bottom:1px dotted #81963b;border-right:1px dotted #81963b}div.grd_tblCont table th,div.grd_headTblCont table th{background:transparent url("images/bg_headers.jpg") 0 0 repeat-x !important;border-bottom:0 !important;border-right:1px dotted #d0d0d0 !important;border-left:0 !important;border-top:0 !important;padding:0 4px 0 4px !important;color:#fff !important;height:35px !important}div.grd_headTblCont table td{border-bottom:1px dotted #39424b !important;border-right:1px dotted #fff !important;border-left:0 !important;border-top:0 !important;background-color:#81963b !important;padding:1px 3px 1px 3px !important}.grd_inf{background-color:#d8d8d8;border-top:1px solid #d0d0d0 !important}.loader{border:0 !important;background:#81963b !important}.defaultLoader{width:32px;height:32px;background:transparent url("images/img_loading.gif") 0 0 no-repeat !important}.even{background-color:#bccd83}.odd{background-color:#fff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.activeHeader{background:#81963b !important}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* tablefilter v0.3.0 by Max Guglielmi
|
||||
* build date: 2016-09-12T09:16:33.045Z
|
||||
* build date: 2016-09-20T13:30:11.327Z
|
||||
* MIT License
|
||||
*/
|
||||
table.TF{padding:0;color:#000;border-right:1px solid #a4bed4;border-top:1px solid #a4bed4;border-left:1px solid #a4bed4;border-bottom:0;}table.TF th{margin:0;color:inherit;background:#d1e5fe url("images/bg_skyblue.gif") 0 0 repeat-x;border-color:#fdfdfd #a4bed4 #a4bed4 #fdfdfd;border-width:1px;border-style:solid}table.TF td{margin:0;padding:5px;color:inherit;border-bottom:1px solid #a4bed4;border-left:0;border-top:0;border-right:0}.fltrow{background-color:#d1e5fe !important;}.fltrow th,.fltrow td{padding:1px 3px 1px 3px !important}.flt,select.flt,select.flt_multi,.flt_s,.single_flt,.div_checklist{border:1px solid #a4bed4 !important}input.flt{width:99% !important}.inf{background-color:#e3efff !important;border:1px solid #a4bed4;height:$min-height;color:#004a6f}div.tot,div.status{border-right:0 !important}.helpBtn:hover{background-color:transparent}input.reset{background:transparent url("images/icn_clear_filters.png") center center no-repeat !important}.nextPage{background:transparent url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.nextPage:hover{background:#ffe4ab url("images/btn_next_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.previousPage{background:transparent url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.previousPage:hover{background:#ffe4ab url("images/btn_prev_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.firstPage{background:transparent url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.firstPage:hover{background:#ffe4ab url("images/btn_first_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.lastPage{background:transparent url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid transparent !important;}.lastPage:hover{background:#ffe4ab url("images/btn_last_page.gif") center center no-repeat !important;border:1px solid #ffb552 !important}.activeHeader{background:#ffe4ab !important;border:1px solid #ffb552 !important;color:inherit !important}div.grd_Cont{background-color:#d9eaed !important;border:1px solid #9cc !important;padding:0 !important;}div.grd_Cont .even{background-color:#fff}div.grd_Cont .odd{background-color:#e3efff}div.grd_headTblCont{background-color:#d9eaed !important;border-bottom:none !important}div.grd_tblCont table{border-right:none !important}div.grd_tblCont table th,div.grd_headTblCont table th,div.grd_headTblCont table td{background:#d9eaed url("images/bg_skyblue.gif") left top repeat-x;border-bottom:1px solid #a4bed4;border-right:1px solid #a4bed4 !important;border-left:1px solid #fff !important;border-top:1px solid #fff !important}div.grd_tblCont table td{border-bottom:1px solid #a4bed4 !important;border-right:0 !important;border-left:0 !important;border-top:0 !important}.grd_inf{background-color:#cce2fe;color:#004a6f;border-top:1px solid #9cc !important;}.grd_inf a{text-decoration:none;font-weight:bold}.loader{background-color:#2d8eef;border:1px solid #cce2fe;border-radius:5px}.even{background-color:#fff}.odd{background-color:#e3efff}span.expClpFlt a.btnExpClpFlt:hover{background-color:transparent !important}.ezActiveRow{background-color:#ffdc61 !important;color:inherit}.ezSelectedRow{background-color:#ffe4ab !important;color:inherit}.ezActiveCell{background-color:#fff !important;color:#000 !important;font-weight:bold}.ezETSelectedCell{background-color:#fff !important;font-weight:bold;color:#000 !important}
|
198
dist/tablefilter/tablefilter.js
vendored
198
dist/tablefilter/tablefilter.js
vendored
|
@ -1435,6 +1435,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
|
||||
TableFilter.prototype._insertFiltersRow = function _insertFiltersRow() {
|
||||
// TODO: prevent filters row generation for popup filters too,
|
||||
// to reduce and simplify headers row index adjusting across lib modules
|
||||
// (GridLayout, PopupFilter etc)
|
||||
if (this.gridLayout) {
|
||||
return;
|
||||
}
|
||||
|
@ -5272,37 +5275,32 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
var tf = this.tf;
|
||||
|
||||
// Override headers row index if no grouped headers
|
||||
if (tf.headersRow <= 1) {
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
if (tf.headersRow <= 1 && isNaN(tf.config().headers_row_index)) {
|
||||
tf.headersRow = 0;
|
||||
}
|
||||
|
||||
for (var i = 0; i < tf.nbCells; i++) {
|
||||
if (tf.getFilterType(i) === _const.NONE) {
|
||||
continue;
|
||||
}
|
||||
var popUpSpan = (0, _dom.createElm)('span', ['id', this.prfxSpan + tf.id + '_' + i], ['ci', i]);
|
||||
popUpSpan.innerHTML = this.iconHtml;
|
||||
var header = tf.getHeaderElement(i);
|
||||
header.appendChild(popUpSpan);
|
||||
(0, _event.addEvt)(popUpSpan, 'click', function (evt) {
|
||||
return _this2.onClick(evt);
|
||||
});
|
||||
this.fltSpans[i] = popUpSpan;
|
||||
this.fltIcons[i] = popUpSpan.firstChild;
|
||||
// Adjust headers row index for grid-layout mode
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
if (tf.gridLayout) {
|
||||
tf.headersRow--;
|
||||
this.buildIcons();
|
||||
}
|
||||
|
||||
// subscribe to events
|
||||
this.emitter.on(['before-filtering'], function () {
|
||||
return _this2.buildIcons();
|
||||
return _this2.setIconsState();
|
||||
});
|
||||
this.emitter.on(['after-filtering'], function () {
|
||||
return _this2.closeAll();
|
||||
});
|
||||
this.emitter.on(['cell-processed'], function (tf, cellIndex) {
|
||||
return _this2.buildIcon(cellIndex, true);
|
||||
return _this2.changeState(cellIndex, true);
|
||||
});
|
||||
this.emitter.on(['filters-row-inserted'], function () {
|
||||
return _this2.tf.headersRow++;
|
||||
return _this2.buildIcons();
|
||||
});
|
||||
this.emitter.on(['before-filter-init'], function (tf, colIndex) {
|
||||
return _this2.build(colIndex);
|
||||
|
@ -5325,6 +5323,36 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
this.buildAll();
|
||||
};
|
||||
|
||||
/**
|
||||
* Build all filters icons
|
||||
*/
|
||||
|
||||
|
||||
PopupFilter.prototype.buildIcons = function buildIcons() {
|
||||
var _this3 = this;
|
||||
|
||||
var tf = this.tf;
|
||||
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
tf.headersRow++;
|
||||
|
||||
for (var i = 0; i < tf.nbCells; i++) {
|
||||
if (tf.getFilterType(i) === _const.NONE) {
|
||||
continue;
|
||||
}
|
||||
var popUpSpan = (0, _dom.createElm)('span', ['id', this.prfxSpan + tf.id + '_' + i], ['ci', i]);
|
||||
popUpSpan.innerHTML = this.iconHtml;
|
||||
var header = tf.getHeaderElement(i);
|
||||
header.appendChild(popUpSpan);
|
||||
(0, _event.addEvt)(popUpSpan, 'click', function (evt) {
|
||||
return _this3.onClick(evt);
|
||||
});
|
||||
this.fltSpans[i] = popUpSpan;
|
||||
this.fltIcons[i] = popUpSpan.firstChild;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Build all pop-up filters elements
|
||||
*/
|
||||
|
@ -5414,9 +5442,9 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
*/
|
||||
|
||||
|
||||
PopupFilter.prototype.buildIcons = function buildIcons() {
|
||||
PopupFilter.prototype.setIconsState = function setIconsState() {
|
||||
for (var i = 0; i < this.fltIcons.length; i++) {
|
||||
this.buildIcon(i, false);
|
||||
this.changeState(i, false);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -5427,7 +5455,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
*/
|
||||
|
||||
|
||||
PopupFilter.prototype.buildIcon = function buildIcon(colIndex, active) {
|
||||
PopupFilter.prototype.changeState = function changeState(colIndex, active) {
|
||||
if (this.fltIcons[colIndex]) {
|
||||
this.fltIcons[colIndex].src = active ? this.activeIconPath : this.iconPath;
|
||||
}
|
||||
|
@ -5439,7 +5467,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
|
||||
PopupFilter.prototype.destroy = function destroy() {
|
||||
var _this3 = this;
|
||||
var _this4 = this;
|
||||
|
||||
if (!this.initialized) {
|
||||
return;
|
||||
|
@ -5470,19 +5498,19 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
// unsubscribe to events
|
||||
this.emitter.off(['before-filtering'], function () {
|
||||
return _this3.buildIcons();
|
||||
return _this4.setIconsState();
|
||||
});
|
||||
this.emitter.off(['after-filtering'], function () {
|
||||
return _this3.closeAll();
|
||||
return _this4.closeAll();
|
||||
});
|
||||
this.emitter.off(['cell-processed'], function (tf, cellIndex) {
|
||||
return _this3.buildIcon(cellIndex, true);
|
||||
return _this4.changeState(cellIndex, true);
|
||||
});
|
||||
this.emitter.off(['filters-row-inserted'], function () {
|
||||
return _this3.tf.headersRow++;
|
||||
return _this4.buildIcons();
|
||||
});
|
||||
this.emitter.off(['before-filter-init'], function (tf, colIndex) {
|
||||
return _this3.build(colIndex);
|
||||
return _this4.build(colIndex);
|
||||
});
|
||||
|
||||
this.initialized = false;
|
||||
|
@ -10174,68 +10202,135 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
__webpack_require__(416);
|
||||
|
||||
var _feature = __webpack_require__(9);
|
||||
|
||||
var _types = __webpack_require__(4);
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var DateType = exports.DateType = function () {
|
||||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
||||
|
||||
/**
|
||||
* Wrapper for Sugar Date module providing datetime helpers and locales
|
||||
* @export
|
||||
* @class DateType
|
||||
*/
|
||||
var DateType = exports.DateType = function (_Feature) {
|
||||
_inherits(DateType, _Feature);
|
||||
|
||||
/**
|
||||
* Creates an instance of DateType
|
||||
* @param {TableFilter} tf TableFilter instance
|
||||
*/
|
||||
function DateType(tf) {
|
||||
_classCallCheck(this, DateType);
|
||||
|
||||
this.tf = tf;
|
||||
this.locale = tf.locale;
|
||||
this.datetime = _sugarDate.Date;
|
||||
this.emitter = tf.emitter;
|
||||
/**
|
||||
* Global locale
|
||||
* @type {String}
|
||||
*/
|
||||
var _this = _possibleConstructorReturn(this, _Feature.call(this, tf, 'dateType'));
|
||||
|
||||
_this.locale = tf.locale;
|
||||
|
||||
/**
|
||||
* Sugar Date instance
|
||||
* @type {Object}
|
||||
*/
|
||||
_this.datetime = _sugarDate.Date;
|
||||
|
||||
_this.enable();
|
||||
return _this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize DateType instance
|
||||
*/
|
||||
|
||||
|
||||
DateType.prototype.init = function init() {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Global locale
|
||||
// Set global locale
|
||||
this.datetime.setLocale(this.locale);
|
||||
|
||||
// Add formats from column types configuration if any
|
||||
this.addConfigFormats(this.tf.colTypes);
|
||||
// locale.addFormat('{dd}/{MM}/{yyyy}');
|
||||
// locale.addFormat('{MM}/{dd}/{yyyy}');
|
||||
// locale.addFormat('{dd}-{months}-{yyyy|yy}');
|
||||
// locale.addFormat('{dd}-{MM}-{yyyy|yy}');
|
||||
|
||||
this.initialized = true;
|
||||
|
||||
// Broadcast date-type initialization
|
||||
this.emitter.emit('date-type-initialized', this.tf, this);
|
||||
|
||||
/** @inherited */
|
||||
this.initialized = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Parse a string representation of a date for a specified locale and return
|
||||
* a date object
|
||||
* @param {String} dateStr String representation of a date
|
||||
* @param {String} localeCode Locale code (ie 'en-us')
|
||||
* @returns {Date}
|
||||
*/
|
||||
|
||||
|
||||
DateType.prototype.parse = function parse(dateStr, localeCode) {
|
||||
// console.log('parse', dateStr, localeCode,
|
||||
// this.datetime.create(dateStr, localeCode));
|
||||
return this.datetime.create(dateStr, localeCode);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check string representation of a date for a specified locale is valid
|
||||
* @param {any} dateStr String representation of a date
|
||||
* @param {any} localeCode Locale code (ie 'en-us')
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
|
||||
|
||||
DateType.prototype.isValid = function isValid(dateStr, localeCode) {
|
||||
// console.log(dateStr, localeCode, this.parse(dateStr, localeCode),
|
||||
// this.datetime.isValid(this.parse(dateStr, localeCode)));
|
||||
return this.datetime.isValid(this.parse(dateStr, localeCode));
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the type object of a specified column as per configuration or
|
||||
* passed collection
|
||||
* @param {Number} colIndex Column index
|
||||
* @param {Array} types Collection of column types, optional
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
|
||||
DateType.prototype.getOptions = function getOptions(colIndex, types) {
|
||||
types = types || this.tf.colTypes;
|
||||
var colType = types[colIndex];
|
||||
return (0, _types.isObj)(colType) ? colType : {};
|
||||
};
|
||||
|
||||
/**
|
||||
* Add date time format(s) to a locale as specified by the passed
|
||||
* collection of column types, ie:
|
||||
* [
|
||||
* 'string',
|
||||
* 'number',
|
||||
* { type: 'date', locale: 'en', format: ['{dd}/{MM}/{yyyy}']}
|
||||
* ]
|
||||
*
|
||||
* @param {Array} [types=[]] Collection of column types
|
||||
*/
|
||||
|
||||
|
||||
DateType.prototype.addConfigFormats = function addConfigFormats() {
|
||||
var _this = this;
|
||||
var _this2 = this;
|
||||
|
||||
var types = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0];
|
||||
|
||||
types.forEach(function (type, idx) {
|
||||
var options = _this.getOptions(idx, types);
|
||||
var options = _this2.getOptions(idx, types);
|
||||
if (options.hasOwnProperty('format')) {
|
||||
(function () {
|
||||
var locale = _this.datetime.getLocale(options.locale || _this.locale);
|
||||
var locale = _this2.datetime.getLocale(options.locale || _this2.locale);
|
||||
if ((0, _types.isArray)(options.format)) {
|
||||
options.format.forEach(function (format) {
|
||||
locale.addFormat(format);
|
||||
|
@ -10248,12 +10343,23 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove DateType instance
|
||||
*/
|
||||
|
||||
|
||||
DateType.prototype.destroy = function destroy() {
|
||||
if (!this.initialized) {
|
||||
return;
|
||||
}
|
||||
this.datetime.removeLocale(this.locale);
|
||||
// TODO: remove added formats
|
||||
|
||||
this.initialized = false;
|
||||
};
|
||||
|
||||
return DateType;
|
||||
}();
|
||||
}(_feature.Feature);
|
||||
|
||||
/***/ },
|
||||
/* 30 */
|
||||
|
|
1
dist/tablefilter/tf-1.js
vendored
1
dist/tablefilter/tf-1.js
vendored
|
@ -2931,7 +2931,6 @@ webpackJsonp([1],{
|
|||
return _this4.sortByColumnIndex(colIdx, desc);
|
||||
});
|
||||
this.sorted = false;
|
||||
this.initialized = false;
|
||||
this.stt.destroy();
|
||||
|
||||
var ids = tf.getFiltersId();
|
||||
|
|
|
@ -490,7 +490,6 @@ export default class AdapterSortableTable extends Feature {
|
|||
this.emitter.off(['sort'],
|
||||
(tf, colIdx, desc) => this.sortByColumnIndex(colIdx, desc));
|
||||
this.sorted = false;
|
||||
this.initialized = false;
|
||||
this.stt.destroy();
|
||||
|
||||
let ids = tf.getFiltersId();
|
||||
|
|
|
@ -1,54 +1,103 @@
|
|||
import {Date as SugarDate} from 'sugar-date';
|
||||
import 'sugar-date/locales';
|
||||
import {Feature} from '../feature';
|
||||
import {isObj, isArray} from '../types';
|
||||
|
||||
export class DateType {
|
||||
/**
|
||||
* Wrapper for Sugar Date module providing datetime helpers and locales
|
||||
* @export
|
||||
* @class DateType
|
||||
*/
|
||||
export class DateType extends Feature {
|
||||
|
||||
/**
|
||||
* Creates an instance of DateType
|
||||
* @param {TableFilter} tf TableFilter instance
|
||||
*/
|
||||
constructor(tf) {
|
||||
this.tf = tf;
|
||||
super(tf, 'dateType');
|
||||
|
||||
/**
|
||||
* Global locale
|
||||
* @type {String}
|
||||
*/
|
||||
this.locale = tf.locale;
|
||||
|
||||
/**
|
||||
* Sugar Date instance
|
||||
* @type {Object}
|
||||
*/
|
||||
this.datetime = SugarDate;
|
||||
this.emitter = tf.emitter;
|
||||
|
||||
this.enable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize DateType instance
|
||||
*/
|
||||
init() {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Global locale
|
||||
// Set global locale
|
||||
this.datetime.setLocale(this.locale);
|
||||
|
||||
// Add formats from column types configuration if any
|
||||
this.addConfigFormats(this.tf.colTypes);
|
||||
// locale.addFormat('{dd}/{MM}/{yyyy}');
|
||||
// locale.addFormat('{MM}/{dd}/{yyyy}');
|
||||
// locale.addFormat('{dd}-{months}-{yyyy|yy}');
|
||||
// locale.addFormat('{dd}-{MM}-{yyyy|yy}');
|
||||
|
||||
this.initialized = true;
|
||||
|
||||
// Broadcast date-type initialization
|
||||
this.emitter.emit('date-type-initialized', this.tf, this);
|
||||
|
||||
/** @inherited */
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a string representation of a date for a specified locale and return
|
||||
* a date object
|
||||
* @param {String} dateStr String representation of a date
|
||||
* @param {String} localeCode Locale code (ie 'en-us')
|
||||
* @returns {Date}
|
||||
*/
|
||||
parse(dateStr, localeCode) {
|
||||
// console.log('parse', dateStr, localeCode,
|
||||
// this.datetime.create(dateStr, localeCode));
|
||||
return this.datetime.create(dateStr, localeCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check string representation of a date for a specified locale is valid
|
||||
* @param {any} dateStr String representation of a date
|
||||
* @param {any} localeCode Locale code (ie 'en-us')
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
isValid(dateStr, localeCode) {
|
||||
// console.log(dateStr, localeCode, this.parse(dateStr, localeCode),
|
||||
// this.datetime.isValid(this.parse(dateStr, localeCode)));
|
||||
return this.datetime.isValid(this.parse(dateStr, localeCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type object of a specified column as per configuration or
|
||||
* passed collection
|
||||
* @param {Number} colIndex Column index
|
||||
* @param {Array} types Collection of column types, optional
|
||||
* @returns {Object}
|
||||
*/
|
||||
getOptions(colIndex, types) {
|
||||
types = types || this.tf.colTypes;
|
||||
let colType = types[colIndex];
|
||||
return isObj(colType) ? colType : {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Add date time format(s) to a locale as specified by the passed
|
||||
* collection of column types, ie:
|
||||
* [
|
||||
* 'string',
|
||||
* 'number',
|
||||
* { type: 'date', locale: 'en', format: ['{dd}/{MM}/{yyyy}']}
|
||||
* ]
|
||||
*
|
||||
* @param {Array} [types=[]] Collection of column types
|
||||
*/
|
||||
addConfigFormats(types=[]) {
|
||||
types.forEach((type, idx) => {
|
||||
let options = this.getOptions(idx, types);
|
||||
|
@ -67,7 +116,16 @@ export class DateType {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove DateType instance
|
||||
*/
|
||||
destroy() {
|
||||
if (!this.initialized) {
|
||||
return;
|
||||
}
|
||||
this.datetime.removeLocale(this.locale);
|
||||
// TODO: remove added formats
|
||||
|
||||
this.initialized = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,10 +162,54 @@ export class PopupFilter extends Feature {
|
|||
let tf = this.tf;
|
||||
|
||||
// Override headers row index if no grouped headers
|
||||
if (tf.headersRow <= 1) {
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
if (tf.headersRow <= 1 && isNaN(tf.config().headers_row_index)) {
|
||||
tf.headersRow = 0;
|
||||
}
|
||||
|
||||
// Adjust headers row index for grid-layout mode
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
if (tf.gridLayout) {
|
||||
tf.headersRow--;
|
||||
this.buildIcons();
|
||||
}
|
||||
|
||||
// subscribe to events
|
||||
this.emitter.on(['before-filtering'], () => this.setIconsState());
|
||||
this.emitter.on(['after-filtering'], () => this.closeAll());
|
||||
this.emitter.on(['cell-processed'],
|
||||
(tf, cellIndex) => this.changeState(cellIndex, true));
|
||||
this.emitter.on(['filters-row-inserted'], () => this.buildIcons());
|
||||
this.emitter.on(['before-filter-init'],
|
||||
(tf, colIndex) => this.build(colIndex));
|
||||
|
||||
/**
|
||||
* @inherited
|
||||
*/
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset previously destroyed feature
|
||||
*/
|
||||
reset() {
|
||||
this.enable();
|
||||
this.init();
|
||||
this.buildAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build all filters icons
|
||||
*/
|
||||
buildIcons() {
|
||||
let tf = this.tf;
|
||||
|
||||
// TODO: Because of the filters row generation, headers row index needs
|
||||
// adjusting: prevent useless row generation
|
||||
tf.headersRow++;
|
||||
|
||||
for (let i = 0; i < tf.nbCells; i++) {
|
||||
if (tf.getFilterType(i) === NONE) {
|
||||
continue;
|
||||
|
@ -182,29 +226,6 @@ export class PopupFilter extends Feature {
|
|||
this.fltSpans[i] = popUpSpan;
|
||||
this.fltIcons[i] = popUpSpan.firstChild;
|
||||
}
|
||||
|
||||
// subscribe to events
|
||||
this.emitter.on(['before-filtering'], () => this.buildIcons());
|
||||
this.emitter.on(['after-filtering'], () => this.closeAll());
|
||||
this.emitter.on(['cell-processed'],
|
||||
(tf, cellIndex) => this.buildIcon(cellIndex, true));
|
||||
this.emitter.on(['filters-row-inserted'], () => this.tf.headersRow++);
|
||||
this.emitter.on(['before-filter-init'],
|
||||
(tf, colIndex) => this.build(colIndex));
|
||||
|
||||
/**
|
||||
* @inherited
|
||||
*/
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset previously destroyed feature
|
||||
*/
|
||||
reset() {
|
||||
this.enable();
|
||||
this.init();
|
||||
this.buildAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -292,9 +313,9 @@ export class PopupFilter extends Feature {
|
|||
/**
|
||||
* Build all the icons representing the pop-up filters
|
||||
*/
|
||||
buildIcons() {
|
||||
setIconsState() {
|
||||
for (let i = 0; i < this.fltIcons.length; i++) {
|
||||
this.buildIcon(i, false);
|
||||
this.changeState(i, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,7 +324,7 @@ export class PopupFilter extends Feature {
|
|||
* @param {Number} colIndex Column index
|
||||
* @param {Boolean} active Apply active state
|
||||
*/
|
||||
buildIcon(colIndex, active) {
|
||||
changeState(colIndex, active) {
|
||||
if (this.fltIcons[colIndex]) {
|
||||
this.fltIcons[colIndex].src = active ?
|
||||
this.activeIconPath : this.iconPath;
|
||||
|
@ -342,11 +363,11 @@ export class PopupFilter extends Feature {
|
|||
this.fltIcons = [];
|
||||
|
||||
// unsubscribe to events
|
||||
this.emitter.off(['before-filtering'], () => this.buildIcons());
|
||||
this.emitter.off(['before-filtering'], () => this.setIconsState());
|
||||
this.emitter.off(['after-filtering'], () => this.closeAll());
|
||||
this.emitter.off(['cell-processed'],
|
||||
(tf, cellIndex) => this.buildIcon(cellIndex, true));
|
||||
this.emitter.off(['filters-row-inserted'], () => this.tf.headersRow++);
|
||||
(tf, cellIndex) => this.changeState(cellIndex, true));
|
||||
this.emitter.off(['filters-row-inserted'], () => this.buildIcons());
|
||||
this.emitter.off(['before-filter-init'],
|
||||
(tf, colIndex) => this.build(colIndex));
|
||||
|
||||
|
|
|
@ -1296,6 +1296,9 @@ export class TableFilter {
|
|||
* Insert filters row at initialization
|
||||
*/
|
||||
_insertFiltersRow() {
|
||||
// TODO: prevent filters row generation for popup filters too,
|
||||
// to reduce and simplify headers row index adjusting across lib modules
|
||||
// (GridLayout, PopupFilter etc)
|
||||
if (this.gridLayout) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,73 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<table id="demo2">
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan="3">Group 1</th>
|
||||
<th colspan="2">Group 2</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>From</th>
|
||||
<th>Destination</th>
|
||||
<th>Road Distance (km)</th>
|
||||
<th>By Air (hrs)</th>
|
||||
<th>By Rail (hrs)</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<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 src="../dist/tablefilter/tablefilter.js"></script>
|
||||
<script src="test-grouped-headers.js"></script>
|
||||
|
||||
|
|
|
@ -76,6 +76,27 @@
|
|||
deepEqual(tf.getValidRows(), [7], 'Filtered rows');
|
||||
});
|
||||
|
||||
module('Pop-up filters, issue #295');
|
||||
test('Sanity checks', function() {
|
||||
var tf2 = new TableFilter('demo2', 2, {
|
||||
base_path: '../dist/tablefilter/',
|
||||
headers_row_index: 1,
|
||||
popup_filters: true
|
||||
});
|
||||
tf2.init();
|
||||
tf2.setFilterValue(1, 'Melb');
|
||||
tf2.filter();
|
||||
|
||||
deepEqual(tf2 instanceof TableFilter, true, 'TableFilter instanciated');
|
||||
deepEqual(tf2.getHeadersRowIndex(), 2, 'Headers row index');
|
||||
deepEqual(tf2.getStartRowIndex(), 3, 'Reference row index');
|
||||
deepEqual(tf2.getValidRows(), [6], 'Filtered rows');
|
||||
|
||||
tf2.clearFilters();
|
||||
tf2.destroy();
|
||||
deepEqual(tf2.isInitialized(), false, 'Filters removed');
|
||||
});
|
||||
|
||||
//Grid-layout currently does not support grouped headers
|
||||
|
||||
module('Tear-down');
|
||||
|
|
|
@ -75,4 +75,4 @@
|
|||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue