2022-02-08 14:46:13 +01:00
|
|
|
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
|
2020-11-06 11:32:58 +01:00
|
|
|
import { environment } from '../../../../environments/environment';
|
2021-05-03 10:06:10 +02:00
|
|
|
import { StorageService } from '../../services/storage.service';
|
2021-05-03 11:32:03 +02:00
|
|
|
import { ApiService } from '../../services/api.service';
|
2021-05-21 12:31:42 +02:00
|
|
|
import { ToastService } from '../../services/toast.service';
|
|
|
|
import { DOCUMENT } from '@angular/common';
|
2021-11-08 11:27:35 +01:00
|
|
|
import { Title } from '@angular/platform-browser';
|
2022-02-14 10:37:38 +01:00
|
|
|
import { PollService } from '../../services/poll.service';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2020-05-01 19:10:17 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-home',
|
|
|
|
templateUrl: './home.component.html',
|
|
|
|
styleUrls: ['./home.component.scss'],
|
|
|
|
})
|
2022-02-08 14:46:13 +01:00
|
|
|
export class HomeComponent implements OnInit {
|
2021-05-03 10:06:10 +02:00
|
|
|
public environment = environment;
|
2022-02-03 14:08:03 +01:00
|
|
|
public AppTitle = environment.appTitle;
|
2021-05-21 12:31:42 +02:00
|
|
|
public nonexistent_email = '';
|
2021-05-21 13:11:54 +02:00
|
|
|
public email_sent = false;
|
2022-02-08 14:37:07 +01:00
|
|
|
display_poll_search_dialog: any = false;
|
2022-02-03 14:08:03 +01:00
|
|
|
|
2021-05-21 12:31:42 +02:00
|
|
|
constructor(
|
|
|
|
@Inject(DOCUMENT) private document: any,
|
|
|
|
public storageService: StorageService,
|
|
|
|
public toastService: ToastService,
|
2021-11-08 11:27:35 +01:00
|
|
|
public titleService: Title,
|
2022-02-08 14:37:07 +01:00
|
|
|
private api: ApiService,
|
2022-02-14 10:37:38 +01:00
|
|
|
private pollService: PollService,
|
|
|
|
private translate: TranslateService,
|
2022-02-08 14:37:07 +01:00
|
|
|
private cd: ChangeDetectorRef
|
2022-02-14 10:37:38 +01:00
|
|
|
) {}
|
|
|
|
|
2022-02-08 14:46:13 +01:00
|
|
|
ngOnInit() {
|
2022-02-09 14:47:51 +01:00
|
|
|
// this.openModalFindPoll();
|
2022-02-14 10:37:38 +01:00
|
|
|
this.pollService.step_current = null;
|
|
|
|
this.pollService.updateTitle();
|
2021-11-08 11:27:35 +01:00
|
|
|
}
|
2021-05-03 10:06:10 +02:00
|
|
|
|
2021-05-03 11:32:03 +02:00
|
|
|
searchMyPolls() {
|
2021-05-21 12:31:42 +02:00
|
|
|
const email = this.storageService.vote_stack.owner.email;
|
2021-05-21 12:56:52 +02:00
|
|
|
this.email_sent = false;
|
2021-05-21 12:31:42 +02:00
|
|
|
this.api.findMyPollsByEmail(email).then(
|
|
|
|
(resp) => {
|
|
|
|
console.log('resp', resp);
|
|
|
|
|
|
|
|
if (resp) {
|
|
|
|
if (resp.data && resp.data.mail_sent == '1') {
|
|
|
|
this.toastService.display("C'est bon, vérifiez votre boite mail");
|
2021-05-21 12:56:52 +02:00
|
|
|
this.email_sent = true;
|
2021-05-21 12:31:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
if (error.response.status == '404') {
|
|
|
|
this.toastService.display('Aucun sondage géré par cet email : ' + email);
|
|
|
|
this.nonexistent_email = email;
|
|
|
|
this.document.querySelector('#search_email').select();
|
|
|
|
}
|
|
|
|
console.log('error', error);
|
|
|
|
}
|
|
|
|
);
|
2021-05-03 11:32:03 +02:00
|
|
|
}
|
2022-02-08 14:37:07 +01:00
|
|
|
|
|
|
|
openModalFindPoll() {
|
|
|
|
this.display_poll_search_dialog = true;
|
|
|
|
this.cd.detectChanges();
|
|
|
|
let buttonClose = this.document.querySelector('#close_dialog');
|
|
|
|
if (buttonClose) {
|
|
|
|
buttonClose.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
focusOnCancelButton() {
|
|
|
|
this.display_poll_search_dialog = false;
|
|
|
|
let buttonClose = this.document.querySelector('#open_popup_button');
|
|
|
|
if (buttonClose) {
|
|
|
|
buttonClose.focus();
|
|
|
|
}
|
|
|
|
}
|
2020-05-01 19:10:17 +02:00
|
|
|
}
|