1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-06-07 16:32:39 +02:00
TableFilter/src/modules/noResults.js

112 lines
2.9 KiB
JavaScript
Raw Normal View History

2015-12-08 12:53:12 +01:00
import {Feature} from './feature';
import Dom from '../dom';
import Types from '../types';
export class NoResults extends Feature{
/**
* No results message UI component
* @param {Object} tf TableFilter instance
*/
constructor(tf){
super(tf, 'noResults');
//configuration object
let f = this.config.no_results_message;
this.text = f.text || 'No results';
this.customContainer = f.custom_container || null;
this.customContainerId = f.custom_container_id || null;
this.isExternal = !Types.isEmpty(this.customContainer) ||
!Types.isEmpty(this.customContainerId);
this.cssClass = f.css_class || 'no-results';
this.cont = null;
//callback before message is displayed
this.onBeforeShowMsg = Types.isFn(f.on_before_show_msg) ?
f.on_before_show_msg : null;
//callback after message is displayed
this.onAfterShowMsg = Types.isFn(f.on_after_show_msg) ?
f.on_after_show_msg : null;
2015-12-08 13:13:18 +01:00
//callback before message is hidden
this.onBeforeHideMsg = Types.isFn(f.on_before_hide_msg) ?
f.on_before_hide_msg : null;
//callback after message is hidden
this.onAfterHideMsg = Types.isFn(f.on_after_hide_msg) ?
f.on_after_hide_msg : null;
2015-12-08 12:53:12 +01:00
this.prfxNoResults = 'nores_';
}
init(){
if(this.initialized){
return;
}
let tf = this.tf;
let target = this.customContainer || Dom.id(this.customContainerId) ||
tf.tbl;
//container
var cont = Dom.create('div', ['id', this.prfxNoResults+tf.id]);
cont.className = this.cssClass;
cont.appendChild(Dom.text(this.text));
target.appendChild(cont);
this.cont = cont;
this.hide();
this.initialized = true;
}
show(){
2015-12-08 13:13:18 +01:00
if(!this.initialized || !this.isEnabled()){
return;
}
if(this.onBeforeShowMsg){
this.onBeforeShowMsg.call(null, this.tf, this);
}
2015-12-08 12:53:12 +01:00
this.setWidth();
this.cont.style.display = '';
2015-12-08 13:13:18 +01:00
if(this.onAfterShowMsg){
this.onAfterShowMsg.call(null, this.tf, this);
}
2015-12-08 12:53:12 +01:00
}
hide(){
2015-12-08 13:13:18 +01:00
if(!this.initialized || !this.isEnabled()){
return;
}
if(this.onBeforeHideMsg){
this.onBeforeHideMsg.call(null, this.tf, this);
}
2015-12-08 12:53:12 +01:00
this.setWidth();
this.cont.style.display = 'none';
2015-12-08 13:13:18 +01:00
if(this.onBeforeHideMsg){
this.onBeforeHideMsg.call(null, this.tf, this);
}
2015-12-08 12:53:12 +01:00
}
setWidth(){
2015-12-08 13:13:18 +01:00
if(!this.initialized || this.isExternal || !this.isEnabled()){
2015-12-08 12:53:12 +01:00
return;
}
this.cont.style.width = this.tf.tbl.clientWidth + 'px';
}
destroy(){
if(!this.initialized){
return;
}
Dom.remove(this.cont);
this.cont = null;
this.initialized = false;
}
}