Skip to content

Commit

Permalink
psgdpr - jquery removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Oksydan committed Nov 3, 2023
1 parent 26d3627 commit b445528
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 35 deletions.
22 changes: 22 additions & 0 deletions modules/psgdpr/views/js/front.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

DOMREady(() => {
psgdpr_front_controller = psgdpr_front_controller.replace(/\amp;/g,'');

eventHandlerOn(document, 'click', '#exportPersonalData', (e) => {
const { request } = useHttpRequest(psgdpr_front_controller);

request
.query({
ajax: true,
action: test,
id_customer: psgdpr_id_customer
})
.post()
.then((data) => {
console.log(data);
})
.catch((err) => {
console.log(err);
});
});
});
75 changes: 40 additions & 35 deletions modules/psgdpr/views/templates/hook/displayGDPRConsent.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,50 +42,55 @@
var psgdpr_guest_token = "{/literal}{$psgdpr_guest_token|escape:'htmlall':'UTF-8'}{literal}";

document.addEventListener('DOMContentLoaded', function() {
let psgdpr_id_module = "{/literal}{$psgdpr_id_module|escape:'htmlall':'UTF-8'}{literal}";
let parentForm = $('.gdpr_module_' + psgdpr_id_module).closest('form');
const psgdpr_id_module = "{/literal}{$psgdpr_id_module|escape:'htmlall':'UTF-8'}{literal}";
const parentForm = document.querySelector('.gdpr_module_' + psgdpr_id_module)?.closest('form');
let toggleFormActive = function() {
let parentForm = $('.gdpr_module_' + psgdpr_id_module).closest('form');
let checkbox = $('#psgdpr_consent_checkbox_' + psgdpr_id_module);
let element = $('.gdpr_module_' + psgdpr_id_module);
let iLoopLimit = 0;
const checkboxElement = document.querySelector('.gdpr_module_' + psgdpr_id_module);
// by default forms submit will be disabled, only will enable if agreement checkbox is checked
if (element.prop('checked') != true) {
element.closest('form').find('[type="submit"]').attr('disabled', 'disabled');
}
$(document).on("change" ,'.psgdpr_consent_checkboxes_' + psgdpr_id_module, function() {
if ($(this).prop('checked') == true) {
$(this).closest('form').find('[type="submit"]').removeAttr('disabled');
} else {
$(this).closest('form').find('[type="submit"]').attr('disabled', 'disabled');
}
// by default forms submit will be disabled, only will enable if agreement checkbox is checked
if (checkboxElement?.checked) {
checkboxElement.closest('form')?.querySelector('[type="submit"]')?.setAttribute('disabled', 'disabled');
}

eventHandlerOn(document, 'change', '.psgdpr_consent_checkboxes_' + psgdpr_id_module, (e) => {
const checkbox = e.delegateTarget;
});
if (checkbox?.checked) {
checkbox.closest('form')?.querySelector('[type="submit"]')?.removeAttribute('disabled');
} else {
checkbox.closest('form')?.querySelector('[type="submit"]')?.setAttribute('disabled', 'disabled');
}
});
}

// Triggered on page loading
toggleFormActive();

$(document).on('submit', parentForm, function(event) {
$.ajax({
data: 'POST',
url: psgdpr_front_controller,
data: {
ajax: true,
action: 'AddLog',
id_customer: psgdpr_id_customer,
customer_token: psgdpr_customer_token,
id_guest: psgdpr_id_guest,
guest_token: psgdpr_guest_token,
id_module: psgdpr_id_module,
},
error: function (err) {
console.log(err);
}
});
});
if (parentForm) {
eventHandlerOn(parentForm, 'submit', () => {
const { request } = useHttpRequest(psgdpr_front_controller);

request
.query({
ajax: true,
action: 'AddLog',
id_customer: psgdpr_id_customer,
customer_token: psgdpr_customer_token,
id_guest: psgdpr_id_guest,
guest_token: psgdpr_guest_token,
id_module: psgdpr_id_module,
})
.post()
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
});
}

});
</script>
{/literal}

0 comments on commit b445528

Please sign in to comment.