1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/resources/js/clients/purchase_orders/accept.js

111 lines
3.7 KiB
JavaScript
Raw Normal View History

2022-06-15 07:20:00 +02:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
class Accept {
constructor(displaySignature, displayTerms) {
this.shouldDisplaySignature = displaySignature;
this.shouldDisplayTerms = displayTerms;
this.termsAccepted = false;
}
submitForm() {
document.getElementById('approve-form').submit();
}
displaySignature() {
let displaySignatureModal = document.getElementById(
'displaySignatureModal'
);
displaySignatureModal.removeAttribute('style');
const signaturePad = new SignaturePad(
document.getElementById('signature-pad'),
{
penColor: 'rgb(0, 0, 0)',
}
);
signaturePad.onEnd = function(){
document.getElementById("signature-next-step").disabled = false;
};
2022-06-15 07:20:00 +02:00
this.signaturePad = signaturePad;
}
displayTerms() {
let displayTermsModal = document.getElementById("displayTermsModal");
displayTermsModal.removeAttribute("style");
}
handle() {
document.getElementById("signature-next-step").disabled = true;
2022-06-15 07:20:00 +02:00
document
.getElementById('approve-button')
.addEventListener('click', () => {
if (this.shouldDisplaySignature && this.shouldDisplayTerms) {
this.displaySignature();
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();
});
});
}
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();
}
});
}
}
const signature = document.querySelector('meta[name="require-purchase_order-signature"]')
.content;
const terms = document.querySelector('meta[name="show-purchase_order-terms"]').content;
new Accept(Boolean(+signature), Boolean(+terms)).handle();