privacy-update.component.ts 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { Component, OnInit } from '@angular/core';
  2. import { ActivatedRoute } from '@angular/router';
  3. import { HttpResponse, HttpErrorResponse } from '@angular/common/http';
  4. import { Observable } from 'rxjs';
  5. import { IPrivacy } from 'app/shared/model/privacy.model';
  6. import { PrivacyService } from './privacy.service';
  7. @Component({
  8. selector: 'jhi-privacy-update',
  9. templateUrl: './privacy-update.component.html'
  10. })
  11. export class PrivacyUpdateComponent implements OnInit {
  12. privacy: IPrivacy;
  13. isSaving: boolean;
  14. constructor(private privacyService: PrivacyService, private activatedRoute: ActivatedRoute) {}
  15. ngOnInit() {
  16. this.isSaving = false;
  17. this.activatedRoute.data.subscribe(({ privacy }) => {
  18. this.privacy = privacy;
  19. });
  20. }
  21. previousState() {
  22. window.history.back();
  23. }
  24. save() {
  25. this.isSaving = true;
  26. if (this.privacy.id !== undefined) {
  27. this.subscribeToSaveResponse(this.privacyService.update(this.privacy));
  28. } else {
  29. this.subscribeToSaveResponse(this.privacyService.create(this.privacy));
  30. }
  31. }
  32. private subscribeToSaveResponse(result: Observable<HttpResponse<IPrivacy>>) {
  33. result.subscribe((res: HttpResponse<IPrivacy>) => this.onSaveSuccess(), (res: HttpErrorResponse) => this.onSaveError());
  34. }
  35. private onSaveSuccess() {
  36. this.isSaving = false;
  37. this.previousState();
  38. }
  39. private onSaveError() {
  40. this.isSaving = false;
  41. }
  42. }