add confirm modal directive
This commit is contained in:
parent
1cd6e16ce4
commit
96be2876b8
@ -0,0 +1,55 @@
|
|||||||
|
import { Directive, Input, TemplateRef, HostListener } from '@angular/core';
|
||||||
|
import { ConfirmModalService } from './confirm-modal.service';
|
||||||
|
import { IDataSource } from '@poweredsoft/data';
|
||||||
|
|
||||||
|
@Directive({
|
||||||
|
selector: '[psbxConfirmModal]'
|
||||||
|
})
|
||||||
|
export class ConfirmModalDirective {
|
||||||
|
|
||||||
|
constructor(private confirmModalService: ConfirmModalService) { }
|
||||||
|
|
||||||
|
|
||||||
|
@Input() dataSource: IDataSource<any>;
|
||||||
|
@Input() command: string;
|
||||||
|
@Input() model: any;
|
||||||
|
@Input() template: TemplateRef<any>;
|
||||||
|
@Input() commandTitle: string;
|
||||||
|
@Input() refreshOnSuccess: boolean;
|
||||||
|
@Input() commandText: string;
|
||||||
|
@Input() cancelText: string;
|
||||||
|
@Input() animated: boolean;
|
||||||
|
|
||||||
|
|
||||||
|
@HostListener('click')
|
||||||
|
wasClicked() {
|
||||||
|
this.dataSource.resolveCommandModelByName({
|
||||||
|
command: this.command,
|
||||||
|
model: this.model
|
||||||
|
}).subscribe(commandModel => {
|
||||||
|
this.confirmModalService.confirm({
|
||||||
|
message: 'Do you want to delete this merchant?',
|
||||||
|
yesText: 'yes delete this merchant',
|
||||||
|
yesClass: 'danger',
|
||||||
|
noText: 'no please dont',
|
||||||
|
noClass: 'light'
|
||||||
|
}).subscribe(result => {
|
||||||
|
if(result){
|
||||||
|
this.dataSource.executeCommandByName(this.command, commandModel).subscribe(
|
||||||
|
res => {
|
||||||
|
this.dataSource.refresh();
|
||||||
|
},
|
||||||
|
err => {
|
||||||
|
console.log(err);
|
||||||
|
alert('failed');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}, error => {
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,16 +3,18 @@ import { CommonModule } from '@angular/common';
|
|||||||
import { ConfirmModalComponent } from './confirm-modal-components/confirm-modal/confirm-modal.component';
|
import { ConfirmModalComponent } from './confirm-modal-components/confirm-modal/confirm-modal.component';
|
||||||
import { ModalModule } from 'ngx-bootstrap/modal';
|
import { ModalModule } from 'ngx-bootstrap/modal';
|
||||||
import { ConfirmModalService } from './confirm-modal.service';
|
import { ConfirmModalService } from './confirm-modal.service';
|
||||||
|
import { ConfirmModalDirective } from './confirm-modal.directive';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [ConfirmModalComponent],
|
declarations: [ConfirmModalComponent, ConfirmModalDirective],
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
ModalModule.forRoot(),
|
ModalModule.forRoot(),
|
||||||
|
|
||||||
],
|
],
|
||||||
|
exports:[ConfirmModalDirective],
|
||||||
providers: [ConfirmModalService]
|
providers: [ConfirmModalService]
|
||||||
})
|
})
|
||||||
export class ConfirmModalModule { }
|
export class ConfirmModalModule { }
|
||||||
|
@ -10,5 +10,6 @@ export * from './lib/pagination/psbxPagination.module';
|
|||||||
export * from './lib/pagination/data-source-pagination/data-source-pagination.component';
|
export * from './lib/pagination/data-source-pagination/data-source-pagination.component';
|
||||||
export * from './lib/confirm-modal/confirm-modal.module';
|
export * from './lib/confirm-modal/confirm-modal.module';
|
||||||
export * from './lib/confirm-modal/confirm-modal.service';
|
export * from './lib/confirm-modal/confirm-modal.service';
|
||||||
|
export * from './lib/confirm-modal/confirm-modal.directive';
|
||||||
export * from './lib/spinner/spinner.module';
|
export * from './lib/spinner/spinner.module';
|
||||||
export * from './lib/spinner/spinner/spinner.component';
|
export * from './lib/spinner/spinner/spinner.component';
|
@ -42,9 +42,9 @@
|
|||||||
<ng-container psDataGridCol="commands">
|
<ng-container psDataGridCol="commands">
|
||||||
<ng-container *psDataGridColHeader>Actions</ng-container>
|
<ng-container *psDataGridColHeader>Actions</ng-container>
|
||||||
<ng-container *psDataGridCell="let model">
|
<ng-container *psDataGridCell="let model">
|
||||||
<!-- <button class="btn-warning btn" psbxCommandModal [commandTitle]="'Change ' + model.name + ' name'" commandText="Update"
|
<button class="btn-danger btn" psbxConfirmModal [commandTitle]="'Are you sure you wnat to remove ' + model.name + '?'" commandText="Remove"
|
||||||
[dataSource]="merchantDataSource" command="changeMerchant" [model]="model" [template]="changeName">Change</button> -->
|
[dataSource]="merchantDataSource" command="removeMerchant" [model]="model" >Remove</button>
|
||||||
<button class="btn-danger btn" (click)="removeMerchant(model.id)">Remove</button>
|
<!-- <button class="btn-danger btn" (click)="removeMerchant(model.id)">Remove</button> -->
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
@ -20,29 +20,29 @@ export class PaginationDemoComponent implements OnInit {
|
|||||||
|
|
||||||
pages:any;
|
pages:any;
|
||||||
|
|
||||||
removeMerchant(id:string) {
|
// removeMerchant(id:string) {
|
||||||
this.confirmModalService.confirm({
|
// this.confirmModalService.confirm({
|
||||||
message: 'Do you want to delete this merchant?',
|
// message: 'Do you want to delete this merchant?',
|
||||||
yesText: 'yes delete this merchant',
|
// yesText: 'yes delete this merchant',
|
||||||
yesClass: 'danger',
|
// yesClass: 'danger',
|
||||||
noText: 'no please dont',
|
// noText: 'no please dont',
|
||||||
noClass: 'light'
|
// noClass: 'light'
|
||||||
}).subscribe(result => {
|
// }).subscribe(result => {
|
||||||
if(result){
|
// if(result){
|
||||||
this.merchantDataSource.executeCommandByName('removeMerchant', {
|
// this.merchantDataSource.executeCommandByName('removeMerchant', {
|
||||||
id: id
|
// id: id
|
||||||
}).subscribe(
|
// }).subscribe(
|
||||||
res => {
|
// res => {
|
||||||
this.merchantDataSource.refresh();
|
// this.merchantDataSource.refresh();
|
||||||
},
|
// },
|
||||||
err => {
|
// err => {
|
||||||
console.log(err);
|
// console.log(err);
|
||||||
alert('failed');
|
// alert('failed');
|
||||||
}
|
// }
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
createDataSource(): IDataSource<IMerchant> {
|
createDataSource(): IDataSource<IMerchant> {
|
||||||
|
Loading…
Reference in New Issue
Block a user