190 lines
6.2 KiB
JavaScript
190 lines
6.2 KiB
JavaScript
|
|
/*jshint esversion: 6 */
|
||
|
|
|
||
|
|
$(document).ready(function () {
|
||
|
|
$.tablesorter.addParser({
|
||
|
|
id: "production_date",
|
||
|
|
is: function () {
|
||
|
|
return false;
|
||
|
|
},
|
||
|
|
format: function (s, table, cell) {
|
||
|
|
return $(cell).find("input[id^=production-date]").val() || "1970-01-01";
|
||
|
|
},
|
||
|
|
parsed: false,
|
||
|
|
type: "text"
|
||
|
|
});
|
||
|
|
$("#allTable").tablesorter({
|
||
|
|
sortList: [[3, 1]],
|
||
|
|
theme: "blue",
|
||
|
|
widthFixed: true,
|
||
|
|
widgets: ["filter", "zebra", "stickyHeaders"],
|
||
|
|
fixedWidth: true,
|
||
|
|
widgetOptions: {
|
||
|
|
resizable: false,
|
||
|
|
filter_formatter: {
|
||
|
|
7: function (cell, index) {
|
||
|
|
return $.tablesorter.filterFormatter.select2(cell, index, {
|
||
|
|
match: true
|
||
|
|
});
|
||
|
|
},
|
||
|
|
8: function (cell, index) {
|
||
|
|
return $.tablesorter.filterFormatter.select2(cell, index, {
|
||
|
|
match: true
|
||
|
|
});
|
||
|
|
},
|
||
|
|
9: function (cell, index) {
|
||
|
|
return $.tablesorter.filterFormatter.select2(cell, index, {
|
||
|
|
match: true
|
||
|
|
});
|
||
|
|
},
|
||
|
|
10: function (cell, index) {
|
||
|
|
return $.tablesorter.filterFormatter.select2(cell, index, {
|
||
|
|
match: true
|
||
|
|
});
|
||
|
|
},
|
||
|
|
12: function (cell, index) {
|
||
|
|
return $.tablesorter.filterFormatter.select2(cell, index, {
|
||
|
|
match: true
|
||
|
|
});
|
||
|
|
},
|
||
|
|
13: function (cell, index) {
|
||
|
|
return $.tablesorter.filterFormatter.select2(cell, index, {
|
||
|
|
match: true
|
||
|
|
});
|
||
|
|
},
|
||
|
|
},
|
||
|
|
filter_functions: {
|
||
|
|
3: function (e, f, i) {
|
||
|
|
return f.includes(i);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
},
|
||
|
|
headers: {
|
||
|
|
3: { sorter: "production_date" },
|
||
|
|
},
|
||
|
|
});
|
||
|
|
$("#duplicateBtn").click(() => duplicatePositions());
|
||
|
|
$("#deleteBtn").click(() => { removePositions(); });
|
||
|
|
$("#excelBtn").click(() => { exportExcel(); });
|
||
|
|
$("#pdfBtn").click(() => { window.alert("In progress."); });
|
||
|
|
$("#productionBtn").click(() => { window.alert("In progress."); });
|
||
|
|
});
|
||
|
|
|
||
|
|
function editQty(id) {
|
||
|
|
$("#edit-" + id).css("display", "none");
|
||
|
|
$("#qty-" + id).css("display", "none");
|
||
|
|
$("#qtyInput-" + id).css("display", "inline");
|
||
|
|
$("#qtyInput-" + id).select();
|
||
|
|
$("#save-" + id).css("display", "inline-block");
|
||
|
|
}
|
||
|
|
function saveQty(id) {
|
||
|
|
showLoader("Trwa aktualizacja...");
|
||
|
|
$("#edit-" + id).css("display", "inline-block");
|
||
|
|
$("#qty-" + id).css("display", "inline");
|
||
|
|
$("#qtyInput-" + id).css("display", "none");
|
||
|
|
$("#save-" + id).css("display", "none");
|
||
|
|
$.ajax({
|
||
|
|
method: "get",
|
||
|
|
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=saveQty&id=" + id + "&qty=" + $("#qtyInput-" + id).val(),
|
||
|
|
success: function () {
|
||
|
|
$("#qty-" + id).html($("#qtyInput-" + id).val());
|
||
|
|
hideLoader();
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function duplicatePositions() {
|
||
|
|
var ids = [];
|
||
|
|
$("input.allCheck:checkbox:checked").each(function () {
|
||
|
|
ids.push($(this).val());
|
||
|
|
});
|
||
|
|
if (ids.length === 0) {
|
||
|
|
window.alert("Wybierz pozycje zamówień");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var userResponse = window.confirm("Zduplikować pozycje?");
|
||
|
|
if (!userResponse) { return; }
|
||
|
|
showLoader("Duplikowanie...");
|
||
|
|
$.ajax({
|
||
|
|
method: "get",
|
||
|
|
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=duplicatePositions&ids=" + ids.join("|"),
|
||
|
|
success: function () {
|
||
|
|
window.location.reload();
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function removePositions() {
|
||
|
|
var ids = [];
|
||
|
|
$("input.allCheck:checkbox:checked").each(function () {
|
||
|
|
ids.push($(this).val());
|
||
|
|
});
|
||
|
|
if (ids.length === 0) {
|
||
|
|
window.alert("Wybierz pozycje zamówień");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var userResponse = window.confirm("Usunąć pozycje?");
|
||
|
|
if (!userResponse) { return; }
|
||
|
|
showLoader("Usuwanie...");
|
||
|
|
$.ajax({
|
||
|
|
method: "get",
|
||
|
|
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=removePositions&ids=" + ids.join("|"),
|
||
|
|
success: function ()
|
||
|
|
{
|
||
|
|
window.location.reload();
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function saveProductionDate(id) {
|
||
|
|
$.ajax({
|
||
|
|
method: "get",
|
||
|
|
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=saveProductionDate&id=" + id + "&date=" + $("#production-date-" + id).val(),
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function editDescription(id) {
|
||
|
|
$("#edit-description-" + id).css("display", "none");
|
||
|
|
$("#description-" + id).css("display", "none");
|
||
|
|
$("#descriptionInput-" + id).css("display", "inline");
|
||
|
|
$("#descriptionInput-" + id).select();
|
||
|
|
$("#save-description-" + id).css("display", "inline-block");
|
||
|
|
}
|
||
|
|
function saveDescription(id) {
|
||
|
|
$("#edit-description-" + id).css("display", "inline-block");
|
||
|
|
$("#description-" + id).css("display", "inline");
|
||
|
|
$("#descriptionInput-" + id).css("display", "none");
|
||
|
|
$("#save-description-" + id).css("display", "none");
|
||
|
|
$.ajax({
|
||
|
|
method: "get",
|
||
|
|
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=saveProductDescription&id=" + id + "&description=" + $("#descriptionInput-" + id).val(),
|
||
|
|
success: function (data) {
|
||
|
|
$("#description-" + id).html($("#descriptionInput-" + id).val());
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function showLoader(msg = "Pobieranie danych") {
|
||
|
|
$.blockUI({
|
||
|
|
css: {
|
||
|
|
border: "none",
|
||
|
|
padding: "15px",
|
||
|
|
backgroundColor: "#000",
|
||
|
|
"-webkit-border-radius": "10px",
|
||
|
|
"-moz-border-radius": "10px",
|
||
|
|
opacity: 0.5,
|
||
|
|
"font-weight": "bold",
|
||
|
|
"font-size": "16px",
|
||
|
|
color: "#fff",
|
||
|
|
},
|
||
|
|
message: msg
|
||
|
|
});
|
||
|
|
}
|
||
|
|
function hideLoader() {
|
||
|
|
$.unblockUI();
|
||
|
|
}
|
||
|
|
function exportExcel() {
|
||
|
|
showLoader("Generowanie pliku...");
|
||
|
|
$.ajax({
|
||
|
|
method: "get",
|
||
|
|
url: $(location).attr("href") + "&to_pdf=1&ajaxAction=exportExcel",
|
||
|
|
success: function (data)
|
||
|
|
{
|
||
|
|
window.console.log(data);
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|