Created
February 24, 2016 07:35
-
-
Save rheajt/8216df2100a8b7f931d9 to your computer and use it in GitHub Desktop.
parent-teacher conference helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parentTeacherConference() { | |
var commentModal = HtmlService | |
.createHtmlOutputFromFile('ptcView') | |
.setSandboxMode(HtmlService.SandboxMode.IFRAME) | |
.setTitle('Parent-Teacher Conference') | |
.setWidth(600) | |
.setHeight(400); | |
SpreadsheetApp.getUi().showModalDialog(commentModal, "Make a comment"); | |
} | |
function getPtcInfo(students) { | |
if(typeof students === 'string') { | |
students = SpreadsheetApp.getActiveSheet() | |
.getRange(2, 1, SpreadsheetApp.getActiveSheet() | |
.getLastRow() - 1) | |
.getValues() | |
.toString() | |
.split(',') | |
.map(Number); | |
} | |
students = students.map(function(student) { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var snColumn = 1; | |
var maxRows = sheet.getLastRow(); | |
var studentRow = sheet.getRange(1, snColumn, maxRows).getValues() | |
.reduce(function(first, second) {return first.concat(second);}) | |
.indexOf(parseInt(student)) + 1; | |
var headings = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues(); | |
var studentInfo = sheet.getRange(studentRow, snColumn, 1, sheet.getLastColumn()).getValues(); | |
var studentData = []; | |
for(var i = 0; i < headings[0].length; i++) { | |
studentData.push([headings[0][i], studentInfo[0][i]]); | |
} | |
return studentData; | |
}); | |
createPtcDocument(students); | |
} | |
function createPtcDocument(data) { | |
var date = new Date(); | |
// create the document title based on the students selected | |
var title = ((data.length + 1) === SpreadsheetApp.getActiveSheet().getLastRow()) | |
? "All Students " + date.toDateString() | |
: data.map(function(student) {return student[1][1]}).join('-') + ' ' + date.toDateString(); | |
var doc = DocumentApp.create(title).getBody(); | |
data.forEach(function(student) { | |
var info = student.slice(0, 6); | |
var grades = student.slice(10); | |
doc.appendParagraph(info[1][1] + ' ' + info[2][1]); | |
doc.appendParagraph(info[3][1] + '-' + info[4][1]); | |
doc.appendHorizontalRule(); | |
doc.appendParagraph("Grades:"); | |
doc.appendTable(grades); | |
doc.appendPageBreak(); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> | |
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> | |
<style> | |
.mainContainer { | |
padding: 15px; | |
} | |
</style> | |
<div class="mainContainer"> | |
<div class="block"> | |
<label class="block" for="tags"><b>Student name...</b></label> | |
<input class="block" type="text" id="tags"> | |
</div> | |
<div class="block"> | |
<button class="action" id="add" type="button">Add to list</button> | |
<button class="create" id="finish" type="button">Complete PTC</button> | |
<button class="create" id="allStudents" type="button">Create doc for all students</button> | |
</div> | |
<div id="studentList"></div> | |
</div> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> | |
<script> | |
var studentList = []; | |
google.script.run | |
.withSuccessHandler(function(availableTags) { | |
$('#tags').autocomplete({ | |
source: availableTags | |
}); | |
}) | |
.getAvailableTags(); | |
$('button#add').click(function() { | |
if($('#tags').val()) { | |
var fullStudent = $('#tags').val().split(' ')[1] + " " + $('#tags').val().split(' ')[2]; | |
var studentNum = $('#tags').val().split(' ')[0]; | |
studentList.push(studentNum); | |
$('#studentList').append('<h1>' + fullStudent + '</h1><input type="hidden" class="studentInfo" value="' + studentNum + '">'); | |
$('#tags').val(''); | |
} | |
}); | |
$('button#finish').click(function() { | |
google.script.run | |
.withSuccessHandler(function() { | |
/* add the data returned to the html | |
* close the html */ | |
google.script.host.close(); | |
}) | |
.getPtcInfo(studentList); | |
}); | |
$('button#allStudents').click(function() { | |
studentList = 'all'; | |
google.script.run | |
.withSuccessHandler(function() { | |
google.script.host.close(); | |
}) | |
.getPtcInfo(studentList); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment