dialog insert update action call api
import { Component, OnInit } from '@angular/core';
import { MatDialog, MatSnackBar } from '@angular/material';
contactTypeData;
id: any;
position = 'before';
formShowStatus = false;
showLoadingStatus = true;
constructor(public dialog: MatDialog, private settingService: SettingService,
public snackBar: MatSnackBar) { }
list page dialog acion perform
firstly call get api
getconatct(): void {
this.settingService.getContactType()
.subscribe(
data => this.getContactResponse(data),
error => this.getContactResponseError(error)
)
}
getContactResponse(data) {
if (data.status === true) {
this.contactTypeData = data.message;
this.showLoadingStatus = false;
}
}
getContactResponseError(error) {
}
------------------------open create dialog -----------------------------------------------------
createContactTypeDialog(): void {
let dialogRef = this.dialog.open(CreateContactTypeComponent, {
width: '500px',
height: 'auto',
data: '',
autoFocus: true
});
dialogRef.afterClosed().subscribe(result => {
if (typeof result === 'object') {
if (result.status === true) {
var lastInsertedData = result.result[0];
this.contactTypeData.push(lastInsertedData);
this.openSnackBar(result.message, 'Dismiss')
}
}
});
}
------------edit create dialog -----------------------------------------------------
editContactTypeDialog(contactType): void {
let dialogRef = this.dialog.open(UpdateContactTypeComponent, {
width: '500px',
height: 'auto',
data: contactType,
autoFocus: false
});
dialogRef.afterClosed().subscribe(result => {
if (typeof result === 'string' || result === undefined) {
return;
}
let updatedData = result.result[0];
if (typeof result === 'object') {
if (result.status === true) {
for (var i = 0; i < this.contactTypeData.length; i++) {
if (this.contactTypeData[i].contact_type_pid === updatedData.contact_type_pid) {
this.contactTypeData[i] = result.result[0];
}
}
this.openSnackBar(result.message, 'Dismiss')
}
}
});
}
----------------delete api-------------------------------------
deleteContactTypeDialog(id: any): void {
let dialogRef = this.dialog.open(DeleteContactTypeComponent, {
width: '500px',
height: '',
data: { contact_id: id },
autoFocus: false
});
dialogRef.afterClosed().subscribe(result => {
if (typeof result === 'object') {
if (result.status === true) {
for (var i = 0; i < this.contactTypeData.length; i++) {
if (this.contactTypeData[i].contact_type_pid === id) {
this.contactTypeData.splice(i, 1);
}
}
this.openSnackBar(result.message, 'Dismiss')
}
}
});
}
----------------open sanckbar-------------------------------------
openSnackBar(message: string, action: string) {
this.snackBar.open(message, action, {
duration: 3000,
panelClass: ['app-bottom-snackbar']
});
}
}
Comments
Post a Comment