Files
doneit-web/src/app/modals/delegar/delegar.page.ts
T
tiago.kayaya 57d9a7f72f save
2021-06-25 14:28:53 +01:00

191 lines
5.6 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AlertController, AnimationController, ModalController, NavParams } from '@ionic/angular';
import { Event } from 'src/app/models/event.model'
import { EventBody } from 'src/app/models/eventbody.model';
import { ProcessesService } from 'src/app/services/processes.service';
import { EventPerson } from 'src/app/models/eventperson.model';
import { EventsService } from 'src/app/services/events.service';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { DiscartExpedientModalPage } from 'src/app/pages/gabinete-digital/discart-expedient-modal/discart-expedient-modal.page';
import { AlertService } from 'src/app/services/alert.service';
import { BadRequestPage } from 'src/app/shared/popover/bad-request/bad-request.page';
import { SuccessMessagePage } from 'src/app/shared/popover/success-message/success-message.page';
import { ToastService } from 'src/app/services/toast.service';
import { AttendeesPageModal } from 'src/app/pages/events/attendees/attendees.page';
@Component({
selector: 'app-delegar',
templateUrl: './delegar.page.html',
styleUrls: ['./delegar.page.scss'],
})
export class DelegarPage implements OnInit {
task: any;
note:string;
taskParticipants: EventPerson[] = [];
taskParticipantsCc: EventPerson[] = [];
taskDocId:string;
loadedAttachments:any;
adding: "intervenient" | "CC" = "intervenient";
postData: Event;
eventBody: EventBody;
eventAttendees: EventPerson;
formLocationSatus: boolean = false;
showAttendees= false;
constructor(
private modalController: ModalController,
private router:Router,
private navParams: NavParams,
private processes:ProcessesService,
private attachmentsService: AttachmentsService,
private calendarService: EventsService,
public alertController: AlertController,
private alertService: AlertService,
private animationController: AnimationController,
private toastService: ToastService,
) {
this.task = this.navParams.get('task');
this.postData = new Event();
this.eventBody = { BodyType : "1", Text : ""};
this.postData.Body = this.eventBody;
/* Initialize 'Subject' with the title of the expedient */
this.postData.Subject = this.task.Folio;
this.postData.CalendarName = "Oficial";
/* this.postData.StartDate = new Date(); */
/* Set + 30minutes to seleted datetime */
let selectedEndDate = new Date();
/* this.postData.EndDate = new Date(selectedEndDate.setMinutes(new Date().getMinutes() + 30)); */
}
ngOnInit() {
this.adding = "intervenient";
console.log(this.task);
}
close() {
this.router.navigate(['/home/gabinete-digital/expediente']);
this.modalController.dismiss(null);
}
cancelTask() {
this.modalController.dismiss(null);
}
async saveTask() {
if(this.taskParticipants.length < 1){
this.toastService.badRequest("Selecione um destinatário");
}
else if(this.taskParticipants.length > 1){
this.toastService.badRequest("Selecione apenas um destinatário");
}
else {
let body = {
"SerialNumber": this.task.SerialNumber,
"DispatchDocId": this.task.DocId,
"FolderID": this.task.FolderId,
"Subject": this.task.Folio,
"Comment": this.note,
"DelegatedUserEmail": this.taskParticipants[0].EmailAddress,
}
console.log(body);
this.processes.DelegateTask(body).subscribe(res=>{
console.log(res);
this.toastService.successMessage('Processo delegado')
this.close();
},
(error)=>{
this.toastService.badRequest("Processo não delegado")
});
}
}
async addParticipants() {
this.adding = "intervenient";
if(window.innerWidth <=800) {
this.showAttendees=false;
const modal = await this.modalController.create({
component: AttendeesPageModal,
componentProps: {
adding: this.adding,
taskParticipants: this.taskParticipants,
taskParticipantsCc: this.taskParticipantsCc
},
cssClass: 'modal attendee',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then((data) => {
if(data) {
data = data['data'];
const newAttendees: EventPerson[] = data['taskParticipants'];
const newAttendeesCC: EventPerson[] = data['taskParticipantsCc'];
this.setIntervenient(newAttendees);
this.setIntervenientCC(newAttendeesCC);
}
});
} else {
this.showAttendees=true
}
}
async setContact(data:EventPerson[]) {
if(this.adding == "intervenient"){
this.taskParticipants = data;
} else if (this.adding == "CC") {
this.taskParticipantsCc = data;
}
}
async setIntervenient(data) {
this.taskParticipants = data;
}
async setIntervenientCC(data) {
this.taskParticipantsCc = data;
}
async closeComponent() {
this.showAttendees = false;
}
async distartExpedientModal(){
const modal = await this.modalController.create({
component: DiscartExpedientModalPage,
componentProps: {
serialNumber: this.task.SerialNumber,
},
cssClass: 'discart-expedient-modal',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss();
}
validateFormInputs(){
let formLocation = this.postData.Location.trim();
if(!this.postData.Location && formLocation.length <= 0){
this.formLocationSatus=true;
}
}
dynamicSetIntervenient({taskParticipants}){
this.taskParticipants = taskParticipants;
}
}