var numAll = '' var numPhoto = '' var token = '' var userData var dataInstrument = [] var start = 0 var nextUrl = '' htmlText = '' var dataUri = [] function getStartPage(){ sesToken = sessionStorage.getItem('token'); if( sesToken === null){ token = localStorage.getItem("token") // console.log(token) // console.log('==================') if( token != null ){ $.ajax({ type: "POST", url: 'http://www.serv.stdb.most.go.th/api-token-verify/', data: { "token" : token }, header: { Authorization: 'Bearer '+ token, }, success: function(respone){ sessionStorage.setItem("token",respone.token) getStat(); }, dataType: 'json' }); } else{ window.location.href = 'index.html' } } else{ getStat(); } } function LogoutPage(){ localStorage.removeItem('token'); sessionStorage.removeItem('token'); window.location.href = 'index.html' } function getStat(){ token = sessionStorage.getItem("token") // console.log(token) // console.log('======== 2 ======') dataUser = jwt_decode(token) userId = dataUser.user_id if( token != null ){ $.ajax({ type: "GET", url: 'http://www.serv.stdb.most.go.th/api/v2/instrument/stats/', headers :{ Authorization: 'Bearer '+ token, }, success: getDataStat, dataType: 'json', }); } } function getUser(status){ token = sessionStorage.getItem("token") // console.log(token) // console.log('======== 2 ======') dataUser = jwt_decode(token) userId = dataUser.user_id.toString() $.ajax({ type: "GET", url: 'http://www.serv.stdb.most.go.th/api/v2/user/'+userId+'/', headers :{ Authorization: 'Bearer '+ token, }, success: function(respone){ // console.log(respone) userData = respone organ = '
'+respone.organizations[0].name+'
' document.getElementById("nameOrgan").innerHTML = organ token = sessionStorage.getItem("token") var searchText = '' if (status === 'search'){ console.log("search") dataInstrument = [] searchText = '&search='+document.getElementById("searchId").value start = 0 $('#modalAll').html(''); $('#card').html(""); htmlText = ''; modalText = ''; dataInstrument = []; console.log(' >> end of search button'); console.log(dataInstrument) console.log($('#card').html()); } var url = 'http://www.serv.stdb.most.go.th/api/v2/instrument/?organization='+respone.organizations[0].id+searchText; console.log('url = ' + url) $.ajax({ type: "GET", url: url, headers :{ Authorization: 'Bearer '+ token, Accept: 'application/json, text/javascript', 'Accept-Language' : 'en-US,en;q=0.8,th;q=0.6', }, success: getData, dataType: 'json', }); }, dataType: 'json', }); } function getDataStat(respone){ getUser('first'); // console.log(respone) document.getElementById("like").innerHTML = '0' document.getElementById("status").innerHTML = '+'+respone.items.recent_update document.getElementById("accountActive").innerHTML = respone.users.active document.getElementById("numAll").innerHTML = respone.items.all document.getElementById("numPhoto").innerHTML = respone.items.photos } function getData(respone) { // console.log(dataInstrument) // console.log(respone) // console.log(respone.results) console.log(dataInstrument) dataInstrument = dataInstrument.concat(respone.results) console.log('*******ฬฬฬฬฬฬฬฬฬ*********') console.log(respone.results) var htmlText = '' var modalText = '' for (i=start;i" +'

'+dataInstrument[i].name+'

' +'

#'+dataInstrument[i].custom_id+'

' +'

@'+dataInstrument[i].caretaker+'

' +''; if(dataInstrument[i].clips.length === 0){ imageTag = '
' +'
' +'
' +'' +'

ไม่มีรูปภาพ

' +'
' +'
' +'' +'
ไม่มีรูปภาพ
' +'' +'
ไม่มีรูปภาพ
' +'' +'
ไม่มีรูปภาพ
' +'
' +'
' +'
' +'
' +'
' +'Upload
' +'' +'
' } else{ if(dataInstrument[i].clips.length > 1){ var tagMiniImage = '' var loopImage = dataInstrument[i].clips.length var style4 = '' for(j=1;j' +'
'; } for(j=loopImage-1;j<3;j++){ if (j==3){ style4 = 'style="margin-top:5px"' } tagMiniImage = tagMiniImage +'' +'
ไม่มีรูปภาพ
'; } } else{ for(j=1;j<4;j++){ if (j==3){ style4 = 'style="margin-top:5px"' } tagMiniImage = tagMiniImage +'' +'
ไม่มีรูปภาพ
'; } } console.log(dataInstrument) imageTag = '
' +'
' +'
' +'' +'

' +'
' +'
' +tagMiniImage +'
' +'
' +'
' +'
' +'
' +'Upload
' +'' +'
' } modalText = modalText+''; } if(respone.next != null){ moreText = "
" +"

More

" +"
"; nextUrl = respone.next document.getElementById("more").innerHTML = moreText; } start = dataInstrument.length document.getElementById("modalAll").innerHTML = document.getElementById("modalAll").innerHTML+modalText document.getElementById("card").innerHTML = document.getElementById("card").innerHTML+htmlText } function getNextUrl(){ // console.log('==================') token = sessionStorage.getItem('token') $.ajax({ type: "GET", url: nextUrl, headers :{ Authorization: 'Bearer '+ token, Accept: 'application/json, text/javascript', 'Accept-Language' : 'en-US,en;q=0.8,th;q=0.6', }, success: getData, dataType: 'json', }); } function modalItem(idCard){ var modal = document.getElementById('modal'+idCard); // console.log(modal) var btn = document.getElementById(idCard); // console.log(btn) modal.style.display = "block"; window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; if(idCard != 'search'){ removeImage(idCard) } dataUri = [] } } } function uploadImage(idImage) { var check = 0 $(":file").change(function () { if (this.files && this.files[0] && check===0) { var reader = new FileReader(); console.log(reader) reader.onload = function(e) { instrument = dataInstrument[parseInt(idImage)] var uriAdd = [{'uri':e.target.result}]; dataUri = dataUri.concat(uriAdd); if(idImage == 'add'){ loopImage = 0 } else{ var loopImage = instrument.clips.length for(idImg=0;idImg