Commit f3407a40 by Nakarin Luankla

UPDATE เปลี่ยน modal ข้อมูลลักษณะงาน

parent 4ba38092
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { EmpGroupModel, MyEmpGroupModel } from 'src/app/shared/model/emp-group.model';
import { EmpGroupService } from 'src/app/shared/services/emp-group.service';
import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
export interface DataModel {
groupId: string
tdesc: string
......@@ -46,16 +48,28 @@ export class EmployeeGroupUnit implements OnInit {
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("employeeGroupUnitModal") employeeGroupUnitModal: any;
dialogRef: any
constructor(private empGroupService: EmpGroupService,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getEmpGroupList()
}
openDialog() {
this.dialogRef = this.dialog.open(this.employeeGroupUnitModal, {
width: '500px',
height: '500px'
})
}
closeDialog() {
this.dialogRef.close()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
this.selectedFileName = this.selectedFile?.name || "กรุณาเลือกไฟล์"
......@@ -135,25 +149,51 @@ export class EmployeeGroupUnit implements OnInit {
}
addEmp_group() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.emp_group.loading = true
this.empGroupService.post(this.emp_group.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getEmpGroupList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.emp_group.loading = false
this.cdr.detectChanges()
this.closeDialog()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.emp_group.loading = false
this.cdr.detectChanges()
this.closeDialog()
}
})
}
})
}
deleteEmp_group() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.emp_group.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.emp_group.dataList.filter(x => selectedKeys.includes(x.groupId) && this.selectedItems.data.get(x.groupId)).map(x => new MyEmpGroupModel(x))
......@@ -175,11 +215,16 @@ export class EmployeeGroupUnit implements OnInit {
}
});
}
});
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
Swal.fire({
icon: type,
title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
})
}
......
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr';
import { MyPositionModel, PositionModel } from 'src/app/shared/model/position.model';
import { FileService } from 'src/app/shared/services/file.service';
import { PositionService } from 'src/app/shared/services/position.service';
import Swal from 'sweetalert2';
@Component({
selector: 'app-position-unit',
templateUrl: './position-unit.component.html',
......@@ -38,14 +40,27 @@ export class PositionUnitComponent implements OnInit {
};
search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("positionUnitModal") positionUnitModal: any;
dialogRef: any
constructor(private positionService: PositionService,
private toastr: ToastrService,
private cdr: ChangeDetectorRef,
private fileService: FileService
private fileService: FileService,
private dialog: MatDialog
) { }
ngOnInit(): void {
this.getPositionList()
}
openDialog() {
this.dialogRef = this.dialog.open(this.positionUnitModal, {
width: '500px',
height: '500px'
})
}
closeDialog() {
this.dialogRef.close()
}
onFileSelected(event: any) {
this.selectedFile = event.target.files.length > 0 ? event.target.files[0] : null;
......@@ -128,25 +143,51 @@ export class PositionUnitComponent implements OnInit {
}
addPosition() {
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ยืนยัน',
}).then((result) => {
if (result.isConfirmed) {
this.position.loading = true
this.positionService.post(this.position.select).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success')
this.getPositionList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.position.loading = false
this.cdr.detectChanges()
this.closeDialog()
}
}, error: error => {
this.showAlert(error.message, 'error')
this.position.loading = false
this.cdr.detectChanges()
this.closeDialog()
}
})
}
})
}
deletePosition() {
if (this.numSelectItem() == 0) {
this.showAlert('กรุณาเลือกข้อมูลที่จะลบ', 'error')
return
}
Swal.fire({
icon: 'question',
title: 'แจ้งเตือน',
text: 'ยืนยันการลบข้อมูลหรือไม่',
showCancelButton: true,
confirmButtonText: 'ลบข้อมูล',
}).then((result) => {
if (result.isConfirmed) {
this.position.loading = true
const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.position.dataList.filter(x => selectedKeys.includes(x.positionId) && this.selectedItems.data.get(x.positionId)).map(x => new MyPositionModel(x))
......@@ -167,11 +208,16 @@ export class PositionUnitComponent implements OnInit {
}
})
}
})
}
showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', {
timeOut: 3000,
positionClass: 'toast-top-right',
});
Swal.fire({
icon: type,
title: 'แจ้งเตือน',
text: text,
showCancelButton: false,
confirmButtonText: 'ยืนยัน',
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment