Fixed conflict between components
This commit is contained in:
56
resources/js/app.js
vendored
56
resources/js/app.js
vendored
@@ -1,9 +1,65 @@
|
||||
import m from "mithril"
|
||||
import SuratKelulusan from "./components/SuratKelulusan"
|
||||
import SKHasilBelajar from "./components/SKHasilBelajar"
|
||||
import Siswa from "./models/Siswa"
|
||||
import AccessLog from "./models/AccessLog"
|
||||
|
||||
m.route.prefix('#');
|
||||
m.route(document.body.querySelector('.container'), '/', {
|
||||
'/': SuratKelulusan,
|
||||
'/hasil-belajar': SKHasilBelajar,
|
||||
});
|
||||
|
||||
// Below is to handle Ctrl+P or MouseR->Print
|
||||
window.addEventListener("beforeprint", function () {
|
||||
if (m.route.get() === '/hasil-belajar') {
|
||||
// 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 () {
|
||||
if (m.route.get() === '/hasil-belajar') {
|
||||
// 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'],
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
50
resources/js/components/SKHasilBelajar.js
vendored
50
resources/js/components/SKHasilBelajar.js
vendored
@@ -6,6 +6,7 @@ import AccessLog from "../models/AccessLog"
|
||||
|
||||
var component = {
|
||||
oninit: () => {
|
||||
Siswa.current = {},
|
||||
AccessLog.fetch('sk-hasil-belajar');
|
||||
},
|
||||
namaMapel: {
|
||||
@@ -350,53 +351,4 @@ 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;
|
||||
|
||||
1
resources/js/components/SuratKelulusan.js
vendored
1
resources/js/components/SuratKelulusan.js
vendored
@@ -5,6 +5,7 @@ import AccessLog from "../models/AccessLog"
|
||||
|
||||
var component = {
|
||||
oninit: () => {
|
||||
Siswa.current = {};
|
||||
AccessLog.fetch('surat-kelulusan');
|
||||
},
|
||||
view: () => {
|
||||
|
||||
Reference in New Issue
Block a user