// REFERENCIEL CLASSES CSS APPELLE DANS roueDenteActive -> onClick
const listOfClasses = ['primaire', 'secondaire', 'menuConxtuel', 'ss_parametres', 'MC_footer', 'menu_contextuel_v2', 'parametrage', 'actionPrincipal', 'ajout_contextuel', 'checkBoxCompo'];

$(document).ready(function () {

	if ($.isFunction(colorTrTable)) {
		colorTrTable();
	} else {
		function colorTrTable(div) {
			var count = 0;

			if (!div) {
				div = '';
			} else {
				div = div + ' ';
			}

			div = '';
			$(div + 'table:not(.noColorLign) > tbody > tr:not(.detail_ligne)').each(function () {
				if ($(this).is(':visible') /*&& !$(this).hasClass('odd_table_V2') && !$(this).hasClass('even_table_V2')*/) {
					if (count % 2 == 1) {
						$(this).removeClass('even_table_V2');
						$(this).addClass('odd_table_V2');

						if ($(this).hasClass('link_tr')) {
							var idTr = $(this).attr('id');
							$('#' + idTr + 'detail').removeClass('even_table_V2');
							$('#' + idTr + 'detail').addClass('odd_table_V2');
						}
					} else {
						$(this).removeClass('odd_table_V2');
						$(this).addClass('even_table_V2');

						if ($(this).hasClass('link_tr')) {
							var idTr = $(this).attr('id');
							$('#' + idTr + 'detail').removeClass('odd_table_V2');
							$('#' + idTr + 'detail').addClass('even_table_V2');
						}
					}
					count++;
				}
			});
		}
		colorTrTable();
	}
});

$.fn.isInViewport = function () {
	if ($(this).length != 0) {
		let elementTop = $(this).offset().top;
		let elementBottom = elementTop + $(this).outerHeight();
	
		let viewportTop = $(window).scrollTop();
		let viewportBottom = viewportTop + $(window).height();
		
		return elementBottom > viewportTop && elementTop < viewportBottom;
	}
};

//le let fait des erreurs JS sur des redeclération
var previousSSparam;
var previousPicto;
var previousTo;

function roueDenteActive(id) {
	let ss_parametre = $(id).parent().find('ul:first');
	let picto = $(id).parent();

	$(previousSSparam).stop(true, true);
	$(previousSSparam).removeClass('activate');
	$(previousSSparam).hide();

	$(ss_parametre).removeClass('reverse');

	$('.parametrage').removeClass('ouvert');
	$('.parametrage').addClass('ferme');
	// $('.parametrage ul').hide(100);
	$(picto).removeClass('ferme');
	$(picto).addClass('ouvert');
	$(ss_parametre).show(200);
	$(ss_parametre).addClass('activate');

	if ($(ss_parametre).find('.MC_footer').isInViewport() == false) {
		$(ss_parametre).addClass('reverse');
	}

	previousSSparam = ss_parametre;
	previousPicto = picto;

	$('.ss_parametres li a').not('.backAction').click(function () {
		$(id).parent().find('ul:first').hide();
		$(id).parent().find('ul:first').removeClass('activate');
		$(id).parent().find('.parametre').removeClass('ouvert');
		$(id).parent().find('.parametre').addClass('ferme');
	});

	function remove() {
		$(ss_parametre).hide(500);
		$(ss_parametre).removeClass('activate');
		$(picto).removeClass('ouvert');
		$(picto).addClass('ferme');
	}

	function removeInstant() {
		$(ss_parametre).hide(100);
		$(ss_parametre).removeClass('activate');
		$(picto).removeClass('ouvert');
		$(picto).addClass('ferme');
	}

	$(ss_parametre).on('mouseout', (function () {
		if(previousTo) {
			clearTimeout(previousTo);
		}
	
		let to = setTimeout(function () {
			remove();
		}, 500);
		previousTo = to;
		
		$(id).parent().on('mouseover', function () {
			clearTimeout(to);
		});

		$(ss_parametre).on('mouseover', function () {
			clearTimeout(to);
		});
	}));

	$(id).parent().on('mouseout', (function () {
		if(previousTo) {
			clearTimeout(previousTo);
		}
	
		let to = setTimeout(function () {
			remove();
		}, 500);
		previousTo = to;;

		$(id).parent().on('mouseover', function () {
			clearTimeout(to);
		});

		$(ss_parametre).on('mouseover', (function () {
			clearTimeout(to);
		}));

	}));

	$('body').on('click', (function (e) {
		let toRemove = false;

		for (let element of listOfClasses) {
			if (e.target.classList.contains(element)) {
				toRemove = false;
				break;
			}
			else {
				toRemove = true;
			}
		}
		if (toRemove) {
			removeInstant();
		}
	}));
}

function activeSousRoueDente(id, menu) {
	var ss_parametre = $(id).parent().parent().parent().find(menu);

	ss_parametre.show();

	$('.Menu_general li a').click(function () {
		ss_parametre.hide();
		$(id).parent().find('.parametre').removeClass('ouvert');
		$(id).parent().find('.parametre').addClass('ferme');
	});

	$(ss_parametre).mouseleave(function () {

		var to = setTimeout(function () {

			$(ss_parametre).hide(500);
			$(ss_parametre).removeClass('activate');
		}, 500);

		$(ss_parametre).on('mouseover', function () {
			clearTimeout(to);
		});
	});

	$(id).mouseleave(function () {

		var to = setTimeout(function () {

			$(ss_parametre).hide(500);
			$(ss_parametre).removeClass('activate');
		}, 2000);

		$(ss_parametre).on('mouseover', function () {
			clearTimeout(to);
		});
	});

}

function retourRoueDente(id) {
	var ss_parametre = $(id).parent().parent().parent().find('ul:first');
	$('.ss_parametres').hide();
	$(ss_parametre).show();
}

$(".parametre").each(function () {

	var attr = $(this).attr("onclick");
	if (typeof attr !== typeof undefined && attr !== false && $(this).attr("onclick").indexOf("roueDenteActive(this);") != -1) {
		var textOnclick = $(this).attr("onclick").replace("roueDenteActive(this);", "");
		$(this).attr("onclick", textOnclick);
	}
});

$('.parametre').attr("onclick", 'roueDenteActive(this);');

//_____________________________________
// Bootstrap tooltip init

$(function () {

	// Apply tooltip after mutation (ajax innerHTML) (1 second after mutation has ceased)
	var timer_tooltip = null;
	var observer = new MutationObserver(function (mutationList, observer) {

		clearTimeout(timer_tooltip);

		timer_tooltip = setTimeout(function () {
			$('[data-toggle="tooltip"]').tooltip();
		}, 1000);
	});
	observer.observe(document.body, {
		attributes: false, childList: true, subtree: true
	});

	// Apply tooltip on load
	$('[data-toggle="tooltip"]').tooltip();
});

//_____________________________________

$('.radio-inline').on('click', function () {
	$('.radio-inline').removeClass('active');
	$(this).addClass('active');

});

$('#filtre_fournisseur [data-toggle="collapse"]').on('click', function () {
	if ($('#filtre_avances').css('display') === "none") {
		$(this).html($('#retract').val());

	} else {
		$(this).html($('#advancedFilters').val());

	}
});
$('#filtre_commande [data-toggle="collapse"]').on('click', function () {
	let $this = $(this);

	if ($('#filtre_avances').css('display') === "none") {
		$(this).html($('#retract').val());

	} else {
		$(this).html($('#advancedFilters').val());

	}
});

$('#filtre_facture [data-toggle="collapse"]').on('click', function () {
	if ($('#filtre_avances').css('display') === "none") {
		$(this).html($('#retract').val());

	} else {
		$(this).html($('#advancedFilters').val());

	}
});

$('#filtre_marche [data-toggle="collapse"]').on('click', function () {
	if ($('#filtre_avances').css('display') === "none") {
		$(this).html($('#retract').val());

	} else {
		$(this).html($('#advancedFilters').val());

	}
});

document.addEventListener('click', (event) => {
	var target = event.target;
	if (!(target instanceof HTMLElement)) return;
	if (!target.classList.contains('loupe')) return;


	var index = $(event.target).closest('tr').attr('id');

	if ($('#' + index + 'detail').hasClass('hide_detail')) {
		$('.detail_ligne').addClass('hide_detail');
		$('.loupe').removeClass('actif');
		$('table tr').removeAttr('style');
		$('#' + index + 'detail').removeAttr('style');
		$('.' + index + 'inter').removeAttr('style');
		$(event.target).addClass('actif')
		$('#' + index + 'detail').removeClass('hide_detail');
		$('#' + index).css({
			'border': '2px solid rgba(102, 175, 233,0.9)',
			'border-bottom': '0px',
			'border-top': '2px solid rgba(102, 175, 233,0.9)',
			'box-shadow': 'none'

		});

		$('.' + index + 'inter').css({
			'border': '2px solid rgba(102, 175, 233,0.9)',
			'border-bottom': '0px',
			'border-top': '0px',
			'box-shadow': 'none'

		});

		$('#' + index + 'detail').css({
			'background-color': 'rgba(74, 85, 107, 0.06)',
			'border': '2px solid rgba(102, 175, 233,0.9)',
			'border-top': '0px',
			'border-bottom': '2px solid rgba(102, 175, 233,0.9)',
			'box-shadow': 'none'
		});
	} else {
		$(event.target).removeClass('actif')
		hideTd(index);
	}
});

function hideTd(index)
{
	$('#' + index + 'detail').addClass('hide_detail');
	$('#' + index).removeAttr('style');
	$('#' + index + 'detail').removeAttr('style');
	$('.' + index + 'inter').removeAttr('style');

	$('#' + index).removeClass('entete_ligne_show');
	$('#' + index + 'detail').removeClass('detail_ligne_show');
}

function vueDetaile() {
	$('.detail_ligne').removeClass('hide_detail');
	$('.multiOpenDetail').addClass('actif');
}

function vueFerme() {
	$('.detail_ligne').addClass('hide_detail');
	$('.multiOpenDetail').removeClass('actif');
}

$('.multiOpenDetail').click(function () {
	var index = $(this).closest('tr').attr('id');

	if ($('#' + index + 'detail').hasClass('hide_detail')) {
		$(this).addClass('actif')
		$('#' + index + 'detail').removeClass('hide_detail');
	} else {
		$(this).removeClass('actif')
		$('#' + index + 'detail').addClass('hide_detail');

	}
});

function SSDetail(div, path, idDiv, data, params, idForm) {
	var ligneaffectation = $(div).closest('tr').attr('id');
	var ligneclass = $(div).closest('tr').attr('class');
	var step = $(ligneaffectation).closest('tr').next();
	var detailligneaffectation = $(div).closest('tr').next();

	if ($(detailligneaffectation).hasClass('hide_detail')) {
		if (path) {
			activeLoader();
			if (idForm != '' && params == '') {
				var data = $('#' + idForm).serialize();
			}
			else {
				var data = params;
			}

			$.ajax
				({
					url: path,
					type: 'POST',
					dataType: 'html',
					data: data,
					success: function (htmlData) {
						desactiveLoader();
						$('#' + idDiv).html(htmlData + "<script type='text/javascript' src='" + baseUrl + "js/parametre.js'></script>");

						index = idDiv.replace('detail', '');
					}
				});
		}
		$('.view-details').addClass('hide_detail');
		$('.ss_detail ').removeClass('actif');
		$(detailligneaffectation).removeClass('hide_detail');
		$('.view-details').removeAttr('style');
		$('table table tr').removeAttr('style');
		$(div).addClass('actif');
		$('#' + ligneaffectation).css({
			'border': '2px solid rgba(102, 175, 233,0.9)',
			'border-bottom': '0px',
			'border-top': '2px solid rgba(102, 175, 233,0.9)',
			'box-shadow': 'none'

		});
		$('#' + ligneaffectation + 'detail').css({
			'background-color': 'rgba(74, 85, 107, 0.06)',
			'border': '2px solid rgba(102, 175, 233,0.9)',
			'border-top': '0px',
			'border-bottom': '2px solid rgba(102, 175, 233,0.9)',
			'box-shadow': 'none'
		});
	} else {

		$(div).removeClass('actif')
		$('#' + ligneaffectation + 'detail').addClass('hide_detail');
		$(detailligneaffectation).addClass('hide_detail');
		$('#' + ligneaffectation).removeAttr('style');
		$('#' + ligneaffectation + 'detail').removeAttr('style');
	}
}



$('.switch input').click(function () {

	if ($(this).is(':checked') == true) {
		$(this).parent().find('.value_switch').text('Oui');
	} else {
		$(this).parent().find('.value_switch').text('Non');

	}

});

document.addEventListener('click', function (event) {
	let target = event.target;
	if (!(target instanceof HTMLElement)) return;

	let wrapSwitch = target.closest('.switchV2');
	if (wrapSwitch == null) return;

	let input = wrapSwitch.querySelector('input');
	wrapSwitch.querySelector('.value_switch').innerHTML =
		input.getAttribute(
			input.checked ?
				'data-oui' : 'data-non'
		);
});

$('#historique .voir_plus').click(function () {

	$('.autres_periodes').css('display', 'table-row');
	$('.cumul_periodes').hide();
	$(this).parent('.lignes_supplementaires').hide();

});

$('.ajouter_contact').click(function () {
	$('.contact_supplementaire').show();
});
$('.supprimer_contact').click(function () {
	$(this).parent().parent().hide();
});

/**** Multi accordeon ******/
if (multisidetabs === undefined) {
	var multisidetabs = (function () {
		var opt, parentid,
		vars = {
			listsub: '.list-sub',
			showclass: 'mg-show'
		},
		events = function () {
	
			document.addEventListener('click', (ev) => {
				if (!(ev.target instanceof HTMLElement)) return;
	
				// TODO : just mark the element with data-
				let parent = ev.target.closest('#'+parentid);
				if (parent == null) return; 
				let link = ev.target.closest('a');
				if (link == null) return; 
	
				ev.preventDefault();
				ev.stopPropagation();
				let atag = $(link);
				let childsub = atag.next(vars.listsub);
				//console.log(atag.text());
				if (childsub) {
					if (childsub.hasClass(vars.showclass)) {
						childsub.removeClass(vars.showclass).slideUp(500);
					} else {
						childsub.addClass(vars.showclass).slideDown(500);
					}
				}
			})
		},
		init = function (options) {//initials
			if (options) {
				opt = options;
				parentid = options.id;
				//test();
				events();
			} else { alert('no options'); }
		}
	
		return { init: init };
	})();
	
	multisidetabs.init({
		"id": "mg-multisidetabs",
	});
}



/* Popup Code Gestion : Treeview */

$(function () {

	var defaultData = [
		{
			text: 'Parent 1',
			href: '#parent1',
			tags: ['4'],
			nodes: [
				{
					text: 'Child 1',
					href: '#child1',
					tags: ['2'],
					nodes: [
						{
							text: 'Grandchild 1',
							href: '#grandchild1',
							tags: ['0']
						},
						{
							text: 'Grandchild 2',
							href: '#grandchild2',
							tags: ['0']
						}
					]
				},
				{
					text: 'Child 2',
					href: '#child2',
					tags: ['0']
				}
			]
		},
		{
			text: 'Parent 2',
			href: '#parent2',
			tags: ['0']
		},
		{
			text: 'Parent 3',
			href: '#parent3',
			tags: ['0']
		},
		{
			text: 'Parent 4',
			href: '#parent4',
			tags: ['0']
		},
		{
			text: 'Parent 5',
			href: '#parent5',
			tags: ['0']
		}
	];

	var alternateData = [
		{
			text: 'Parent 1',
			tags: ['2'],
			nodes: [
				{
					text: 'Child 1',
					tags: ['3'],
					nodes: [
						{
							text: 'Grandchild 1',
							tags: ['6']
						},
						{
							text: 'Grandchild 2',
							tags: ['3']
						}
					]
				},
				{
					text: 'Child 2',
					tags: ['3']
				}
			]
		},
		{
			text: 'Parent 2',
			tags: ['7']
		},
		{
			text: 'Parent 3',
			icon: 'glyphicon glyphicon-earphone',
			href: '#demo',
			tags: ['11']
		},
		{
			text: 'Parent 4',
			icon: 'glyphicon glyphicon-cloud-download',
			href: '/demo.html',
			tags: ['19'],
			selected: true
		},
		{
			text: 'Parent 5',
			icon: 'glyphicon glyphicon-certificate',
			color: 'pink',
			backColor: 'red',
			href: 'http://www.tesco.com',
			tags: ['available', '0']
		}
	];

	var json = '[' +
		'{' +
		'"text": "Parent 1",' +
		'"nodes": [' +
		'{' +
		'"text": "Child 1",' +
		'"nodes": [' +
		'{' +
		'"text": "Grandchild 1"' +
		'},' +
		'{' +
		'"text": "Grandchild 2"' +
		'}' +
		']' +
		'},' +
		'{' +
		'"text": "Child 2"' +
		'}' +
		']' +
		'},' +
		'{' +
		'"text": "Parent 2"' +
		'},' +
		'{' +
		'"text": "Parent 3"' +
		'},' +
		'{' +
		'"text": "Parent 4"' +
		'},' +
		'{' +
		'"text": "Parent 5"' +
		'}' +
		']';



	$('#treeview6').treeview({
		color: "#428bca",
		expandIcon: "glyphicon glyphicon-plus",
		collapseIcon: "glyphicon glyphicon-minus",
		nodeIcon: "glyphicon glyphicon-eye-close",
		showTags: true,
		//  data: defaultData
	});




	var $searchableTree = $('#treeview-searchable').treeview({
		data: defaultData,
	});

	var search = function (e) {
		var pattern = $('#input-search').val();
		var options = {
			ignoreCase: $('#chk-ignore-case').is(':checked'),
			exactMatch: $('#chk-exact-match').is(':checked'),
			revealResults: $('#chk-reveal-results').is(':checked')
		};
		var results = $searchableTree.treeview('search', [pattern, options]);

		var output = '<p>' + results.length + ' matches found</p>';
		$.each(results, function (index, result) {
			output += '<p>- ' + result.text + '</p>';
		});
		$('#search-output').html(output);
	}

	$('#btn-search').on('click', search);
	$('#input-search').on('keyup', search);

	$('#btn-clear-search').on('click', function (e) {
		$searchableTree.treeview('clearSearch');
		$('#input-search').val('');
		$('#search-output').html('');
	});


	var initSelectableTree = function () {
		return $('#treeview-selectable').treeview({
			data: defaultData,
			multiSelect: $('#chk-select-multi').is(':checked'),
			onNodeSelected: function (event, node) {
				$('#selectable-output').prepend('<p>' + node.text + ' was selected</p>');
			},
			onNodeUnselected: function (event, node) {
				$('#selectable-output').prepend('<p>' + node.text + ' was unselected</p>');
			}
		});
	};
	var $selectableTree = initSelectableTree();

	var findSelectableNodes = function () {
		return $selectableTree.treeview('search', [$('#input-select-node').val(), { ignoreCase: false, exactMatch: false }]);
	};
	var selectableNodes = findSelectableNodes();

	$('#chk-select-multi:checkbox').on('change', function () {
		//          console.log('multi-select change');
		$selectableTree = initSelectableTree();
		selectableNodes = findSelectableNodes();
	});

	// Select/unselect/toggle nodes
	$('#input-select-node').on('keyup', function (e) {
		selectableNodes = findSelectableNodes();
		$('.select-node').prop('disabled', !(selectableNodes.length >= 1));
	});

	$('#btn-select-node.select-node').on('click', function (e) {
		$selectableTree.treeview('selectNode', [selectableNodes, { silent: $('#chk-select-silent').is(':checked') }]);
	});

	$('#btn-unselect-node.select-node').on('click', function (e) {
		$selectableTree.treeview('unselectNode', [selectableNodes, { silent: $('#chk-select-silent').is(':checked') }]);
	});

	$('#btn-toggle-selected.select-node').on('click', function (e) {
		$selectableTree.treeview('toggleNodeSelected', [selectableNodes, { silent: $('#chk-select-silent').is(':checked') }]);
	});



	var $expandibleTree = $('#treeview-expandible').treeview({
		data: defaultData,
		onNodeCollapsed: function (event, node) {
			$('#expandible-output').prepend('<p>' + node.text + ' was collapsed</p>');
		},
		onNodeExpanded: function (event, node) {
			$('#expandible-output').prepend('<p>' + node.text + ' was expanded</p>');
		}
	});

	var findExpandibleNodess = function () {
		return $expandibleTree.treeview('search', [$('#input-expand-node').val(), { ignoreCase: false, exactMatch: false }]);
	};
	var expandibleNodes = findExpandibleNodess();

	// Expand/collapse/toggle nodes
	$('#input-expand-node').on('keyup', function (e) {
		expandibleNodes = findExpandibleNodess();
		$('.expand-node').prop('disabled', !(expandibleNodes.length >= 1));
	});

	$('#btn-expand-node.expand-node').on('click', function (e) {
		var levels = $('#select-expand-node-levels').val();
		$expandibleTree.treeview('expandNode', [expandibleNodes, { levels: levels, silent: $('#chk-expand-silent').is(':checked') }]);
	});

	$('#btn-collapse-node.expand-node').on('click', function (e) {
		$expandibleTree.treeview('collapseNode', [expandibleNodes, { silent: $('#chk-expand-silent').is(':checked') }]);
	});

	$('#btn-toggle-expanded.expand-node').on('click', function (e) {
		$expandibleTree.treeview('toggleNodeExpanded', [expandibleNodes, { silent: $('#chk-expand-silent').is(':checked') }]);
	});

	// Expand/collapse all
	$('#btn-expand-all').on('click', function (e) {
		var levels = $('#select-expand-all-levels').val();
		$expandibleTree.treeview('expandAll', { levels: levels, silent: $('#chk-expand-silent').is(':checked') });
	});

	$('#btn-collapse-all').on('click', function (e) {
		$expandibleTree.treeview('collapseAll', { silent: $('#chk-expand-silent').is(':checked') });
	});



	var $checkableTree = $('#treeview-checkable').treeview({
		data: defaultData,
		showIcon: false,
		showCheckbox: true,
		onNodeChecked: function (event, node) {
			$('#checkable-output').prepend('<p>' + node.text + ' was checked</p>');
		},
		onNodeUnchecked: function (event, node) {
			$('#checkable-output').prepend('<p>' + node.text + ' was unchecked</p>');
		}
	});

	var findCheckableNodess = function () {
		return $checkableTree.treeview('search', [$('#input-check-node').val(), { ignoreCase: false, exactMatch: false }]);
	};
	var checkableNodes = findCheckableNodess();

	// Check/uncheck/toggle nodes
	$('#input-check-node').on('keyup', function (e) {
		checkableNodes = findCheckableNodess();
		$('.check-node').prop('disabled', !(checkableNodes.length >= 1));
	});

	$('#btn-check-node.check-node').on('click', function (e) {
		$checkableTree.treeview('checkNode', [checkableNodes, { silent: $('#chk-check-silent').is(':checked') }]);
	});

	$('#btn-uncheck-node.check-node').on('click', function (e) {
		$checkableTree.treeview('uncheckNode', [checkableNodes, { silent: $('#chk-check-silent').is(':checked') }]);
	});

	$('#btn-toggle-checked.check-node').on('click', function (e) {
		$checkableTree.treeview('toggleNodeChecked', [checkableNodes, { silent: $('#chk-check-silent').is(':checked') }]);
	});

	// Check/uncheck all
	$('#btn-check-all').on('click', function (e) {
		$checkableTree.treeview('checkAll', { silent: $('#chk-check-silent').is(':checked') });
	});

	$('#btn-uncheck-all').on('click', function (e) {
		$checkableTree.treeview('uncheckAll', { silent: $('#chk-check-silent').is(':checked') });
	});



	var $disabledTree = $('#treeview-disabled').treeview({
		data: defaultData,
		onNodeDisabled: function (event, node) {
			$('#disabled-output').prepend('<p>' + node.text + ' was disabled</p>');
		},
		onNodeEnabled: function (event, node) {
			$('#disabled-output').prepend('<p>' + node.text + ' was enabled</p>');
		},
		onNodeCollapsed: function (event, node) {
			$('#disabled-output').prepend('<p>' + node.text + ' was collapsed</p>');
		},
		onNodeUnchecked: function (event, node) {
			$('#disabled-output').prepend('<p>' + node.text + ' was unchecked</p>');
		},
		onNodeUnselected: function (event, node) {
			$('#disabled-output').prepend('<p>' + node.text + ' was unselected</p>');
		}
	});

	var findDisabledNodes = function () {
		return $disabledTree.treeview('search', [$('#input-disable-node').val(), { ignoreCase: false, exactMatch: false }]);
	};
	var disabledNodes = findDisabledNodes();

	// Expand/collapse/toggle nodes
	$('#input-disable-node').on('keyup', function (e) {
		disabledNodes = findDisabledNodes();
		$('.disable-node').prop('disabled', !(disabledNodes.length >= 1));
	});

	$('#btn-disable-node.disable-node').on('click', function (e) {
		$disabledTree.treeview('disableNode', [disabledNodes, { silent: $('#chk-disable-silent').is(':checked') }]);
	});

	$('#btn-enable-node.disable-node').on('click', function (e) {
		$disabledTree.treeview('enableNode', [disabledNodes, { silent: $('#chk-disable-silent').is(':checked') }]);
	});

	$('#btn-toggle-disabled.disable-node').on('click', function (e) {
		$disabledTree.treeview('toggleNodeDisabled', [disabledNodes, { silent: $('#chk-disable-silent').is(':checked') }]);
	});

	// Expand/collapse all
	$('#btn-disable-all').on('click', function (e) {
		$disabledTree.treeview('disableAll', { silent: $('#chk-disable-silent').is(':checked') });
	});

	$('#btn-enable-all').on('click', function (e) {
		$disabledTree.treeview('enableAll', { silent: $('#chk-disable-silent').is(':checked') });
	});



});


/* filtre dynamique table */
/**
 * filtre : 
	<div id="filter_dynamique">
	  <input name="filter_search" class="NOM_DU_FILTRE form-control form-control-sm " type="text" />
	</div>
    
	Mettre la class filter_Dynamique dans le TR ou DIV à afficher ou cacher selon la recherche
    
	et mettre NOM_DU_FILTRE dans le TD ou DIV ou effectuer la recherche
 */


var $rows = $('.filter_Dynamique');
var $filters = $('#filter_dynamique input');

$filters.on("keyup", function () {
	var $i = $filters.filter(function () {
		return $.trim(this.value).length > 0;
	}),
		len = $i.length;

	if (len === 0) return $rows.show();

	var cls = '.' + $i.map(function () {
		var classFilter;

		for (var i = 0; i < this.classList.length; i++) {
			var value = this.classList[i];
			if (value.substr(0, 7) == 'filter_') {
				classFilter = value;
			}
		}

		return classFilter;
	}).get().join(',.');

	$rows.hide().filter(function () {
		return $('td, div', this).filter(cls).filter(function () {
			var classFilter;
			for (var i = 0; i < this.classList.length; i++) {
				var value = this.classList[i];
				if (value.substr(0, 7) == 'filter_') {
					classFilter = value;
				}
			}

			var content = this.textContent.toUpperCase();
			var inputVal = $i.filter('.' + classFilter).val();

			return content.indexOf(inputVal.toUpperCase()) > -1;

		}).length === len;
	}).show();
});