function removeLoadStatus(elemId){
document.getElementById(elemId).classList.remove('btnLoading');
}
function chkBoxToggle(elem){
if(elem.checked == true){
elem.value = 'on';
} else {
elem.value = 'off';
}
}
function addLinkNotif(){
changeCSS(document.getElementById('adminLinkNotif'), 'hidden', 'add');
}
function btnLoad(clsList){
if(clsList.contains('btnLoading') == true){
setTimeout(function(){ clsList.remove('btnLoading'); }, 250, clsList);
} else {
clsList.add('btnLoading');
}
}
function prepForNurse(params, callbackId, url, action, target, srcElemId){
//console.log('params' + ' : ' + params);
//console.log('callbackId' + ' : ' + callbackId);
//console.log('url' + ' : ' + url);
//console.log('action' + ' : ' + action);
//console.log('target' + ' : ' + target);
//console.log('srcElemId' + ' : ' + srcElemId);
if (url == '') { //url is optional
var url = 'inv/jarvisPFCortex.php';
}
if (typeof target === 'undefined') { //target is optional
var target = '';
}
if (typeof srcElemId === 'undefined') { //srcElemId is optional, but useful if you want something else to be the source element - like an element in a div inherits the onclick, but you want the container div to be the source element
if (typeof event !== 'undefined') {
if(typeof event.target.id !== 'undefined'){
if(event.target.id == ''){
alert('need to set an ID on the element that called the event');
var srcElem = '';
} else {
var srcElemId = event.target.id;
}
}
}
}
if (typeof action === 'undefined') {
action = '';
} else if(action == 'btnSubmit'){
var srcElem = document.getElementById(srcElemId);
if(srcElem.nodeName == 'BUTTON'){
changeCSS(srcElem, 'btnLoading', 'add');
} else {
alert('didn\'t pass a button ID');
}
}
//---------------------constructor----------------------
var obj = {};
obj.url = url; //defaults to inv/jarvisPFCortex.php.
obj.params = params; //alla värden
obj.srcId = srcElemId; //vad som skickade det
obj.targetId = target; //vart innehållet ska hamna
obj.callbackId = callbackId; //vad transaktionen ska heta
obj.action = action; //action name
obj.params = 'callbackId=' + callbackId + '&' + obj.params;
if(obj.action != ''){
obj.params = obj.params + '&action=' + obj.action;
}
sendToSOM(obj);
}
function sendToSOM(obj){
//console.log(obj);
if (window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
} else {
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}
console.log(obj.url);
xmlHttp.open('POST', obj.url, true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200){
// console.log('url: ' + obj.url + ' state: ' + xmlHttp.readyState + ' status: ' + xmlHttp.status);
if(obj.action == 'feedback'){
obj.msg = xmlHttp.responseText;
jarvix.responseOBJ = obj;
jarvix.bgTasks.status = 'processing';
prepForJarvis('&name='+obj.callbackId, 'doorman', '', 'doorman');
} else if(obj.action == 'doorman'){
jarvix.bgTasks.status = 'finalizing';
} else {
loadSuccess(obj.callbackId, obj.action, xmlHttp.responseText, obj.srcId, obj.targetId);
}
} else if (xmlHttp.status == 403) {
onlyChangeClassIfTrue(document.getElementById('reLoginModal').classList, 'hiddenModal', true);
} else if (xmlHttp.status == 500) {
alert('something didn\'t go as planned');
}
}
}
xmlHttp.send(obj.params);
}
function sendSingleFile(fileElemId, savePath, userId, callbackId, url, target, params){
var formData = new FormData();
formData.append('file', document.getElementById(fileElemId).files[0]);
formData.append('savePath', savePath);
formData.append('userId', userId);
formData.append('callbackId', callbackId);
console.log(params);
for(var i = 0; i < params.length; i++){
formData.append('param'+i, params[i]);
}
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.onreadystatechange = function() {
if(xhr.readyState == 4) {
if(xhr.status == 200){
loadSuccess(callbackId, 'fileUpload', xhr.responseText, '', target);
} else if (xhr.status == 403) {
onlyChangeClassIfTrue(document.getElementById('reLoginModal').classList, 'hiddenModal', true);
} else if (xhr.status == 500) {
alert('something didnt go as planned');
}
}
}
xhr.send(formData);
}
function loadSuccess(callbackId, action, msg, srcId, targetId){
//----------------------checking data--------------------
//----------------------limit to section specific--------------------
console.log('callbackId: '+ callbackId);
console.log('action: '+ action);
console.log('msg: '+ msg);
console.log('from: '+ srcId);
console.log('target: '+ targetId);
var targetElem = document.getElementById(targetId);
if(targetId != ''){
targetElem.innerHTML = msg;
}
if(callbackId == 'addChatFiles'){
if(msg != 'error'){
document.getElementById('customModal').innerHTML = msg;
}
}
if(callbackId == 'editZeDoc'){
if(msg != 'error'){
document.getElementById('customModal').innerHTML = '';
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add');
document.getElementById('fileContainer').innerHTML = msg;
}
}
if(callbackId == 'UploadProfile' || callbackId == 'UploadMentorProfile'){
if(msg != ''){
document.getElementById('profileImg').style.backgroundImage = 'url('+msg+')';
document.getElementById('pressoImgBig').style.backgroundImage = 'url('+msg+')';
}
}
if(callbackId == 'chkEmailQueue'){
if(msg != 'too recent'){
document.getElementById('emailQueue').innerHTML = msg;
}
}
if(callbackId == 'sendAsSom'){
setTimeout(function() { removeLoadStatus('sendEmailButton'); }, 500);
if(msg != 'too recent'){
document.getElementById('emailQueue').innerHTML = msg;
}
}
if(callbackId == 'saveProfile'){
if(msg == 'complete'){
document.getElementById('incompletePresso').style.display = 'none';
document.getElementById('chatto').style.display = '';
}
}
if(callbackId == 'saveMentorProfile'){
if(msg == 'complete'){
document.getElementById('incompletePresso').style.display = 'none';
document.getElementById('fankoo').style.display = '';
}
}
if(callbackId == 'register'){
if(msg == 'Invalid email format' || msg == 'email allready registered'){
alert(msg);
} else {
if(msg == 'ok1'){
window.location.href = 'mentee.php';
}
if(msg == 'ok2'){
window.location.href = 'mentor.php';
}
}
}
if(callbackId == 'rememberPassw'){
document.getElementById('customModal').innerHTML = msg;
}
if(callbackId == 'prepLogin'){
if(msg != 'error'){
document.getElementById('customModal').innerHTML = msg;
}
}
if(callbackId == 'getChatMsg'){
if(msg != ''){
var obj = JSON.parse(msg);
if(obj[1] != 'noNew'){
if(obj[1] != 'noMessages'){
console.log(document.getElementById('orgNotesDiv').innerHTML);
if(document.getElementById('orgNotesDiv').innerHTML == 'To start chatting, please write your message in the text box below'){
document.getElementById('orgNotesDiv').innerHTML ='';
}
var txt = '';
for(var i = 0; i < obj[1].length; i++){
txt = txt + obj[1][i];
}
document.getElementById('orgNotesDiv').innerHTML = document.getElementById('orgNotesDiv').innerHTML + txt;
document.getElementById('orgNotesDiv').scrollTop = document.getElementById('orgNotesDiv').scrollHeight;
document.getElementById('postsCount').value = obj[0];
console.log(obj);
var sharedCollection = document.getElementsByClassName('sharedFilesFromChat');
var sharedFilesHTML = '';
for(var i = 0; i < sharedCollection.length; i++){
sharedFilesHTML = sharedFilesHTML + '';
}
document.getElementById('fileSharLib').innerHTML = sharedFilesHTML;
updateFilesAndLinks();
}
}
}
}
if(callbackId == 'selectMentor'){
if(msg != 'error'){
window.location.href = 'mentee.php';
}
}
if(callbackId == 'editFile'){
document.getElementById('customModal').innerHTML = msg;
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove')
}
if(callbackId == 'UploadDocument'){
document.getElementById(targetId).innerHTML = msg;
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add');
changeCSS(document.getElementById('adminLinkNotif'), 'hidden', 'remove');
setTimeout(function() { addLinkNotif(); }, 3000);
}
if(callbackId == 'delFile'){
document.getElementById('fileContainer').innerHTML = msg;
}
if(callbackId == 'approveFile'){
document.getElementById('fileContainer').innerHTML = msg;
}
if(callbackId == 'newMentee'){
document.getElementById('chatScreen').style.display = 'none';
document.getElementById('fankoo').style.display = 'none';
document.getElementById('newMenteeScreen').innerHTML = msg;
document.getElementById('newMenteeScreen').style.display = 'initial';
}
if(callbackId == 'acceptMentee'){
document.getElementById('scriptHoler').innerHTML = msg;
prepForNurse('&pid=' + document.getElementById('hiddenMenteeThatYouSelected').value, 'acceptMenteeNi', 'inv/cortex.php');
}
if(callbackId == 'acceptMenteeNi'){
document.getElementById('chatScreen').style.display = 'initial';
document.getElementById('newMenteeScreen').style.display = 'none';
document.getElementById('leftMentorMenuCortex').innerHTML = msg;
document.getElementById('menteeListDiv').innerHTML = document.getElementById('scriptHoler').innerHTML;
document.getElementById('scriptHoler').innerHTML = '';
}
if(callbackId == 'selMentee' || callbackId == 'adminChat'){
document.getElementById('postsCount').value = 0;
document.getElementById('orgNotesDiv').innerHTML = '';
document.getElementById('leftMentorMenuCortex').innerHTML = msg;
sendChatMsg();
// updateFilesAndLinks();
}
if(callbackId == 'screenMentors'){
document.getElementById('customModal').innerHTML = msg;
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove');
}
if(callbackId == 'fancyDisplay'){
document.getElementById('customModal').innerHTML = msg;
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove');
}
if(callbackId == 'addselectOption'){
var optField = srcId.substr(0, 6)+'Name'+srcId.substr(6);
document.getElementById(optField).value = '';
toggleCSS(document.getElementById(srcId), 'hidden');
}
if(callbackId == 'downFile'){
document.getElementById('downfile').src = msg;
}
if(callbackId == 'saveAvailability'){
var data = JSON.parse(msg);
console.log(data.length);
var calCol = document.getElementsByClassName('calDay');
for(var i = 0; i < calCol.length; i++){
var addBlock = 'yes';
for(var j = 0; j < data.length; j++){
if(calCol[i].id == data[j]){
var addBlock = 'no';
}
}
// if(calCol[i].classList.contains('calDayBlocked') == false && addBlock == 'yes'){
// calCol[i].classList.add('calDayBlocked');
// }
}
onlyChangeClassIfTrue(document.getElementById('customModal').classList, 'hiddenModal', false);
}
if(action == 'modalDone' || callbackId == 'deleteLink'){
document.getElementById('customModal').innerHTML = '';
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add');
document.getElementById('linkContainerContent').innerHTML = msg;
}
if(callbackId == 'AddLink'){
document.getElementById('linkContainerContent').innerHTML = msg;
changeCSS(document.getElementById('adminLinkNotif'), 'hidden', 'remove');
setTimeout(function() { addLinkNotif(); }, 3000);
}
if(callbackId == 'approveLink'){
document.getElementById('linkContainerContent').innerHTML = msg;
}
if(callbackId == 'toggleBlockCal' && msg != ''){
if(msg != ''){
document.getElementById('customModal').innerHTML = msg;
}
}
if(action == 'refreshAddon'){
document.getElementById('customModal').innerHTML = msg;
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove');
}
if(callbackId == 'pwrem'){
if(msg == 'not found'){
document.getElementById('errorNote').style.display = 'block';
} else if(msg = 'Message has been sent'){
prepForNurse('&email=' + document.getElementById('emailremind').value, 'cngPwConfirm', 'inv/login.php');
}
}
if(callbackId == 'pwconf'){
if(msg == 'not found'){
document.getElementById('errorNote').style.display = 'block';
} else {
document.getElementById('customModal').innerHTML = msg;
}
}
if(callbackId == 'emailUpdate'){
document.getElementById('customModal').innerHTML = '';
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'add');
document.getElementById('emailDiv').innerHTML = msg;
}
if(callbackId == 'approveMentor'){
document.getElementById('approvalDiv').innerHTML = msg;
}
if(callbackId == 'editEmail'){
document.getElementById('customModal').innerHTML = msg;
changeCSS(document.getElementById('customModal'), 'hiddenModal', 'remove');
}
if(callbackId == 'cngPwConfirm'){
if(msg == 'not found'){
document.getElementById('errorNote').style.display = 'block';
} else {
document.getElementById('customModal').innerHTML = msg;
}
}
if(action == 'pagination'){
var str = window.location.search;
const urlParams = new URLSearchParams(str);
if(urlParams.get('page') == null){
str = str + '?page=' + msg;
} else {
var repString = '&page=' + urlParams.get('page');
str = str.replace(repString, '&page=' + msg);
}
window.location.href = str;
}
if(action == 'playVideo'){
var data = JSON.parse(msg);
var src = decodeURIComponent(data.vidReqName);
var vidSource = document.getElementById('vidSrc');
var vidplayer = vidSource.parentElement;
var loopData = data.dbVidSettings;
for (var key in loopData) {
if (loopData.hasOwnProperty(key)) {
if(key.substr(0, 4) == 'opt_'){
var tarElem = document.getElementById(key);
if(tarElem.nodeName == 'INPUT'){
tarElem.value = loopData[key];
if(tarElem.type == 'checkbox'){
if(loopData[key] == 'on'){
tarElem.checked = true;
} else {
tarElem.checked = false;
}
}
}
if(tarElem.nodeName == 'SELECT'){
for(var i = 0; i < tarElem.length; i++){
tarElem.options[i].selected = false;
if(tarElem.options[i].value == loopData[key]){
tarElem.options[i].selected = true;
}
}
}
}
}
}
document.getElementById('vidName').innerHTML = src;
vidSource.setAttribute('src', data.vidReqFolder + data.vidReqId + '.mp4');
vidSource.setAttribute('type', 'video/mp4');
vidplayer.load();
vidplayer.play();
}
if(callbackId == 'logOut'){
window.location.replace('index.php');
}
if(callbackId == 'writeChatMsg'){
if(document.getElementById('postsCount').value == 0){
document.getElementById('orgNotesDiv').innerHTML = '';
}
console.log(msg.replaceAll(/<div>/g,'