1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/resources/js/clients/quotes/approve.js

169 lines
5.8 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
*
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 {
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;
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)',
}
);
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
}
displayInput() {
let displayInputModal = document.getElementById("displayInputModal");
displayInputModal.removeAttribute("style");
}
2020-03-23 18:10:42 +01:00
handle() {
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', () => {
const approveButton = document.getElementById("approve-button");
2023-07-16 04:40:32 +02:00
console.log('close button');
if(approveButton)
approveButton.disabled = false;
});
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', () => {
if (!this.shouldDisplaySignature && !this.shouldDisplayTerms && this.shouldDisplayUserInput){
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();
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();
});
2020-11-17 16:57:42 +01:00
});
}
2020-03-23 18:10:42 +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();
document.querySelector(
'input[name="user_input"'
).value = document.getElementById('user_input').value;
2020-11-17 16:57:42 +01:00
this.submitForm();
});
}
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();
});
}
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
const user_input = document.querySelector('meta[name="accept-user-input"]').content;
new Approve(Boolean(+signature), Boolean(+terms), Boolean(+user_input)).handle();