Files
Peter Maquiran eba2b7f9ce commit
2023-07-15 11:01:09 +01:00

247 lines
6.0 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { AlertController, ModalController, NavParams } from '@ionic/angular';
import { Attachment } from 'src/app/models/attachment.model';
import { Event } from 'src/app/models/event.model';
import { EventBody } from 'src/app/models/eventbody.model';
import { EventPerson } from 'src/app/models/eventperson.model';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { EventsService } from 'src/app/services/events.service';
import { AttachmentsPage } from '../attachments/attachments.page';
import { AttendeesPageModal } from '../attendees/attendees.page';
@Component({
selector: 'app-event-detail-modal',
templateUrl: './event-detail-modal.page.html',
styleUrls: ['./event-detail-modal.page.scss'],
})
export class EventDetailModalPage implements OnInit {
loadedEvent: Event;
loadedEventAttachments: Attachment[];
pageId: string;
showLoader: boolean;
backURL: string;
ionicForm: FormGroup;
isSubmitted = false;
minDate: Date;
profile:string;
constructor(
public formBuilder: FormBuilder,
public alertController: AlertController,
private router: Router,
private activatedRoute: ActivatedRoute,
private eventsService: EventsService,
private modalCtrl: ModalController,
private attachamentsService: AttachmentsService,
private route: Router,) {
this.loadedEvent = new Event();
this.loadedEvent.Body = new EventBody();
}
ngOnInit() {
this.loadEvent();
this.loadAttachments();
this.ionicForm = this.formBuilder.group({
subject: ['', [Validators.required]]
})
// this.setDefaultTime()
}
// setDefaultTime() {
// this.loadedEvent.StartDate = new Date()
// this.loadedEvent.EndDate = (new Date(new Date().getTime() + 15 * 60000))
// }
get errorControl() {
return this.ionicForm.controls;
}
loadEvent(){
let eventid: string;
this.activatedRoute.paramMap.subscribe(paramMap =>
{
if (!paramMap.has("eventId")){
return;
}
else{
this.pageId = paramMap.get('eventId');
eventid = paramMap.get('eventId');
}
if (paramMap.has("caller")){
this.backURL = "/home/" + paramMap.get('caller');
}
}
);
this.eventsService.getEvent(eventid).subscribe(response => {
this.loadedEvent = response;
});
}
async openAttendees(){
const modal = await this.modalCtrl.create({
component: AttendeesPageModal,
componentProps: {
eventAttendees: this.loadedEvent.Attendees
},
cssClass: 'attendee modal-desktop',
backdropDismiss: false
});
modal.onDidDismiss().then((data) => {
if (data['data'] != null)
{
let newattendees: EventPerson[] = data['data'];
this.loadedEvent.Attendees = newattendees;
}
});
await modal.present();
}
getEventAttendees(): EventPerson[]
{
return this.loadedEvent.Attendees;
}
setEventAttendees(newattendes: EventPerson[])
{
this.loadedEvent.Attendees = newattendes;
}
async deleteConfirm()
{
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Apagar evento!',
message: 'Deseja <strong>apagar</strong> o evento da agenda ' + this.loadedEvent.CalendarName + '?',
buttons: [
{
text: 'Não',
role: 'cancel',
cssClass: 'secondary',
handler: () => { }
}, {
text: 'Sim',
handler: () => {
this.Delete();
}
}
]
});
await alert.present();
}
Delete()
{
this.eventsService.deleteEvent(this.loadedEvent.EventId, 0, this.loadedEvent.CalendarName).subscribe(async () =>
{
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento removido',
buttons: ['OK']
});
setTimeout(()=>{
alert.dismiss();
}, 1500);
this.router.navigate(['/home/events']);
});
}
Save()
{
if (this.ionicForm.valid)
{
this.eventsService.putEvent(this.loadedEvent, 2, 3, "md").subscribe(async () =>
{
const alert = await this.alertController.create({
cssClass: 'my-custom-class',
header: 'Evento actualizado',
buttons: ['OK']
});
setTimeout(()=>{
alert.dismiss();
}, 1500);
});
}
}
loadAttachments()
{
/* this.attachamentsService.getEventAttachments(this.pageId).subscribe(attachments => {
this.loadedEventAttachments = attachments;
}); */
this.attachamentsService.getAttachmentsById(this.pageId).subscribe(res => {
},((erro) => {
console.error('loadAttchament', erro)
}));
}
async viewDocument(documenturl:string)
{
const url: string = documenturl.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
/* const browser = this.iab.create(url,"_blank");
browser.show(); */
}
back()
{
//this.back();
}
doRefresh(event){
/* this.RefreshEvents(); */
try {
event?.target?.complete();
} catch(error) {}
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
}, 2000);
}
navigateTo(ev){
this.route.navigate(['/home/events',ev]);
}
async openAttachments() {
const modal = await this.modalCtrl.create({
component: AttachmentsPage,
componentProps: {
eventId: this.pageId,
attachments: this.loadedEventAttachments
},
cssClass: 'attachments',
backdropDismiss: false
});
modal.onDidDismiss().then((data) => {
if (data['data'] != null)
{
let newattendees: EventPerson[] = data['data'];
this.loadedEvent.Attendees = newattendees;
}
});
await modal.present();
}
}