diff options
Diffstat (limited to 'dist/js/gsec.js')
-rw-r--r-- | dist/js/gsec.js | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/dist/js/gsec.js b/dist/js/gsec.js index 7925d00..36d49a5 100644 --- a/dist/js/gsec.js +++ b/dist/js/gsec.js @@ -4,7 +4,7 @@ function stripHtml(html){var tmp=document.createElement("DIV");tmp.innerHTML=htm function slDayToInt(inputString){let fourChars=inputString.substring(1,5);let fourCharDays=["oned","orek","reda","etrt","etek","obot","edel"];return fourCharDays.indexOf(fourChars);} const GSE_URL="https://zgimsis.gimb.tk/gse/";const GSEC_ERR_NET="GSEC NETWORK ERROR (ajax error)";const GSEC_ERR_NET_POSTBACK_GET="GSEC NETWORK ERROR (ajax error) in postback GET" const GSEC_ERR_NET_POSTBACK_POST="GSEC NETWORK ERROR (ajax error) in postback POST" -const GSEC_MSGTYPE_RECEIVED=0;const GSEC_MSGTYPE_SENT=1;const GSEC_MSGTYPE_DELETED=2;const GSEC_ERR_LOGIN="GSEC LOGIN ERROR";const GSEC_NO_ABSENCES="noAbsences";const GSEC_MSGTYPES=["msgReceived","msgSent","msgDeleted"];class gsec{constructor(){} +const GSEC_MSGTYPE_RECEIVED=0;const GSEC_MSGTYPE_SENT=1;const GSEC_MSGTYPE_DELETED=2;const GSEC_ERR_LOGIN="GSEC LOGIN ERROR";const GSEC_NO_ABSENCES="noAbsences";const GSEC_MSGTYPES=["msgReceived","msgSent","msgDeleted"];const GSEC_NORMAL_GRADE="GSEC NORMAL GRADE";const GSEC_ZAKLJUCNA_GRADE="GSEC ZAKLJUCNA GRADE";class gsec{constructor(){} parseAndPost(inputHTML,params,formId=null,useDiffAction=null){return new Promise((resolve,reject)=>{let parser=new DOMParser();let parsed=parser.parseFromString(inputHTML,"text/html");var form;if(formId==null){form=parsed.getElementsByTagName("form")[0];}else{form=parsed.getElementById(formId);} var otherParams=$(form).serializeArray();for(const input of otherParams){if(!(input.name in params)){params[input.name]=input.value;}} var action;if(useDiffAction==null||useDiffAction==false){action=new URL($(form).attr("action"),GSE_URL);}else{action=useDiffAction;} @@ -32,12 +32,13 @@ var dataToBeSent={"ctl00$ContentPlaceHolder1$edtDatZacetka":`${fromDate.getDay() var absences=[];for(const izostanek of rowElements){var subFields=izostanek.getElementsByTagName("td");var date=subFields[0].innerHTML.trim().split(".");var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]}`));var subjects=[];subFields[2].innerHTML.match(SUBJECT_LIST_REGEX).forEach((subject)=>{subjects.push(subject);});var absencesBySubject={};for(const subject of subjects){const matched_info=FIELDS_REGEX.exec(subject);var subjectName=matched_info[1];var status=Number(matched_info[2]);var period=matched_info[3];period=period.includes("P")?Number(period.replace("P",""))+7:Number(period);absencesBySubject[period]={status:status,subject:subjectName};} absences.push({subjects:absencesBySubject,date:dateObj});} resolve(absences);});});} -fetchGrades(){var grades=[];return new Promise((resolve,reject)=>{$.ajax({xhrFields:{withCredentials:true},crossDomain:true,url:GSE_URL+"Page_Gim/Ucenec/OceneUcenec.aspx",cache:false,type:"GET",dataType:"html",processData:false,success:(data)=>{let parser=new DOMParser();let parsed=parser.parseFromString(data,"text/html");let gradeSpans=parsed.getElementsByClassName("txtVOcObd");for(const grade of gradeSpans){var ist=grade.getElementsByTagName("span")[0].getAttribute("title").split("\n");var date=ist[0].split(": ")[1].trim().split(".");var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]}`));var teacher=ist[1].split(": ")[1].trim();var subject=ist[2].split(": ")[1].trim();var name=[];name.push(ist[3].split(": ")[1].trim()) +fetchGrades(){var grades=[];return new Promise((resolve,reject)=>{$.ajax({xhrFields:{withCredentials:true},crossDomain:true,url:GSE_URL+"Page_Gim/Ucenec/OceneUcenec.aspx",cache:false,type:"GET",dataType:"html",processData:false,success:(data)=>{let parser=new DOMParser();let parsed=parser.parseFromString(data,"text/html");let gradeSpans=parsed.getElementsByClassName("txtVOcObd");for(const grade of gradeSpans){var ist=grade.getElementsByTagName("span")[0].getAttribute("title").split("\n");if(ist.length==1){var gradeToAdd={"gradeType":GSEC_ZAKLJUCNA_GRADE,"grade":Number(grade.getElementsByTagName("span")[0].innerHTML),"subject":grade.parentElement.parentElement.parentElement.parentElement.getElementsByTagName("th")[0].innerText} +grades.push(gradeToAdd);}else{var date=ist[0].split(": ")[1].trim().split(".");var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]}`));var teacher=ist[1].split(": ")[1].trim();var subject=ist[2].split(": ")[1].trim();var name=[];name.push(ist[3].split(": ")[1].trim()) name.push(ist[4].split(": ")[1].trim()) name.push(ist[5].split(": ")[1].trim()) -var gradeNumber=Number(grade.getElementsByTagName("span")[0].innerHTML);var temporary=grade.getElementsByTagName("span")[0].classList.contains("ocVmesna");var gradeToAdd={"date":dateObj,"teacher":teacher,"subject":subject,"name":name,"temporary":temporary,"grade":gradeNumber};if(grade.getElementsByTagName("span").length>1){if(grade.getElementsByTagName("span")[1].classList.contains("ocVmesna")){gradeToAdd["temporary"]=true;}else{gradeToAdd["temporary"]=false;} +var gradeNumber=Number(grade.getElementsByTagName("span")[0].innerHTML);var temporary=grade.getElementsByTagName("span")[0].classList.contains("ocVmesna");var gradeToAdd={"gradeType":GSEC_NORMAL_GRADE,"date":dateObj,"teacher":teacher,"subject":subject,"name":name,"temporary":temporary,"grade":gradeNumber};if(grade.getElementsByTagName("span").length>1){if(grade.getElementsByTagName("span")[1].classList.contains("ocVmesna")){gradeToAdd["temporary"]=true;}else{gradeToAdd["temporary"]=false;} gradeToAdd["grade"]=Number(grade.getElementsByTagName("span")[1].innerHTML);gradeToAdd["oldgrade"]=Number(grade.getElementsByTagName("span")[0].innerHTML);} -grades.push(gradeToAdd);} +grades.push(gradeToAdd);}} resolve(grades);},error:()=>{reject(new Error(GSEC_ERR_NET));}});});} fetchMessageOld(selectId){const TIME_REGEX=/ \(.+ (.+?)\)/;const DATE_REGEX=/ \(.+? /;const SENDER_REGEX=/^(.+?) \(/;var message;return new Promise((resolve)=>{var dataToBeSent={"__EVENTTARGET":"ctl00$ContentPlaceHolder1$gvwSporocila","__EVENTARGUMENT":"Select$"+selectId};this.postback(GSE_URL+"Page_Gim/Uporabnik/Sporocila.aspx",dataToBeSent,null,true).then((response)=>{let parser=new DOMParser();let parsed=parser.parseFromString(response.data,"text/html");let subject=parsed.getElementsByClassName("msgSubjectS")[0].innerHTML.trim();let body=parsed.getElementsByClassName("gCursorAuto")[0].innerHTML.trim();let sender=SENDER_REGEX.exec(parsed.querySelectorAll("[id$=Label7]")[0].innerHTML)[1];let recipient=parsed.querySelectorAll("[id$=Label8]")[0].innerHTML;var date=DATE_REGEX.exec(parsed.querySelectorAll("[id$=Label7]")[0].innerHTML)[1];var tume=TIME_REGEX.exec(parsed.querySelectorAll("[id$=Label7]")[0].innerHTML)[1];var dateObj=new Date(Date.parse(`${date[2]}-${date[1]}-${date[0]} ${tume}`));var msgId=parsed.getElementById("ctl00_ContentPlaceHolder1_hfIdSporocilo").getAttribute("value");message={"subject":subject,"body":body,"sender":sender,"recipient":recipient,"date":dateObj,"msgId":msgId};resolve(message);});});} fetchMessagesLastPageNumber(category=GSEC_MSGTYPE_RECEIVED){var msgCategory=GSEC_MSGTYPES[category];return new Promise((resolve)=>{var dataToBeSent={"ctl00$ContentPlaceHolder1$ddlPrikaz":msgCategory,"__EVENTARGUMENT":"Page$Last","__EVENTTARGET":"ctl00$ContentPlaceHolder1$gvwSporocila"};this.postback(GSE_URL+"Page_Gim/Uporabnik/Sporocila.aspx",dataToBeSent,null,true).then((response)=>{let parser=new DOMParser();let parsed=parser.parseFromString(response.data,"text/html");let currentPage;if(parsed.getElementsByClassName("pager").length==0){currentPage=1;}else{currentPage=Number(parsed.getElementsByClassName("pager")[0].getElementsByTagName("span")[0].innerHTML);} |