Skip to content

Commit

Permalink
Merge pull request #2597 from phili67/phili67-no-more-ajax
Browse files Browse the repository at this point in the history
no more ajax
  • Loading branch information
phili67 committed Apr 11, 2024
2 parents cb78766 + a138c2a commit 2f3535a
Show file tree
Hide file tree
Showing 8 changed files with 928 additions and 1,000 deletions.
75 changes: 39 additions & 36 deletions src/skin/js/CRMJSOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
options.method = "GET"
}

if (!options.ContentType) {
options.ContentType = "application/json; charset=utf-8";
}

fetch(window.CRM.root + "/api/" + options.path, {
method: options.method,
headers: {
'Content-Type': "application/json; charset=utf-8",
'Content-Type': options.ContentType,
'Authorization': 'Bearer ' + window.CRM.jwtToken,
},
body: options.data
Expand Down Expand Up @@ -150,24 +154,27 @@
})
}

window.CRM.VerifyThenLoadAPIContent = function(url) {
var error = i18next.t("There was a problem retrieving the requested object");
$.ajax({
method: 'HEAD',
url: url,
async: false,
statusCode: {
200: function() {
window.open(url);
},
404: function() {
window.CRM.DisplayErrorMessage(url, {message: error});
},
500: function() {
window.CRM.DisplayErrorMessage(url, {message: error});
}
window.CRM.VerifyThenLoadAPIContent = async function(url) {
const error = i18next.t("There was a problem retrieving the requested object");

try {
const response = await fetch(url, {
method: 'HEAD'
});

if (response.ok) {
console.log('Promise resolved and HTTP status is successful');
} else {
// Custom message for failed HTTP codes
if (response.status === 200) window.open(url);
else if (response.status === 404) window.CRM.DisplayErrorMessage(url, {message: error});
else if (response.status === 500) window.CRM.DisplayErrorMessage(url, {message: error});
// For any other server error
throw new Error(response.status);
}
});
} catch (error) {
console.error('Fetch VerifyThenLoadAPIContent', error);
}
}

window.CRM.cart={
Expand Down Expand Up @@ -255,7 +262,7 @@
}
});

function BootboxContentCartTogroup (){
const BootboxContentCartTogroup = () => {
var frm_str = '<form id="some-form">'
+'<table border=0 cellpadding=2 width="100%">'
+'<tr>'
Expand Down Expand Up @@ -405,8 +412,7 @@
// we hide by default the GroupCreation
$("#GroupCreation").hide();

function addGroups()
{
const addGroups = () => {
window.CRM.APIRequest({
path:"groups/",
method:"GET"
Expand Down Expand Up @@ -970,7 +976,7 @@
}

window.CRM.register = function () {
function BootboxContentRegister(data){
const BootboxContentRegister = (data) => {
var frm_str = '<div class="card card-warning">'
+ ' <div class="card-body">'
+ ' ' + i18next.t('If you need to make changes to registration data, go to ') + '<a href="'+ window.CRM.root + '/v2/systemsettings">'+ i18next.t('Admin->Edit General Settings') + '</a>'
Expand Down Expand Up @@ -1016,18 +1022,15 @@
label: i18next.t("Send"),
className: "btn btn-primary pull-left",
callback: function() {
$.ajax({
type: "POST",
url: window.CRM.root + "/api/register",
data: {
emailmessage: $("#registeremailmessage").val(),
EcclesiaCRMURL: $("input[name=EcclesiaCRMURL]").val()
},
success: function (data) {
alert(i18next.t('Your software is now registered. Thank you !'));
location.reload();
}
});
window.CRM.APIRequest({
method: 'POST',
path: 'register',
data: JSON.stringify({ "emailmessage": $("#registeremailmessage").val(), EcclesiaCRMURL: $("input[name=EcclesiaCRMURL]").val() })
}, function (data) {
window.CRM.DisplayAlert("EcclesiaCRM",i18next.t('Your software is now registered. Thank you !'), function (){
location.reload();
});
});
}
},
{
Expand Down Expand Up @@ -1754,13 +1757,13 @@
}
});

function LimitTextSize(theTextArea, size) {
const LimitTextSize = (theTextArea, size) => {
if (theTextArea.value.length > size) {
theTextArea.value = theTextArea.value.substr(0, size);
}
}

function popUp(URL) {
const popUp = (URL) => {
var day = new Date();
var id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=yes,width=600,height=400,left = 100,top = 50');");
Expand Down
37 changes: 17 additions & 20 deletions src/skin/js/event/Checkin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ window.CRM.editor = null;

$(function() {

function addEvent(dateStart, dateEnd) {
const addEvent = (dateStart, dateEnd) => {
window.CRM.APIRequest({
method: 'POST',
path: 'calendar/numberofcalendars',
Expand Down Expand Up @@ -387,23 +387,21 @@ $(function() {
$(this).parent().find(".fa-chevron-up").removeClass("fa-chevron-up").addClass("fa-chevron-down");
});

var $input = $("#child, #adult, #adultout");
$input.autocomplete({
var input = $("#child, #adult, #adultout");
input.autocomplete({
source: function (request, response) {
$.ajax({
url: window.CRM.root + '/api/persons/search/' + request.term,
dataType: 'json',
type: 'GET',
success: function (data) {
console.log(data);
response($.map(data, function (item) {
return {
label: item.text,
value: item.objid,
obj: item
};
}));
}
window.CRM.APIRequest({
method: 'GET',
path: 'persons/search/' + request.term
},function (data) {
console.log(data);
response($.map(data, function (item) {
return {
label: item.text,
value: item.objid,
obj: item
};
}));
})
},
minLength: 2,
Expand All @@ -422,7 +420,7 @@ $(function() {
});


function SetPersonHtml(element, perArr) {
const SetPersonHtml = (element, perArr) => {
if (perArr) {
element.html(
'<div class="text-center">' +
Expand All @@ -439,8 +437,7 @@ $(function() {
}

/* QRCode code */

function BootboxContent(){
const BootboxContent = () => {

var frm_str = '<h3 style="margin-top:-5px"></h3>'
+ '<div>'
Expand Down
Loading

0 comments on commit 2f3535a

Please sign in to comment.