File
Implements
Metadata
selector |
cd-rbd-trash-restore-modal |
styleUrls |
./rbd-trash-restore-modal.component.scss |
templateUrl |
./rbd-trash-restore-modal.component.html |
executingTasks
|
Type : ExecutingTask[]
|
|
Public
modalRef
|
Type : BsModalRef
|
|
import { Component, OnInit } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { RbdService } from '../../../shared/api/rbd.service';
import { CdFormBuilder } from '../../../shared/forms/cd-form-builder';
import { CdFormGroup } from '../../../shared/forms/cd-form-group';
import { ExecutingTask } from '../../../shared/models/executing-task';
import { FinishedTask } from '../../../shared/models/finished-task';
import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
@Component({
selector: 'cd-rbd-trash-restore-modal',
templateUrl: './rbd-trash-restore-modal.component.html',
styleUrls: ['./rbd-trash-restore-modal.component.scss']
})
export class RbdTrashRestoreModalComponent implements OnInit {
metaType: string;
poolName: string;
imageName: string;
imageId: string;
executingTasks: ExecutingTask[];
restoreForm: CdFormGroup;
constructor(
private rbdService: RbdService,
public modalRef: BsModalRef,
private fb: CdFormBuilder,
private taskWrapper: TaskWrapperService
) {}
ngOnInit() {
this.restoreForm = this.fb.group({
name: this.imageName
});
}
restore() {
const name = this.restoreForm.getValue('name');
this.taskWrapper
.wrapTaskAroundCall({
task: new FinishedTask('rbd/trash/restore', {
pool_name: this.poolName,
image_id: this.imageId,
new_image_name: name
}),
call: this.rbdService.restoreTrash(this.poolName, this.imageId, name)
})
.subscribe(
undefined,
() => {
this.restoreForm.setErrors({ cdSubmitButton: true });
},
() => {
this.modalRef.hide();
}
);
}
}
<cd-modal>
<ng-container i18n
class="modal-title">Restore Image</ng-container>
<ng-container class="modal-content">
<form name="restoreForm"
class="form"
#formDir="ngForm"
[formGroup]="restoreForm"
novalidate>
<div class="modal-body">
<p>
<ng-container i18n>To restore</ng-container>
<kbd>{{ poolName }}/{{ imageName }}@{{ imageId }}</kbd>,
<ng-container i18n>type the image's new name and click</ng-container>
<kbd i18n>Restore Image</kbd>.
</p>
<div class="form-group"
[ngClass]="{'has-error': restoreForm.showError('name', formDir)}">
<label for="name"
i18n>New Name</label>
<input type="text"
class="form-control"
name="name"
id="name"
autocomplete="off"
formControlName="name"
autofocus>
<span class="help-block"
*ngIf="restoreForm.showError('name', formDir, 'required')"
i18n>This field is required.</span>
</div>
</div>
<div class="modal-footer">
<div class="button-group text-right">
<cd-submit-button [form]="restoreForm"
(submitAction)="restore()"
i18n>Restore Image</cd-submit-button>
<cd-back-button [back]="modalRef.hide"
name="Cancel"
i18n-name>
</cd-back-button>
</div>
</div>
</form>
</ng-container>
</cd-modal>
Legend
Html element with directive