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

131 lines
3.5 KiB
TypeScript
Raw Normal View History

import { Component, OnInit } from '@angular/core';
2021-01-29 14:13:31 +01:00
import { ModalController, NavParams } 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 '../../../models/event.model';
import { AttendeesPage } from '../../events/attendees/attendees.page';
@Component({
selector: 'app-new-event',
templateUrl: './new-event.page.html',
styleUrls: ['./new-event.page.scss'],
})
export class NewEventPage implements OnInit {
2021-01-29 14:13:31 +01:00
postEvent: Event;
eventBody: EventBody;
segment:string = "true";
profile:string;
eventAttendees: EventPerson[];
selectedSegment: string;
selectedDate: Date;
minDate: string;
constructor(
private modalController: ModalController,
2021-01-29 14:13:31 +01:00
private navParams: NavParams,
private eventService: EventsService,
) {
this.postEvent = new Event();
this.eventBody = { BodyType : "1", Text : ""};
this.postEvent.Body = this.eventBody;
this.profile = this.navParams.get('profile');
this.selectedSegment = this.navParams.get('segment');
this.selectedDate = this.navParams.get('eventSelectedDate');
}
ngOnInit() {
2021-01-29 14:13:31 +01:00
console.log(this.profile);
let selectedStartdDate = this.selectedDate;
let selectedEndDate = new Date(this.selectedDate);
/* Set + 30minutes to seleted datetime */
selectedEndDate.setMinutes(this.selectedDate.getMinutes() + 30) ;
this.minDate = this.selectedDate.toString();
2021-01-29 14:13:31 +01:00
if(this.selectedSegment != "Combinada"){
this.postEvent ={
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
CalendarName: this.selectedSegment,
StartDate: selectedStartdDate,
EndDate: new Date(selectedEndDate),
EventType: 'Reunião',
Attendees: null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
2021-02-02 09:02:13 +01:00
Categories: ['Reunião'],
2021-01-29 14:13:31 +01:00
HasAttachments: false,
};
}
else{
this.postEvent ={
EventId: '',
Subject: '',
Body: this.eventBody,
Location: '',
CalendarId: '',
CalendarName: 'Oficial',
StartDate: selectedStartdDate,
EndDate: new Date(selectedEndDate),
EventType: 'Reunião',
Attendees: null,
IsMeeting: false,
IsRecurring: false,
AppointmentState: 0,
TimeZone: '',
Organizer: '',
2021-02-02 09:02:13 +01:00
Categories: ['Reunião'],
2021-01-29 14:13:31 +01:00
HasAttachments: false,
};
}
}
close(){
this.modalController.dismiss();
}
save(){
2021-01-29 14:13:31 +01:00
console.log(this.postEvent);
console.log(this.profile);
if(this.profile=='mdgpr'){
this.eventService.postEventMd(this.postEvent, this.postEvent.CalendarName).subscribe();
}
else if(this.profile=='pr'){
this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).subscribe();
}
this.modalController.dismiss(this.postEvent);
}
2021-01-29 14:13:31 +01:00
async openAttendees()
{
const modal = await this.modalController.create({
component: AttendeesPage,
componentProps: {
eventAttendees: this.postEvent.Attendees
},
cssClass: 'attendee',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then((data) => {
if (data['data'] != null)
{
let newattendees: EventPerson[] = data['data'];
this.postEvent.Attendees = newattendees;
}
});
}
}