sk-hasil-belajar can only be printed once, prevented to be printed multiple times, error texts will be removed on retry
This commit is contained in:
60
resources/js/components/SKHasilBelajar.js
vendored
60
resources/js/components/SKHasilBelajar.js
vendored
@@ -34,6 +34,10 @@ var component = {
|
||||
usbn: [],
|
||||
unbk: [],
|
||||
},
|
||||
// This prop is to prevent double dialog when printing,
|
||||
// caused by the print button's confirm()
|
||||
// and the beforeprint's alert()
|
||||
confirmPrint: 0,
|
||||
view: () => {
|
||||
component.rataRata = {
|
||||
raport: [],
|
||||
@@ -93,6 +97,7 @@ var component = {
|
||||
: m('button.print-button', {
|
||||
onclick: () => {
|
||||
if (confirm('Surat Keterangan ini hanya dapat dicetak satu kali. Lanjutkan?')) {
|
||||
component.confirmPrint = 1;
|
||||
AccessLog.create({siswaId: Siswa.current.id, src: 'sk-hasil-belajar'}).then(() => {
|
||||
AccessLog.fetch('sk-hasil-belajar');
|
||||
window.print();
|
||||
@@ -265,7 +270,7 @@ var component = {
|
||||
]);
|
||||
})),
|
||||
m('tr', [
|
||||
m('th', 'A.'),
|
||||
m('th', 'B.'),
|
||||
m('th[colspan=5].text-left', 'Adaptif'),
|
||||
]),
|
||||
m('tbody.counter',
|
||||
@@ -282,7 +287,7 @@ var component = {
|
||||
]);
|
||||
}),
|
||||
m('tr', [
|
||||
m('th', 'A.'),
|
||||
m('th', 'C.'),
|
||||
m('th[colspan=5].text-left', 'Produktif'),
|
||||
])),
|
||||
m('tbody.counter',
|
||||
@@ -299,7 +304,7 @@ var component = {
|
||||
]);
|
||||
})),
|
||||
m('tr', [
|
||||
m('th', 'A.'),
|
||||
m('th', 'D.'),
|
||||
m('th[colspan=5].text-left', 'Mulok'),
|
||||
]),
|
||||
m('tbody.counter',
|
||||
@@ -345,4 +350,53 @@ var component = {
|
||||
},
|
||||
};
|
||||
|
||||
// Below is to handle Ctrl+P or MouseR->Print
|
||||
window.addEventListener("beforeprint", function () {
|
||||
// If the print button did not exists, show nothing when printing
|
||||
if (document.body.querySelector('button.print-button') === null)
|
||||
document.body.style.display = 'none';
|
||||
else {
|
||||
if (!component.confirmPrint) {
|
||||
alert('Surat Keterangan ini hanya dapat dicetak satu kali. Lanjutkan?');
|
||||
component.confirmPrint = 1;
|
||||
AccessLog.create({siswaId: Siswa.current.id, src: 'sk-hasil-belajar'}).then(() => {
|
||||
AccessLog.fetch('sk-hasil-belajar');
|
||||
})
|
||||
.catch(e => {
|
||||
if (e.code === 0) {
|
||||
AccessLog.error = {
|
||||
message: e.message,
|
||||
errors: {
|
||||
create: ['Terjadi kesalahan saat menghubungkan ke server.'],
|
||||
},
|
||||
};
|
||||
}
|
||||
else {
|
||||
AccessLog.error = JSON.parse(e.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("afterprint", function () {
|
||||
// Give back the whole document.body
|
||||
if (document.body.querySelector('button.print-button') === null)
|
||||
document.body.style.display = 'block';
|
||||
|
||||
// Hide the print button
|
||||
if (document.body.querySelector('button.print-button') !== null)
|
||||
document.body.querySelector('button.print-button').style.display = 'none';
|
||||
|
||||
// To redraw the content to prevent printing
|
||||
let nisn = document.body.querySelector('input[name=nisn]').value,
|
||||
tanggalLahir = document.body.querySelector('input[name=tanggalLahir]').value;
|
||||
Siswa.cariData({
|
||||
nisn,
|
||||
tanggalLahir,
|
||||
src: 'sk-hasil-belajar',
|
||||
with: ['hasilBelajar', 'accessLog'],
|
||||
});
|
||||
});
|
||||
|
||||
export default component;
|
||||
|
||||
Reference in New Issue
Block a user