1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-18 00:53:10 +01:00
invoiceninja/resources/js/clients/quotes/approve.js

104 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-03-23 18:10:42 +01:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @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();