add-visiting-time.component.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { DashboardService } from './../../../shared/dashboard.service';
  2. import { AuthServiceService } from './../../../shared/auth-service.service';
  3. import { UserService } from './../../../shared/user.service';
  4. import { ActivatedRoute, Params } from '@angular/router';
  5. import { ToastrService } from 'ngx-toastr';
  6. import { Location } from '@angular/common';
  7. import { Component, OnInit, ViewChild } from '@angular/core';
  8. import { NgForm } from '@angular/forms';
  9. import { NgxSpinnerService } from 'ngx-spinner';
  10. @Component({
  11. selector: 'app-add-visiting-time',
  12. templateUrl: './add-visiting-time.component.html',
  13. styleUrls: ['./add-visiting-time.component.css']
  14. })
  15. export class AddVisitingTimeComponent implements OnInit {
  16. @ViewChild('f') dataForm: NgForm;
  17. constructor(private userSer:UserService,
  18. public authSer:AuthServiceService,
  19. private toastr: ToastrService,
  20. private spinner: NgxSpinnerService,
  21. private dashboardSer: DashboardService,
  22. private location: Location,
  23. private route:ActivatedRoute) { }
  24. typeMode:boolean = false; //default false for create page
  25. typeLink: string;
  26. visitingTimeId:number;
  27. checkDisabledSave:boolean = false;
  28. checkSaveClick: boolean = false;
  29. visitingTime = {
  30. name: '',
  31. name_en: '',
  32. open_time: '',
  33. close_time: '',
  34. status: 1,
  35. };
  36. ngOnInit() {
  37. this.route.params.subscribe(
  38. (params: Params) => {
  39. if(params['typeVisitingTime'] == 'add'){
  40. this.typeMode = false;
  41. this.typeLink = 'إنشاء موعد';
  42. } else if(params['typeVisitingTime'] == 'edit') {
  43. this.spinner.show();
  44. this.typeMode = true;
  45. this.visitingTimeId = parseInt(localStorage.getItem('editvisitingTimeIdStorage'));
  46. this.typeLink = 'تعديل موعد';
  47. this.dashboardSer.getItemData(this.visitingTimeId, 'visitingTime').subscribe(
  48. (responce) => {
  49. console.log(responce);
  50. this.visitingTime = responce['visiting_time'];
  51. console.log(this.visitingTime);
  52. this.spinner.hide();
  53. },
  54. (error) => {
  55. console.log(error);
  56. }
  57. );
  58. } else {
  59. console.log('Catch Error Go To Home !');
  60. }
  61. }
  62. );
  63. }//ngOnInit
  64. onSubmitted() {
  65. this.checkDisabledSave = true;
  66. const dataFormContactUs = this.dataForm.value;
  67. this.checkSaveClick = true;
  68. console.log(dataFormContactUs)
  69. if(this.typeMode) {
  70. this.dashboardSer.editItem( this.visitingTimeId,dataFormContactUs, 'visitingTime').subscribe(
  71. (responce) => {
  72. console.log(responce);
  73. this.toastr.success('تم التعديل بنجاح ');
  74. this.checkSaveClick = false;
  75. this.location.back();
  76. },
  77. (error) => {
  78. console.log(error);
  79. this.checkSaveClick = false;
  80. this.toastr.error(' خطأ في التعديل !');
  81. }
  82. );
  83. }
  84. }
  85. }