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
|
|
|
*
|
2022-06-08 06:25:44 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-03-23 18:10:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
class Approve {
|
2023-02-02 09:10:41 +01:00
|
|
|
constructor(displaySignature, displayTerms, userInput) {
|
2020-03-23 18:10:42 +01:00
|
|
|
this.shouldDisplaySignature = displaySignature;
|
2020-11-17 16:57:42 +01:00
|
|
|
this.shouldDisplayTerms = displayTerms;
|
2023-02-02 09:10:41 +01:00
|
|
|
this.shouldDisplayUserInput = userInput;
|
2020-11-17 16:57:42 +01:00
|
|
|
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)',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2022-07-20 02:41:36 +02:00
|
|
|
signaturePad.onEnd = function(){
|
|
|
|
document.getElementById("signature-next-step").disabled = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
this.signaturePad = signaturePad;
|
|
|
|
}
|
|
|
|
|
|
|
|
displayTerms() {
|
|
|
|
let displayTermsModal = document.getElementById("displayTermsModal");
|
|
|
|
displayTermsModal.removeAttribute("style");
|
2020-03-23 18:10:42 +01:00
|
|
|
}
|
|
|
|
|
2023-02-02 11:04:55 +01:00
|
|
|
displayInput() {
|
|
|
|
let displayInputModal = document.getElementById("displayInputModal");
|
|
|
|
displayInputModal.removeAttribute("style");
|
|
|
|
}
|
|
|
|
|
2020-03-23 18:10:42 +01:00
|
|
|
handle() {
|
2022-07-20 02:41:36 +02:00
|
|
|
|
|
|
|
document.getElementById("signature-next-step").disabled = true;
|
2023-02-03 01:13:57 +01:00
|
|
|
|
2023-07-16 04:40:32 +02:00
|
|
|
document.getElementById("close-button").addEventListener('click', () => {
|
2022-07-20 02:53:43 +02:00
|
|
|
const approveButton = document.getElementById("approve-button");
|
|
|
|
|
2023-07-16 04:40:32 +02:00
|
|
|
console.log('close button');
|
|
|
|
|
2022-07-20 02:53:43 +02:00
|
|
|
if(approveButton)
|
|
|
|
approveButton.disabled = false;
|
|
|
|
|
|
|
|
});
|
2022-07-20 02:41:36 +02:00
|
|
|
|
2023-07-16 04:40:32 +02:00
|
|
|
document.getElementById("close-terms-button").addEventListener('click', () => {
|
2023-02-03 01:13:57 +01:00
|
|
|
const approveButton = document.getElementById("approve-button");
|
|
|
|
|
2023-07-16 04:40:32 +02:00
|
|
|
console.log('close terms-button');
|
|
|
|
|
|
|
|
if (approveButton)
|
2023-02-03 01:13:57 +01:00
|
|
|
approveButton.disabled = false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-07-16 04:40:32 +02:00
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
document
|
|
|
|
.getElementById('approve-button')
|
|
|
|
.addEventListener('click', () => {
|
2023-02-02 11:04:55 +01:00
|
|
|
|
2023-02-07 07:19:38 +01:00
|
|
|
if (!this.shouldDisplaySignature && !this.shouldDisplayTerms && this.shouldDisplayUserInput){
|
2023-02-02 11:04:55 +01:00
|
|
|
this.displayInput();
|
|
|
|
|
|
|
|
document
|
|
|
|
.getElementById('input-next-step')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
document.querySelector(
|
|
|
|
'input[name="user_input"'
|
|
|
|
).value = document.getElementById('user_input').value;
|
|
|
|
this.termsAccepted = true;
|
|
|
|
this.submitForm();
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.shouldDisplayUserInput)
|
|
|
|
this.displayInput();
|
|
|
|
|
|
|
|
|
|
|
|
if (this.shouldDisplaySignature && this.shouldDisplayTerms) {
|
2020-11-17 16:57:42 +01:00
|
|
|
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();
|
2023-02-02 11:04:55 +01:00
|
|
|
document.querySelector(
|
|
|
|
'input[name="user_input"'
|
|
|
|
).value = document.getElementById('user_input').value;
|
2020-11-17 16:57:42 +01:00
|
|
|
this.termsAccepted = true;
|
|
|
|
this.submitForm();
|
|
|
|
});
|
2023-02-02 09:10:41 +01:00
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
});
|
|
|
|
}
|
2020-03-23 18:10:42 +01:00
|
|
|
|
2023-02-02 11:04:55 +01:00
|
|
|
if (this.shouldDisplaySignature && !this.shouldDisplayTerms) {
|
|
|
|
|
2020-11-17 16:57:42 +01:00
|
|
|
this.displaySignature();
|
|
|
|
|
|
|
|
document
|
|
|
|
.getElementById('signature-next-step')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
document.querySelector(
|
|
|
|
'input[name="signature"'
|
|
|
|
).value = this.signaturePad.toDataURL();
|
2023-02-02 11:04:55 +01:00
|
|
|
document.querySelector(
|
|
|
|
'input[name="user_input"'
|
|
|
|
).value = document.getElementById('user_input').value;
|
2020-11-17 16:57:42 +01:00
|
|
|
this.submitForm();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-02 11:04:55 +01:00
|
|
|
if (!this.shouldDisplaySignature && this.shouldDisplayTerms) {
|
2020-11-17 16:57:42 +01:00
|
|
|
this.displayTerms();
|
|
|
|
|
|
|
|
document
|
|
|
|
.getElementById('accept-terms-button')
|
|
|
|
.addEventListener('click', () => {
|
|
|
|
this.termsAccepted = true;
|
|
|
|
this.submitForm();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-02-07 07:19:38 +01:00
|
|
|
if (!this.shouldDisplaySignature && !this.shouldDisplayTerms && !this.shouldDisplayUserInput) {
|
2020-11-17 16:57:42 +01:00
|
|
|
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
|
|
|
|
2023-02-02 09:10:41 +01:00
|
|
|
const user_input = document.querySelector('meta[name="accept-user-input"]').content;
|
|
|
|
|
|
|
|
new Approve(Boolean(+signature), Boolean(+terms), Boolean(+user_input)).handle();
|