jQuery(document).ready(function () {
custom_switch_merchants();
initLcSortableList();
initLcCkEditor();
initLcSortableProductsList();
initLcSortableList();
initDataTable();
initAdminLtePlugin();
//generateNotice('error', 'Ceci est une notice');
});
function initLcNoty() {
$('.lc-noty').each(function () {
generateNotice($(this).data('type'), $(this).html());
});
}
function initAdminLtePlugin(){
$('[data-toggle="tooltip"]').tooltip()
if($('.select2, select.form-control').length) {
$('form select.form-control').each(function (i, elm) {
myselect = $(elm).select2({
//theme: 'bootstrap',
//width: "100%",
dropdownAutoWidth: false,
placeholder: "Select an option"
});
myselect.on('select2:select', function (e) {
var event = new Event('change');
e.target.dispatchEvent(event);
});
});
}
if($('.select2-no-search').length) {
$('.select2-no-search').select2({
minimumResultsForSearch: Infinity
});
}
}
function custom_switch_merchants() {
$('#switch-merchant select').change(function () {
$('#switch-merchant form').submit();
});
}
function initLcSortableProductsList() {
if ($('.lc-sortable-products').length > 0) {
$('.lc-sortable-products tbody').sortable({
placeholder: "ui-state-highlight"
});
$('.lc-sortable-products tbody').on("sortupdate", function (event, ui) {
updateSortableProducts();
});
}
}
function updateSortableProducts() {
if ($('.lc-sortable-products').length > 0) {
$('.lc-sortable-products tr.lc-draggable').each(function (index, li) {
$(li).find('.field-position').val(index);
});
}
}
function initLcSortableList() {
if ($('.lc-sortable').length > 0) {
$('.lc-sortable tbody').sortable({
placeholder: "ui-state-highlight"
});
$('.lc-sortable tbody').on("sortupdate", function (event, ui) {
prototype = $('#form_entities').data('prototype');
$('.lc-sortable tr.lc-draggable').each(function (index, li) {
// instead be a number based on how many items we have
var newForm = prototype.replace(/__name__/g, index);
// Replace '__name__' in the prototype's HTML to
$(li).find('div:last-child').remove();
$(li).append(newForm);
$(li).find('#form_entities_' + index + '_id').val($(li).data('id'));
if ($('.lc-sortable').data('parent-position') !== '') val = $('.lc-sortable').data('parent-position') + '_' + index
else val = index;
log($(li).find('#form_entities_' + index + '_position'));
$(li).find('#form_entities_' + index + '_position').val(val);
});
});
}
}
function initDataTable() {
$(".checkbox-switch input").each(function(){
$(this).bootstrapSwitch('state', $(this).prop('checked'));
});
if ($(".table.datatable-simple").length > 0) {
//$(".table.datatable-simple thead tr").clone(true).appendTo( '.table.datatable-simple tfoot' );
$(".table.datatable-simple thead tr").clone(true).appendTo('.table.datatable-simple thead');
$(".table.datatable-simple thead tr:eq(1) th").each(function (i) {
if ($(this).data('searchable') == "input") {
var title = $(this).text();
var cssClass = '';
if($(this).text().trim().toLowerCase() =='id')cssClass = 'small'
$(this).html('');
$('input', this).on('keyup change', function () {
if(this.value === "") {
$('.table.datatable-simple thead tr:eq(0) th:eq(' + i + ')').removeClass('filtered')
}else{
$('.table.datatable-simple thead tr:eq(0) th:eq('+i+')').addClass('filtered')
}
if (table.column(i).search() !== this.value) {
table
.column(i)
.search(this.value)
.draw();
var searchVal = this.value;
var body = $( table.table().body() );
body.unhighlight();
body.highlight(searchVal);
}
});
} else if ($(this).data('searchable') == 'select' ){
$(this).html(''); //LC_TRAD
} else if ($(this).data('searchable') == 'select-text') {
$(this).html(''); //LC_TRAD
} else if ($(this).data('searchable') == 'toggle') {
$(this).html(''); //LC_TRAD
} else {
$(this).html('')
}
});
var table = $(".table.datatable-simple").DataTable({
orderCellsTop: true,
fixedHeader: {
header: true,
headerOffset: $('.main-header').outerHeight(),
},
paging: true,
//responsive: true,
initComplete: function () {
this.api().columns().every( function (i) {
var column = this;
var select = false;
toggle = $('.table.datatable-simple thead tr:eq(1) th:eq('+i+') select.toggle')
if(toggle.length) {
toggle.select2({
'placeholder': 'Filtrer'//LC_TRAD['search']
});
toggle.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex($(this).val());
if(val=="all"){
column.search('').draw();
}else {
var niche = table.column('2');
log(column.cell('4').data());
/*
val = "bootstrap-switch-on";
column.data().each(function(d){
log(d)
});
//filter in column 5, with an regex, no smart filtering, not case sensitive
column.search( val ? '^'+val+'$' : '', true, false ).draw();*/
}
} );
}
if($('.table.datatable-simple thead tr:eq(1) th:eq('+i+') select.list-text').length) {
select = $('.table.datatable-simple thead tr:eq(1) th:eq(' + i + ') select.list-text');
}
if(select.length) {
column.data().unique().sort().each(function (d, j) {
values = d.split('\n');
for(k=0; k< values.length; k++) {
val = values[k];
select.append('')
}
});
}
if(!select) select = $('.table.datatable-simple thead tr:eq(1) th:eq('+i+') select.list')
if(select.length) {
column.data().unique().sort().each(function (d, j) {
$(d).each(function (k, val) {
select.append('')
});
});
select.select2({
'placeholder': 'Filtrer'//LC_TRAD['search']
});
select.on( 'change', function () {
var val = $(this).val();
if(val=="all"){
$('.table.datatable-simple thead tr:eq(0) th:eq('+i+')').removeClass('filtered')
column.search('').draw();
}else {
log($(this).val());
$('.table.datatable-simple thead tr:eq(0) th:eq('+i+')').addClass('filtered')
column.search(val, false).draw();
}
} );
}
} );
},
language: {
"sEmptyTable": "Aucune donnée disponible dans le tableau",
"sInfo": "Affichage de l'élément _START_ à _END_ sur _TOTAL_ éléments",
"sInfoEmpty": "Affichage de l'élément 0 à 0 sur 0 élément",
"sInfoFiltered": "(filtré à partir de _MAX_ éléments au total)",
"sInfoPostFix": "",
"sInfoThousands": ",",
"sLengthMenu": "Afficher _MENU_ éléments",
"sLoadingRecords": "Chargement...",
"sProcessing": "Traitement...",
"sSearch": "Rechercher :",
"sZeroRecords": "Aucun élément correspondant trouvé",
"oPaginate": {
"sFirst": "Premier",
"sLast": "Dernier",
"sNext": "Suivant",
"sPrevious": "Précédent"
},
"oAria": {
"sSortAscending": ": activer pour trier la colonne par ordre croissant",
"sSortDescending": ": activer pour trier la colonne par ordre décroissant"
},
"select": {
"rows": {
"_": "%d lignes sélectionnées",
"0": "Aucune ligne sélectionnée",
"1": "1 ligne sélectionnée"
}
}
},
});
}
}