Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module fixes and updates #7429

Merged
merged 11 commits into from
May 20, 2024
8 changes: 7 additions & 1 deletion config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,13 @@ assets:
script: jszip.min.js
jspdf:
basePath: '%assets_static_relative%/jspdf/dist/'
script: jspdf.umd.min.js
script: jspdf.min.js
jspdfdebug:
basePath: '%assets_static_relative%/jspdf/dist/'
script: jspdf.debug.js
jstiff:
basePath: '%assets_static_relative%/tiff/'
script: tiff.min.js
dwv:
basePath: '%assets_static_relative%/dwv/'
script:
Expand Down
119 changes: 64 additions & 55 deletions interface/modules/custom_modules/oe-module-faxsms/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,68 +96,77 @@
}
}
// when the form is submitted
$('#contact-form').on('submit', function (e) {
if (!e.isDefaultPrevented()) {
let wait = '<div class="text-center wait"><i class="fa fa-cog fa-spin fa-2x"></i></div>';
let url = 'sendFax?type=fax';
if (isSms) {
url = 'sendSMS?type=sms';
}
if (isForward) {
url = 'forwardFax?type=fax';
}
if (isEmail) {
url = 'sendEmail?type=email';
}
if (isOnetime) {
url = "./library/api_onetime.php?";
if (isSms) {
url += 'sendOneTime&type=sms'
} else {
url += 'sendOneTime&type=email';
}
}
$(document).ready(function() {
// Ensuring event handlers are set after the DOM is fully loaded
$('#contact-form').on('submit', function(e) {
e.preventDefault(); // Prevent the default form submit

const wait = '<div class="text-center wait"><i class="fa fa-cog fa-spin fa-2x"></i></div>';
$('#contact-form').find('.messages').html(wait);
// POST values in the background the script URL

const url = buildUrl();
const formData = $(this).serialize();

$.ajax({
type: "POST",
url: url,
data: $(this).serialize(),
success: function (data) {
try {
let t_data = JSON.parse(data);
data = t_data;
} catch (e) {
}
let err = (data.search(/Exception/) !== -1 ? 1 : 0);
if (!err) {
err = (data.search(/Error:/) !== -1) ? 1 : 0;
}
// Type of the message: success or danger. Apply it to the alert.
let messageAlert = 'alert-' + (err !== 0 ? 'danger' : 'success');
let messageText = data;

// let's compose alert box HTML
let alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable">' +
'<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';

// If we have messageAlert and messageText
if (messageAlert && messageText) {
// inject the alert to messages div in our form
$('#contact-form').find('.messages').html(alertBox);
setTimeout(function () {
if (!err) {
// close dialog as we have success.
dlgclose();
}
// if error let user close dialog for time to read error message.
}, 4000);
}
data: formData,
success: handleResponse,
error: function() {
showErrorMessage('An unexpected error occurred and your request could not be completed.');
}
});
return false;
});

function buildUrl() {
// Simplify logic by directly mapping conditions to URLs
if (isOnetime) {
const type = isSms ? 'sms' : 'email';
return `./library/api_onetime.php?sendOneTime&type=${encodeURIComponent(type)}`;
}

if (isSms) {
return 'sendSMS?type=sms';
} else if (isForward) {
return 'forwardFax?type=fax';
} else if (isEmail) {
return 'sendEmail?type=email';
} else {
return 'sendFax?type=fax';
}
}

function handleResponse(data) {
let jsonData;
try {
jsonData = JSON.parse(data);
} catch (e) {
jsonData = data; // Use data as is if it can't be parsed as JSON
}

const isError = /Exception|Error:/.test(jsonData);
const messageType = isError ? 'danger' : 'success';
const messageText = jsonData;
const alertBox = `<div class="alert alert-${messageType} alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
${messageText}
</div>`;

$('#contact-form').find('.messages').html(alertBox);
if (!isError) {
setTimeout(() => { dlgclose(); }, 4000); // Auto-close dialog on success
}
}
})

function showErrorMessage(message) {
const alertBox = `<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
${message}
</div>`;
$('#contact-form').find('.messages').html(alertBox);
}
});

});

function sel_patient() {
Expand Down
Loading
Loading