Commit 3c490f8b by Natthaphat

pdpa add edit delete

parent 36fa5d75
...@@ -3,3 +3,81 @@ ...@@ -3,3 +3,81 @@
height: auto; height: auto;
flex-direction: column; flex-direction: column;
} }
/* Base styling for the modal body content */
.ti-modal-body-content {
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
/* Form labels */
.ti-form-label {
font-size: 0.95rem;
color: #333;
}
/* Form inputs */
.ti-form-input {
border: 1px solid #d1d5db;
border-radius: 4px;
padding: 0.6rem 1rem;
font-size: 1rem;
transition: all 0.2s ease-in-out;
}
.ti-form-input:focus {
outline: none;
border-color: #3b82f6; /* Example primary color */
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}
/* Read-only input styling */
.bg-input-readonly {
background-color: #e5e7eb;
cursor: not-allowed;
}
/* Error text */
.text-danger {
color: #ef4444;
}
/* Tab button styling */
.tab-btn {
display: flex;
justify-content: center;
align-items: center;
width: 120px; /* Consistent width for tabs */
padding: 0.75rem 1rem;
border: 1px solid #d1d5db;
border-bottom: none; /* Remove bottom border for active tab effect */
border-top-left-radius: 4px;
border-top-right-radius: 4px;
font-size: 0.95rem;
font-weight: 500;
text-align: center;
color: #6b7280;
transition: all 0.2s ease-in-out;
text-decoration: none; /* Remove underline from anchor tags */
}
.tab-btn:hover {
color: #111827;
background-color: #f3f4f6;
}
/* Active tab styling */
.tab-btn.hs-tab-active {
background-color: #3b82f6; /* Example primary color */
border-color: #3b82f6;
color: #ffffff;
}
/* Custom primary color (replace with your actual primary color if different) */
.text-primary {
color: #3b82f6;
}
.bg-primary {
background-color: #3b82f6;
}
\ No newline at end of file
...@@ -20,20 +20,9 @@ ...@@ -20,20 +20,9 @@
translate}} translate}}
</a> </a>
<div> <div>
<input class="form-control form-control" type="text" placeholder="ค้นหาสมาชิก" <input class="form-control form-control" type="text" placeholder="ค้นหาเวอร์ชั่น"
aria-label=".form-control-sm example" [(ngModel)]='searchTerm'> aria-label=".form-control-sm example" [(ngModel)]='searchTerm'>
</div> </div>
<!-- <div>
<input class="form-control form-control" type="text" placeholder="กรองตามบริษัท"
aria-label=".form-control-sm example" [(ngModel)]='searchTerm'>
</div> -->
<!-- <a href="javascript:void(0);" class="ti-btn ti-btn-primary-full !py-1 !px-2" aria-expanded="false">
เรียงตาม<i class="ri-arrow-down-s-line align-middle ms-1 inline-block"></i>
</a>
<ul class="hs-dropdown-menu ti-dropdown-menu hidden" role="menu">
<li><a class="ti-dropdown-item" href="javascript:void(0);">Newest</a></li>
<li><a class="ti-dropdown-item" href="javascript:void(0);">Oldest</a></li>
</ul> -->
</div> </div>
</div> </div>
<div class="box-body"> <div class="box-body">
...@@ -62,29 +51,6 @@ ...@@ -62,29 +51,6 @@
[checked]="selectedItems.get(item.version)" (change)="onCheckboxChange(item.version)" [checked]="selectedItems.get(item.version)" (change)="onCheckboxChange(item.version)"
aria-label="..." value=""> aria-label="..." value="">
</td> </td>
<!-- <td>
<div class="flex items-center">
<span class="avatar avatar-sm p-1 me-1 bg-light !rounded-full">
<img [src]="item.getPicture()" alt="" id="profile-img">
</span>
<div class="ms-2">
<p class="font-semibold mb-0 flex items-center text-primary"><a (click)="view(item)">
{{item.getFullname()}}</a></p>
<p class="text-[0.75rem] text-muted mb-0">{{item.memberId}}</p>
</div>
</div>
</td> -->
<!-- <td>
<div class="flex">
<div class="ms-2">
<p class="font-semibold mb-0 flex items-center text-primary"><a (click)="view(item)"
data-hs-overlay="#modal-detail">
{{item.username}}</a></p>
<p class="text-[0.75rem] text-muted mb-0">{{item.memberId}}</p>
</div>
</div>
</td> -->
<td> <td>
<div> <div>
<span class="block">{{item.version}}</span> <span class="block">{{item.version}}</span>
...@@ -111,7 +77,7 @@ ...@@ -111,7 +77,7 @@
<a aria-label="anchor" (click)="view(item)" <a aria-label="anchor" (click)="view(item)"
class="ti-btn ti-btn-wave !gap-0 !m-0 bg-info/10 text-info hover:bg-info hover:text-white hover:border-info"><i class="ti-btn ti-btn-wave !gap-0 !m-0 bg-info/10 text-info hover:bg-info hover:text-white hover:border-info"><i
class="ri-pencil-line"></i></a> class="ri-pencil-line"></i></a>
<a aria-label="anchor" href="javascript:void(0);" (click)="deleteVersion(item.version)" <a aria-label="anchor" href="javascript:void(0);" (click)="deleteVersion(item)"
class="ti-btn ti-btn-wave product-btn !gap-0 !m-0 bg-danger/10 text-danger hover:bg-danger hover:text-white hover:border-danger"><i class="ti-btn ti-btn-wave product-btn !gap-0 !m-0 bg-danger/10 text-danger hover:bg-danger hover:text-white hover:border-danger"><i
class="ri-delete-bin-line"></i></a> class="ri-delete-bin-line"></i></a>
</div> </div>
...@@ -249,7 +215,6 @@ ...@@ -249,7 +215,6 @@
<!-- End:: Add Version Oldest --> <!-- End:: Add Version Oldest -->
<ng-template #modalDetail let-modal> <ng-template #modalDetail let-modal>
<!-- <div id="modal-detail" class="hs-overlay hidden ti-modal [--overlay-backdrop:static]"> -->
<div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out"> <div class="hs-overlay-open:mt-7 ti-modal-box mt-0 ease-out">
<div class="ti-modal-content"> <div class="ti-modal-content">
<div class="ti-modal-header flex justify-between items-center p-5"> <div class="ti-modal-header flex justify-between items-center p-5">
...@@ -263,135 +228,115 @@ ...@@ -263,135 +228,115 @@
<i class="ri-close-line"></i> <i class="ri-close-line"></i>
</button> </button>
</div> </div>
<div class="ti-modal-body px-4"> <div class="ti-modal-body-content pt-6 pr-6 pl-6 pb-3 mb-4">
<div class="!page"> <div class="flex items-end justify-start md:justify-end">
<div class="grid grid-cols-12 gap-6"> <a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-primary-full w-full md:w-auto"
<div class="xl:col-span-12 col-span-12"> (click)="new()" data-hs-overlay="#modal-detail">
<div class="box"> <i class="ri-add-line font-semibold align-middle"></i>
<div class="box-header flex justify-between items-center flex-wrap gap-4"> {{ 'Consent List' | translate }}
<!-- ฝั่งซ้าย --> </a>
<div class="flex items-center gap-3"> </div>
<!-- <div class="box-title"> <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-8">
{{ 'Edit Version' | translate }} <div class="flex flex-col">
<span class="badge bg-light text-default rounded-full ms-1 text-[0.75rem] align-middle"> <label class="ti-form-label mb-2 text-primary font-bold">Version *</label>
{{ itemsList.length }} <input type="text" class="ti-form-input w-full"
</span> [ngClass]="{ '!bg-input-readonly': modalStatus === 'edit' }" [(ngModel)]="consent.version"
</div> --> [readonly]="modalStatus === 'edit'" />
<div class="text-danger text-sm mt-1" *ngIf="!consent.version">
Please fill in information
</div>
</div>
<div class="flex flex-col">
<label class="ti-form-label mb-2 text-primary font-bold">{{ 'Status' | translate }} </label>
</div> <div class="flex items-center space-x-6">
<div class="flex flex-wrap gap-2"> <label class="inline-flex items-center space-x-2">
<a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-primary-full me-2" <input type="radio" name="status" [(ngModel)]="consent.status" value="1" />
(click)="new()" data-hs-overlay="#modal-detail"><i <span>{{ 'Active' | translate }}</span>
class="ri-add-line font-semibold align-middle"></i>{{ 'Consent List' | </label>
translate}}
</a>
<label class="inline-flex items-center space-x-2">
<input type="radio" name="status" [(ngModel)]="consent.status" value="0" />
<span>{{ 'Unactive' | translate }}</span>
</label>
</div>
<a href="javascript:void(0);" class="hs-dropdown-toggle ti-btn ti-btn-danger-full me-2" <div class="text-danger text-sm mt-1" *ngIf="consent.status === null || consent.status === undefined">
*ngIf="someSelected" (click)="deleteSelect()"><i Please fill in information
class="ri-delete-bin-line font-semibold align-middle"></i>{{ 'Delete' |
translate}}
</a>
<!-- <div>
<input class="form-control form-control" type="text" placeholder="ค้นหาสมาชิก"
aria-label=".form-control-sm example" [(ngModel)]='searchTerm'>
</div> -->
</div> </div>
</div> </div>
<div class="ti-modal-body-content " style="margin-top: 10px;">
<div class="sm:grid grid-cols-12 gap-x-6 space-y-4 lg:space-y-0">
<div <div class="flex flex-col">
class="col-span-12 lg:col-span-5 sm:inline-flex sm:items-center space-y-2 sm:space-y-0 sm:space-x-3 w-full rtl:space-x-reverse" <label class="ti-form-label mb-2 text-primary font-bold">Start Date </label>
style="margin-left: 10%;"> <input type="datetime-local" class="ti-form-input w-full" [(ngModel)]="consent.startDate" />
<label class="w-56 ti-form-label mb-0 text-primary font-bold">{{"Version" | translate}} <div class="text-danger text-sm mt-1" *ngIf="!consent.startDate">
*</label> Please fill in information
<input type="text" class="my-auto ti-form-input w-full bg-input-readonly" readonly
[(ngModel)]="consent.version">
</div> </div>
</div> </div>
<div class="sm:grid grid-cols-12 gap-x-6 space-y-4 lg:space-y-0 mt-1">
<div <div class="flex flex-col">
class="col-span-12 lg:col-span-5 sm:inline-flex sm:items-center space-y-2 sm:space-y-0 sm:space-x-3 w-full rtl:space-x-reverse" <label class="ti-form-label mb-2 text-primary font-bold">End Date</label>
style="margin-left: 10%;"> <input type="datetime-local" class="ti-form-input w-full" [(ngModel)]="consent.endDate" />
<label class="w-56 ti-form-label mb-0 text-primary font-bold">{{"Start Date" | translate}} <div class="text-danger text-sm mt-1" *ngIf="!consent.endDate">
*</label> Please fill in information
<input type="text" class="my-auto ti-form-input w-full" [(ngModel)]="consent.startDate">
</div> </div>
<div
class="col-span-12 lg:col-span-5 sm:inline-flex sm:items-center space-y-2 sm:space-y-0 sm:space-x-3 w-full rtl:space-x-reverse"
style="margin-left: 10%;">
<label class="w-56 ti-form-label mb-0 text-primary font-bold">{{"End Date" |
translate}}</label>
<input type="text" class="ti-form-input w-full" [(ngModel)]="consent.endDate">
</div> </div>
</div> </div>
<div class="body-content mt-8"> <div class="body-content pt-0">
<div class="!page"> <nav class="flex space-x-2 border-b border-gray-200 mb-4">
<nav class="flex rtl:space-x-reverse space-x-2 border-b border-gray-200"> <a (click)="currentTab = 1" class="tab-btn" [ngClass]="{
<a (click)="currentTab=1" '!bg-primary border-primary !text-white': currentTab === 1
class="border w-32 justify-center rounded-4px hs-tab-active:!bg-primary hs-tab-active:border-primary hs-tab-active:!text-white -mb-px py-2 px-3 inline-flex items-center gap-2 font-size-16px font-weight-500 text-center text-gray-600 hover:text-gray-900 active" }" href="javascript:void(0);">
href="javascript:void(0);" id="card-type-item-1" data-hs-tab="#card-type-1"
aria-controls="card-type-1">
ไทย ไทย
</a> </a>
<a (click)="currentTab=2" <a (click)="currentTab = 2" class="tab-btn" [ngClass]="{
class="border w-32 justify-center rounded-4px hs-tab-active:!bg-primary hs-tab-active:border-primary hs-tab-active:!text-white -mb-px py-2 px-3 inline-flex items-center gap-2 font-size-16px font-weight-500 text-center text-gray-600 hover:text-gray-900" '!bg-primary border-primary !text-white': currentTab === 2
href="javascript:void(0);" id="card-type-item-2" data-hs-tab="#card-type-2" }" href="javascript:void(0);">
aria-controls="card-type-2">
อังกฤษ อังกฤษ
</a> </a>
<a (click)="currentTab=3" <a (click)="currentTab = 3" class="tab-btn" [ngClass]="{
class="border w-32 justify-center rounded-4px hs-tab-active:!bg-primary hs-tab-active:border-primary hs-tab-active:!text-white -mb-px py-2 px-3 inline-flex items-center gap-2 font-size-16px font-weight-500 text-center text-gray-600 hover:text-gray-900" '!bg-primary border-primary !text-white': currentTab === 3
href="javascript:void(0);" id="card-type-item-3" data-hs-tab="#card-type-3" }" href="javascript:void(0);">
aria-controls="card-type-3">
จีน จีน
</a> </a>
</nav> </nav>
<div class="pt-50px">
<div *ngIf="currentTab==1" id="card-type-1" role="tabpanel" <div>
aria-labelledby="card-type-item-1"> <div *ngIf="currentTab == 1">
<quill-editor [modules]="quillConfig" [styles]="{'max-height': '200px','overflow-y': 'auto'}" <quill-editor [modules]="quillConfig" [styles]="{ 'height': '400px', 'overflow-y': 'auto' }"
[(ngModel)]="consent.requestConsentThai" [ngModelOptions]="{standalone: true}" [(ngModel)]="consent.requestConsentThai" [ngModelOptions]="{ standalone: true }"
theme="snow"> theme="snow"></quill-editor>
</quill-editor>
</div>
<div *ngIf="currentTab==2" id="card-type-2" role="tabpanel"
aria-labelledby="card-type-item-2">
<quill-editor [modules]="quillConfig" [styles]="{'max-height': '200px','overflow-y': 'auto'}"
[(ngModel)]="consent.requestConsentEng" [ngModelOptions]="{standalone: true}"
theme="snow">
</quill-editor>
</div>
<div *ngIf="currentTab==3" id="card-type-3" role="tabpanel"
aria-labelledby="card-type-item-3">
<quill-editor [modules]="quillConfig" [styles]="{'max-height': '200px','overflow-y': 'auto'}"
[(ngModel)]="consent.requestConsentChina" [ngModelOptions]="{standalone: true}"
theme="snow">
</quill-editor>
</div>
</div>
</div>
</div>
</div> </div>
<div *ngIf="currentTab == 2">
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '400px', 'overflow-y': 'auto' }"
[(ngModel)]="consent.requestConsentEng" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
</div> </div>
<div *ngIf="currentTab == 3">
<quill-editor [modules]="quillConfig" [styles]="{ 'height': '400px', 'overflow-y': 'auto' }"
[(ngModel)]="consent.requestConsentChina" [ngModelOptions]="{ standalone: true }"
theme="snow"></quill-editor>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="ti-modal-footer flex justify-center gap-4">
<button type="button" class="hs-dropdown-toggle ti-btn ti-btn-light align-middle" <div class="ti-modal-footer flex justify-center gap-4 mb-3">
data-hs-overlay="#modal-detail"> <button type="button" class="hs-dropdown-toggle ti-btn bg-danger align-middle text-white !font-medium"
(click)="modalRef.close()" #closeModal>
{{'Cancel' | translate}} {{'Cancel' | translate}}
</button> </button>
<button type="button" (click)="save()" class="ti-btn bg-primary text-white !font-medium">{{'Save' | <button type="button" (click)="save()" [disabled]="isSaving"
translate}}</button> class="ti-btn bg-primary text-white !font-medium">
{{ isSaving ? ('Saving...' | translate) : ('Save' | translate) }}
</button>
</div> </div>
</div> </div>
</div> </div>
<!-- </div> -->
</ng-template> </ng-template>
</ng-container> </ng-container>
<ng-container *ngIf="edit"> <ng-container *ngIf="edit">
......
...@@ -40,23 +40,19 @@ import { MatDialog } from "@angular/material/dialog"; ...@@ -40,23 +40,19 @@ import { MatDialog } from "@angular/material/dialog";
export class PdpaManageComponent { export class PdpaManageComponent {
quillConfig = { quillConfig = {
toolbar: [ toolbar: [
['link'], // เพิ่มปุ่มลิงก์ ['link'],
['bold', 'italic', 'underline', 'strike'], // toggled buttons ['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block'], ['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered' }, { 'list': 'bullet' }], [{ 'list': 'ordered' }, { 'list': 'bullet' }],
[{ 'script': 'sub' }, { 'script': 'super' }], // superscript/subscript [{ 'script': 'sub' }, { 'script': 'super' }],
[{ 'indent': '-1' }, { 'indent': '+1' }], // outdent/indent [{ 'indent': '-1' }, { 'indent': '+1' }],
[{ 'direction': 'rtl' }], // text direction [{ 'direction': 'rtl' }],
[{ 'size': ['small', false, 'large', 'huge'] }],
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }], [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'align': [] }], [{ 'align': [] }],
['clean'], // remove formatting button ['clean'],
] ]
}; };
@ViewChild('closeModal') public childModal?: ElementRef; @ViewChild('closeModal') public childModal?: ElementRef;
...@@ -69,21 +65,16 @@ export class PdpaManageComponent { ...@@ -69,21 +65,16 @@ export class PdpaManageComponent {
currentTab = 1 currentTab = 1
// modalStatus = "new";
allSelected = false; allSelected = false;
someSelected = false; someSelected = false;
confirmPassword = ""
itemsList: MyPdpaConsentModel[] = [] itemsList: MyPdpaConsentModel[] = []
filterList: MyPdpaConsentModel[] = [] filterList: MyPdpaConsentModel[] = []
consent: MyPdpaConsentModel = new MyPdpaConsentModel() consent: MyPdpaConsentModel = new MyPdpaConsentModel()
selectedItems = new Map<string, boolean>(); selectedItems = new Map<string, boolean>();
roleList: MyPdpaConsentModel[] = []
empList: MyPdpaConsentModel[] = []
descName = 'engName'
pageIndex = 0; pageIndex = 0;
uploaderProfile: FileUploader | undefined;
uploadErrorMsg: string = "";
modalStatus: "add" | "edit" = "add" modalStatus: "add" | "edit" = "add"
isSaving = false;
get searchTerm(): string { get searchTerm(): string {
return this._searchTerm; return this._searchTerm;
...@@ -99,23 +90,11 @@ export class PdpaManageComponent { ...@@ -99,23 +90,11 @@ export class PdpaManageComponent {
} }
} }
editVersion(version: string) {
this.pdpaService.getConfigList().subscribe(res => {
const matched = res.find(item => item.version === version);
if (matched) {
this.pdpaconfig = new MyPdpaConsentModel(matched, this.translate);
this.edit = true;
}
});
}
_searchTerm = ""; _searchTerm = "";
constructor(private pdpaService: PdpaService, public translate: TranslateService, private tokenService: TokenService, private router: Router, private modal: MatDialog) { constructor(private pdpaService: PdpaService, public translate: TranslateService, private modal: MatDialog) {
} }
ngOnInit(): void { ngOnInit(): void {
this.pdpaService.getConfigList().subscribe(res => { this.pdpaService.getConfigList().subscribe(res => {
this.itemsList = res.map(item => new MyPdpaConsentModel(item, this.translate)); this.itemsList = res.map(item => new MyPdpaConsentModel(item, this.translate));
...@@ -123,30 +102,6 @@ export class PdpaManageComponent { ...@@ -123,30 +102,6 @@ export class PdpaManageComponent {
}); });
} }
createNewVersion() {
this.router.navigate(['/admin/pdpa-config/new']);
}
deleteVersion(version: string) {
swal({
title: "ยืนยันลบเวอร์ชัน?",
text: version,
icon: "warning",
dangerMode: true,
buttons: ["ยกเลิก", "ลบ"]
}).then(confirm => {
if (confirm) {
this.pdpaService.deleteConfig(version).subscribe(() => {
swal("สำเร็จ", "ลบเวอร์ชันเรียบร้อย", "success");
this.ngOnInit();
});
}
});
}
filter(v: string): MyPdpaConsentModel[] { filter(v: string): MyPdpaConsentModel[] {
const search = v.toLowerCase(); const search = v.toLowerCase();
return this.itemsList.filter(x => return this.itemsList.filter(x =>
...@@ -157,107 +112,99 @@ export class PdpaManageComponent { ...@@ -157,107 +112,99 @@ export class PdpaManageComponent {
); );
} }
delete(item: PdpaModel) {
swal({
title: "Are you sure?",
text: "You won't be able to revert this!",
icon: "warning",
dangerMode: true,
buttons: ["Cancel", "Yes,Delete it!"],
})
.then((willDelete: any) => {
if (willDelete) {
this.pdpaService.deletePost(item).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit()
})
}
});
}
new() { new() {
this.modalStatus = 'add' this.modalStatus = 'add'
this.openModal() this.consent = new MyPdpaConsentModel(); // สร้างอ็อบเจกต์ใหม่เสมอเมื่อเปิดหน้าต่างเพิ่ม
this.consent = new MyPdpaConsentModel() this.openModal();
} }
view(item: MyPdpaConsentModel) { view(item: MyPdpaConsentModel) {
this.modalStatus = 'edit' this.modalStatus = 'edit';
this.confirmPassword = '' // สร้าง MyPdpaConsentModel ใหม่จาก item เพื่อให้ไม่กระทบข้อมูลเดิม
this.openModal() // และเรียกใช้ formatDatesForDatetimeLocal เพื่อปรับรูปแบบวันที่
this.consent = new MyPdpaConsentModel(item, this.translate); this.consent = new MyPdpaConsentModel(item, this.translate);
this.formatDatesForDatetimeLocal(this.consent); // เพิ่มโค้ดนี้
this.openModal();
}
// --- เพิ่มฟังก์ชันนี้เข้าไปในคลาส PdpaManageComponent ---
private formatDatesForDatetimeLocal(consentModel: MyPdpaConsentModel): void {
if (consentModel.startDate) {
// ตัดสตริงให้เหลือแค่ YYYY-MM-DDTHH:mm
consentModel.startDate = consentModel.startDate.substring(0, 16);
}
if (consentModel.endDate) {
// ตัดสตริงให้เหลือแค่ YYYY-MM-DDTHH:mm
consentModel.endDate = consentModel.endDate.substring(0, 16);
} }
}
// ----------------------------------------------------
save() { save() {
if (this.isSaving) return;
swal({ swal({
title: "Are you sure?", title: "Are you sure?",
text: "คุณต้องการบันทึกหรือไม่", text: "คุณต้องการบันทึกหรือไม่",
icon: "warning", icon: "warning",
dangerMode: false, dangerMode: false,
buttons: ["Cancel", "Confirm"], buttons: ["Cancel", "Confirm"],
}) }).then(willSave => {
.then((willDelete: any) => { if (willSave) {
if (willDelete) { this.isSaving = true;
console.log(this.consent);
// 🔧 สร้าง payload เปล่า (ถ้ายังไม่ได้แก้ class)
// if (this.modalStatus == 'add') { const payload = {
// this.pdpaService.postPdpa(this.consent).subscribe(result => { version: this.consent.version,
// console.log(result) startDate: this.consent.startDate,
// swal("Save Success!!", "บันทึกข้อมูลสมาชิก", "success"); endDate: this.consent.endDate,
// this.ngOnInit() status: this.consent.status,
// this.childModal?.nativeElement.click() requestConsentThai: this.consent.requestConsentThai,
// }) requestConsentEng: this.consent.requestConsentEng,
// } else if (this.modalStatus == 'edit') { requestConsentChina: this.consent.requestConsentChina
// this.pdpaService.postPdpa(this.consent).subscribe(result => { };
// console.log(result)
// swal("Update Success!!", "บันทึกข้อมูลสมาชิก", "success");
// this.ngOnInit()
// this.childModal?.nativeElement.click()
// })
// }
this.pdpaService.postConfig(payload).subscribe({
next: res => {
swal("Success", "บันทึกแล้ว", "success");
this.isSaving = false;
this.ngOnInit();
this.modalRef.close();
},
error: err => {
swal("Error", "เกิดข้อผิดพลาด", "error");
this.isSaving = false;
} }
}); });
} }
});
updatePagedItems() {
const startIndex = this.pageIndex * 10;
const endIndex = startIndex + 10;
this.filterList = this.itemsList.slice(startIndex, endIndex);
} }
toggleAll(event: any) {
this.allSelected = event.target.checked; deleteVersion(item: PdpaConsentModel) {
this.selectedItems.clear(); swal({
this.itemsList.forEach(item => { title: "Are you sure?",
this.selectedItems.set(item.version, this.allSelected); text: "You won't be able to revert this!",
icon: "warning",
dangerMode: true,
buttons: ["Cancel", "Yes,Delete it!"],
}).then((willDelete: any) => {
if (willDelete) {
this.pdpaService.deleteConfig(item.version).subscribe(result => {
swal("Delete Success!!", "ลบข้อมูลสำเร็จ", "success");
this.ngOnInit();
}); });
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.version));
} }
});
onCheckboxChange(version: string) {
const isSelected = this.selectedItems.get(version) || false;
this.selectedItems.set(version, !isSelected);
this.allSelected = this.itemsList.every(item => this.selectedItems.get(item.version));
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.version));
} }
deleteSelect() { deleteSelect() {
let employeeInfo = ''; let employeeInfo = '';
this.selectedItems.forEach((isSelected, version) => { this.selectedItems.forEach((isSelected, version) => {
if (isSelected) { if (isSelected) {
const user = this.itemsList.find(user => user.version === version) as MyPdpaConsentModel; const pdpa = this.itemsList.find(pdpa => pdpa.version === version) as MyPdpaConsentModel;
if (user) { if (pdpa) {
employeeInfo += `${this.translate.instant('version')}: ${user.version}\n`; employeeInfo += `${this.translate.instant('version')}: ${pdpa.version}\n`;
} }
} }
}); });
...@@ -273,10 +220,10 @@ export class PdpaManageComponent { ...@@ -273,10 +220,10 @@ export class PdpaManageComponent {
if (willDelete) { if (willDelete) {
this.selectedItems.forEach((isSelected, version) => { this.selectedItems.forEach((isSelected, version) => {
if (isSelected) { if (isSelected) {
const user = this.itemsList.find(user => user.version === version); const pdpa = this.itemsList.find(pdpa => pdpa.version === version);
if (user) { if (pdpa) {
this.pdpaService.deletePost(user).subscribe(result => { this.pdpaService.deleteConfig(version).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success"); swal("Delete Success!!", "ลบข้อมูลที่เลือกสำเร็จ", "success");
this.ngOnInit(); this.ngOnInit();
}); });
} }
...@@ -286,46 +233,32 @@ export class PdpaManageComponent { ...@@ -286,46 +233,32 @@ export class PdpaManageComponent {
}); });
} }
// adjustSelect(status: number) { updatePagedItems() {
// let title = "Are you sure?" const startIndex = this.pageIndex * 10;
// let employeeInfo = ''; // ตัวแปรสำหรับเก็บข้อมูลพนักงาน const endIndex = startIndex + 10;
// this.selectedItems.forEach((isSelected, version) => { this.filterList = this.itemsList.slice(startIndex, endIndex);
// if (isSelected) { }
// const user = this.itemsList.find(user => user.version === version);
// if (user) { toggleAll(event: any) {
// employeeInfo += `${this.translate.instant('Fullname')}: ${user.getFullname()}\n`; this.allSelected = event.target.checked;
// } this.selectedItems.clear();
// } this.itemsList.forEach(item => {
// }); this.selectedItems.set(item.version, this.allSelected);
// swal({ });
// title: title, this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.version));
// text: employeeInfo, }
// icon: "warning",
// dangerMode: false,
// buttons: ["Cancel", "Confirm"],
// })
// .then((willDelete: any) => {
// if (willDelete) {
// this.selectedItems.forEach((isSelected, version) => {
// if (isSelected) {
// const user = this.itemsList.find(user => user.version === version);
// if (user) {
// user.pdpa.status = status
// this.pdpaService.postPdpa(user).subscribe(result => {
// swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
// this.ngOnInit();
// });
// }
// }
// });
// }
// }); onCheckboxChange(version: string) {
// } const isSelected = this.selectedItems.get(version) || false;
this.selectedItems.set(version, !isSelected);
this.allSelected = this.itemsList.every(item => this.selectedItems.get(item.version));
this.someSelected = this.itemsList.some(item => this.selectedItems.get(item.version));
}
openModal() { openModal() {
this.modalRef = this.modal.open(this.modalDetail, { this.modalRef = this.modal.open(this.modalDetail, {
width: '1000px', width: '1500px',
height: '750px'
}) })
} }
...@@ -334,7 +267,7 @@ export class PdpaManageComponent { ...@@ -334,7 +267,7 @@ export class PdpaManageComponent {
} }
filterEmp(empId: string) { filterEmp(empId: string) {
this.consent = this.empList.filter(e => e.version == empId)[0] this.consent = this.itemsList.filter(e => e.version == empId)[0]
} }
} }
\ No newline at end of file
...@@ -36,7 +36,7 @@ export class MyPdpaModel extends BaseModel implements PdpaModel { ...@@ -36,7 +36,7 @@ export class MyPdpaModel extends BaseModel implements PdpaModel {
pdpa: PdpaConsentModel pdpa: PdpaConsentModel
consentStatus: boolean consentStatus: boolean
constructor(data?: Partial<PdpaModel>, translateService?: TranslateService) { constructor(data?: Partial<PdpaModel>, translateService?: TranslateService) {
super(data, translateService) super(data)
this.profileId = data?.profileId || '' this.profileId = data?.profileId || ''
this.thFirstname = data?.thFirstname || '' this.thFirstname = data?.thFirstname || ''
this.engFirstname = data?.engFirstname || '' this.engFirstname = data?.engFirstname || ''
......
...@@ -116,18 +116,19 @@ export class NavService implements OnDestroy { ...@@ -116,18 +116,19 @@ export class NavService implements OnDestroy {
}, },
{ {
icon: 'user-check', icon: 'news',
path: '/admin/admin-manage', path: '/admin/pdpa-manage',
title: 'จัดการสิทธิ์ผู้ดูแลระบบ', title: 'จัดการ PDPA',
type: 'link', type: 'link',
}, },
{ {
icon: 'news', icon: 'user-check',
path: '/admin/pdpa-manage', path: '/admin/admin-manage',
title: 'จัดการ PDPA', title: 'จัดการสิทธิ์ผู้ดูแลระบบ',
type: 'link', type: 'link',
}, },
// { headTitle: 'User Management' }, // { headTitle: 'User Management' },
]; ];
......
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