add-event-calendar.component.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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-event-calendar',
  12. templateUrl: './add-event-calendar.component.html',
  13. styleUrls: ['./add-event-calendar.component.css']
  14. })
  15. export class AddEventCalendarComponent implements OnInit {
  16. @ViewChild('f') dataForm: NgForm;
  17. constructor(private userSer:UserService,
  18. private 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. eventCalendarId:number;
  27. checkDisabledSave:boolean = false;
  28. eventCalendar = {
  29. title: '',
  30. title_en: '',
  31. description: '',
  32. description_en: '',
  33. event_time: '',
  34. status: 1,
  35. };
  36. ngOnInit() {
  37. this.route.params.subscribe(
  38. (params: Params) => {
  39. console.log(params)
  40. if(params['typeEventCalendar'] == 'add'){
  41. this.typeMode = false;
  42. this.typeLink = 'إنشاء حدث';
  43. } else if(params['typeEventCalendar'] == 'edit') {
  44. this.spinner.show();
  45. this.typeMode = true;
  46. this.eventCalendarId = parseInt(params.eventCalendarId);
  47. this.typeLink = 'تعديل حدث';
  48. this.dashboardSer.getItemData(this.eventCalendarId, 'eventCalendar').subscribe(
  49. (responce) => {
  50. console.log(responce);
  51. this.eventCalendar = responce['event_calendar'];
  52. console.log(this.eventCalendar);
  53. this.spinner.hide();
  54. },
  55. (error) => {
  56. console.log(error);
  57. }
  58. );
  59. } else {
  60. console.log('sdsd');
  61. }
  62. }
  63. );
  64. }//ngOnInit
  65. onSubmitted() {
  66. this.checkDisabledSave = true;
  67. const dataFormEventBar = this.dataForm.value;
  68. console.log(dataFormEventBar);
  69. if(this.typeMode) {
  70. this.dashboardSer.editItem( this.eventCalendarId,dataFormEventBar, 'eventCalendar').subscribe(
  71. (responce) => {
  72. console.log(responce);
  73. this.toastr.success('تم التعديل بنجاح ');
  74. this.checkDisabledSave = false;
  75. this.location.back();
  76. },
  77. (error) => {
  78. console.log(error);
  79. this.checkDisabledSave = false;
  80. this.toastr.error(' خطأ في التعديل !');
  81. }
  82. );
  83. } else {
  84. this.dashboardSer.addItem(dataFormEventBar,'eventCalendar').subscribe(
  85. (responce) => {
  86. this.toastr.success('تم الاضافه بنجاح');
  87. this.checkDisabledSave = false;
  88. console.log(responce);
  89. this.location.back();
  90. },
  91. (error) => {
  92. console.log(error);
  93. this.checkDisabledSave = false;
  94. this.toastr.error('خطأ في الاضافه');
  95. }
  96. );
  97. }
  98. }
  99. }