import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; import { ModalController } from '@ionic/angular'; import { EventBody } from 'src/app/models/eventbody.model'; import { EventPerson } from 'src/app/models/eventperson.model'; import { EventsService } from 'src/app/services/events.service'; import { Event } from 'src/app/models/event.model'; import { AlertController } from '@ionic/angular'; import { removeDuplicate } from 'src/plugin/removeDuplicate.js' @Component({ selector: 'app-edit-event', templateUrl: './edit-event.component.html', styleUrls: ['./edit-event.component.scss'], }) export class EditEventComponent implements OnInit { stEvent: Event; isRecurring:string; isEventEdited: boolean; loadedEvent: Event; eventBody: EventBody; segment:string = "true"; eventAttendees: EventPerson[]; minDate: string; @Input() taskParticipants: EventPerson[]; @Input() taskParticipantsCc: EventPerson[]; @Input() profile:string; @Input() selectedSegment: string; @Input() postEvent: Event; @Output() clearContact = new EventEmitter(); @Output() openAttendeesComponent = new EventEmitter(); @Output() closeComponent = new EventEmitter(); @Output() setIntervenient = new EventEmitter(); @Output() setIntervenientCC = new EventEmitter(); @Output() clearPostEvent = new EventEmitter(); constructor( private modalController: ModalController, private eventsService: EventsService, public alertController: AlertController, ) { } ngOnInit() { if(!this.restoreTemporaryData()){ if(this.postEvent){ this.postEvent.Body.Text = this.postEvent.Body.Text.replace(/<[^>]+>/g, ''); } // attendees list alert(JSON.stringify(this.postEvent.Attendees)) if(this.postEvent.Attendees != null) { this.postEvent.Attendees.forEach(e =>{ if(e.IsRequired) { this.taskParticipants.push(e); } else { this.taskParticipantsCc.push(e); } }) } this.taskParticipants = removeDuplicate(this.taskParticipants); this.taskParticipantsCc = removeDuplicate(this.taskParticipantsCc); this.setIntervenient.emit(this.taskParticipants); this.setIntervenientCC.emit(this.taskParticipantsCc); this.isEventEdited = false; if(this.postEvent.IsRecurring == false){ this.isRecurring = "Não se repete"; } else{ this.isRecurring = "Repete"; } } } close(){ this.closeComponent.emit(); this.setIntervenient.emit([]); this.setIntervenientCC.emit([]); this.clearContact.emit(); this.deleteTemporaryData(); } async save(){ this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc); await this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => { /* const alert = await this.alertController.create({ cssClass: 'my-custom-class', header: 'Evento actualizado', buttons: ['OK'] }); await alert.present(); */ }); this.clearPostEvent.emit(); this.deleteTemporaryData(); this.close(); } async addParticipants() { this.saveTemporaryData(); this.openAttendeesComponent.emit({ type: "intervenient" }); this.clearContact.emit(); } async addParticipantsCc() { this.saveTemporaryData(); this.openAttendeesComponent.emit({ type: "CC" }); this.clearContact.emit(); } saveTemporaryData(){ window['temp.path:/home/agenda/edit-event.component.ts'] = { postEvent: this.postEvent, eventBody: this.eventBody, segment: this.segment } } restoreTemporaryData(): boolean{ const restoredData = window['temp.path:/home/agenda/edit-event.component.ts'] if(JSON.stringify(restoredData) != "{}" && undefined != restoredData){ this.postEvent = restoredData.postEvent this.eventBody = restoredData.eventBody this.segment = restoredData.segment return true; } else { return false; } } deleteTemporaryData(){ window['temp.path:/home/agenda/edit-event.component.ts'] = {} } }