Commit 27565d13 by Natthaphat

แก้ modal ใหม่ ทะเบียนกำหนดชื่อ > ประเภทสมรรถนะ

parent 9d230e89
...@@ -27,15 +27,15 @@ ...@@ -27,15 +27,15 @@
</div> </div>
<div class="px-1"> <div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-secondary h-10 m-0 shadow-md" <button type="button" class="ti-btn ti-btn-soft-secondary h-10 m-0 shadow-md"
data-hs-overlay="#type-registration-component-page-modal" (click)="currentModal='add';edit()"> data-hs-overlay="#type-registration-component-page-modal" (click)="currentModal='add';edit()"
(click)="openDialog()">
<i class="ri-add-line"></i> <i class="ri-add-line"></i>
Add Add
</button> </button>
</div> </div>
<div class="px-1"> <div class="px-1">
<button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10 m-0 shadow-md" <button href="javascript:void(0);" class="ti-btn ti-btn-soft-danger h-10 m-0 shadow-md"
data-hs-overlay="#type-registration-component-page-alert-modal" (click)="currentModal='delete';deleteType_registration()">
(click)="currentModal='delete';edit()">
<i class="ri-delete-bin-6-line"></i> <i class="ri-delete-bin-6-line"></i>
Delete Delete
</button> </button>
...@@ -48,13 +48,68 @@ ...@@ -48,13 +48,68 @@
<div class="page px-rem"> <div class="page px-rem">
<app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="typeList" <app-datagrid-syncfution [searchSettings]="searchSettings" [searchText]="search" [dataSource]="typeList"
[columns]="columns" [selectedItems]="selectedItems" modalName="#type-registration-component-page-modal" [columns]="columns" [selectedItems]="selectedItems"
(sendSelectData)="currentModal='edit';edit($event)" (sendSelectedItems)="onSelectItemChange($event)"> (sendSelectData)="currentModal='edit';edit($event);openDialog()"
(sendSelectedItems)="onSelectItemChange($event)">
</app-datagrid-syncfution> </app-datagrid-syncfution>
</div> </div>
<div id="type-registration-component-page-modal" class="hs-overlay hidden ti-modal"> <ng-template #typeRegistrationModal let-modal>
<h3 mat-dialog-title>
{{currentModal=='add'?'เพิ่มประเภทสมรรถนะ':'แก้ไขประเภทสมรรถนะ'}}
</h3>
<div class="w-full flex justify-end">
<div class="absolute flex">
<div class="px-1">
<button type="button" class="ti-btn ti-btn-soft-indigo h-45px m-0 shadow-md" (click)="selectCompetencyType()">
<i class="ti ti-eraser text-base"></i>
Clear
</button>
</div>
</div>
</div>
<mat-dialog-content>
<label for="input-label" class="ti-form-label mt-2rem">รหัส
<span class="text-danger">*
<ng-container *ngIf="checkPrimary()&&currentModal=='add'">
รหัสซ้ำ
</ng-container>
</span>
</label>
<input type="text" id="input-label" class="ti-form-input w-1/2"
[ngClass]="{'bg-input-readonly':currentModal=='edit'}" [readonly]="currentModal=='edit'"
[(ngModel)]="competoncy_type.competencyTypeId">
<label for="detail_th" class="ti-form-label mt-1rem">ชื่อประเภท (ไทย)<span class="text-danger">*</span></label>
<input type="text" id="detail_th" class="ti-form-input w-2/3" [(ngModel)]="competoncy_type.tdesc">
<label for="detail_eng" class="ti-form-label mt-1rem">ชื่อประเภท (อังกฤษ)</label>
<input type="text" id="detail_eng" class="ti-form-input w-2/3" [(ngModel)]="competoncy_type.edesc">
<label for="detail_eng" class="ti-form-label mt-1rem">ชื่อย่อ<span class="text-danger">*</span></label>
<input type="text" id="detail_eng" class="ti-form-input w-2/3" [(ngModel)]="competoncy_type.shortName">
<label for="detail_eng" class="ti-form-label mt-1rem">ระดับความคาดหวัง <span
class="text-danger">*</span></label>
<input type="text" id="detail_eng" class="ti-form-input" style="width: 200px;"
oninput="this.value = this.value.replace(/\D/g, '')" [(ngModel)]="competoncy_type.expectationLevel">
<label for="detail_eng" class="ti-form-label mt-1rem">น้ำหนัก</label>
<input type="text" id="detail_eng" class="ti-form-input" style="width: 200px;"
oninput="this.value = this.value.replace(/[^\d.]/g, '').replace(/(\..*?)\..*/g, '$1').replace(/(\..*?)(\d{2})./g, '$1$2');"
onchange="this.value = this.value.replace('', '0');this.value = parseFloat(this.value).toFixed(2)"
[(ngModel)]="competoncy_type.weight">
</mat-dialog-content>
<mat-dialog-actions align="end">
<button type="button" mat-button [mat-dialog-close]
class="hs-dropdown-toggle ti-btn ti-border font-medium bg-white text-gray-700 shadow-sm align-middle hover:bg-gray-50 focus:ring-offset-white focus:ring-primary dark:bg-bgdark dark:hover:bg-black/20 dark:border-white/10 dark:text-white/70 dark:hover:text-white dark:focus:ring-offset-white/10">
ย้อนกลับ
</button>
<button type="button" class="ti-btn ti-btn-success" mat-button (click)="addType_registration()"
[class.ti-btn-disabled]="!competoncy_type.competencyTypeId||!competoncy_type.tdesc||!competoncy_type.shortName||(currentModal=='add'&&checkPrimary())"
[disabled]="!competoncy_type.competencyTypeId||!competoncy_type.tdesc||!competoncy_type.shortName||(currentModal=='add'&&checkPrimary())">
บันทึกข้อมูล
</button>
</mat-dialog-actions>
</ng-template>
<!-- <div id="type-registration-component-page-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)]"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)]">
<div class="max-h-full overflow-hidden ti-modal-content"> <div class="max-h-full overflow-hidden ti-modal-content">
<div class="ti-modal-header"> <div class="ti-modal-header">
...@@ -131,7 +186,7 @@ ...@@ -131,7 +186,7 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div> -->
<div id="type-registration-component-page-alert-modal" class="hs-overlay hidden ti-modal"> <div id="type-registration-component-page-alert-modal" class="hs-overlay hidden ti-modal">
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)] flex items-center"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out h-[calc(100%-3.5rem)] flex items-center">
......
import { ChangeDetectorRef, Component, EventEmitter, Input, Output } from '@angular/core'; import { ChangeDetectorRef, Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { ColumnModel } from '@syncfusion/ej2-grids'; import { ColumnModel } from '@syncfusion/ej2-grids';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
import { CompetencytypeModel, MyCompetencytypeModel } from 'src/app/shared/model/competencytype.model'; import { CompetencytypeModel, MyCompetencytypeModel } from 'src/app/shared/model/competencytype.model';
import { CompetencytypeService } from 'src/app/shared/services/competencytype.service'; import { CompetencytypeService } from 'src/app/shared/services/competencytype.service';
import { FileService } from 'src/app/shared/services/file.service'; import { FileService } from 'src/app/shared/services/file.service';
import Swal from 'sweetalert2';
@Component({ @Component({
selector: 'app-type-registration', selector: 'app-type-registration',
...@@ -44,7 +46,10 @@ export class TypeRegistration { ...@@ -44,7 +46,10 @@ export class TypeRegistration {
search = '' search = ''
selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() }; selectedItems: { key: string, count: number, data: Map<string, boolean> } = { key: '', count: 0, data: new Map<string, boolean>() };
@ViewChild("typeRegistrationModal") typeRegistrationModal: any;
dialogRef: any
constructor(private competencytypeService: CompetencytypeService, constructor(private competencytypeService: CompetencytypeService,
private dialog: MatDialog,
private toastr: ToastrService, private toastr: ToastrService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
private fileService: FileService private fileService: FileService
...@@ -128,57 +133,92 @@ export class TypeRegistration { ...@@ -128,57 +133,92 @@ export class TypeRegistration {
this.competoncy_type = new MyCompetencytypeModel(item || {}) this.competoncy_type = new MyCompetencytypeModel(item || {})
} }
selectCompetencyType(CompetencyType?: CompetencytypeModel) {
if (CompetencyType) {
this.competoncy_type = new MyCompetencytypeModel(CompetencyType)
} else if (this.currentModal == 'add') {
this.competoncy_type = new MyCompetencytypeModel()
} else if (this.currentModal == 'edit') {
this.competoncy_type = new MyCompetencytypeModel({ competencyTypeId: this.competoncy_type.competencyTypeId })
}
}
// ฟังก์ชันสำหรับการเพิ่ม ลบ หรือแก้ไข ข้อมูล
addType_registration() { addType_registration() {
const body = new MyCompetencytypeModel(this.competoncy_type) Swal.fire({
this.dataLoading = true icon: 'question',
this.competencytypeService.post(body).subscribe({ title: 'แจ้งเตือน',
next: response => { text: 'ยืนยันการบันทึกข้อมูลหรือไม่',
if (response.success) { showCancelButton: true,
this.showAlert(response.message, 'success') confirmButtonText: 'บันทึกข้อมูล',
this.getCompetencytypeList() cancelButtonText: 'ย้อนกลับ',
} else { reverseButtons: true,
this.showAlert(response.message, 'error') }).then((result) => {
this.dataLoading = false if (result.isConfirmed) {
this.cdr.detectChanges() this.dataLoading = true
} this.competencytypeService.post(this.competoncy_type).subscribe({
}, error: error => { next: response => {
this.showAlert(error.message, 'error') if (response.success) {
this.dataLoading = false this.showAlert(response.message, 'success')
this.cdr.detectChanges() this.getCompetencytypeList()
this.closeDialog()
} else {
this.showAlert(response.message, 'error')
this.dataLoading = false
}
}, error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
}
})
} }
}) })
} }
deleteType_registration() {
this.dataLoading = true deleteType_registration() {
const selectedKeys = Array.from(this.selectedItems.data.keys()); if (!this.numSelectItem()) {
const body = this.typeList.filter(x => selectedKeys.includes(x.competencyTypeId) && this.selectedItems.data.get(x.competencyTypeId)).map(x => new MyCompetencytypeModel(x)) this.showAlert('กรุณาเลือกข้อมูลที่ต้องการลบ', 'error')
this.competencytypeService.delete(body).subscribe({ return
next: response => { }
if (response.success) { Swal.fire({
this.showAlert(response.message, 'success'); icon: 'question',
} else { title: 'แจ้งเตือน',
this.showAlert(response.message, 'error'); text: 'ยืนยันการลบข้อมูลหรือไม่',
} showCancelButton: true,
this.getCompetencytypeList(); confirmButtonText: 'ลบข้อมูล',
this.cdr.detectChanges() cancelButtonText: 'ย้อนกลับ',
}, reverseButtons: true,
error: error => { }).then((result) => {
this.showAlert(error.message, 'error') if (result.isConfirmed) {
this.dataLoading = false this.dataLoading = true
this.cdr.detectChanges() const selectedKeys = Array.from(this.selectedItems.data.keys());
const body = this.typeList.filter(x => selectedKeys.includes(x.competencyTypeId) && this.selectedItems.data.get(x.competencyTypeId)).map(x => new MyCompetencytypeModel(x))
this.competencytypeService.delete(body).subscribe({
next: response => {
if (response.success) {
this.showAlert(response.message, 'success');
} else {
this.showAlert(response.message, 'error');
}
this.getCompetencytypeList();
this.cdr.detectChanges()
},
error: error => {
this.showAlert(error.message, 'error')
this.dataLoading = false
this.cdr.detectChanges()
}
})
} }
}); });
} }
showAlert(text: string, type: 'success' | 'error') { showAlert(text: string, type: 'success' | 'error') {
this.toastr[type](text, 'แจ้งเตือน', { Swal.fire({
timeOut: 3000, title: 'แจ้งเตือน',
positionClass: 'toast-top-right', text: text,
}) icon: type,
confirmButtonText: 'ตกลง',
});
} }
...@@ -204,5 +244,15 @@ export class TypeRegistration { ...@@ -204,5 +244,15 @@ export class TypeRegistration {
onSelectItemChange(arg: any) { onSelectItemChange(arg: any) {
this.selectedItems = arg this.selectedItems = arg
} }
openDialog() {
this.dialogRef = this.dialog.open(this.typeRegistrationModal, {
width: '500px',
disableClose: false,
});
}
closeDialog() {
this.dialogRef.close()
}
} }
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