Commit 942244cb by Natthaphat

แจ้งเตือนเปลี่ยนสถานะเวอร์ชั่น

parent 0617e985
......@@ -69,12 +69,14 @@
</td>
<td>
<div>
<span class="badge bg-info/10 text-primary"><i class="bi bi-clock me-1"></i>{{item.startDate| date : 'dd/MM/yyyy hh:mm a' : '+0000'}}</span>
<span class="badge bg-info/10 text-primary"><i class="bi bi-clock me-1"></i>{{item.startDate| date
: 'dd/MM/yyyy hh:mm a' : '+0000'}}</span>
</div>
</td>
<td>
<div>
<span class="badge bg-info/10 text-primary"><i class="bi bi-clock me-1"></i>{{item.endDate| date : 'dd/MM/yyyy hh:mm a' : '+0000'}}</span>
<span class="badge bg-info/10 text-primary"><i class="bi bi-clock me-1"></i>{{item.endDate| date :
'dd/MM/yyyy hh:mm a' : '+0000'}}</span>
</div>
</td>
<td> <span
......@@ -252,7 +254,11 @@
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
<div class="flex flex-col">
<label class="ti-form-label mb-2 text-primary font-bold">{{'Version' | translate}}
<span class="text-danger text-sm mt-1">*</span>
<span class="text-danger">*
<ng-container *ngIf="modalStatus=='add'&&checkPrimary()">
เวอร์ชั่นซ้ำ
</ng-container>
</span>
</label>
<input type="number" class="ti-form-input w-full" [(ngModel)]="pdpa.version" />
<div class="text-danger text-sm mt-1" *ngIf="!pdpa.version">
......@@ -305,28 +311,19 @@
<a (click)="currentTab = 1" class="tab-btn"
[ngClass]="{ '!bg-primary border-primary !text-white': currentTab === 1 }" href="javascript:void(0);">
{{ 'Thai' | translate }}
<span *ngIf="!pdpa.requestConsentThai" [ngClass]="{
'text-danger': currentTab !== 1,
'text-white': currentTab === 1
}" class="text-sm">&nbsp;*</span>
</a>
<a (click)="currentTab = 2" class="tab-btn"
[ngClass]="{ '!bg-primary border-primary !text-white': currentTab === 2 }" href="javascript:void(0);">
{{ 'Eng' | translate }}
<span *ngIf="!pdpa.requestConsentEng" [ngClass]="{
'text-danger': currentTab !== 2,
'text-white': currentTab === 2
}" class="text-sm">&nbsp;*</span>
</a>
<a (click)="currentTab = 3" class="tab-btn"
[ngClass]="{ '!bg-primary border-primary !text-white': currentTab === 3 }" href="javascript:void(0);">
{{ 'China' | translate }}
<span *ngIf="!pdpa.requestConsentChina" [ngClass]="{
'text-danger': currentTab !== 3,
'text-white': currentTab === 3
}" class="text-sm">&nbsp;*</span>
</a>
</nav>
......@@ -336,25 +333,16 @@
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '500px', 'overflow-y': 'auto' }"
[(ngModel)]="pdpa.requestConsentThai" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
<div class="text-danger text-sm mt-1" *ngIf="!pdpa.requestConsentThai">
{{'Please fill in information' | translate}}
</div>
</div>
<div *ngIf="currentTab == 2">
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '500px', 'overflow-y': 'auto' }"
[(ngModel)]="pdpa.requestConsentEng" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
<div class="text-danger text-sm mt-1" *ngIf="!pdpa.requestConsentEng">
{{'Please fill in information' | translate}}
</div>
</div>
<div *ngIf="currentTab == 3">
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '500px', 'overflow-y': 'auto' }"
[(ngModel)]="pdpa.requestConsentChina" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
<div class="text-danger text-sm mt-1" *ngIf="!pdpa.requestConsentChina">
{{'Please fill in information' | translate}}
</div>
</div>
</div>
</div>
......@@ -369,17 +357,11 @@
[class.ti-btn-disabled]="
!pdpa.version ||
!pdpa.startDate ||
!pdpa.endDate ||
!pdpa.requestConsentThai ||
!pdpa.requestConsentEng ||
!pdpa.requestConsentChina
!pdpa.endDate
" [disabled]="
!pdpa.version ||
!pdpa.startDate ||
!pdpa.endDate ||
!pdpa.requestConsentThai ||
!pdpa.requestConsentEng ||
!pdpa.requestConsentChina
!pdpa.endDate
">
{{ isSaving ? ('Saving...' | translate) : ('Save' | translate) }}
</button>
......
......@@ -82,6 +82,8 @@ export class PdpaManageComponent {
filterListConsent: MyPdpaModel[] = []
consent: MyPdpaModel = new MyPdpaModel()
isActiveExist: boolean = false;
get searchTerm(): string {
return this._searchTerm;
}
......@@ -166,7 +168,7 @@ export class PdpaManageComponent {
// ถ้ามีเวอร์ชันอื่นที่เปิดใช้งานอยู่แล้ว และกำลังจะเปิดอีกเวอร์ชัน
swal({
title: "มีรายการที่เปิดใช้งานอยู่แล้ว",
text: "คุณแน่ใจหรือไม่ว่าต้องการเปิดใช้งานเวอร์ชั่นใหม่นี้?",
text: "คุณกำลังจะเปิดใช้งานเวอร์ชันใหม่ แต่มีเวอร์ชันอื่นที่เปิดใช้งานอยู่แล้ว?",
icon: "warning",
buttons: ["ยกเลิก", "ยืนยัน"],
dangerMode: false,
......@@ -279,7 +281,97 @@ export class PdpaManageComponent {
}
adjustSelect(status: number) {
let title = "Are you sure?";
this.pdpaService.getConfigList().subscribe({
next: configs => {
this.isActiveExist = configs.some(cfg => cfg.status === "1" && cfg.version !== this.pdpa.version);
if (status === 1) {
let isSelectedAlreadyActive = false;
this.selectedItems.forEach((isSelected, version) => {
if (isSelected) {
const pdpa = this.itemsList.find(item => item.version === version);
if (pdpa && pdpa.status === '1') {
isSelectedAlreadyActive = true;
}
}
});
if (isSelectedAlreadyActive) {
// แจ้งเตือนว่ามีเวอร์ชันที่เลือกเปิดอยู่แล้ว
swal({
title: "เวอร์ชันนี้เปิดใช้งานอยู่แล้ว",
text: "หนึ่งในเวอร์ชันที่คุณเลือกได้ถูกเปิดใช้งานอยู่แล้ว คุณต้องการดำเนินการต่อหรือไม่?",
icon: "info",
buttons: ["ยกเลิก", "ยืนยัน"],
dangerMode: false,
}).then((confirm: boolean) => {
if (confirm) {
this.proceedUpdate(status);
}
});
return;
}
if (this.isActiveExist) {
// แจ้งเตือนว่ามีเวอร์ชันอื่นเปิดใช้งานอยู่แล้ว
swal({
title: "มีเวอร์ชันอื่นที่เปิดใช้งานอยู่แล้ว",
text: "คุณกำลังจะเปิดใช้งานเวอร์ชันใหม่ แต่มีเวอร์ชันอื่นที่เปิดใช้งานอยู่แล้ว?",
icon: "warning",
buttons: ["ยกเลิก", "ยืนยัน"],
dangerMode: false,
}).then((confirm: boolean) => {
if (confirm) {
let pdpaConfig = ''; // เก็บข้อมูลเวอร์ชันที่เลือก
this.selectedItems.forEach((isSelected, version) => {
if (isSelected) {
const pdpa = this.itemsList.find(pdpa => pdpa.version === version);
if (pdpa) {
pdpaConfig += `${this.translate.instant('Version')}: ${pdpa.version}\n`;
}
}
});
this.selectedItems.forEach((isSelected, version) => {
if (isSelected) {
const pdpa = this.itemsList.find(pdpa => pdpa.version === version);
if (pdpa) {
const cleanPdpa = {
version: pdpa.version,
startDate: pdpa.startDate,
endDate: pdpa.endDate,
status: status.toString(),
requestConsentThai: pdpa.requestConsentThai,
requestConsentEng: pdpa.requestConsentEng,
requestConsentChina: pdpa.requestConsentChina
};
this.pdpaService.update(cleanPdpa).subscribe(result => {
swal("บันทึกสำเร็จ!", "ข้อมูลถูกบันทึกเรียบร้อยแล้ว", "success");
this.ngOnInit(); // รีเฟรชข้อมูลหลังจากอัปเดต
});
}
}
});
}
});
return;
}
}
this.proceedUpdate(status);
},
error: err => {
console.error('Failed to load config list', err);
}
});
}
proceedUpdate(status: number) {
let title = "คุณแน่ใจหรือไม่?";
let pdpaConfig = ''; // เก็บข้อมูลเวอร์ชันที่เลือก
this.selectedItems.forEach((isSelected, version) => {
......@@ -296,14 +388,13 @@ export class PdpaManageComponent {
text: pdpaConfig,
icon: "warning",
dangerMode: false,
buttons: ["Cancel", "Confirm"],
}).then((willDelete: any) => {
if (willDelete) {
buttons: ["ยกเลิก", "ยืนยัน"],
}).then((willProceed: any) => {
if (willProceed) {
this.selectedItems.forEach((isSelected, version) => {
if (isSelected) {
const pdpa = this.itemsList.find(pdpa => pdpa.version === version);
if (pdpa) {
// แปลง pdpa ให้เป็น Plain Object เพื่อป้องกัน JSON.stringify error
const cleanPdpa = {
version: pdpa.version,
startDate: pdpa.startDate,
......@@ -314,8 +405,8 @@ export class PdpaManageComponent {
requestConsentChina: pdpa.requestConsentChina
};
this.pdpaService.update(cleanPdpa).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit();
swal("บันทึกสำเร็จ!", "ข้อมูลถูกบันทึกเรียบร้อยแล้ว", "success");
this.ngOnInit(); // รีเฟรชข้อมูลหลังจากอัปเดต
});
}
}
......@@ -373,4 +464,8 @@ export class PdpaManageComponent {
this.pdpa = this.itemsList.filter(e => e.version == empId)[0]
}
checkPrimary() {
return this.itemsList.find(x => x.version == this.pdpa.version)
}
}
\ No newline at end of file
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