2016-05-14 12:04:00 +02:00
|
|
|
import {Feature} from '../feature';
|
2016-05-25 09:31:53 +02:00
|
|
|
import {createElm, createText, elm, removeElm} from '../dom';
|
2016-06-02 06:13:56 +02:00
|
|
|
import {addEvt} from '../event';
|
2015-02-19 06:28:50 +01:00
|
|
|
|
2016-05-24 10:42:11 +02:00
|
|
|
export class ClearButton extends Feature {
|
2015-02-19 06:28:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear button component
|
|
|
|
* @param {Object} tf TableFilter instance
|
|
|
|
*/
|
2016-05-24 10:42:11 +02:00
|
|
|
constructor(tf) {
|
2015-11-15 11:20:40 +01:00
|
|
|
super(tf, 'btnReset');
|
|
|
|
|
2015-02-19 06:28:50 +01:00
|
|
|
// Configuration object
|
2016-05-24 10:42:11 +02:00
|
|
|
let f = this.config;
|
2015-02-19 06:28:50 +01:00
|
|
|
|
|
|
|
//id of container element
|
|
|
|
this.btnResetTgtId = f.btn_reset_target_id || null;
|
|
|
|
//reset button element
|
|
|
|
this.btnResetEl = null;
|
|
|
|
//defines reset text
|
|
|
|
this.btnResetText = f.btn_reset_text || 'Reset';
|
|
|
|
//defines reset button tooltip
|
|
|
|
this.btnResetTooltip = f.btn_reset_tooltip || 'Clear filters';
|
|
|
|
//defines reset button innerHtml
|
|
|
|
this.btnResetHtml = f.btn_reset_html ||
|
|
|
|
(!tf.enableIcons ? null :
|
2016-05-24 10:42:11 +02:00
|
|
|
'<input type="button" value="" class="' + tf.btnResetCssClass +
|
|
|
|
'" ' + 'title="' + this.btnResetTooltip + '" />');
|
2015-04-12 09:52:19 +02:00
|
|
|
//span containing reset button
|
|
|
|
this.prfxResetSpan = 'resetspan_';
|
2015-02-19 06:28:50 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 10:42:11 +02:00
|
|
|
onClick() {
|
|
|
|
if (!this.isEnabled()) {
|
2015-11-15 11:20:40 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-02-21 04:39:09 +01:00
|
|
|
this.tf.clearFilters();
|
2015-02-19 06:28:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build DOM elements
|
|
|
|
*/
|
2016-05-24 10:42:11 +02:00
|
|
|
init() {
|
|
|
|
let tf = this.tf;
|
2015-02-19 06:28:50 +01:00
|
|
|
|
2016-05-24 10:42:11 +02:00
|
|
|
if (this.initialized) {
|
2015-02-19 06:28:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-24 10:42:11 +02:00
|
|
|
let resetspan = createElm('span', ['id', this.prfxResetSpan + tf.id]);
|
2015-02-19 06:28:50 +01:00
|
|
|
|
|
|
|
// reset button is added to defined element
|
2016-05-24 10:42:11 +02:00
|
|
|
if (!this.btnResetTgtId) {
|
2015-02-21 04:39:09 +01:00
|
|
|
tf.setToolbar();
|
2015-02-19 06:28:50 +01:00
|
|
|
}
|
2016-05-25 09:31:53 +02:00
|
|
|
let targetEl = !this.btnResetTgtId ? tf.rDiv : elm(this.btnResetTgtId);
|
2015-02-19 06:28:50 +01:00
|
|
|
targetEl.appendChild(resetspan);
|
|
|
|
|
2016-05-24 10:42:11 +02:00
|
|
|
if (!this.btnResetHtml) {
|
2016-05-25 09:31:53 +02:00
|
|
|
let fltreset = createElm('a', ['href', 'javascript:voelm(0);']);
|
2015-02-19 06:28:50 +01:00
|
|
|
fltreset.className = tf.btnResetCssClass;
|
2016-05-24 10:42:11 +02:00
|
|
|
fltreset.appendChild(createText(this.btnResetText));
|
2015-02-19 06:28:50 +01:00
|
|
|
resetspan.appendChild(fltreset);
|
2016-06-02 06:13:56 +02:00
|
|
|
addEvt(fltreset, 'click', () => this.onClick());
|
2015-02-19 06:28:50 +01:00
|
|
|
} else {
|
|
|
|
resetspan.innerHTML = this.btnResetHtml;
|
2016-05-24 10:42:11 +02:00
|
|
|
let resetEl = resetspan.firstChild;
|
2016-06-02 06:13:56 +02:00
|
|
|
addEvt(resetEl, 'click', () => this.onClick());
|
2015-02-19 06:28:50 +01:00
|
|
|
}
|
|
|
|
this.btnResetEl = resetspan.firstChild;
|
2015-11-15 11:20:40 +01:00
|
|
|
|
|
|
|
this.initialized = true;
|
2015-02-19 06:28:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove clear button UI
|
|
|
|
*/
|
2016-05-24 10:42:11 +02:00
|
|
|
destroy() {
|
|
|
|
let tf = this.tf;
|
2015-02-19 06:28:50 +01:00
|
|
|
|
2016-05-24 10:42:11 +02:00
|
|
|
if (!this.initialized) {
|
2015-02-19 06:28:50 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-25 09:31:53 +02:00
|
|
|
let resetspan = elm(this.prfxResetSpan + tf.id);
|
2016-05-24 10:42:11 +02:00
|
|
|
if (resetspan) {
|
|
|
|
removeElm(resetspan);
|
2015-02-19 06:28:50 +01:00
|
|
|
}
|
|
|
|
this.btnResetEl = null;
|
2015-11-15 11:20:40 +01:00
|
|
|
this.initialized = false;
|
2015-02-19 06:28:50 +01:00
|
|
|
}
|
|
|
|
}
|