/***** Created by Terje Rudi, HVL, 2017 *****/ function domReady () { // JQUERY ready-alternative - det blir ingen feil dersom denne funksjonen gjentas document.body.className += " javascript"; //... } function isNotVal(val){ // brukes til sjekking om verdi har innhold og/eller er gyldig return (val==null || val===false); } // Mozilla, Opera, Webkit if ( document.addEventListener ) { document.addEventListener( "DOMContentLoaded", function(){ document.removeEventListener( "DOMContentLoaded", arguments.callee, false); domReady(); // <- kan brukes ute i html-doc }, false ); // If IE event model is used (Explorer 8...) } else if ( document.attachEvent ) { // ensure firing before onload document.attachEvent("onreadystatechange", function(){ if ( document.readyState === "complete" ) { document.detachEvent( "onreadystatechange", arguments.callee ); domReady(); // <- kan brukes ute i html-doc } }); } // AJAX var AJAXerrors = { "0":"Unknown Error", "100":"Continue", "101":"Switching Protocol", "103":"Processing (WebDAV)", "200":"OK", "201":"Created", "202":"Accepted", "203":"Non-Authoritative Information", "204":"No Content", "205":"Reset Content", "206":"Partial Content", "207":"Multi-Status (WebDAV)", "208":"Multi-Status (WebDAV)", "226":"IM Used (HTTP Delta encoding)", "300":"Multiple Choice", "301":"Moved Permanently", "302":"Found", "303":"See Other", "304":"Not Modified", "305":"Use Proxy ", "306":"unused", "307":"Temporary Redirect", "308":"Permanent Redirect", "400":"Bad Request", "401":"Unauthorized", "402":"Payment Required", "403":"Forbidden", "404":"Not Found", "405":"Method Not Allowed", "406":"Not Acceptable", "407":"Proxy Authentication Required", "408":"Request Timeout", "409":"Conflict", "410":"Gone", "411":"Length Required", "412":"Precondition Failed", "413":"Payload Too Large", "414":"URI Too Long", "415":"Unsupported Media Type", "416":"Requested Range Not Satisfiable", "417":"Expectation Failed", "418":"I'm a teapot", "421":"Misdirected Request", "422":"Unprocessable Entity (WebDAV)", "423":"Locked (WebDAV)", "424":"Failed Dependency (WebDAV)", "426":"Upgrade Required", "428":"Precondition Required", "429":"Too Many Requests", "431":"Request Header Fields Too Large", "451":"Unavailable For Legal Reasons", "500":"Internal Server Error", "501":"Not Implemented", "502":"Bad Gateway", "503":"Service Unavailable", "504":"Gateway Timeout", "505":"HTTP Version Not Supported", "506":"Variant Also Negotiates", "507":"Insufficient Storage", "508":"Loop Detected (WebDAV)", "510":"Not Extended", "511":"Network Authentication Required" } function makeRequest(url,callback,ref,callbackExstraArgsObj) { // AJAX-kall if (typeof callback != "undefined"){ var req = new XMLHttpRequest(); if (!req) { alert('Gir opp :( XMLHTTP instance not created -1'); return false; } req.onreadystatechange = function(){ try { if (req.readyState === XMLHttpRequest.DONE) { if (req.status !== 200) { try { console.log('En feil oppstod: ' + AJAXerrors[req.status] + ' (' + req.status + ')'); }catch (e){ console.log('Det var et problem med å hente data. Feilkode: ' + req.status); } }else{ try{ if (callbackExstraArgsObj && typeof callbackExstraArgsObj == "object"){ callback(req.responseText,callbackExstraArgsObj); }else{ callback(req.responseText); } }catch(e){ try { console.log('En feil oppstod [-1]: ' + e + ' (Melding: ' + AJAXerrors[req.status] + ' (sjekk callback))'); }catch (f){ console.log('Kunne ikke aktivere callback: ' + e + ' (Status: ' + req.status + ')'); } } } } }catch( e ) { console.log('Opplevde et unntak: ' + e.description); } }; req.open('GET', url); req.send(); }else{ console.log("Callback undefinert i 'makeRequest', referanse: " + ref); } } function postJson(url,json,callback,ref,callbackExstraArgsObj) { // Sendes som btoa (base64) // AJAX-kall if (typeof callback != "undefined"){ var req = new XMLHttpRequest(); if (!req) { alert('Gir opp :( XMLHTTP instance not created -2'); return false; } req.onreadystatechange = function(){ try { if (req.readyState === XMLHttpRequest.DONE) { if (req.status !== 200) { try { console.log('En feil oppstod: ' + AJAXerrors[req.status]); }catch (e){ console.log('Det var et problem med å hente data. Feilkode: ' + req.status); } }else{ try{ if (callbackExstraArgsObj && typeof callbackExstraArgsObj == "object"){ callback(req.responseText,callbackExstraArgsObj); }else{ callback(req.responseText); } }catch(e){ try { console.log('En feil oppstod [-2]: ' + e + ' (Melding: ' + AJAXerrors[req.status] + ', Callback = ' + JSON.stringify(callback) + ')'); }catch (f){ console.log('Kunne ikke aktivere callback: ' + e + ' (Status: ' + req.status + ')'); } } } } }catch( e ) { console.log('Opplevde et unntak: ' + e.description); } }; req.open("POST", url); var params = "btoajson=" + btoa(JSON.stringify(json)); //Send the proper header information along with the request req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //req.setRequestHeader("Content-length", params.length); //req.setRequestHeader("Connection", "close"); req.send(params); }else{ console.log("Callback undefinert i 'makeJSONpostRequest', referanse: " + ref); } } function addCSSRule(sheet, selector, rules, index) { return true; /* FASET UT try{ if("insertRule" in sheet) { sheet.insertRule(selector + "{" + rules + "}", index); }else if("addRule" in sheet) { sheet.addRule(selector, rules, index); } }catch(e){ console.log("FEIL ved innsetting av i stilark: " + e + ". Sheet = " + sheet + " Selector = " + selector + " Index = " + index); } */ } // SlideUp SlideDown SlideToggle /* Element to slide gets the following CSS: max-height: 0;opacity: 0;overflow: hidden;transition: max-height 0.4s ease 0s; */ function slideElemDown(elem) { elem.style.maxHeight = '1000px'; // We're using a timer to set opacity = 0 because setting max-height = 0 doesn't (completely) hide the element. elem.style.opacity = '1'; } function slideElemUp(elem) { elem.style.maxHeight = '0'; once( 1, function () { elem.style.opacity = '0'; }); } function slideElemToggle(elem){ if (elem.style.opacity == 1){ slideElemUp(elem); }else{ slideElemDown(elem); } } function once (seconds, callback) { var counter = 0; var time = window.setInterval( function () { counter++; if ( counter >= seconds ) { callback(); window.clearInterval( time ); } }, 400 ); } // Sliding ferdig /* UTFASET // direkte manipulering av stilark for HVL-Bouvet-stil try{ // Fjerne dobbel ned-pil i Explorer i rullegardinmeny: addCSSRule(document.styleSheets[0],'select::-ms-expand','display: none',0); // Sette inn spinner addCSSRule(document.styleSheets[0],'@-webkit-keyframes rwSpinnerRotate','{-webkit-transform:rotate(0deg);}to{-webkit-transform:rotate(360deg);}',document.styleSheets[0].cssRules.length); addCSSRule(document.styleSheets[0],'@-moz-keyframes rwSpinnerRotate','{-moz-transform:rotate(0deg);}to{-moz-transform:rotate(360deg);}',document.styleSheets[0].cssRules.length); addCSSRule(document.styleSheets[0],'@-ms-keyframes rwSpinnerRotate','{-ms-transform:rotate(0deg);}to{-ms-transform:rotate(360deg);}',document.styleSheets[0].cssRules.length); addCSSRule(document.styleSheets[0],'@keyframes rwSpinnerRotate','{transform:rotate(0deg);}to{transform:rotate(360deg);}',document.styleSheets[0].cssRules.length); addCSSRule(document.styleSheets[0],'.rwSpin','position:relative;top:0.3rem;left:0.3rem;padding: 0.2rem;color: #fff;width: 0.6rem;height: 0.6rem;background: #acb7b2;border-radius: 0.6rem;-webkit-animation-name: rwSpinnerRotate;-webkit-animation-duration: 0.8s;-webkit-animation-iteration-count: infinite;-webkit-animation-timing-function: linear;-moz-animation-name: rwSpinnerRotate;-moz-animation-duration: 0.8s;-moz-animation-iteration-count: infinite;-moz-animation-timing-function: linear;-ms-animation-name: rwSpinnerRotate;-ms-animation-duration: 0.8s;-ms-animation-iteration-count: infinite;-ms-animation-timing-function: linear;'); }catch(e){ console.log("addRule or insertRule not supported"); } */ /*** FASTE HJELPERE ***/ function swapLang(){ // Bytter ut all elementers tekst med verdi fra 'data-english' - oversetter rett ot slett, // men bare derson verdi i data-english eksisterer: // Eks: try{ var otherLangVals = document.querySelectorAll("[data-english]"); for (key in otherLangVals){ try{ var otherLangString = otherLangVals[key].getAttribute("data-english"); if (otherLangString != "undefined"){ var originalString = otherLangVals[key].innerHTML; otherLangVals[key].innerHTML = otherLangString; otherLangVals[key].setAttribute("data-english",originalString); } }catch(f){ console.log(f); } } }catch(e){ alert("Sorry, translation unavailable :-("); } } /*** FASTE HJELPERE SLUTT ***/ // EXTENSION applicationForms async function fetchFormsForAll(){ const currHost = 'v.hvl.no'; let formHTML = []; formHTML.push('
'); formHTML.push('
'); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push(' '); formHTML.push('
Opprett påmeldingsskjema her:
Kontaktperson si e-postadresse:
Tittelen på aktiviteten:
'); formHTML.push('
'); formHTML.push('
'); // Skrive ut skjema try{ document.getElementById('opprettepamelding').innerHTML = formHTML.join('\n'); }catch(e){ console.error('HVL: Leveringsstad for skjema er ikkje tilgjenge, eit DOM-element med ID opprettepamelding manglar: ' + e); } var currentUser = false; let headerProfileImg = document.querySelector('.header__profile').getElementsByTagName('img')[0]; let fullName = headerProfileImg.alt; let u = 'https://' + currHost + '/verktyg/tilsette/getADinfoByForAutoComplete.php?q=' + encodeURIComponent(fullName); try{ fetch(u) .then(response => response.json()) .then(data => { if (data.success == true && (typeof data.data == 'object')){ for(let user in data.data){ if(data.data[user].Navn == fullName){ currentUser = { userName : user, fullName : fullName, fullEmail : data.data[user].email, dep : data.data[user].Avdeling, camp : data.data[user].Campus }; //console.info('currentUser=' + JSON.stringify(currentUser,'',' ')); try{ document.getElementById('applicationFormEmail').value = data.data[user].email; }catch(e){ console.log('HVL: applicationFormEmail ikkje tilgengeleg ' + e); } } } }else{ console.log('HVL: Mottatt: ' + JSON.stringify(data)); } }) .catch(error => console.error(error)) }catch(e){ console.log('HVL: ingen profilinfo tilgjengelig: ' + e); } let spinnerHTML = function(id = 'spinnerId',color = '#acb7b2',size = '62px'){ let h = ['']; for (let r = 0;r < 10;r++){ h.push(''); h.push(''); } h.push(''); return h.join(''); }/* Lightweight accordeon by Terje Rudi, 2019 Example: After class, use javascript: let concertina = new Concertina([ document.getElementById('concertinaPanel') ]); Where array is array of elements containing elements of css class 'concertina'. Open concertinas has extra class 'open'. Remember to insert CSS from https://v.hvl.no/css/concertina.php.css OR use param $extension = "css" in parent script before requiring this */ // Insert CSS into page try{ let cCss = document.createElement('link'); cCss.rel = 'stylesheet'; cCss.href = 'https://v.hvl.no/css/concertina.php.css'; document.head.appendChild(cCss); }catch(e){ console.error('Could not insert Concertina CSS: ' + e); } let Concertina = function(elementArray){ console.info('Concertina activated with array: ' + elementArray); // Collect all concertina elements for later use this.concertinaCollection = []; // Class for handling css by opening and closing let CssClassHandler = function(el){ let hasClass = function (el, className) { return el.classList ? el.classList.contains(className) : new RegExp('\\b'+ className +'\\b').test(el.className); }; let addClass = function (el, className) { if (el.classList) el.classList.add(className); else if (!hasClass(el, className)) el.className += ' ' + className; }; let removeClass = function (el, className) { if (el.classList) el.classList.remove(className); else el.className = el.className.replace(new RegExp('\\b'+ className+'\\b', 'g'), ''); }; let headerItem = el.querySelector('*'); headerItem.setAttribute('data-before','\u25BC'); if (hasClass(el,'open')){ headerItem.setAttribute('data-before','\u25B2'); } if (headerItem.hasEvent !== true){ headerItem.hasEvent = true; headerItem.addEventListener('click',function(){ if (hasClass(headerItem.parentNode,'open')){ //console.info('close: ' + headerItem.innerHTML); let r = removeClass(headerItem.parentNode,'open'); headerItem.setAttribute('data-before','\u25BC'); }else{ //console.info('open: ' + headerItem.innerHTML); let a = addClass(headerItem.parentNode,'open'); headerItem.setAttribute('data-before','\u25B2'); } }); }; } // Go, find the elements with class concertina and append style and events for (let cParent = 0;cParent < elementArray.length;cParent++){ let waitForConcertinas = setInterval(function(){ let concertinas = elementArray[cParent].querySelectorAll('.concertina'); if (concertinas.length > 0){ clearInterval(waitForConcertinas); for (let c = 0; c < concertinas.length;c++){ let thisConcertina = concertinas[c]; thisConcertina.eventHandler = new CssClassHandler(thisConcertina); } if (this.concertinaCollection != undefined){ this.concertinaCollection.push(concertinas); } }; },1000); } // Adjust sub concertinas bottom space let targ = document.querySelectorAll('.concertina > .concertina:last-child'); targ.forEach(function(elm){ elm.parentNode.style.paddingBottom = '0'; }); } let regFormList = document.createElement('div'); regFormList.id = 'regFormList'; regFormList.innerHTML = spinnerHTML(); document.getElementById('regRegForm').appendChild(regFormList); function listRegFormsItems(items,email = 'noMailAvailable'){ html = []; for (let i = 0;i < items.length;i++){ html.push('
  • '); // Did not work: html.push(``); html.push('' + items[i].Title + ''); html.push(''); html.push('Frist: ' + items[i].Expires); //if (items[i].Owner != email){ let check = new RegExp(email,"i"); if (!check.test(items[i].Owner)){ html.push('. Skjema-eigar: ' + items[i].Owner); } html.push(''); html.push('
  • '); } return ''; } setTimeout(function(){ if (currentUser !== false){ console.info('currentUser = ' + JSON.stringify(currentUser)); let u = 'https://' + currHost + '/pameldingssystem/listRegFormsByContact.php?user=' + encodeURIComponent(btoa(JSON.stringify(currentUser))); //console.log('HVL: ' + JSON.stringify(currentUser)); fetch(u) .then(response => response.json()) .then(data => { //console.log(JSON.stringify(data,'','\t')); if (data.success == true && (typeof data.data == 'object')){ let html = []; html.push('
    '); if (data.data.selfowned.length > 0){ html.push('
    '); html.push('

    Administrasjon av ' + currentUser.fullName + ' sine påmeldingsskjema (' + data.data.selfowned.length + ')

    '); html.push('

    Klikk på aktivitet for å redigera og administrera skjema:

    '); html.push(listRegFormsItems(data.data.selfowned,currentUser)); html.push('
    '); }else{ html.push('

    ' + currentUser.fullName + ' har ingen eigne påmeldingsskjema å administrera.

    '); } if (data.data.others.length > 0){ // Se pameldingssystem/listRegFormsByContact.php for innsnevring avdelingsvis! const adminList = ['TERJE.RUDI@HVL.NO','LARS.SMITH@HVL.NO','INGVILD.RORTVEIT.MYKLEBUST@HVL.NO','MORTEN.DAHLE@HVL.NO','TORA.MYKLEBUST.OPTUN@HVL.NO']; if (adminList.indexOf(currentUser.fullEmail.toUpperCase()) != -1){ html.push('

    ' + currentUser.fullName + ' kan òg ved høve bistå med å redigera andre sine påmeldingsskjema:

    '); html.push('
    '); html.push('

    Administrasjon av andre sine påmeldingsskjema (' + data.data.others.length + ')

    '); html.push('

    ' + currentUser.fullName + ' kan òg administrera andre sine skjema:

    '); html.push(listRegFormsItems(data.data.others)); html.push('
    '); }/*else{ console.info('currentUser = ' + JSON.stringify(currentUser,'',' ')); }*/ } html.push('
    '); regFormList.innerHTML = html.join('\n'); let concertina = new Concertina([ document.getElementById('regFormList') ]); }else{ console.error('HVL: Feil: ' + data.errormsg); regFormList.innerHTML = ''; } }) .catch(error => console.error(error)) }else{ //console.info('C'); regFormList.innerHTML = ''; } },300); } fetchFormsForAll(); async function setAppIcon(){ try{ let l = document.createElement('link'); l.rel = 'apple-touch-icon'; l.href = 'https://v.hvl.no/grafikk/ikoner/ORG-appikon-hengelaas.png' document.head.appendChild(l); }catch(e){ console.error('Kunne ikke sette app-ikon: ' + e); } } setAppIcon();