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

150 lines
4.0 KiB
TypeScript
Raw Normal View History

2021-05-03 20:02:07 +01:00
import { Component, OnInit } from '@angular/core';
2021-06-08 15:59:06 +01:00
import { AnimationController, ModalController } from '@ionic/angular';
2021-05-19 12:03:00 +01:00
import { SearchDocument } from 'src/app/models/search-document';
import { SearchPage } from 'src/app/pages/search/search.page';
2021-06-08 15:59:06 +01:00
import { BadRequestPage } from 'src/app/shared/popover/bad-request/bad-request.page';
import { SuccessMessagePage } from 'src/app/shared/popover/success-message/success-message.page';
2021-05-03 20:02:07 +01:00
@Component({
selector: 'app-add-note',
templateUrl: './add-note.page.html',
styleUrls: ['./add-note.page.scss'],
})
export class AddNotePage implements OnInit {
2021-05-19 12:03:00 +01:00
note: string = '';
documents:SearchDocument[] = [];
loadedAttachments:any;
2021-05-03 20:02:07 +01:00
constructor(
private modalController: ModalController,
2021-06-08 15:59:06 +01:00
private animationController: AnimationController,
2021-05-03 20:02:07 +01:00
) {
2021-05-19 12:03:00 +01:00
this.note = '';
2021-05-03 20:02:07 +01:00
}
ngOnInit() {
}
close(){
this.modalController.dismiss('');
}
save(){
2021-05-19 12:03:00 +01:00
let body = {
"note":this.note,
"documents":this.documents,
}
this.modalController.dismiss(body);
}
2021-05-25 13:38:46 +01:00
async getDoc() {
2021-05-19 12:03:00 +01:00
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);
}
});
2021-05-25 13:38:46 +01:00
2021-05-19 12:03:00 +01:00
}
removeAttachment(index: number){
this.documents = this.documents.filter( (e, i) => index != i);
2021-05-25 13:38:46 +01:00
}
async successMessage(message?: string) {
2021-06-08 15:59:06 +01:00
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
2021-05-25 13:38:46 +01:00
const modal = await this.modalController.create({
2021-06-08 15:59:06 +01:00
enterAnimation,
leaveAnimation,
component: SuccessMessagePage,
2021-05-25 13:38:46 +01:00
componentProps: {
message: message || 'Processo efetuado' ,
},
2021-06-08 15:59:06 +01:00
cssClass: 'notification-modal'
2021-05-25 13:38:46 +01:00
});
modal.present()
setTimeout(()=>{
modal.dismiss()
},3000)
}
async badRequest(message?: string) {
2021-06-08 15:59:06 +01:00
const enterAnimation = (baseEl: any) => {
const backdropAnimation = this.animationController.create()
.addElement(baseEl.querySelector('ion-backdrop')!)
.fromTo('opacity', '0.01', 'var(--backdrop-opacity)');
const wrapperAnimation = this.animationController.create()
.addElement(baseEl.querySelector('.modal-wrapper')!)
.keyframes([
{ offset: 0, opacity: '1', right: '-100%' },
{ offset: 1, opacity: '1', right: '0px' }
]);
return this.animationController.create()
.addElement(baseEl)
.easing('ease-out')
.duration(500)
.addAnimation([backdropAnimation, wrapperAnimation]);
}
const leaveAnimation = (baseEl: any) => {
return enterAnimation(baseEl).direction('reverse');
}
2021-05-25 13:38:46 +01:00
const modal = await this.modalController.create({
2021-06-08 15:59:06 +01:00
enterAnimation,
leaveAnimation,
component: BadRequestPage,
2021-05-25 13:38:46 +01:00
componentProps: {
2021-06-08 15:59:06 +01:00
message: message || 'Processo efetuado' ,
2021-05-25 13:38:46 +01:00
},
2021-06-08 15:59:06 +01:00
cssClass: 'notification-modal'
2021-05-25 13:38:46 +01:00
});
2021-05-19 12:03:00 +01:00
2021-05-25 13:38:46 +01:00
modal.present()
setTimeout(()=>{
modal.dismiss()
},3000)
2021-05-03 20:02:07 +01:00
}
}