prompt allert
parent
f9f879e424
commit
f4b6f9de1b
|
|
@ -16,3 +16,4 @@
|
|||
<footer class="space"></footer>
|
||||
</div>
|
||||
<fullscreen-gallery></fullscreen-gallery>
|
||||
<cms-dialog></cms-dialog>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import {Component, Input} from '@angular/core';
|
||||
import {FormsService, ListsService, ObjectsService} from "@app/_services";
|
||||
import { DialogService } from '@app/_services/dialog.service';
|
||||
|
||||
@Component({
|
||||
selector: 'page-menu',
|
||||
|
|
@ -14,7 +15,11 @@ export class PageMenuComponent {
|
|||
@Input() modelId: string;
|
||||
@Input() modelType: string;
|
||||
|
||||
constructor(private formsService: FormsService, private objectsService: ObjectsService, private listsService: ListsService) {
|
||||
constructor(
|
||||
private formsService: FormsService,
|
||||
private objectsService: ObjectsService,
|
||||
private listsService: ListsService,
|
||||
private dialog: DialogService) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
|
@ -50,9 +55,12 @@ export class PageMenuComponent {
|
|||
}
|
||||
|
||||
delete() {
|
||||
//r u sure?
|
||||
if (confirm('Удалить этот блок?')) this.objectsService.destroy(this.section.id).subscribe(res => {
|
||||
this.listsService.refresh();
|
||||
});
|
||||
this.dialog.prompt('Удалить этот блок?').subscribe(
|
||||
resp=>{
|
||||
if (resp) this.objectsService.destroy(this.section.id).subscribe(res => {
|
||||
this.listsService.refresh();
|
||||
});
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
<cms-modal (close)="close()" *ngIf="showAllert">
|
||||
<div header>
|
||||
<h4>Внимание</h4>
|
||||
</div>
|
||||
<div body>
|
||||
{{allert}}
|
||||
</div>
|
||||
<div footer>
|
||||
<button class="prime" (click)="close()">
|
||||
Закрыть
|
||||
</button>
|
||||
</div>
|
||||
</cms-modal>
|
||||
|
||||
<cms-modal (close)="respNo()" *ngIf="showPrompt">
|
||||
<div header>
|
||||
<h4>Подтверждение</h4>
|
||||
</div>
|
||||
<div body>
|
||||
{{prompt}}
|
||||
</div>
|
||||
<div footer>
|
||||
<button class="prime outline" (click)="respNo()">
|
||||
ОТМЕНА
|
||||
</button>
|
||||
<button class="prime" (click)="respYes()">
|
||||
ПОДТВЕРДИТЬ
|
||||
</button>
|
||||
</div>
|
||||
</cms-modal>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
[footer]{
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 20px;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { DialogService } from '@app/_services/dialog.service';
|
||||
import { Subscription, BehaviorSubject } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'cms-dialog',
|
||||
templateUrl: './cms-dialog.component.html',
|
||||
styleUrls: ['./cms-dialog.component.scss']
|
||||
})
|
||||
export class CmsDialogComponent {
|
||||
constructor(
|
||||
private dialog: DialogService
|
||||
){}
|
||||
|
||||
allert: string;
|
||||
prompt: string;
|
||||
resp: BehaviorSubject<string>;
|
||||
showAllert: boolean;
|
||||
showPrompt: boolean;
|
||||
|
||||
ngOnInit(){
|
||||
this.dialog.modalAllertSubject.subscribe(
|
||||
allert=>{
|
||||
if (allert) {
|
||||
this.allert = allert;
|
||||
this.showAllert = true;
|
||||
}
|
||||
}
|
||||
)
|
||||
this.dialog.modalPromptSubject.subscribe(
|
||||
prompt=>{
|
||||
if (prompt) {
|
||||
this.prompt = prompt;
|
||||
this.showPrompt = true;
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
respYes(){
|
||||
this.dialog.modalRespSubject.next(true);
|
||||
this.close();
|
||||
}
|
||||
|
||||
respNo(){
|
||||
this.dialog.modalRespSubject.next(false);
|
||||
this.close();
|
||||
}
|
||||
|
||||
close(){
|
||||
this.showPrompt = this.showAllert = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ import {SwiperModule} from "swiper/angular";
|
|||
import { SwiperGalleryComponent } from './swiper-gallery/swiper-gallery.component';
|
||||
import {FullscreenGalleryComponent} from "@app/_modules/widjet/swiper-gallery/fullscreen/fullscreen-gallery.component";
|
||||
import { CmsModalComponent } from './cms-modal/cms-modal.component';
|
||||
import { CmsDialogComponent } from './cms-dialog/cms-dialog.component';
|
||||
|
||||
|
||||
@NgModule({
|
||||
|
|
@ -34,7 +35,8 @@ import { CmsModalComponent } from './cms-modal/cms-modal.component';
|
|||
ModalComponent,
|
||||
SwiperGalleryComponent,
|
||||
FullscreenGalleryComponent,
|
||||
CmsModalComponent
|
||||
CmsModalComponent,
|
||||
CmsDialogComponent
|
||||
],
|
||||
exports: [
|
||||
IcoComponent,
|
||||
|
|
@ -47,7 +49,8 @@ import { CmsModalComponent } from './cms-modal/cms-modal.component';
|
|||
ModalComponent,
|
||||
SwiperGalleryComponent,
|
||||
FullscreenGalleryComponent,
|
||||
CmsModalComponent
|
||||
CmsModalComponent,
|
||||
CmsDialogComponent
|
||||
]
|
||||
})
|
||||
export class WidjetModule {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {environment} from '@environments/environment';
|
||||
import {Observable, BehaviorSubject} from "rxjs";
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DialogService {
|
||||
|
||||
public modalAllertSubject = new BehaviorSubject<string>(null)
|
||||
public modalPromptSubject = new BehaviorSubject<string>(null);
|
||||
public modalRespSubject = new BehaviorSubject<boolean>(null);
|
||||
private userResp: BehaviorSubject<boolean>
|
||||
|
||||
constructor(){
|
||||
this.modalRespSubject.subscribe(
|
||||
resp=>{
|
||||
if (resp !== null){
|
||||
this.userResp.next(resp);
|
||||
this.userResp.complete();
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
alert(txt:string){
|
||||
this.modalAllertSubject.next(txt)
|
||||
}
|
||||
prompt(txt:string){
|
||||
this.modalPromptSubject.next(txt);
|
||||
this.userResp = new BehaviorSubject(null)
|
||||
return this.userResp;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue