Files
backend/public/dist/js/cmms.js
2024-02-01 09:53:53 +00:00

306 lines
12 KiB
JavaScript

var table ;
function showLoaderScreen() {
$(".starter-loader-container").css("display", "flex").hide().fadeIn();
}
function hideLoaderScreen() {
$(".starter-loader-container").fadeOut();
}
$(document).ready(function () {
console.log("start")
showLoaderScreen()
$.ajax({
url: '/public/cmms-download',
type: 'GET',
success: function(data) {
JSZipUtils.getBinaryContent('/storage/cmms.zip', function(err, data) {
if(err) {
throw err; // or handle err
}
JSZip.loadAsync(data).then(function (zip) {
// console.log(zip.files)
// zip.forEach(function (relativePath, zipEntry) {
// console.log(zipEntry.name)
// });
var x = [];
zip.file("cmms.json").async("text").then(function (qqq) {
hideLoaderScreen()
var z = JSON.parse(qqq)
console.log('qqq', z.data)
///// start data table
// fail;
console.log('yes')
table = $("#example").DataTable({
dom: "lBfrtip",
pagingType: "full_numbers",
language: {
sEmptyTable: "هیچ داده‌ای در جدول وجود ندارد",
sInfo: "نمایش _START_ تا _END_ از _TOTAL_ ردیف",
sInfoEmpty: "نمایش 0 تا 0 از 0 ردیف",
sInfoFiltered: "(فیلتر شده از _MAX_ ردیف)",
sInfoPostFix: "",
sInfoThousands: ",",
sLengthMenu: "نمایش _MENU_ ردیف",
sLoadingRecords: "در حال بارگزاری...",
sProcessing: "در حال پردازش...",
sSearch: "جستجو / فیلتر: ",
sZeroRecords: "رکوردی با این مشخصات پیدا نشد",
oPaginate: {
sFirst: "برگه‌ی نخست",
sLast: "برگه‌ی آخر",
sNext: "بعدی",
sPrevious: "قبلی",
},
oAria: {
sSortAscending: ": فعال سازی نمایش به صورت صعودی",
sSortDescending: ": فعال سازی نمایش به صورت نزولی",
},
},
scrollX: true,
orderCellsTop: true,
fixedHeader: true,
order: [[0, "asc"][(1, "asc")], [2, "desc"], [3, "desc"], [4, "desc"]],
order: [[0, "desc"]],
processing: true,
select: true,
destroy: true,
data: z.data,
// ajax: {
// url: "/public/cmms-down",
// type: "GET",
// dataSrc: function (json) {
// // console.log("ttt" , json.data)
// console.log("hi")
// console.log(json)
// var new_zip = new JSZip();
// // more files !
// new_zip.loadAsync(json)
// .then(function(zip) {
// // you now have every files contained in the loaded zip
// // zip.file("hello.txt").async("string"); // a promise of "Hello World\n"
// console.log("zip", zip)
// });
// // return json.data;
// },
// },
buttons: [
{
extend: "excelHtml5",
title: "Excel",
text: "خروجی به اکسل",
messageTop: "بانک ماشین آلات",
},
],
initComplete: function () {
this.api().columns([2]).every(function () {
$('.mythead .showfilter th:eq(2)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(2)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
this.api().columns([3]).every(function () {
$('.mythead .showfilter th:eq(3)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(3)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
this.api().columns([4]).every(function () {
$('.mythead .showfilter th:eq(4)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(4)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
this.api().columns([8]).every(function () {
$('.mythead .showfilter th:eq(8)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(8)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
this.api().columns([14]).every(function () {
$('.mythead .showfilter th:eq(14)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(14)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
this.api().columns([18]).every(function () {
$('.mythead .showfilter th:eq(18)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(18)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
this.api().columns([19]).every(function () {
$('.mythead .showfilter th:eq(19)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(19)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
this.api().columns([23]).every(function () {
$('.mythead .showfilter th:eq(23)').empty();
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo('.mythead .showfilter th:eq(23)')
.on('change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search(val ? '^' + val + '$' : '', true, false)
.draw();
});
column.data().unique().sort().each(function (d, j) {
select.append('<option value="' + d + '">' + d + '</option>')
});
});
$("#kalakrashti").click();
// $("#example thead tr:eq(0) th:eq(0)").on("load" , function(
// $("#example thead tr:eq(0) th:eq(0)").click();
// ))
}
// }
});
///// end data table
});
});
});
}
});
console.log("end")
})
// $('.mythead tr').clone(true).appendTo( '.mythead' );
$('.mythead .showfilter th').each( function (i) {
if (i!=2 && i!=3 && i!=4 && i!=8 && i!=14 && i!=18 && i!=19 && i!=23) {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="'+title+'" />' );
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table
.column(i)
.search( this.value )
.draw();
}
} );
}
} );