Improved error information to client on both surat-kelulusan and sk-hasil-belajar

This commit is contained in:
Gregorio Chiko Putra
2019-05-16 09:30:36 +07:00
parent 5839165531
commit 30a93871e5
7 changed files with 90 additions and 35 deletions

View File

@@ -1,9 +1,3 @@
/*
* TODO
*
* - Buat pesan error print
*/
import m from "mithril"
import _isEmpty from "lodash.isempty"
import _map from "lodash.map"
@@ -55,7 +49,7 @@ var component = {
' / ',
AccessLog.current.total,
]),
' siswa yang telah melihat surat keterangan hasil belajar.'
' siswa yang telah mencetak surat keterangan hasil belajar.'
]),
m('h1.title', 'Surat Keterangan Hasil Belajar Siswa SMK Bhakti Anindya'),
m('span', 'Silahkan masukkan Nama Lengkap dan NISN kamu di bawah ini.'),
@@ -76,19 +70,19 @@ var component = {
m('label.form-label[for=input-nisn]', 'NISN'),
m('input.form-input.input-text#input-nisn[name=nisn][type=text][autocomplete=off][required]'),
m('p.input-helper', [
'Nomor Induk Siswa Nasional. ',
!_isEmpty(Siswa.error) ?
Siswa.error.errors.siswa != undefined ? m('span.error', Siswa.error.errors.siswa[0] + ' ')
: Siswa.error.errors.nisn != undefined ? m('span.error', Siswa.error.errors.nisn[0] + ' ')
: '' : '',
'Nomor Induk Siswa Nasional.',
]),
]),
m('.form-group', [
m('label.form-label[for=input-tanggalLahir]', 'Tanggal Lahir'),
m('input.form-input.input-text#input-tanggalLahir[name=tanggalLahir][type=text][autocomplete=off][required]'),
m('p.input-helper', [
'Tanggal lahir dengan format YYYYMMDD. Contoh: untuk tanggal 29 Mei 2000 ditulis 20000529. ',
!_isEmpty(Siswa.error) && Siswa.error.errors.tanggalLahir != undefined ? m('span.error', Siswa.error.errors.tanggalLahir[0] + ' ') : '',
'Tanggal lahir dengan format YYYYMMDD. Contoh: untuk tanggal 29 Mei 2000 ditulis 20000529',
]),
]),
m('button.form-submit#input-submit[type=submit]', 'Lihat'),
@@ -99,11 +93,21 @@ var component = {
onclick: () => {
if (confirm('Surat Keterangan ini hanya dapat dicetak satu kali. Lanjutkan?')) {
AccessLog.create({siswaId: Siswa.current.id, src: 'sk-hasil-belajar'}).then(() => {
AccessLog.fetch('sk-hasil-belajar');
window.print();
})
.catch(e => {
//AccessLog.error = JSON.parse(e.message);
console.log(e, e.message, e.code, e.response);
if (e.code === 0) {
AccessLog.error = {
message: e.message,
errors: {
create: ['Terjadi kesalahan saat menghubungkan ke server.'],
},
};
}
else {
AccessLog.error = JSON.parse(e.message);
}
});
}
}
@@ -111,6 +115,9 @@ var component = {
m.trust('⎙'),
' Print',
]),
!_isEmpty(AccessLog.error)
? m('span.error.ml-2', AccessLog.error.errors.create[0])
: null,
m('.letter__header', [
m('img[src=img/letter-head.jpg]'),
]),

View File

@@ -37,19 +37,19 @@ var component = {
m('label.form-label[for=input-nisn]', 'NISN'),
m('input.form-input.input-text#input-nisn[name=nisn][type=text][autocomplete=off][required]'),
m('p.input-helper', [
'Nomor Induk Siswa Nasional. ',
!_isEmpty(Siswa.error) ?
Siswa.error.errors.siswa != undefined ? m('span.error', Siswa.error.errors.siswa[0] + ' ')
: Siswa.error.errors.nisn != undefined ? m('span.error', Siswa.error.errors.nisn[0] + ' ')
: '' : '',
'Nomor Induk Siswa Nasional.',
]),
]),
m('.form-group', [
m('label.form-label[for=input-tanggalLahir]', 'Tanggal Lahir'),
m('input.form-input.input-text#input-tanggalLahir[name=tanggalLahir][type=text][autocomplete=off][required]'),
m('p.input-helper', [
'Tanggal lahir dengan format YYYYMMDD. Contoh: untuk tanggal 29 Mei 2000 ditulis 20000529. ',
!_isEmpty(Siswa.error) && Siswa.error.errors.tanggalLahir != undefined ? m('span.error', Siswa.error.errors.tanggalLahir[0] + ' ') : '',
'Tanggal lahir dengan format YYYYMMDD. Contoh: untuk tanggal 29 Mei 2000 ditulis 20000529',
]),
]),
m('button.form-submit#input-submit[type=submit]', 'Lihat'),