Skip to content

Instantly share code, notes, and snippets.

@neno-tech
Last active January 16, 2021 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neno-tech/cf92a40b4f1ab1bb654d0d1db4c9330e to your computer and use it in GitHub Desktop.
Save neno-tech/cf92a40b4f1ab1bb654d0d1db4c9330e to your computer and use it in GitHub Desktop.
เว็บแอพส่งงาน-ของขวัญวันครู 64 จากครูอภิวัฒน์ วงศ์กัณหา
function doGet(e) {
return HtmlService.createTemplateFromFile("form").evaluate()
.setTitle("ฟอร์มอัปโหลดงานส่งครูอภิวัฒน์")
.addMetaTag('viewport', 'width=device-width, initial-scale=1')
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
var url = "xxx";
var folderId = "xxx";
var ss = SpreadsheetApp.openByUrl(url);
var sheet = ss.getSheets()[0];
function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
function uploadFiles(data) {
var file = data.myFile;
var folder = DriveApp.getFolderById(folderId);
var createFile = folder.createFile(file);
return createFile.getUrl();
}
function addNewRow2(rowData2) {
const currentDate = new Date();
var files = DriveApp.getFilesByName(rowData2.img);
while (files.hasNext()) {
var file = files.next();
var linkFile = file.getUrl();
var sizeFileTemp = file.getSize();
var sizeFile = (sizeFileTemp / 1000).toString() + " KB";
}
sheet.appendRow([currentDate, rowData2.d1, rowData2.d2, rowData2.d3,
rowData2.d5, rowData2.img, linkFile, rowData2.d4])
copyToSheet()
return true;
}
function copyToSheet() {
var data = sheet.getRange(2, 1, 1, 8).getValues()[0];
var subject = sheet.getRange(2, 8).getValue()
var sheetNew = ss.getSheetByName(subject);
if (sheetNew == null) {
sheetNew = ss.insertSheet(subject);
}
sheetNew.appendRow(data);
sheet.deleteRow(2);
}
<!doctype html>
<html lang="en">
<head>
<base target="_self">
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href='https://fonts.googleapis.com/css?family=Assistant' rel='stylesheet'>
<link href='https://fonts.googleapis.com/css?family=Prompt' rel='stylesheet'>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css"
integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<?!= include("page-css"); ?>
</head>
<body>
<div class="container" id="app">
<!--- Frame perizinan -->
<div class="z-depth-4" novalidate="novalidate" style="max-width: 480px;margin: 40px auto;"
id="divMenuUraianKerja">
<!-- <span class="black-text"></span> -->
<div class="card-panel teal lighten-2 text-white">
<h6 style="font-size:24px;">ส่งงาน</br>ครูอภิวัฒน์</h6>
<div class="center"> <img src="xxx" width="60px" height="60px"></div>
</div>
<div class="container questionBox mb-4">
<div class="input-field col s12">
<i class="material-icons" style="color:#00796b">person_pin</i>
<input style="color: black" type="text" id="d1" placeholder="ชื่อ สกุล*">
<label for="input1"></label>
</div><br>
<div class="input-field col s12">
<i class="material-icons" style="color:#00796b">store_mall_directory</i>
<input style="color: black" type="text" id="d2" placeholder="ชั้น (เช่น ม.5/3)*">
<label for="input2"></label>
</div><br>
<div class="input-field col s12">
<i class="material-icons" style="color:#00796b">lightbulb_outline</i>
<input style="color: black" type="text" id="d3" placeholder="เลขที่*">
<label for="input2"></label>
</div><br>
</div>
<div class="row questionBox mb-4">
<div class="col">
<i class="material-icons" style="color:#00796b">import_contacts</i>
<label style="font-size:18px; color:black" for="d4">วิชาที่เรียนกับครูอภิวัฒน์*:</label>
<select class="form-control" id="d4">
<option>เลือกวิชา</option>
<option>ม.2-3-หน้าที่พลเมือง</option>
<option>ม.3-การสร้างการ์ตูนเอนิเมชั่น</option>
<option>ม.4-3-การสร้างเว็บไซต์</option>
<option>ม.5-3-การสร้างแอพพลิเคชั่น</option>
</select>
</div>
</div>
<div class="row questionBox mb-4">
<div class="input-field col s12">
<i class="material-icons" style="color:#00796b">chat</i>
<textarea class="materialize-textarea" id="d5"></textarea>
<label for="d5" style="font-size:18px; color:black;">
ระบุเรื่อง/ชื่องาน/ลิ้งค์ไฟล์งาน*:
</label>
</div>
</div>
<center>
<div class="row questionBox">
<i class="material-icons" style="color:#00796b">file_upload</i>
<span style="font-size:18px; color:black;">อัปโหลดไฟล์</span><br><br>
<form>
<input style="color:black;" type="file" name="myFile" multiple>
<span id="resp-spinnerA" class="spinner-border spinner-grow-sm text-danger d-none" role="status" aria-hidden="true"></span>
<br><br>
<input style="color:white; background-color:#990099; display: none" class="multi-lainnya" type="button" id="submitBtn" value="Upload" >
</form>
</div>
</center>
<br>
<div id="divMainButton2" style="display: none">
<center>
<button style="background-color: #4db6ac; color: white;" class="btn waves-effect waves-light" type="submit" name="mainButton2"><b>ส่งงาน</b><i class="material-icons right">send</i> </button>
<span id="resp-spinner5" class="spinner-grow spinner-grow-sm text-danger d-none" role="status" aria-hidden="true"></span>
<span id="resp-spinner6" class="spinner-grow spinner-grow-sm text-warning d-none" role="status" aria-hidden="true"></span>
<span id="resp-spinner7" class="spinner-grow spinner-grow-sm text-info d-none" role="status" aria-hidden="true"></span>
</center>
</div>
</div>
<!-- Frame perizinan -->
</div>
<center>
<footer class="footer">
<section class="container">
<p style="font-size:10px;">
<a target="_blank" href="https://www.facebook.com/mynameisapiwat"
title="Consulthink Programmer">ครูอภิวัฒน์"สอนสร้างสื่อ"®</a>
<a style="color:red;" target="_blank"
href="https://www.youtube.com/c/ApiwatWongkanha?sub_confirmation=1" title="Youtube"> |
Youtube</a>
</p>
</section>
</footer>
</center>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous">
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous">
</script>
<?!= include("page-js"); ?>
</body>
</html>
<style>
.container {
margin-top: 3em !important;
}
h6 {text-align: center;}
#frame {
border: 1px solid rgba(0,0,0,0.2);
padding: 20px;
margin-left:10px;
margin-right:10px;
margin-top: 2px;
border: 1px solid;
padding: 10px;
box-shadow: 5px 10px #888888;
}
#subBody1{
font-family: 'Prompt';
}
#subBody2{
font-family: 'Prompt';
}
#subBody3{
font-family: 'Prompt';
}
#divKategoriBaru {
border: 1px solid rgba(0,0,0,0.2);
padding: 20px;
margin-left:10px;
margin-right:10px;
margin-top: 2px;
border: 1px solid;
padding: 10px;
box-shadow: 5px 10px #888888;
}
#divMenuUraianKerja{
border: 1px solid rgba(0,0,0,0.2);
padding: 20px;
margin-left:10px;
margin-right:10px;
margin-top: 15px;
font-family: 'Prompt';
}
.swal-modal .swal-text {
text-align: center;
}
#subButton2 {
animation: mymove 10s infinite;
}
#subButton2:focus {
outline: none;
box-shadow: 0px 0px 2px #0066ff;
}
@keyframes mymove {
50% {transform: rotate(360deg);}
}
.multi-lainnya{
width: 25%;
border-radius: 13px;
border: 1px solid grey;
padding-left: 8px;
}
.multi-lainnya:focus {
outline: none;
box-shadow: 0px 0px 2px #0066ff;
}
.questionBox {
border: 1px solid rgba(0,0,0,0.2);
padding: 1.5rem;
margin-left:10px;
margin-right:10px;
border-radius: 13px;
margin: auto;
width: 100%;
}
</style>
<script>
//script upload file
document.getElementsByName('myFile')[0].addEventListener('change',unggahFiles)
function unggahFiles(e){
if(document.getElementsByName('myFile')[0].value !== ""){
document.getElementById('resp-spinnerA').classList.remove("d-none");
google.script.run.withSuccessHandler(onSuccess).uploadFiles(this.parentNode)
} else {
sweetAlert({text: "โปรดเลือกไฟล์", icon:"warning", timer:2000})
}
}
function onSuccess(data){
document.getElementById('resp-spinnerA').classList.add("d-none");
document.getElementById('submitBtn').value = "Uploaded";
sweetAlert({text: "ไฟล์พร้อมส่งแล้วให้คลิกปุ่ม..ส่งงาน ได้เลย", icon:"success", timer:2000})
document.getElementById('divMainButton2').style.display = "block";
}
//batas script upload file
document.getElementsByName("mainButton2")[0].addEventListener("click", afterButttonClicked2);
function afterButttonClicked2(){
var d1 = document.getElementById("d1");
var d2 = document.getElementById("d2");
var d3 = document.getElementById("d3");
var d4 = document.getElementById("d4");
var d5 = document.getElementById("d5");
var input = document.getElementsByName('myFile')[0];
var file = input.value.split("\\");
var img = file[file.length-1];
var submit2 = document.getElementById('submitBtn');
var rowData2 = {
d1: d1.value,
d2: d2.value,
d3: d3.value,
d4: d4.value,
d5: d5.value,
img: img
}
if(d1.value == "เลือกรายการ" || d2.value == "เลือกรายการ" || d3.value == "เลือกรายการ" || d4.value == "เลือกรายการ" || input.value == "" || d5.value == "" || submit2.value == "Upload"){
sweetAlert({text: "Warning!!!"+"\n\n"+"ต้องกรอกข้อมูลทุกช่อง.", icon:"error", timer:2000})
}else{
document.getElementById('resp-spinner5').classList.remove("d-none");
document.getElementById('resp-spinner6').classList.remove("d-none");
document.getElementById('resp-spinner7').classList.remove("d-none");
google.script.run.withSuccessHandler(afterSubmit2).addNewRow2(rowData2);
}
}
function afterSubmit2(){
document.getElementById('resp-spinner5').classList.add("d-none");
document.getElementById('resp-spinner6').classList.add("d-none");
document.getElementById('resp-spinner7').classList.add("d-none");
sweetAlert({text: "ส่งงานให้ครูอภิวัฒน์..ตรวจ"+"\n\n"+"เรียบร้อยแล้ว", icon:"success", timer:2000})
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment