var modalPop = '';
function certStudentPrompt(el) {
const name = prompt("Enter student's name for certificate");
el.href += '&name=' + name;
return true;
}
function addSlidePop(courseId) {
modalPop = new bumbleBox('/?page_type=modal_slide_add&course_id=' + courseId, 'Add a new slide', '500px', 'auto');
modalPop.show();
return false;
}
function editSlidePop(slideId) {
modalPop = new bumbleBox('/?page_type=modal_slide_edit&slide_id=' + slideId, 'Edit slide', '500px', 'auto', '',slideUploadFileUpdate,'','','','','alt');
modalPop.show();
return false;
}
function slidesRefresh() {
const courseId = $('#course_id').val();
const ajaxData = new FormData();
ajaxData.append('action', 'manage-slides');
ajaxData.append('course_id', courseId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
const slides = $('#course_slides');
slides.html(dataObj.html);
},
error: function(returnObj, textStatus, errorThrown) {
if (returnObj.responseText) {
modalPop.hide();
alert('Error loading slide');
}
},
complete: function() {
}
});
}
function slideAdd(type) {
const courseId = $('#course_id').val();
const ajaxData = new FormData();
ajaxData.append('action', 'manage-slides');
ajaxData.append('task', 'new');
ajaxData.append('type', type);
ajaxData.append('course_id', courseId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
modalPop.hide();
setTimeout(function() {
editSlidePop(dataObj.slideId);
}, 500);
},
error: function(returnObj, textStatus, errorThrown) {
//alert(returnObj.responseText);
alert('There was problem adding this slide - please refresh and try again');
modalPop.hide();
},
complete: function() {
}
});
}
function slideUploadFileUpdate() {
setTimeout(function() {
const update = $('#upload_file_name');
const modal = $('.modal_box');
const modalHeight = parseInt(modal.css('height'));
const modalNewHeight = modalHeight + 50;
$('.admin_content input[type="file"]').change(function(e){
var fileName = e.target.files[0].name;
if (fileName && fileName != '') {
update.text('Selected file: ' + fileName);
update.css('display', 'block');
var thisTrans = new bumbleTransitionObj(modalPop.modalContainer, 'height', modalHeight, modalNewHeight, 'px', 500, 'circ');
}
});
}, 1000);
}
function slidesVidListen() {
$('.course_slide_container > .vid_container > video')[0].addEventListener('ended', function(e) {
$('.slide_all_done_msg').css('display','block');
slidesAdvance();
}, false);
}
function slidesAdvance() {
const courseId = $('#course_id').val();
const ajaxData = new FormData();
ajaxData.append('action', 'course');
ajaxData.append('task', 'advance');
ajaxData.append('course_id', courseId);
$.ajax({
url: '/?page_type=me',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function bookingCalendarCreate() {
const calendar = new bumbleCalendar('session_book_calendar','','','',false,'',true,false,bookingCalendarBook);
}
function bookingCalendarBook(event) {
let triggerEl = (event.currentTarget) ? event.currentTarget : event.srcElement;
let thisDate = triggerEl.getAttribute('data-cell-date');
if (!thisDate) {
triggerEl = triggerEl.parentNode;
thisDate = triggerEl.getAttribute('data-cell-date');
}
bookingCalendarBookPop(thisDate);
}
function bookingCalendarBookPop(date) {
modalPop = new bumbleBox('/?page_type=modal_session_booking&date=' + date, 'Book a session', '500px', 'auto', '', refreshTimepick);
modalPop.show();
return false;
}
function refreshTimepick() {
$('.timepicker').timepicki({
min_hour_value:0,
max_hour_value:23,
show_meridian:false,
overflow_minutes:true,
step_size_minutes:5
});
}
function adminUsersArchive(e) {
if (confirm('Are you sure you wish to archive this user?')) {
e.target.parentNode.parentNode.style.display = 'none';
const userId = e.target.getAttribute('data-id');
const ajaxData = new FormData();
ajaxData.append('action', 'users');
ajaxData.append('task', 'archive');
ajaxData.append('user_id', userId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
console.log(dataObj);
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
}
return false;
}
function adminUsersPause(e) {
$(e.target).toggleClass('red');
const userId = e.target.getAttribute('data-id');
const ajaxData = new FormData();
ajaxData.append('action', 'users');
ajaxData.append('task', 'pause');
ajaxData.append('user_id', userId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
console.log(dataObj);
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
return false;
}
function adminUsersDelete(e) {
if (confirm('Are you sure you wish to delete this user?')) {
e.target.parentNode.parentNode.style.display = 'none';
const userId = e.target.getAttribute('data-id');
console.log(userId);
const ajaxData = new FormData();
ajaxData.append('action', 'users');
ajaxData.append('task', 'delete');
ajaxData.append('user_id', userId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
console.log(dataObj);
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
}
return false;
}
function adminReferralDelete(e) {
const resultId = e.target.getAttribute('data-id');
if (confirm('Are you sure you wish to delete this referral?')) {
const item = e.target.parentNode.parentNode;
const container = item.parentNode;
// any more nodes in this container?
if (container.childNodes.length <= 2) {
// no...
// remove previous sibling (the heading)
container.previousSibling.parentNode.removeChild(container.previousSibling);
// remove the container
container.parentNode.removeChild(container);
}
else {
// yes - remove the item
item.parentNode.removeChild(item);
}
const ajaxData = new FormData();
ajaxData.append('action', 'new-referrals');
ajaxData.append('task', 'delete');
ajaxData.append('result_id', resultId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
console.log(dataObj);
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
}
return false;
}
function getCurrentURLAction() {
// Get the current URL
var currentURL = window.location.href;
// remove query stream
currentURL = currentURL.split('?')[0];
// Split the URL by the slash ("/") character
let urlParts = currentURL.split('/');
urlParts = urlParts.filter(value => value);
// Get the last part of the URL (excluding any trailing slash)
var lastPart = urlParts[urlParts.length - 1];
console.log(urlParts);
return lastPart;
}
function adminReferralApprove(e) {
const resultId = e.target.getAttribute('data-id');
const item = e.target.parentNode.parentNode;
const container = item.parentNode;
// any more nodes in this container?
if (container.childNodes.length <= 2) {
// no...
// remove previous sibling (the heading)
container.previousSibling.parentNode.removeChild(container.previousSibling);
// remove the container
container.parentNode.removeChild(container);
}
else {
// yes - remove the item
item.parentNode.removeChild(item);
}
const ajaxData = new FormData();
ajaxData.append('action', getCurrentURLAction());
ajaxData.append('task', 'approve');
ajaxData.append('result_id', resultId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
console.log(dataObj);
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
return false;
}
function adminReferralHold(e, onhold='1') {
const resultId = e.target.getAttribute('data-id');
const item = e.target.parentNode.parentNode;
const container = item.parentNode;
// any more nodes in this container?
if (container.childNodes.length <= 2) {
// no...
// remove previous sibling (the heading)
container.previousSibling.parentNode.removeChild(container.previousSibling);
// remove the container
container.parentNode.removeChild(container);
}
else {
// yes - remove the item
item.parentNode.removeChild(item);
}
const ajaxData = new FormData();
ajaxData.append('action', getCurrentURLAction());
ajaxData.append('task', 'onhold');
ajaxData.append('onhold', onhold);
ajaxData.append('result_id', resultId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
console.log(dataObj);
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
return false;
}
function adminReferralContacted(e) {
e.stopPropagation();
const dateCell = e.target.parentNode.previousSibling.previousSibling.previousSibling;
const row = dateCell.parentNode;
const userId = e.target.getAttribute('data-id');
const ajaxData = new FormData();
ajaxData.append('action', 'referrals');
ajaxData.append('task', 'contacted');
ajaxData.append('user_id', userId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
dateCell.innerHTML = dataObj.contactedDate;
e.target.parentNode.removeChild(e.target);
row.className = 'row highlight';
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
return false;
}
function toggleSessionMissed(e, sessionId=0) {
e.stopPropagation();
const ajaxData = new FormData();
ajaxData.append('action', 'sessions');
ajaxData.append('task', 'toggleMissed');
ajaxData.append('session_id', sessionId);
$(e.target).toggleClass('amber');
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
return false;
}
function toggleCourseComplete(e, sessionId=0) {
e.stopPropagation();
const ajaxData = new FormData();
ajaxData.append('action', 'sessions');
ajaxData.append('task', 'toggleComplete');
ajaxData.append('session_id', sessionId);
$(e.target).addClass('rotate');
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
console.log(dataObj);
if (dataObj.complete == 'yes') {
$(e.target).addClass('green');
}
else {
$(e.target).removeClass('green');
}
$(e.target).removeClass('rotate');
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
return false;
}
function adminCancelSession(sessionId, cancelAll='false', noSessions=1, cancelUrl) {
let cancelAllStr = cancelAll && cancelAll == true ? 'true' : 'false';
if (cancelAllStr === 'true') {
if (confirm('Are you sure you wish to cancel this programme?')) {
document.location.href = cancelUrl + 'booking-' + sessionId + '--task-cancelAll.html';
}
return false;
}
let modalPop = new bumbleBox('/?page_type=modal_session_cancel&no_sessions=' + noSessions + '&session_id=' + sessionId + '&cancel_all=' + cancelAllStr + '&cancel_url=' + cancelUrl, 'Log session cancellation', '500px', 'auto');
modalPop.show();
return false;
}
function adminCancelSessionAction(btn) {
let log = btn.getAttribute('data-log');
let reason = btn.getAttribute('data-reason');
let reasonText = '';
if (reason == '4') {
reasonText = document.getElementById('modal-cancel-reason').value;
}
if (reasonText) {
reason += '--cancel_reason_other-' + reasonText;
}
let url = document.getElementById('modal-cancel-url').value;
url += '--log-' + log + '--reason-' + reason + '.html';
//console.log(url);
document.location.href = url;
}
function toggleSessionCancelled(e, sessionId=0) {
e.stopPropagation();
const ajaxData = new FormData();
ajaxData.append('action', 'sessions');
ajaxData.append('task', 'toggleCancelled');
ajaxData.append('session_id', sessionId);
$(e.target).toggleClass('purple');
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
},
error: function(returnObj, textStatus, errorThrown) {
console.log(returnObj.responseText);
},
complete: function() {
}
});
return false;
}
function changeURLPostCancel() {
// change the URL after clicking 'cancel' or 'cancel all'
// Get the current URL
var currentURL = window.location.href;
// Find the position of '--task-cancel' in the URL
var index = currentURL.indexOf('--task-cancel');
// Check if '--task-cancel' is found in the URL
if (index !== -1) {
// Extract the portion of the URL before '--task-cancel'
var newURL = currentURL.substring(0, index);
// Change the URL without refreshing the page
history.pushState({}, document.title, newURL);
}
}
function checkLabel(e) {
var self = e.target;
setTimeout(function() {
if (self.checked) {
$(self).parent('label').addClass('checked');
}
else {
$(self).parent('label').removeClass('checked');
}
}, 100);
}
function adminReferrerAccess(uid) {
modalPop = new bumbleBox('/?page_type=admin&action=referrer_access&user_id=' + uid, 'Referrer access & Admin triage', '700px', 'auto', 'ajax');
modalPop.show();
}
function adminReferrerAccessSave(uid) {
const checked = $('input[name=referrer_access_user]:checked');
const triage = $('input[name=admin_triage]:checked');
const refId = [];
$.each(checked, function(key, item) {
refId.push($(item).val());
});
refIdStr = refId.join();
const ajaxData = new FormData();
ajaxData.append('action', 'referrer_access');
ajaxData.append('task', 'save');
ajaxData.append('user_id', uid);
const newTriage = triage.val();
ajaxData.append('admin_triage', newTriage);
ajaxData.append('ref_id_str', refIdStr);
const newTriageDetails = triageAdmin[newTriage];
const triageCell = $('td[data-triage='+ uid + ']');
let newTriageHTML = '';
if (newTriageDetails && newTriageDetails.colour) {
newTriageHTML = "
" + newTriageDetails.name + "
";
}
triageCell.html(newTriageHTML);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function(data) {
}
});
}
function searchBin(el) {
setTimeout(function() {
if (el.value == '') {
return $('div[data-name]').show();
}
$('div[data-name]').hide();
$('div[data-name*=' + el.value + ' i]').show();
}, 50);
}
function viewFormSubmission(resultId, title='Form submission') {
modalPop = new bumbleBox('/?page_type=admin&action=form_submission&result_id=' + resultId, title, '700px', 'auto', 'ajax');
modalPop.show();
return false;
}
function adminReferralTriage(e) {
const resultId = e.target.getAttribute('data-id');
title = 'Admin triage';
modalPop = new bumbleBox('/?page_type=admin&action=referral_triage&result_id=' + resultId, title, '700px', 'auto', 'ajax');
modalPop.show();
return false;
}
function adminReferralView(e, referralUserId) {
const resultId = e.target.getAttribute('data-id');
let title = e.target.getAttribute('title');
if (!title || title == '') {
title = 'Submission details';
}
if (referralUserId) {
modalPop = new bumbleBox('/?page_type=admin&action=form_submission&referral_user_id=' + referralUserId, title, '700px', 'auto', 'ajax');
}
else {
modalPop = new bumbleBox('/?page_type=admin&action=form_submission&result_id=' + resultId, title, '700px', 'auto', 'ajax');
}
modalPop.show();
return false;
}
function adminChangeContactedDates(userId) {
modalPop = new bumbleBox('/?page_type=admin&action=users_change_contacted_dates&user_id=' + userId, 'Contact attempts', '500px', 'auto', 'ajax');
modalPop.show();
}
function coachChangeContactedDates(userId) {
modalPop = new bumbleBox('/?page_type=admin&action=coach_change_contacted_dates&user_id=' + userId, 'Coach contact attempts', '500px', 'auto', 'ajax');
modalPop.show();
}
function coachChangeContactAction(userId) {
const ajaxData = new FormData();
ajaxData.append('action', 'coach_change_contacted_dates');
ajaxData.append('task', 'save');
ajaxData.append('user_id', userId);
ajaxData.append('contacted_1', $('#modal_contact_1').val());
ajaxData.append('contacted_2', $('#modal_contact_2').val());
ajaxData.append('contacted_3', $('#modal_contact_3').val());
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
const contacted_el = document.getElementById('contacted_str_' + userId);
contacted_el.innerHTML = dataObj.str;
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function(data) {
}
});
}
function adminUsersChangeContactAction(userId) {
const ajaxData = new FormData();
ajaxData.append('action', 'users_change_contacted_dates');
ajaxData.append('task', 'save');
ajaxData.append('user_id', userId);
ajaxData.append('contacted_1', $('#modal_contact_1').val());
ajaxData.append('contacted_2', $('#modal_contact_2').val());
ajaxData.append('contacted_3', $('#modal_contact_3').val());
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
const familyGroupId = dataObj.family;
const cell = $('td[data-contacted-group-id=' + familyGroupId + ']');
cell.html(dataObj.str);
if (parseInt(dataObj.attempts) >= 3) {
cell.parent().addClass('red');
}
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function(data) {
}
});
}
//function
function adminChangeTermsSubmitted(userId) {
modalPop = new bumbleBox('/?page_type=admin&action=users_change_terms_submitted&user_id=' + userId, 'Terms submitted', '500px', 'auto', 'ajax');
modalPop.show();
}
function adminChangeTermsAction(userId) {
const ajaxData = new FormData();
ajaxData.append('action', 'users_change_terms_submitted');
ajaxData.append('task', 'save');
ajaxData.append('user_id', userId);
ajaxData.append('terms_submitted', $('#modal_terms_submitted').val());
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
const familyGroupId = dataObj.family;
const cell = $('td[data-terms-group-id=' + familyGroupId + ']');
cell.html(dataObj.str);
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function(data) {
}
});
}
function adminToggleImportant(e) {
const parentRow = e.target.parentNode.parentNode;
const familyId = parentRow.getAttribute('data-family-id');
const userId = parentRow.getAttribute('data-user-id');
const tableRow = $('tr[data-family-id="' + familyId + '"]');
const ajaxData = new FormData();
ajaxData.append('action', 'referrals');
ajaxData.append('task', 'important');
ajaxData.append('user_id', userId);
tableRow.css('opacity', '0.5');
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
if ($(parentRow).hasClass('important')) {
tableRow.removeClass('important');
}
else {
tableRow.addClass('important');
}
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
tableRow.css('opacity', '1');
}
});
}
function refPauseChangeArea() {
if (typeof pauseData == 'undefined') return;
const data = pauseData;
const area = $('#referrer-pause-area').val();
const refs = $('input[data-org]');
const courses = $('input[data-course]');
refs.prop('checked', true);
courses.prop('checked', true);
if (data) {
if (data.ref && data.ref[area]) {
for (const org of data.ref[area]) {
$('input[data-org="' + addslashes(org) + '"').prop('checked', false);
}
}
if (data.courses && data.courses[area]) {
for (const course of data.courses[area]) {
$('input[data-course="' + addslashes(course) + '"').prop('checked', false);
}
}
$('#ref-pause-data').val(JSON.stringify(data));
}
}
function changeAreaRef(el, refOrCourse='ref') {
const data = pauseData;
const area = $('#referrer-pause-area').val();
const rootObj = data[refOrCourse];
if (!rootObj[area]) {
rootObj[area] = [];
}
const org = refOrCourse === 'ref' ? el.getAttribute('data-org') : el.getAttribute('data-course');
const orgIndex = rootObj[area]?.indexOf(org);// && rootObj[area]?.indexOf(org) >= 0 ? rootObj[area]?.indexOf(org) : -1;
console.log(rootObj[area]);
console.log(org);
console.log(orgIndex);
if (el.checked && orgIndex >= 0) {
delete rootObj[area][orgIndex];
}
else if (!el.checked && orgIndex < 0) {
rootObj[area].push(org);
}
rootObj[area] = rootObj[area]?.filter(function(){return true});
console.log(data);
$('#ref-pause-data').val(JSON.stringify(data));
}
function newRefFilter() {
const rows = $('.row');
rows.removeClass('hidden');
const sections = $('.admin_users_container');
sections.removeClass('hidden');
$('h2').removeClass('hidden');
const ccg = $('#filter_ccg').val();
if (ccg != '') {
$('.row[data-ccg!="' + addslashes(ccg) + '"]').addClass('hidden');
}
const ref = $('#filter_referred_from').val();
if (ref != '') {
$('.row[data-ref!="' + addslashes(ref) + '"]').addClass('hidden');
}
sections.each(function() {
const visibleChildren = $(this).find('.row').not('.hidden');
if (visibleChildren.length === 0) {
$(this).addClass('hidden');
$(this).prev('h2').addClass('hidden');
}
});
}
function userFilterCCG(e) {
const link = e.target;
if (link === link.parentNode.firstElementChild) {
$('.filter_ccg a').removeClass('active');
$(link).addClass('active');
}
else {
$('.filter_ccg a').first().removeClass('active');
$(link).toggleClass('active');
}
if ($('.filter_ccg a + a.active').length === 0) {
$('.filter_ccg a').first().addClass('active');
}
referralApplyFilter();
}
var filterCourse = '';
var filterRef = '';
var filterSchool = '';
function userFilterByCourse() {
const course = $('#filter_course');
filterCourse = course.val();
const ref = $('#filter_referred_from');
filterRef = ref.val();
const type = $('#filter_school_type');
filterSchool = type.val();
referralApplyFilter();
}
function referralApplyFilter() {
const filterCCG = [];
$('tr[data-ccg]').css('display','table-row');
if ($('.filter_ccg a').first().hasClass('active') === false) {
$('.filter_ccg a').each(function() {
if ($(this).hasClass('active')) {
filterCCG.push($(this).attr('data-ccg'));
}
});
}
if (filterCCG.length > 0) {
$('tr[data-ccg]').css('display','none');
for (const thisCCG of filterCCG) {
$("tr.row[data-ccg='" + thisCCG + "']").css('display','table-row');
}
}
if (filterCourse != '') {
if (filterCourse === '6week' || filterCourse === '12week') {
const courseArr = [];
const options = $('#filter_course > option');
options.each(function() {
let thisType = $(this).attr('data-course-type');
let thisCourse = $(this).attr('value');
if (typeof courseArr[thisType] === 'undefined') {
courseArr[thisType] = [];
}
courseArr[thisType].push(thisCourse);
});
$("tr.row").each(function() {
let thisId = $(this).attr('data-course-id');
let thisCourseArr = filterCourse === '6week' ? courseArr['6'] : courseArr['12'];
if (!thisId || thisCourseArr.indexOf(thisId) === -1) {
$(this).css('display','none');
}
});
return;
}
$("tr.row[data-course-id!='" + filterCourse + "']").css('display','none');
}
if (filterSchool && filterSchool != '') {
console.log(filterSchool);
$("tr.row[data-school-type!='" + filterSchool + "']").css('display','none');
}
if (typeof filterRef != 'undefined' && filterRef != '') {
console.log(filterRef);
$("tr.row[data-referrer!='" + filterRef + "']").css('display','none');
}
if ($('#filter_cancelled_cancelled')[0].checked == true) {
$("tr.row td[data-cancelled='false']").parent().css('display','none');
}
const coach = $('#filter_coach').val();
if (coach != '') {
$("tr.row td[data-coach]").each(function() {
if ($(this).attr('data-coach') != coach) {
$(this).parent().css('display','none');
}
});
}
}
function referralsPopulateCourses(courses={}) {
const coursesArr = Object.entries(courses);
const select = $('#filter_course');
for (const [courseName, courseId] of coursesArr) {
let o = new Option(courseName, courseId);
if (courseName.substring(0,1) === '6') {
o.setAttribute('data-course-type', '6');
}
if (courseName.substring(0,2) === '12') {
o.setAttribute('data-course-type', '12');
}
select.append($(o));
}
}
function adminUsersGeneratePassword(e) {
let userId = e.target.getAttribute('data-id');
if (!userId || userId == null) {
userId = e.target.parentNode.getAttribute('data-id');
}
if (confirm("Do you wish to email the user a new password?")) {
const ajaxData = new FormData();
ajaxData.append('action', 'users');
ajaxData.append('task', 'generatepw');
ajaxData.append('user_id', userId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
return false;
}
function userMissSession(sessionId) {
modalPop = new bumbleBox('/?page_type=me&category=miss-session&session_id=' + sessionId, 'Miss this session', '500px', 'auto');
modalPop.show();
return false;
}
function adminUsersChangePassword(e, redir=false) {
let userId = e.target.getAttribute('data-id');
if (!userId || userId == null) {
userId = e.target.parentNode.getAttribute('data-id');
}
//console.log('/?page_type=admin&action=users_change_password&user_id=' + userId);
modalPop = new bumbleBox('/?page_type=admin&action=users_change_password&redir=' + redir + '&user_id=' + userId, 'Change password', '500px', 'auto', null, function() {
$('#modal_password')[0].focus();
});
modalPop.show();
return false;
}
function adminUsersChangePasswordAction(userId, redir=false) {
console.log(userId);
const ajaxData = new FormData();
ajaxData.append('action', 'users');
ajaxData.append('task', 'changepw');
ajaxData.append('user_id', userId);
ajaxData.append('password', $('#modal_password').val());
ajaxData.append('confirm', $('#modal_confirm').val());
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
if (redir) {
window.location.href='/';
}
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminDoCheckIn(userId, callBack) {
const ajaxData = new FormData();
ajaxData.append('action', 'check-in');
ajaxData.append('task', 'check-in');
ajaxData.append('user_id', userId);
console.log(userId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
callBack();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminCheckedIn(el) {
//if (confirm('Have you checked in with this user?')) {
const userId = $(el).attr('data-id');
const item = $(el).parent().parent().parent();
item.css('opacity', 0.5);
adminDoCheckIn(userId, function() {
const container = item.parent();
const containerDone = $('.checkin-container.done');
const containerDue = $('.checkin-container.due');
const moveTo = container.hasClass('due') ? containerDone : containerDue;
moveTo.append(item);
containerDone.find('.round-icon.icon-approve').removeClass('icon-approve').addClass('icon-restore').attr('title', 'Not checked in');
containerDue.find('.round-icon.icon-restore').removeClass('icon-restore').addClass('icon-approve').attr('title', 'Checked in');
item.css('opacity', 1);
});
//}
return false;
}
function adminUsersEditUser(e) {
const userId = e.target.getAttribute('data-id');
modalPop = new bumbleBox('/?page_type=admin&action=users_edit_user&user_id=' + userId, 'Edit user', '500px', 'auto','',function() {
makeColourPickers();
refreshSelects();
});
modalPop.show();
return false;
}
function adminUsersAddUser(e, accountType) {
const userId = e.target.getAttribute('data-id');
let userIdStr = '';
if (userId && userId > 0) {
userIdStr = '&parent_id=' + userId;
}
modalPop = new bumbleBox('/?page_type=admin&action=users_edit_user&type=' + accountType + userIdStr, 'Add user', '500px', 'auto','',function() {
makeColourPickers();
});
modalPop.show();
return false;
}
function adminUsersEditUserAction(userId) {
console.log(userId);
const ajaxData = new FormData();
ajaxData.append('action', 'users');
ajaxData.append('task', 'save_user');
ajaxData.append('user_id', userId);
ajaxData.append('username', $('#modal_username').val());
ajaxData.append('relationship', $('#modal_relationship').val());
ajaxData.append('dob', $('#modal_dob').val());
let checked = $('#modal_parents_taking_programme').is(":checked") ? 1 : 0;
ajaxData.append('parents_taking_programme', checked);
ajaxData.append('firstname', $('#modal_firstname').val());
ajaxData.append('surname', $('#modal_surname').val());
ajaxData.append('school_id', $('#modal_school_id').val());
ajaxData.append('school_name', $('#modal_school_name').val());
ajaxData.append('school_number', $('#modal_school_number').val());
ajaxData.append('school_type', $('#modal_school_type').val());
ajaxData.append('lead_name', $('#modal_lead_name').val());
ajaxData.append('email', $('#modal_email').val());
ajaxData.append('tel_day', $('#modal_phone').val());
ajaxData.append('address', $('#modal_address').val());
ajaxData.append('address_2', $('#modal_address_2').val());
ajaxData.append('town', $('#modal_town').val());
ajaxData.append('county', $('#modal_county').val());
ajaxData.append('postcode', $('#modal_postcode').val());
ajaxData.append('parent_id', $('#parent_id').val());
ajaxData.append('type', $('#modal_type').val());
ajaxData.append('colour', $('#modal_colour').val());
ajaxData.append('referrer_id', $('#modal_referrer_id').val());
ajaxData.append('referred_from', $('#modal_referred_from').val());
ajaxData.append('ccg_area', $('#modal_ccg').val());
ajaxData.append('business', $('#modal_organisation').val());
ajaxData.append('programmes_delim', $('#modal_programmes').val());
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
if (dataObj.parentId && dataObj.parentId > 0) {
location.href = window.location.search + '&open=' + dataObj.parentId + '#user' + dataObj.parentId;
}
else {
location.reload();
}
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminUsersEditCourses(e) {
const userId = e.target.getAttribute('data-id');
modalPop = new bumbleBox('/?page_type=admin&action=users_edit_courses&user_id=' + userId, 'Course allocation', '700px', 'auto');
modalPop.show();
return false;
}
function adminUsersSaveCourses(userId) {
console.log(userId);
const ajaxData = new FormData();
ajaxData.append('action', 'users');
ajaxData.append('task', 'save_courses');
ajaxData.append('user_id', userId);
let manageUsers = $('#manage_users_delim').val();
let manageUsersArr = manageUsers.split(',');
$.each(manageUsersArr, function(key, thisUserId) {
let thisEl = 'courses_' + thisUserId;
let thisElVal = '';
$("input[data-parent-id='" + userId + "'][data-user-id='" + thisUserId + "']").each(function() {
if (this.checked && this.getAttribute('data-course-id') != 'undefined') {
thisElVal += this.getAttribute('data-course-id') + ',';
}
});
ajaxData.append(thisEl, thisElVal);
});
ajaxData.append('funded', $('#modal_funded')[0].checked ? 1 : 0);
let ticks = $('.modal_course_tick[data-parent-course=1]:checked');
let tickIds = '';
ticks.each(function() {
tickIds += $(this).attr('data-id') + ',';
});
ajaxData.append('tick_ids', tickIds);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminCalendarSessionCreate(date='', time='', coachId='', weeks='') {
modalPop = new bumbleBox('/?page_type=admin&action=session_edit&coach_id=' + coachId + '&date=' + date + '&time=' + time + '&weeks=' + weeks + '¤t_page=calendar', 'New booking', '800px', '515px', '', function() {
refreshTimepick();
refreshSelects();
} );
modalPop.show();
return false;
}
function adminSessionEdit(e, width='800', rebook='0') {
let sessId = e.target.getAttribute('data-event-data') ?
e.target.getAttribute('data-event-data') :
e.target.getAttribute('data-id');
if (!sessId) {
sessId = e.target.parentNode.getAttribute('data-event-data');
}
const coachId = $('#sessions_coach_id').val();
if (rebook == '1') {
modalPop = new bumbleBox('/?page_type=admin&action=session_edit&rebook_id=' + sessId + '&coach_id=' + coachId, 'Repeat/rebook programme', width + 'px', '515px', '', function() {
refreshTimepick();
adminSessionChangeUser();
adminSessionPopulateWeek();
refreshSelects();
} );
}
else {
modalPop = new bumbleBox('/?page_type=admin&action=session_edit&session_id=' + sessId + '&coach_id=' + coachId, 'Edit booking', width + 'px', '515px', '', function() {
refreshTimepick();
adminSessionChangeUser();
adminSessionPopulateWeek();
refreshSelects();
} );
}
modalPop.show();
return false;
}
function adminSessionPopulateWeek() {
const weekEl = $('#session_week_id');
if (weekEl && weekEl.length > 0) {
const weekContainer = $('#session_week_id_container');
const selectEl = $('#session_slide_id');
const selectElSelected = selectEl.find('option:selected');
const selectedCourse = selectElSelected.attr('data-course-id');
const weekOptions = weekEl.find('option[data-course-id="' + selectedCourse + '"]');
weekEl.val('');
if (selectedCourse > 0 && weekOptions.length > 0) {
weekContainer.css('display', 'block');
weekEl.find('option').css('display', 'none');
weekEl.find('option').prop('disabled', true);
weekOptions.css('display', 'initial');
weekOptions.prop('disabled', false);
weekEl[0].selectedIndex = weekOptions[0].index;
weekEl.trigger('change.select2');
}
else {
weekContainer.css('display', 'none');
}
}
}
function adminSessionChangeUser() {
const childContainer = $('#session_child_id_container');
const selectEl = $('#session_user_id');
const selectElSelected = selectEl.find('option:selected');
const selectedType = selectElSelected.attr('data-type');
const parentId = selectEl.val(); console.log(parentId);
const selectedId = selectEl.attr('data-selected-id');
const selectedParentId = selectEl.attr('data-selected-parent-id');
const childSelectEl = $('#session_child_id');
const childOptions = childSelectEl.find('option[data-parent-id="' + parentId + '"]');
const firstChild = childOptions.length > 0 ? childOptions[0].index : 0;
console.log('parentId=' + parentId + ' length=' + childOptions.length);
if (parentId > 0 && childOptions.length > 0) {
childContainer.css('display', 'block');
switch(selectedType) {
case "2.0":
childContainer.find('label').text('Class');
break;
default:
childContainer.find('label').text('Family member');
}
childSelectEl.find('option + option').css('display', 'none');
childSelectEl.find('option + option').prop('disabled', true);
childOptions.css('display', 'initial');
childOptions.prop('disabled', false);
if (selectedParentId != childOptions[0].getAttribute('data-parent-id')) {
childSelectEl[0].selectedIndex = firstChild;
}
else {
childOptions.each(function() {
if ($(this).val() == selectedId) {
$(this).prop("selected",true);
return false;
}
});
}
}
else {
/*
if (selectedId > 0) {
selectEl[0].value = selectedId;
}
*/
childSelectEl[0].selectedIndex = 0;
childContainer.css('display', 'none');
}
refreshSelects();
}
function adminViewNotes(userId, width='700') {
modalPop = new bumbleBox('/?page_type=admin&action=notes_view&user_id=' + userId, 'Notes', width + 'px', 'auto');
modalPop.show();
return false;
}
function adminNotesEdit(e, width='700') {
const userId = e.target.getAttribute('data-id');
modalPop = new bumbleBox('/?page_type=admin&action=notes_edit&user_id=' + userId, 'Edit notes', width + 'px', 'auto');
modalPop.show();
return false;
}
function adminAdminNotesEdit(e, width='700') {
const userId = e.target.getAttribute('data-id');
modalPop = new bumbleBox('/?page_type=admin&action=admin_notes_edit&user_id=' + userId, 'Admin notes', width + 'px', 'auto');
modalPop.show();
return false;
}
function adminSafeguardingNotesEdit(userId) {
console.log(userId);
const width = 700;
modalPop = new bumbleBox('/?page_type=admin&action=safeguarding_notes_edit&user_id=' + userId, 'Safeguarding notes', width + 'px', 'auto');
modalPop.show();
return false;
}
function adminCheckinNotes(uid) {
modalPop = new bumbleBox('/?page_type=admin&action=checkin_notes&user_id=' + uid, 'Check-in notes', '700px', 'auto');
modalPop.show();
return false;
}
function adminSessionViewNotes(sessionId, width='700') {
modalPop = new bumbleBox('/?page_type=admin&action=session_notes_view&session_id=' + sessionId, 'Notes', width + 'px', 'auto');
modalPop.show();
return false;
}
function sessionViewNotes(sessionId, width='700') {
modalPop = new bumbleBox('/?page_type=admin&action=session_notes_view&session_id=' + sessionId, 'Session notes', width + 'px', 'auto');
modalPop.show();
return false;
}
function sessionViewNotesUpdate() {
let notesSelect = $('#notes_select_session');
const selectedOption = notesSelect[0].selectedIndex;
notesSelect.css('opacity', 0.2);
const sessionId = notesSelect.val();
const ajaxData = new FormData();
const notesContainer = $('#modal_notes_content');
ajaxData.append('action', 'session_notes_view');
ajaxData.append('task', 'get_notes');
ajaxData.append('session_id', sessionId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
notesContainer.html(dataObj.notes);
notesSelect = $('#notes_select_session');
modalPop.resizeHeight(function() {
setTimeout(function() {
let notesSelect = $('#notes_select_session');
notesSelect.prop('selectedIndex', selectedOption);
notesSelect.css('opacity', 1);
}, 100);
});
},
error: function(returnObj, textStatus, errorThrown) {
if (returnObj.responseText) {
alert('Error loading notes');
notesSelect.css('opacity', 1);
}
}
});
}
function adminSessionNotesEdit(e, width='700') {
const sessionId = e.target.getAttribute('data-id');
modalPop = new bumbleBox('/?page_type=admin&action=session_notes_edit&session_id=' + sessionId, 'Edit notes', width + 'px', 'auto');
modalPop.show();
return false;
}
function adminNotesSave() {
const userId = $('#modal_user_id').val();
const notes = $('#modal_notes').val();
const ajaxData = new FormData();
ajaxData.append('action', 'notes_edit');
ajaxData.append('task', 'save');
ajaxData.append('user_id', userId);
ajaxData.append('notes', notes);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminSafeguardingNotesSave() {
const userId = $('#modal_user_id').val();
const notes = $('#modal_notes').val();
const ajaxData = new FormData();
ajaxData.append('action', 'safeguarding_notes_edit');
ajaxData.append('task', 'save');
ajaxData.append('user_id', userId);
ajaxData.append('notes', notes);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
scriptCharset: "utf-8",
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminAdminNotesSave(trigger) {
trigger.disabled = true;
trigger.style.opacity = '7';
let container = trigger.parentNode.parentNode;
container.style.opacity = '0.5';
const userId = $('#modal_user_id').val();
const notes = $('#modal_notes').val();
const ajaxData = new FormData();
ajaxData.append('action', 'admin_notes_edit');
ajaxData.append('task', 'save');
ajaxData.append('user_id', userId);
ajaxData.append('notes', notes);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
container.style.opacity = '1';
trigger.style.opacity = '1';
}
});
}
function adminCheckinNotesSave() {
const userId = $('#modal_user_id').val();
const notes = $('#modal_notes').val();
const ajaxData = new FormData();
ajaxData.append('action', 'checkin_notes');
ajaxData.append('task', 'save');
ajaxData.append('user_id', userId);
ajaxData.append('notes', notes);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
const item = $('#checkin_user_' + userId);
const container = item.parent();
if (container.hasClass('due') && confirm('Would you now like to archive this user?')) {
adminDoCheckIn(userId, function() {
const moveTo = $('.checkin-container.done');
moveTo.append(item);
item.find('.round-icon.icon-approve').removeClass('icon-approve').addClass('icon-restore').attr('title', 'Not checked in');
});
}
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminSessionNotesSave() {
const sessionId = $('#modal_session_id').val();
const notes = $('#modal_notes').val();
const ajaxData = new FormData();
ajaxData.append('action', 'session_notes_edit');
ajaxData.append('task', 'save');
ajaxData.append('session_id', sessionId);
ajaxData.append('notes', notes);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
scriptCharset: "utf-8",
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function inboxAdminMarkRead(userId) {
const ajaxData = new FormData();
ajaxData.append('action', 'inbox');
ajaxData.append('task', 'read');
ajaxData.append('user_id', userId);
const link = $('.inbox-row > a[data-id=' + userId + ']');
link.parent().removeClass('active');
link.find('span').css('display','none');
link.next().find('*').remove();
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
scriptCharset: "utf-8",
success: function(dataObj) {
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function inboxAdminMarkUnRead(userId) {
const ajaxData = new FormData();
ajaxData.append('action', 'inbox');
ajaxData.append('task', 'unread');
ajaxData.append('user_id', userId);
const link = $('.inbox-row > a[data-id=' + userId + ']');
link.parent().addClass('active');
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
scriptCharset: "utf-8",
success: function(dataObj) {
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminSessionEditVid(e) {
const sessId = e.target.getAttribute('data-event-data') ?
e.target.getAttribute('data-event-data') :
e.target.getAttribute('data-id');
console.log(sessId);
modalPop = new bumbleBox('/?page_type=admin&action=session_edit&session_id=' + sessId, 'Edit video link', '500px', 'auto');
modalPop.show();
return false;
}
function adminSessionEditSave(sessionId, callback=false) {
console.log(sessionId);
const ajaxData = new FormData();
const rebooking = $('#session_rebooking').val() == '1' ? '1' : '0';
ajaxData.append('action', 'sessions');
ajaxData.append('task', 'save_session');
if (rebooking != '1') {
ajaxData.append('session_id', sessionId);
}
ajaxData.append('user_id', $('#session_user_id').val());
ajaxData.append('child_id', $('#session_child_id').val());
ajaxData.append('slide_id', $('#session_slide_id').val());
ajaxData.append('rebooking', rebooking);
ajaxData.append('course_id', $('#session_slide_id > option:selected').attr('data-course-id'));
if ($('#session_week_id').length > 0) {
ajaxData.append('week_id', $('#session_week_id').val());
}
ajaxData.append('date', $('#session_date').val());
ajaxData.append('time', $('#timepicker').val());
ajaxData.append('type', $('#session_method').val());
ajaxData.append('call_url', $('#call_url').val());
ajaxData.append('coach', $('#session_coach').val());
let recurring = $('#session_recurring');
if (recurring.length > 0 && recurring[0].checked) {
ajaxData.append('recurring', 1);
}
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
modalPop.hide();
if (typeof callback === 'function') {
callback();
}
else location.reload();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
}
});
}
function adminToggleUserArchive(e) {
const tableRow = $(e.target).parent().parent();
const userId = e.target.getAttribute('data-id');
const reason = e.target.getAttribute('data-reason');
const colour = e.target.getAttribute('data-colour');
const ajaxData = new FormData();
tableRow.css('opacity', '0.5');
ajaxData.append('action', 'referrals');
ajaxData.append('task', 'toggle_archive');
if (reason) {
ajaxData.append('reason', reason);
}
ajaxData.append('user_id', userId);
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else if (colour && colour != '' && colour != 'undefined') {
if (colour == 'red') {
tableRow.removeClass('amber');
}
else if (colour == 'amber') {
tableRow.removeClass('red');
}
tableRow.toggleClass(colour);
}
else {
tableRow.remove();
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
tableRow.css('opacity', '1');
}
});
}
function adminBinAction(e) {
e.preventDefault();
const container = $(e.target).parent().parent();
const id = e.target.getAttribute('data-id');
const userId = e.target.getAttribute('data-user-id');
const cancelled = e.target.getAttribute('data-cancelled');
const action = e.target.getAttribute('data-action');
if (action == 'delete') {
if (!confirm('Are you sure you wish to delete this session?')) return;
}
if (action == 'restore') {
if (!confirm('Are you sure you wish to restore this session?')) return;
}
if (action == 'restoreAll') {
if (!confirm('Are you sure you wish to restore all sessions for this user?')) return;
}
if (action == 'restoreUser') {
if (!confirm('Are you sure you wish to restore this user profile?')) return;
}
if (action == 'deleteUser') {
if (!confirm('Are you sure you wish to delete this user?')) return;
}
container.css('opacity', '0.5');
const ajaxData = new FormData();
ajaxData.append('id', id);
ajaxData.append('user_id', userId);
ajaxData.append('cancelled', cancelled);
ajaxData.append('task', action);
ajaxData.append('action', 'bin');
$.ajax({
url: '/?page_type=admin',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else if (action != 'restoreAll') {
container.remove();
}
else {
$('.round-icon[data-user-id=' + userId + ']').each(function() {
$(this).parent().parent().remove();
});
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
container.css('opacity', '1');
}
});
}
function forumAction(e) {
const tableRow = $(e.target).parent().parent();
const status = tableRow.first('td').find('div');
const id = e.target.getAttribute('data-id');
const action = e.target.getAttribute('data-action');
if (action == 'delete-thread') {
if (!confirm('Are you sure you wish to delete this conversation?')) return;
}
const sticky = status.hasClass('sticky') ? 0 : 1;
const closed = status.hasClass('closed') ? 0 : 1;
tableRow.css('opacity', '0.5');
const ajaxData = new FormData();
ajaxData.append('id', id);
ajaxData.append('task', action);
ajaxData.append('sticky', sticky);
ajaxData.append('closed', closed);
$.ajax({
url: '/?page_type=forum',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
switch(action) {
case "sticky":
status.toggleClass('sticky');
break;
case "lock":
status.toggleClass('closed');
break;
case "delete-thread":
tableRow.remove();
break;
}
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
tableRow.css('opacity', '1');
}
});
}
function forumToggleRemove(e, postId) {
const container = $(e.target).parent();
const msg = container.find('.forum-post-reply-text');
container.css('opacity', '0.5');
const ajaxData = new FormData();
ajaxData.append('id', postId);
ajaxData.append('task', 'toggle-remove-post');
$.ajax({
url: '/?page_type=forum',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
$(e.target).html(dataObj.linkText);
msg.html(dataObj.message);
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
container.css('opacity', '1');
}
});
}
function adminSwitchUser(uid) {
document.location.href='/?action=sitelogin&uid=' + uid;
return false;
}
function analyticsChangeFilters() {
const select1 = $('#analytics-organisation');
const select2 = $('#analytics-course');
const select3 = $('#analytics-ccg');
const org = select1.val() || '';
const course = select2.val() || '';
const ccg = select3.val() || '';
let qs = 'organisation=' + org;
qs += '&course_type=' + course;
qs += '&ccg_area=' + ccg;
qs += $('#analytics-qs')?.val();
document.location.href = '/admin/analytics/?' + qs;
return false;
}
function analyticsDownload() {
const select = $('#analytics-organisation');
const org = select.val();
const qs = 'organisation=' + org + $('#analytics-qs').val();
document.location.href = '/?page_type=analytics&' + qs;
return false;
}
function forumReportPost(e, postId) {
if (confirm('Do you wish to report this post to our moderators?')) {
const container = $(e.target).parent();
const msg = container.find('.forum-post-reply-text');
container.css('opacity', '0.5');
const ajaxData = new FormData();
ajaxData.append('id', postId);
ajaxData.append('task', 'report-post');
$.ajax({
url: '/?page_type=forum',
type: 'post',
data: ajaxData,
dataType: 'json',
cache: false,
contentType: false,
processData: false,
success: function(dataObj) {
if (dataObj.error && dataObj.error != '') {
alert(dataObj.error);
}
else {
$(e.target).replaceWith('' + dataObj.linkText + '
');
}
},
error: function(returnObj, textStatus, errorThrown) {
alert(returnObj.responseText);
},
complete: function() {
container.css('opacity', '1');
}
});
}
}
function adminCalendarCreate(bookingData) {
const calendarObj = document.getElementById('admin_bookings_calendar');
calendarObj.bumbleCalendar = new bumbleCalendar('admin_bookings_calendar','','','',false,'',true,false,'');
adminCalendarPopulate(bookingData);
}
function adminCalendarPopulate(bookingData) {
const calendarObj = document.getElementById('admin_bookings_calendar');
const calendar = calendarObj.bumbleCalendar;
calendar.clearEvents(true);
const calData = JSON.parse(bookingData);
num = calData.length;
for (var x=0; x < num; x++) {
let thisDate = calData[x].date.replace(/\D/g,'');
let lastDate = calData[x].last;
let thisStr = calData[x].time;
if (calData[x].name && calData[x].name != '' && calData[x].name != ' ' && calData[x].name != 'null') {
thisStr += '
' + calData[x].name;
if (calData[x].title && calData[x].title != '' && calData[x].title != ' ' && calData[x].title != 'null') {
thisStr += ' - ' + calData[x].title;
}
thisStr += '';
}
if (lastDate) {
thisStr += 'Last session: ';
thisStr += lastDate;
thisStr += '
';
}
if (calData[x].coach && calData[x].coach != '' && calData[x].coach != ' ' && calData[x].coach != 'null') {
thisStr += 'Coach: ' + calData[x].coach + '
';
}
let thisClass = calData[x].status.toLowerCase();
calendar.addEvent(thisDate, thisDate, thisStr, calData[x].session_id, thisClass, '', adminSessionEdit, '', false, calData[x].colour);
}
calendar.populateMonthSelect();
calendar.populateDays(1);
}
function adminBookingsCalendarUserChange(userSelect) {
const userId = userSelect.value;
userSelect.style.opacity = '0.5';
$('#admin_bookings_calendar').css('opacity', '0.5');
$.ajax({
url: '/?page_type=admin&action=calendar&uid=' + userId,
type: 'POST',
cache: false,
processData: false,
contentType: false,
complete: function() {
userSelect.style.opacity = '1';
$('#admin_bookings_calendar').css('opacity', '1');
},
success: function(data) {
adminCalendarPopulate(data);
},
error: function(obj,errorStr) {
alert('There was a problem updating the calendar');
console.log(errorStr);
}
});
}
var popQuestionsScore = 0;
function questionsWizard() {
$('.question_wizard > a').click(function() {
let thisAnswer = $(this).text();
let slide = $('.question_wizard_slide.active');
let slideKey = slide.attr('data-key');
let answers = $('#questions_wizard_answers');
answers.val(answers.val() + slideKey + '=' + thisAnswer + '&');
if (thisAnswer == 'Yes') {
popQuestionsScore++;
}
slide.removeClass('active');
if (slideKey < 4) {
slide.next('div').addClass('active');
}
else {
$.ajax({url: "/?page_type=questions_response&" + answers.val()});
window.setTimeout(function() {
/*
if (popQuestionsScore >= 3) {
window.location.href = '/shop/courses/6-steps-to-resilience/';
}
else {
window.location.href = '/holistic-therapies/';
}
*/
window.location.href = '/thanks/';
}, 500);
modalPop.hide();
}
});
}
function homeLogin() {
let modal = new bumbleBox('/?page_type=modal_login', 'My NOW', '500px', '400px');
modal.show();
return false;
}
function homeSignup() {
let modal = new bumbleBox('/?page_type=modal_signup', 'Let\'s get started', '500px', '550px', '','','','','','','alt');
modal.show();
return false;
}
function contentModal(pageName, title) {
let modal = new bumbleBox('/?page_type=modal_content&page=' + pageName, title, '600px', 'auto', '','','','','','','alt');
modal.show();
return false;
}
function modalVideo(contentId) {
let modal = new bumbleBox('/?page_type=modal_video&id=' + contentId, '', '100%', 'auto');
modal.show();
return false;
}
function modalIframe(src='',title='') {
if (src != '') {
let modal = new bumbleBox('', title, '100%', '90%', 'text');
const content = '