Files
doneit-web/src/app/pages/agenda/edit-event/edit-event.page.ts
T

148 lines
3.6 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
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';
@Component({
selector: 'app-edit-event',
templateUrl: './edit-event.page.html',
styleUrls: ['./edit-event.page.scss'],
})
export class EditEventPage implements OnInit {
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";
constructor(
private modalController: ModalController,
private navParams: NavParams,
private eventsService: EventsService,
private alertService: AlertService,
public alertController: AlertController,
2021-04-07 10:04:58 +01:00
) {
this.isEventEdited = false;
this.postEvent = this.navParams.get('event');
2021-04-08 09:14:28 +01:00
if(this.postEvent){
this.postEvent.Body.Text = this.postEvent.Body.Text.replace(/<[^>]+>/g, '');
}
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 = [];
if(this.postEvent.IsRecurring == false){
this.isRecurring = "Não se repete";
}
else{
this.isRecurring = "Repete";
}
this.profile = this.navParams.get('profile');
}
ngOnInit() {
2021-04-08 09:14:28 +01:00
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-04-07 11:52:28 +01:00
close(){
this.modalController.dismiss();
}
2021-04-07 11:52:28 +01:00
save(){
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;
this.modalController.dismiss(this.isEventEdited);
}
2021-04-07 10:04:58 +01:00
async openAttendees() {
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-04-07 10:04:58 +01:00
}