Files
doneit-web/src/app/modals/delegar/delegar.page.ts
T

222 lines
6.0 KiB
TypeScript
Raw Normal View History

2021-04-30 12:57:54 +01:00
import { Component, OnInit } from '@angular/core';
2023-06-23 11:47:20 +01:00
import { AlertController, ModalController, NavParams } from '@ionic/angular';
2021-04-30 12:57:54 +01:00
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 { DiscartExpedientModalPage } from 'src/app/pages/gabinete-digital/discart-expedient-modal/discart-expedient-modal.page';
2021-06-15 15:09:20 +01:00
import { ToastService } from 'src/app/services/toast.service';
2021-06-18 12:09:44 +01:00
import { AttendeesPageModal } from 'src/app/pages/events/attendees/attendees.page';
2021-08-20 12:02:27 +01:00
import { SearchList } from 'src/app/models/search-document';
2021-08-19 16:19:29 +01:00
import { SearchPage } from 'src/app/pages/search/search.page';
2021-10-22 15:43:57 +01:00
import { ThemeService } from 'src/app/services/theme.service'
2023-02-27 09:34:36 +01:00
import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
2021-10-22 15:43:57 +01:00
2021-04-30 12:57:54 +01:00
@Component({
selector: 'app-delegar',
templateUrl: './delegar.page.html',
styleUrls: ['./delegar.page.scss'],
})
export class DelegarPage implements OnInit {
task: any;
2021-05-03 12:57:26 +01:00
note:string;
2022-02-16 13:52:32 +01:00
2021-04-30 12:57:54 +01:00
taskParticipants: EventPerson[] = [];
taskParticipantsCc: EventPerson[] = [];
2022-02-16 13:52:32 +01:00
2021-04-30 12:57:54 +01:00
taskDocId:string;
loadedAttachments:any;
adding: "intervenient" | "CC" = "intervenient";
postData: Event;
eventBody: EventBody;
2021-05-03 12:57:26 +01:00
eventAttendees: EventPerson;
2021-04-30 12:57:54 +01:00
formLocationSatus: boolean = false;
showAttendees= false;
2021-08-19 16:19:29 +01:00
hideThisFeature: boolean = true;
2021-08-20 12:02:27 +01:00
documents: SearchList[] = [];
2021-08-19 16:19:29 +01:00
2021-04-30 12:57:54 +01:00
constructor(
private modalController: ModalController,
private navParams: NavParams,
private processes:ProcessesService,
2021-05-03 12:57:26 +01:00
public alertController: AlertController,
2021-06-15 15:09:20 +01:00
private toastService: ToastService,
2023-02-27 09:34:36 +01:00
public ThemeService: ThemeService,
private httpErrorHandle: HttpErrorHandle
2021-04-30 12:57:54 +01:00
) {
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)); */
2021-08-19 16:19:29 +01:00
this.hideThisFeature = this.navParams.get('showAttachmentBtn');
2021-04-30 12:57:54 +01:00
}
ngOnInit() {
this.adding = "intervenient";
2022-02-16 13:52:32 +01:00
2021-04-30 12:57:54 +01:00
}
2021-06-09 14:45:36 +01:00
close() {
2021-08-20 15:43:37 +01:00
this.modalController.dismiss('close');
2021-04-30 12:57:54 +01:00
}
2021-06-09 14:45:36 +01:00
cancelTask() {
2021-04-30 12:57:54 +01:00
this.modalController.dismiss(null);
}
2021-04-30 14:05:55 +01:00
2021-06-09 15:32:54 +01:00
async saveTask() {
2021-06-18 14:32:50 +01:00
if(this.taskParticipants.length < 1){
2021-11-09 15:37:59 +01:00
this.toastService._badRequest("Selecione um destinatário");
2021-06-18 14:32:50 +01:00
}
else if(this.taskParticipants.length > 1){
2021-11-09 15:37:59 +01:00
this.toastService._badRequest("Selecione apenas um destinatário");
2021-04-30 12:57:54 +01:00
}
2021-06-09 15:32:54 +01:00
else {
2021-05-03 12:57:26 +01:00
let body = {
"SerialNumber": this.task.SerialNumber,
"DispatchDocId": this.task.DocId,
2021-11-03 15:04:30 +01:00
"FolderID": this.task.FolderId || this.task.FolderID,
2021-05-03 12:57:26 +01:00
"Subject": this.task.Folio,
"Comment": this.note,
"DelegatedUserEmail": this.taskParticipants[0].EmailAddress,
}
2021-08-20 15:43:37 +01:00
const loader = this.toastService.loading()
2021-05-03 12:57:26 +01:00
this.processes.DelegateTask(body).subscribe(res=>{
2023-02-27 09:34:36 +01:00
this.httpErrorHandle.httpsSucessMessagge('Delegar')
2021-06-18 14:32:50 +01:00
this.close();
2021-05-25 13:38:46 +01:00
},
(error)=>{
2023-02-27 09:34:36 +01:00
this.httpErrorHandle.httpStatusHandle(error)
2021-08-20 15:43:37 +01:00
},
()=>{
loader.remove()
2021-05-03 12:57:26 +01:00
});
2021-04-30 12:57:54 +01:00
}
}
2021-06-18 14:32:50 +01:00
async addParticipants() {
2021-04-30 12:57:54 +01:00
this.adding = "intervenient";
2021-06-18 12:09:44 +01:00
if(window.innerWidth <=800) {
this.showAttendees=false;
2021-04-30 12:57:54 +01:00
const modal = await this.modalController.create({
2021-06-18 12:09:44 +01:00
component: AttendeesPageModal,
componentProps: {
adding: this.adding,
taskParticipants: this.taskParticipants,
taskParticipantsCc: this.taskParticipantsCc
2021-04-30 12:57:54 +01:00
},
2021-08-25 10:40:17 +01:00
cssClass: 'modal attendee modal-desktop',
2021-04-30 12:57:54 +01:00
backdropDismiss: false
});
2021-06-18 12:09:44 +01:00
2021-04-30 12:57:54 +01:00
await modal.present();
2021-06-18 12:09:44 +01:00
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);
}
2021-04-30 12:57:54 +01:00
});
} else {
2021-06-18 12:09:44 +01:00
this.showAttendees=true
}
2021-06-18 14:32:50 +01:00
}
2021-06-18 12:09:44 +01:00
async setContact(data:EventPerson[]) {
2023-06-23 11:47:20 +01:00
if(this.adding == "intervenient") {
2021-06-18 12:09:44 +01:00
this.taskParticipants = data;
} else if (this.adding == "CC") {
2022-02-16 13:52:32 +01:00
2021-06-18 12:09:44 +01:00
this.taskParticipantsCc = data;
2021-04-30 12:57:54 +01:00
}
2022-02-16 13:52:32 +01:00
2021-06-18 12:09:44 +01:00
}
async setIntervenient(data) {
this.taskParticipants = data;
}
2022-02-16 13:52:32 +01:00
2021-06-18 12:09:44 +01:00
async setIntervenientCC(data) {
this.taskParticipantsCc = data;
}
async closeComponent() {
this.showAttendees = false;
2021-04-30 12:57:54 +01:00
}
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();
}
2022-02-16 13:52:32 +01:00
2021-04-30 12:57:54 +01:00
validateFormInputs(){
let formLocation = this.postData.Location.trim();
if(!this.postData.Location && formLocation.length <= 0){
this.formLocationSatus=true;
}
}
2021-05-03 12:57:26 +01:00
dynamicSetIntervenient({taskParticipants}){
2021-04-30 12:57:54 +01:00
this.taskParticipants = taskParticipants;
}
2021-08-19 16:19:29 +01:00
async getDoc() {
const modal = await this.modalController.create({
component: SearchPage,
cssClass: 'modal-width-100-width-background modal',
componentProps: {
type: 'AccoesPresidenciais & ArquivoDespachoElect',
showSearchInput: true,
select: true
}
});
await modal.present();
modal.onDidDismiss().then((res)=>{
if(res){
const data = res.data;
this.documents.push(data.selected);
}
});
}
removeAttachment(index: number){
this.documents = this.documents.filter( (e, i) => index != i);
}
2022-02-16 13:52:32 +01:00
}