Files
doneit-web/src/app/shared/agenda/edit-event/edit-event.component.ts
T

170 lines
4.2 KiB
TypeScript
Raw Normal View History

2021-02-24 09:14:58 +01:00
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';
2021-04-08 20:11:25 +01:00
import { removeDuplicate } from 'src/plugin/removeDuplicate.js'
import { SearchPage } from 'src/app/pages/search/search.page';
2021-02-24 09:14:58 +01:00
@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;
2021-04-08 13:39:48 +01:00
@Input() taskParticipants: EventPerson[];
@Input() taskParticipantsCc: EventPerson[];
2021-02-24 09:14:58 +01:00
@Input() profile:string;
@Input() selectedSegment: string;
@Input() postEvent: Event;
@Output() clearContact = new EventEmitter<any>();
2021-02-24 09:14:58 +01:00
2021-03-25 15:18:12 +01:00
@Output() openAttendeesComponent = new EventEmitter<any>();
@Output() closeComponent = new EventEmitter<any>();
2021-04-07 15:13:31 +01:00
@Output() setIntervenient = new EventEmitter<any>();
@Output() setIntervenientCC = new EventEmitter<any>();
2021-04-08 13:39:48 +01:00
@Output() clearPostEvent = new EventEmitter<any>();
2021-02-24 09:14:58 +01:00
constructor(
private modalController: ModalController,
private eventsService: EventsService,
public alertController: AlertController,
2021-04-08 13:39:48 +01:00
) {
2021-04-08 20:11:25 +01:00
2021-02-24 09:14:58 +01:00
}
ngOnInit() {
2021-04-08 13:39:48 +01:00
if(!this.restoreTemporaryData()){
if(this.postEvent){
this.postEvent.Body.Text = this.postEvent.Body.Text.replace(/<[^>]+>/g, '');
}
// attendees list
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";
}
2021-02-24 09:14:58 +01:00
}
2021-02-24 09:14:58 +01:00
}
2021-04-05 14:13:13 +01:00
2021-02-24 09:14:58 +01:00
close(){
this.closeComponent.emit();
2021-04-08 13:39:48 +01:00
this.setIntervenient.emit([]);
this.setIntervenientCC.emit([]);
this.clearContact.emit();
this.deleteTemporaryData();
2021-02-24 09:14:58 +01:00
}
2021-04-08 13:39:48 +01:00
2021-04-08 13:39:48 +01:00
async save(){
2021-04-08 20:11:25 +01:00
this.postEvent.Attendees = this.taskParticipants.concat(this.taskParticipantsCc);
2021-04-08 13:39:48 +01:00
await this.eventsService.editEvent(this.postEvent, 2, 3).subscribe(async () => {
2021-04-12 09:45:08 +01:00
const alert = await this.alertController.create({
2021-02-24 09:14:58 +01:00
cssClass: 'my-custom-class',
header: 'Evento actualizado',
buttons: ['OK']
});
2021-04-12 09:45:08 +01:00
await alert.present();
2021-04-08 13:39:48 +01:00
2021-02-24 09:14:58 +01:00
});
2021-04-08 13:39:48 +01:00
this.clearPostEvent.emit();
this.deleteTemporaryData();
2021-04-08 13:39:48 +01:00
this.close();
}
2021-04-07 15:13:31 +01:00
2021-04-08 13:39:48 +01:00
async addParticipants() {
this.saveTemporaryData();
2021-04-08 13:39:48 +01:00
this.openAttendeesComponent.emit({
type: "intervenient"
});
this.clearContact.emit();
2021-02-24 09:14:58 +01:00
}
2021-04-08 13:39:48 +01:00
async addParticipantsCc() {
this.saveTemporaryData();
2021-04-08 13:39:48 +01:00
this.openAttendeesComponent.emit({
type: "CC"
});
2021-02-24 09:14:58 +01:00
2021-03-25 15:18:12 +01:00
this.clearContact.emit();
2021-04-07 15:13:31 +01:00
}
2021-02-24 09:14:58 +01:00
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'] = {}
}
2021-02-24 09:14:58 +01:00
}