The given code is written in Google Apps Script. It has three functions, namely doGet()
, include(filename)
, and sub(vl)
.
The doGet()
function returns an HTML template created from the 'index' file. It sets the title of the template to 'SGS-L Tracker' and adds a meta tag to set the viewport to the width of the device and initial scale to 1. It also allows all websites to frame the template.
The include(filename)
function returns the content of an HTML file.
The sub(vl)
function takes a parameter vl
and uses it to search for a value in the first column of the 'Sheet1' sheet of the active spreadsheet. It creates a table with the values in the matching row and returns the HTML code for that table.
function doGet(){ return HtmlService.createTemplateFromFile('index').evaluate() .setTitle('SGS-L Tracker') .addMetaTag('viewport', 'width=device-width , initial-scale=1') .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) } var dt = Utilities.formatDate(new Date(),Intl.DateTimeFormat().resolvedOptions().timeZone, 'yyyy-MM-dd HH:mm:ss'); function include(filename) { return HtmlService.createHtmlOutputFromFile(filename).getContent(); } function sub(vl){ var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); var dl = ws.getDataRange().getValues(); var tb = ''; for(var i=1; i<dl.length ; i++){ if(dl[i][0]==vl){ tb+='<table cellspacing="0"><tbody id="profile"><tr><td colspan="1" class="subLabel">UNID: </td><td colspan="5" id="res_unid">'+dl[i][0]+'</td></tr><tr><td class="subLabel">SHEI: </td><td colspan="5" id="res_shei">'+dl[i][1]+'</td></tr><tr><td class="subLabel">DHEI: </td><td colspan="5" id="res_dhei">'+dl[i][2]+'</td></tr><tr><td class="subLabel">SCHOLARSHIP STATUS: </td><td colspan="2" id="res_sstatus">'+dl[i][3]+'</td><td class="subLabel">SCHOLARSHIP TYPE: </td><td colspan="2" id="res_stype">'+dl[i][4]+'</td></tr></tbody><tbody id="laStatus"><tr><td class="label" colspan="6">LIVING ALLOWANCE</td></tr><tr><td colspan="6" class="ay3rd1617">AY 2016-2017 3RD TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status3rd">'+dl[i][5]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem3rd">'+dl[i][6]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act3rd">'+dl[i][7]+'</td></tr><tr><td colspan="6" class="ay4th1617">AY 2016-2017 4TH TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status4th">'+dl[i][8]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem4th">'+dl[i][9]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act4th">'+dl[i][10]+'</td></tr><tr><td colspan="6" class="ay1st1718">AY 2017-2018 1ST TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status1st">'+dl[i][11]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem1st">'+dl[i][12]+'</td></tr> <tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act1st">'+dl[i][13]+'</td></tr><tr><td colspan="6" class="ay2nd1718">AY 2017-2018 2nd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status2nd">'+dl[i][14]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem2nd">'+dl[i][15]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act2nd">'+dl[i][16]+'</td></tr><tr><td colspan="6" class="ay3rd1718">AY 2017-2018 3rd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status3rda">'+dl[i][17]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem3rda">'+dl[i][18]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act3rda">'+dl[i][19]+'</td></tr><tr><td colspan="6" class="ay4th1718">AY 2017-2018 4th TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status4tha">'+dl[i][20]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem4tha">'+dl[i][21]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act4tha">'+dl[i][22]+'</td></tr> <tr><td colspan="6" class="ay1st1819">AY 2018-2019 1ST TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status1sta">'+dl[i][23]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem1sta">'+dl[i][24]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act1sta">'+dl[i][25]+'</td></tr><tr><td colspan="6" class="ay2nd1819">AY 2018-2019 2nd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status2nda">'+dl[i][26]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem2nda">'+dl[i][27]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act2nda">'+dl[i][28]+'</td></tr><tr><td colspan="6" class="ay3rd1819">AY 2018-2019 3rd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status3rdb">'+dl[i][29]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem3rdb">'+dl[i][30]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act3rdb">'+dl[i][31]+'</td></tr> <tr><td colspan="6" class="ay4th1819">AY 2018-2019 4th TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status4thb">'+dl[i][32]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem4thb">'+dl[i][33]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act4thb">'+dl[i][34]+'</td></tr><tr><td colspan="6" class="ay1st1920">AY 2019-2020 1st TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status1stb">'+dl[i][35]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem1stb">'+dl[i][36]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act1stb">'+dl[i][37]+'</td></tr> <tr><td colspan="6" class="ay2nd1920">AY 2019-2020 2nd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status2ndb">'+dl[i][38]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem2ndb">'+dl[i][39]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act2ndb">'+dl[i][40]+'</td></tr></tbody><tbody id="tdStatus"><tr><td class="label" colspan="6">THESIS / DISSERTATION</td></tr><tr><td colspan="6" class="td80">EIGHTY PERCENT (80%)</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="td_status80"><pre>'+dl[i][41]+'</pre></td></tr><tr><td colspan="1" class="subLabel">REMARKS</td><td colspan="5" id="td_remarks80"><pre>'+dl[i][42]+'</pre></td></tr><tr><td colspan="6" class="td20">TWENTY PERCENT (20%)</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="td_status20"><pre>'+dl[i][43]+'</pre></td></tr><tr><td colspan="1" class="subLabel">REMARKS</td><td colspan="5" id="td_remarks20">'+dl[i][44]+'</td></tr></tbody></table><center><font face=times size=1px>Date of issue: '+dt+' | ℗Power by CodyLab Technology. | www.codylab.blogspot.com</font></center>'; }}; return tb; }
This is an HTML code snippet that contains a form for inputting a UNID and viewing the status associated with it. The form is centered on the page and includes an image header, a subheader, a container for the input form and a container for displaying the result.
The form includes an input field for the UNID, with an associated label and a placeholder. There is also a button for submitting the form, which triggers the JavaScript function view_status()
when clicked.
The view_status()
function retrieves the value of the UNID input field and displays a loading message in the result container. It then calls a Google Apps Script function sub()
with the UNID value as an argument, using the google.script.run
method. If the sub()
function succeeds, the res()
function is called with the result value as an argument, which is then displayed in the result container. If the sub()
function fails, the res()
function is called with an empty argument, and a "No record!" message is displayed in the result container.
The HTML code also includes a meta
tag for setting the viewport width and initial scale, and two link
tags for importing CSS stylesheets from external sources. The include('css')
statement is used to include additional CSS code that is shown in next snippet.
<!DOCTYPE html> <html> <head> <base target="_top"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <?!= include('css'); ?> </head> <body> <center><header> <div id="imgheader"> <img src="https://i.postimg.cc/FRqpWNmd/K12-Generic-Form-Banner-preview.png"width="60%"> </div> </header> <div id="subheader"> </div> <div id="cont"> <p> Input your UNID and click the button to view your status.</p> <label>UNID : </label> <input type="text" id="UNID" onkeydown="if(event.keyCode == 13){document.getElementById('view').click()}" placeholder="e.x. 2016b-111111"> <button onclick="view_status()" id="view">View Status </button> </div> <div id="result" style="display: block;"> </div> </center> <script> function view_status(){ var vl = document.getElementById('UNID').value; if(vl!=''){ var lo = '<i class="fa fa-circle-o-notch fa-spin" style="font-size:12px"></i> Fetching...'; document.getElementById("result").innerHTML = lo; google.script.run.withFailureHandler(res) .withSuccessHandler(res) .sub(vl);}else{document.getElementById("result").innerHTML='Please enter UNID.'}} function res(v){ if(v===''){ var re = 'No record!';}else{var re = v;} document.getElementById("result").innerHTML = re;} </script> </body> </html>