2020-03-23 18:10:42 +01:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-13 09:22:36 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-03-23 18:10:42 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Approve {
|
2020-11-17 16:57:42 +01:00
|
|
|
constructor(displaySignature, displayTerms) {
|
2020-03-23 18:10:42 +01:00
|
|
|
this.shouldDisplaySignature = displaySignature;
|
2020-11-17 16:57:42 +01:00
|
|
|
this.shouldDisplayTerms = displayTerms;
|
|
|
|
this.termsAccepted = false;
|
2020-03-23 18:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
submitForm() {
|
|
|
|
document.getElementById('approve-form').submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
displaySignature() {
|
2020-11-17 16:57:42 +01:00
|
|
|
let displaySignatureModal = document.getElementById(
|
|
|
|
'displaySignatureModal'
|
|
|
|
);
|
2020-03-23 18:10:42 +01:00
|
|
|
displaySignatureModal.removeAttribute('style');
|
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
const signaturePad = new SignaturePad(
|
|
|
|
document.getElementById('signature-pad'),
|
|
|
|
{
|
|
|
|
penColor: 'rgb(0, 0, 0)',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.signaturePad = signaturePad;
|
|
|
|
}
|
|
|
|
|
|
|
|
displayTerms() {
|
|
|
|
let displayTermsModal = document.getElementById("displayTermsModal");
|
|
|
|
displayTermsModal.removeAttribute("style");
|
2020-03-23 18:10:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handle() {
|
2020-11-17 16:57:42 +01:00
|
|
|
document
|
|
|
|
.getElementById('approve-button')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
if (this.shouldDisplaySignature && this.shouldDisplayTerms) {
|
|
|
|
this.displaySignature();
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
document
|
|
|
|
.getElementById('signature-next-step')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
this.displayTerms();
|
|
|
|
|
|
|
|
document
|
|
|
|
.getElementById('accept-terms-button')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
document.querySelector(
|
|
|
|
'input[name="signature"'
|
|
|
|
).value = this.signaturePad.toDataURL();
|
|
|
|
this.termsAccepted = true;
|
|
|
|
this.submitForm();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
if (this.shouldDisplaySignature && !this.shouldDisplayTerms) {
|
|
|
|
this.displaySignature();
|
|
|
|
|
|
|
|
document
|
|
|
|
.getElementById('signature-next-step')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
document.querySelector(
|
|
|
|
'input[name="signature"'
|
|
|
|
).value = this.signaturePad.toDataURL();
|
|
|
|
this.submitForm();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.shouldDisplaySignature && this.shouldDisplayTerms) {
|
|
|
|
this.displayTerms();
|
|
|
|
|
|
|
|
document
|
|
|
|
.getElementById('accept-terms-button')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
this.termsAccepted = true;
|
|
|
|
this.submitForm();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.shouldDisplaySignature && !this.shouldDisplayTerms) {
|
|
|
|
this.submitForm();
|
|
|
|
}
|
|
|
|
});
|
2020-03-23 18:10:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
const signature = document.querySelector('meta[name="require-quote-signature"]')
|
|
|
|
.content;
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
const terms = document.querySelector('meta[name="show-quote-terms"]').content;
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
new Approve(Boolean(+signature), Boolean(+terms)).handle();
|