edit-organization.component.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { Component, OnInit } from '@angular/core';
  2. import { OrganizationsService } from '@app/services/organizations.service';
  3. import { FormBuilder, FormGroup, Validators } from '@angular/forms';
  4. import { ActivatedRoute } from '@angular/router';
  5. import Swal from 'sweetalert2';
  6. @Component({
  7. selector: 'app-edit-organization',
  8. templateUrl: './edit-organization.component.html',
  9. styleUrls: ['./edit-organization.component.scss']
  10. })
  11. export class EditOrganizationComponent implements OnInit {
  12. [x: string]: any;
  13. title:string = "Editar organización";
  14. listOrganization: any;
  15. organizationExists:boolean;
  16. organizationForm: FormGroup;
  17. organizationId:any;
  18. role_number: any;
  19. constructor(private orgService: OrganizationsService, private formBuilder: FormBuilder, private route: ActivatedRoute) {
  20. this.route.params.subscribe(params => {
  21. this.organizationId = params['id'];
  22. });
  23. this.orgService.getOrganization(this.organizationId).subscribe(res => {
  24. this.listOrganization = res["data"]["organization"];
  25. this.organizationExists = true;
  26. this.organizationForm = this.formBuilder.group({
  27. name: [this.listOrganization.name],
  28. address: [this.listOrganization.address],
  29. city: [this.listOrganization.city],
  30. country: [this.listOrganization.country],
  31. contactName: [this.listOrganization.contactName],
  32. contactNumber: [this.listOrganization.contactNumber],
  33. });
  34. }, (err) => {
  35. Swal.fire({
  36. type: 'error',
  37. title: 'Error en el servidor',
  38. text: err.message
  39. });
  40. });
  41. }
  42. ngOnInit() {
  43. }
  44. get f() { return this.organizationForm.controls; }
  45. editOrganization() {
  46. this.orgService.updateOrganization(this.organizationId,
  47. {
  48. name: this.f.name.value,
  49. address: this.f.address.value,
  50. city: this.f.city.value,
  51. country: this.f.country.value,
  52. contactName: this.f.contactName.value,
  53. contactNumber: this.f.contactNumber.value,
  54. assets: [""],
  55. }
  56. )
  57. .subscribe(success => {
  58. if (success) {
  59. Swal.fire({
  60. allowOutsideClick: false,
  61. type: 'success',
  62. text: 'Informacion actualizada con exito'
  63. });
  64. //window.location.href="#/dashboard";
  65. }
  66. });
  67. }
  68. }