]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | import { Component, OnInit } from '@angular/core'; |
2 | import { FormControl } from '@angular/forms'; | |
3 | ||
f67539c2 | 4 | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; |
9f95a23c | 5 | |
f67539c2 TL |
6 | import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service'; |
7 | import { ActionLabelsI18n } from '~/app/shared/constants/app.constants'; | |
8 | import { CdFormGroup } from '~/app/shared/forms/cd-form-group'; | |
9 | import { FinishedTask } from '~/app/shared/models/finished-task'; | |
10 | import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service'; | |
9f95a23c TL |
11 | |
12 | @Component({ | |
13 | selector: 'cd-edit-site-mode-modal', | |
14 | templateUrl: './edit-site-name-modal.component.html', | |
15 | styleUrls: ['./edit-site-name-modal.component.scss'] | |
16 | }) | |
17 | export class EditSiteNameModalComponent implements OnInit { | |
18 | siteName: string; | |
19 | ||
20 | editSiteNameForm: CdFormGroup; | |
21 | ||
22 | constructor( | |
f67539c2 TL |
23 | public activeModal: NgbActiveModal, |
24 | public actionLabels: ActionLabelsI18n, | |
9f95a23c TL |
25 | private rbdMirroringService: RbdMirroringService, |
26 | private taskWrapper: TaskWrapperService | |
27 | ) { | |
28 | this.createForm(); | |
29 | } | |
30 | ||
31 | createForm() { | |
32 | this.editSiteNameForm = new CdFormGroup({ | |
33 | siteName: new FormControl('', {}) | |
34 | }); | |
35 | } | |
36 | ||
37 | ngOnInit() { | |
38 | this.editSiteNameForm.get('siteName').setValue(this.siteName); | |
39 | this.rbdMirroringService.getSiteName().subscribe((response: any) => { | |
40 | this.editSiteNameForm.get('siteName').setValue(response.site_name); | |
41 | }); | |
42 | } | |
43 | ||
44 | update() { | |
45 | const action = this.taskWrapper.wrapTaskAroundCall({ | |
46 | task: new FinishedTask('rbd/mirroring/site_name/edit', {}), | |
47 | call: this.rbdMirroringService.setSiteName(this.editSiteNameForm.getValue('siteName')) | |
48 | }); | |
49 | ||
f67539c2 TL |
50 | action.subscribe({ |
51 | error: () => this.editSiteNameForm.setErrors({ cdSubmitButton: true }), | |
52 | complete: () => { | |
9f95a23c | 53 | this.rbdMirroringService.refresh(); |
f67539c2 | 54 | this.activeModal.close(); |
9f95a23c | 55 | } |
f67539c2 | 56 | }); |
9f95a23c TL |
57 | } |
58 | } |