2021-01-29 09:45:27 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2021-01-31 01:40:19 +01:00
|
|
|
import { AlertController, ModalController, NavParams } from '@ionic/angular';
|
|
|
|
|
import { EventBody } from 'src/app/models/eventbody.model';
|
|
|
|
|
import { EventPerson } from 'src/app/models/eventperson.model';
|
|
|
|
|
import { AlertService } from 'src/app/services/alert.service';
|
|
|
|
|
import { EventsService } from 'src/app/services/events.service';
|
|
|
|
|
import { Event } from '../../../models/event.model';
|
|
|
|
|
import { AttendeesPage } from '../../events/attendees/attendees.page';
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-edit-event',
|
|
|
|
|
templateUrl: './edit-event.page.html',
|
|
|
|
|
styleUrls: ['./edit-event.page.scss'],
|
|
|
|
|
})
|
|
|
|
|
export class EditEventPage implements OnInit {
|
|
|
|
|
|
2021-01-31 01:40:19 +01:00
|
|
|
postEvent: Event;
|
|
|
|
|
isRecurring:string;
|
|
|
|
|
isEventEdited: boolean;
|
|
|
|
|
loadedEvent: Event;
|
|
|
|
|
eventBody: EventBody;
|
|
|
|
|
segment:string = "true";
|
|
|
|
|
profile:string;
|
|
|
|
|
eventAttendees: EventPerson[];
|
|
|
|
|
selectedSegment: string;
|
|
|
|
|
selectedDate: Date;
|
|
|
|
|
minDate: string;
|
|
|
|
|
|
2021-04-06 11:28:46 +01:00
|
|
|
|
|
|
|
|
taskParticipants: any = [];
|
|
|
|
|
taskParticipantsCc: any = [];
|
|
|
|
|
adding: "intervenient" | "CC" = "intervenient";
|
|
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
constructor(
|
|
|
|
|
private modalController: ModalController,
|
2021-01-31 01:40:19 +01:00
|
|
|
private navParams: NavParams,
|
|
|
|
|
private eventsService: EventsService,
|
|
|
|
|
private alertService: AlertService,
|
|
|
|
|
public alertController: AlertController,
|
2021-04-07 10:04:58 +01:00
|
|
|
) {
|
2021-01-31 01:40:19 +01:00
|
|
|
this.isEventEdited = false;
|
|
|
|
|
this.postEvent = this.navParams.get('event');
|
2021-04-06 11:28:46 +01:00
|
|
|
|
|
|
|
|
this.taskParticipants = [];
|
|
|
|
|
this.taskParticipantsCc = [];
|
|
|
|
|
|
|
|
|
|
if(this.postEvent.Attendees == null){
|
|
|
|
|
this.taskParticipants = []
|
|
|
|
|
} else {
|
|
|
|
|
this.taskParticipants = this.postEvent.Attendees;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.taskParticipantsCc = [];
|
|
|
|
|
|
2021-01-31 01:40:19 +01:00
|
|
|
if(this.postEvent.IsRecurring == false){
|
|
|
|
|
this.isRecurring = "Não se repete";
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.isRecurring = "Repete";
|
|
|
|
|
}
|
|
|
|
|
this.profile = this.navParams.get('profile');
|
|
|
|
|
}
|
2021-01-29 09:45:27 +01:00
|
|
|
|
|
|
|
|
ngOnInit() {
|
2021-02-24 20:23:15 +01:00
|
|
|
|
|
|
|
|
window.onresize = (event) => {
|
|
|
|
|
// if not mobile remove all component
|
2021-04-01 15:06:05 +01:00
|
|
|
if( window.innerWidth >= 800){
|
2021-02-24 20:23:15 +01:00
|
|
|
this.modalController.dismiss();
|
|
|
|
|
}
|
|
|
|
|
};
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
close(){
|
2021-01-31 01:40:19 +01:00
|
|
|
this.modalController.dismiss();
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
2021-04-07 11:52:28 +01:00
|
|
|
|
2021-01-29 09:45:27 +01:00
|
|
|
save(){
|
|
|
|
|
|
2021-01-31 01:40:19 +01:00
|
|
|
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();
|
|
|
|
|
});
|
2021-02-01 09:17:38 +01:00
|
|
|
this.isEventEdited = true;
|
2021-01-31 01:40:19 +01:00
|
|
|
this.modalController.dismiss(this.isEventEdited);
|
2021-01-29 09:45:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 10:04:58 +01:00
|
|
|
async openAttendees() {
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-04-07 10:04:58 +01:00
|
|
|
if(window.innerWidth <= 1024) {
|
2021-04-06 11:28:46 +01:00
|
|
|
const modal = await this.modalController.create({
|
|
|
|
|
component: AttendeesPage,
|
|
|
|
|
componentProps: {
|
2021-04-07 11:52:28 +01:00
|
|
|
adding: this.adding,
|
|
|
|
|
taskParticipants: this.taskParticipants,
|
|
|
|
|
taskParticipantsCc: this.taskParticipantsCc
|
2021-04-06 11:28:46 +01:00
|
|
|
},
|
|
|
|
|
cssClass: 'attendee',
|
|
|
|
|
backdropDismiss: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await modal.present();
|
|
|
|
|
|
|
|
|
|
modal.onDidDismiss().then((data) => {
|
2021-04-07 11:52:28 +01:00
|
|
|
|
|
|
|
|
if(data){
|
|
|
|
|
data = data['data'];
|
|
|
|
|
|
|
|
|
|
const newAttendees: EventPerson[] = data['taskParticipants'];
|
|
|
|
|
const newAttendeesCC: EventPerson[] = data['taskParticipantsCc'];
|
|
|
|
|
|
|
|
|
|
this.setIntervenient(newAttendees);
|
|
|
|
|
this.setIntervenientCC(newAttendeesCC);
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
setIntervenient(data){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipants = data;
|
|
|
|
|
this.postEvent.Attendees = data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
setIntervenientCC(data){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.taskParticipantsCc = data;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
addParticipants(){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.adding = 'intervenient'
|
2021-04-07 10:04:58 +01:00
|
|
|
|
|
|
|
|
this.openAttendees();
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-07 11:52:28 +01:00
|
|
|
addParticipantsCC(){
|
2021-04-06 11:28:46 +01:00
|
|
|
this.adding = 'CC'
|
2021-04-07 10:04:58 +01:00
|
|
|
this.openAttendees();
|
2021-04-06 11:28:46 +01:00
|
|
|
}
|
2021-01-31 01:40:19 +01:00
|
|
|
|
2021-04-07 10:04:58 +01:00
|
|
|
}
|