Created
May 10, 2019 17:30
-
-
Save HBBisenieks/f237f4450d865d39ab486d09b71b6564 to your computer and use it in GitHub Desktop.
js for new employee info webapp
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
/** | |
* README | |
* | |
* All of the checkbox automation that happens on the main | |
* HiringPage area is controlled by needsXXXX(role) functions. | |
* These functions are, as much as possible, controlled by | |
* switch() statements that will return true, and check the | |
* associated box, if one of the affiliations listed with | |
* | |
* case "affiliation": | |
* | |
* before the "default:" block. To update the affiliations | |
* that receive a particular service, add, remove, or update | |
* the appropriate switch statement. | |
* | |
* NOTE: affiliations are case-sensitive and will not give the | |
* expected results if not entered exactly as they appear in | |
* the properties of the roleSelect dropdown element on HiringPage | |
**/ | |
/** | |
* Helper function to print lists with oxford commas | |
**/ | |
function printList(l) { | |
var d = ""; | |
if (l.length == 2) | |
d += (l[0] + " and " + l[1]); | |
else { | |
var i; | |
for (i = 0; i < l.length; i++) { | |
if (i > 0) { | |
d += ", "; | |
if (i == (l.length - 1)) | |
d += "and "; | |
} | |
d += l[i]; | |
} | |
} | |
return d; | |
} | |
function needsComputer(role) { | |
// Logic to try to figure out if user needs a computer issued. | |
switch (role) { | |
case "Administration": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
function needsEmail(role) { | |
// Returns true for affiliations that should recieve | |
// an HRS email account | |
switch (role) { | |
case "Administration": | |
case "ASP": | |
case "Heads Up Academic": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
/*function enableEmailMessage(role) { | |
var enable = "Employee needs HRS email address"; | |
var disable = enable + " IT HAS BEEN DETERMINED THAT AN INDIVIDUAL EMAIL ADDRESS IS INAPPROPRIATE FOR THIS ROLE"; | |
if (needsEmail(role)) | |
return enable; | |
return disable; | |
}*/ | |
function needsPortal(role) { | |
// Returns true for affiliations that should recieve | |
// a portal account | |
switch (role) { | |
case "Administration": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
function needsVoicemail(role) { | |
// Logic to try to figure out if user needs voicemail. | |
switch (role) { | |
case "Administration": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
function needsPhone(voicemail,role) { | |
// Logic to try to figure out if user needs a desk phone. | |
// Current settings issue a phone to employees with the | |
// affiliations of Administration and Professional Staff | |
if (voicemail === true) { | |
switch (role) { | |
case "Administration": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
return false; | |
} | |
function needsGateFob(role) { | |
// Logic to try to figure out if user needs a gate fob. | |
// To add another affiliation that should get a fob, add | |
// case "Role": | |
// on a new line before "return true;" | |
switch (role) { | |
case "Administration": | |
case "ASP": | |
case "Heads Up Academic": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
function appearInDirectory(role) { | |
// Logic to try to figure out if user should appear in online directory. | |
// Current settings return false for part-time contractors | |
switch (role) { | |
case "Administration": | |
case "After School Music": | |
case "ASP": | |
case "ASP Enrichment": | |
case "Coaching": | |
case "Heads Up Academic": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
function notifyAdvancement(role) { | |
// Function to determin if Advancement should be notified | |
// of user's arrival | |
switch (role) { | |
case "Administration": | |
case "After School Music": | |
case "ASP Enrichment": | |
case "Coaching": | |
case "Debate": | |
case "Heads Up Academic": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Music": | |
case "Professional Staff": | |
return true; | |
case "ASP": | |
return !app.pages.HiringPage.descendants.displayIsStudent.value; // return true only if ASP employee is not a teacher | |
default: | |
return false; | |
} | |
} | |
function clearName() { | |
// Function to clear name fields but preserve all other settings | |
app.pages.HiringPage.descendants.firstName.value = ''; | |
app.pages.HiringPage.descendants.lastName.value = ''; | |
app.pages.HiringPage.descendants.title.value = ''; | |
} | |
function clearAll() { | |
// Function to clear all settings | |
clearName(); | |
app.pages.HiringPage.descendants.roleSelect.value = null; | |
app.pages.HiringPage.descendants.divisionSelect.values = []; | |
app.pages.HiringPage.descendants.alarmAreas.value = ''; | |
app.pages.HiringPage.descendants.needsBlackbaud.value = false; | |
app.pages.HiringPage.descendants.needsAlarm.value = false; | |
app.pages.HiringPage.descendants.pleaseContact.value = false; | |
} | |
function enableGroups(role) { | |
// Enables group select if user should recieve email address AND if | |
// that user has an affiliation that should get group membership | |
if (app.pages.HiringPage.descendants.displayNeedsEmail.enabled) { | |
switch (role) { | |
case "Administration": | |
case "Instructional": | |
case "Long-Term Substitute Teaching": | |
case "Professional Staff": | |
return true; | |
default: | |
return false; | |
} | |
} | |
return false; | |
} | |
function emailGroups(role,divisions) { | |
// Does its best to automatically populate what email groups an | |
// employee should be a member of | |
var groupInfo = app.pages.HiringPage.descendants.inputPanel.descendants; | |
var groups = ["professionalcommunity"]; | |
switch (role) { | |
case "Instructional": | |
groups.push("faculty"); | |
break; | |
case "Professional Staff": | |
groups.push("staff"); | |
break; | |
default: | |
break; | |
} | |
if (divisions.length > 0) { | |
for (var i = 0; i < divisions.length; i++) | |
if (divisions[i] != "Office") | |
groups.push(divisions[i].toLowerCase()); | |
} | |
return groups; | |
} | |
function assembleEmails() { | |
// Assemble an array of emails that should be sent to helpdesk | |
// and other involved parties as part of the hiring request | |
// process. | |
// | |
// Tickets are automatically assigned using hash commands within | |
// Spiceworks. Ticket-assignment variables below represent the | |
// existing hash commands. If other Spiceworks users need automatic | |
// ticket assignment through this system, they must be added both | |
// in the variables below, to be appended to any ticket emails meant | |
// for them and in Spiceworks. | |
var emails = []; | |
var widgetOutputs = app.pages.HiringPage.descendants; | |
var helpdesk = ; | |
var comms = ; | |
var parking = ; | |
var keys = ; | |
var devo = ; | |
// Assemble common variables | |
var cc = widgetOutputs.ccUsers.value; | |
var firstName = widgetOutputs.firstName.value; | |
var lastName = widgetOutputs.lastName.value; | |
var fullName = firstName + " " + lastName; | |
var title = widgetOutputs.title.value; | |
var startDate = widgetOutputs.startDate.value.toDateString(); | |
var divisions = ''; | |
if (widgetOutputs.divisionSelect.values.length > 0) | |
divisions = printList(widgetOutputs.divisionSelect.values); | |
var parkingInfo = " " + widgetOutputs.roleSelect.value + ", " + widgetOutputs.title.value; | |
if (divisions.length > 0) | |
parkingInfo += (", working in " + divisions); | |
// Pre-assemble chunks for ticket email subject lines | |
var subjPre = "New Employee "; | |
var subjPost = " – " + fullName + ", " + title + " – Start Date: " + startDate; | |
var dateAdd = "<br><br>Start date: " + startDate; | |
var disclaimer = dateAdd + "<br><br>This message was automatically generated by the New Employee Information webform."; | |
// vars for ticket assignment | |
// Loop through the elements of HiringPage to assemble each ticket email needed | |
var child; | |
for (child in widgetOutputs) { | |
var email = [helpdesk,cc]; // email is an array with four elements: to, cc, subject, body | |
switch (widgetOutputs[child].name) { | |
case "displayDirectory": | |
if (widgetOutputs[child].value) { | |
email.push((subjPre + "Include in Online Directory" + subjPost)); | |
email.push(("Employee should be included in online directory." + ifo)); | |
} | |
break; | |
case "displayNeedsComputer": | |
if (widgetOutputs[child].value) { | |
email.push((subjPre + "Prepare Computer" + subjPost)); | |
email.push(("Prepare computer for " + title + ", " + fullName + matt)); | |
} | |
break; | |
case "displayNeedsEmail": | |
if (widgetOutputs[child].value) { | |
widgetOutputs.emailLists.values.push("classroom_teachers"); | |
email.push((subjPre + "Create Email" + subjPost)); | |
email.push(("Create email for " + fullName + " and add user to " + printList(widgetOutputs.emailLists.values) + "<br><br>Notify HR of email address." + hilary)); | |
} | |
break; | |
case "displayNeedsPortal": | |
if (widgetOutputs[child].value) { | |
email.push((subjPre + "Create AD Account" + subjPost)); | |
email.push(("Create AD login for " + fullName + hilary)); | |
emails.push(email); | |
email = [helpdesk,cc]; | |
email.push((subjPre + "Create Portal Account" + subjPost)); | |
email.push(("Create portal account for " + fullName + ifo)); | |
} | |
break; | |
case "displayNeedsKeyfob": | |
if (widgetOutputs[child].value) { | |
email.push((subjPre + "Program Keyfob" + subjPost)); | |
email.push(("Prepare keyfob with front gate access." + hilary)); | |
} | |
break; | |
case "displayNeedsPhone": | |
if (widgetOutputs[child].value) { | |
email.push((subjPre + "Set up Desk Phone" + subjPost)); | |
email.push(("Set up desk phone for " + title + ", " + fullName + hilary)); | |
} | |
else { | |
if (widgetOutputs.needsVoicemail.value) { | |
email.push((subjPre + "Set up Voicemail" + subjPost)); | |
email.push(("Set up voicemail." + hilary)); | |
} | |
} | |
break; | |
case "displayNeedsBusinessCards": | |
if (widgetOutputs[child].value) { | |
email.push((subjPre + "Business Card Info to Cathy" + subjPost)); | |
email.push(("Get business card info: name and phone extension to Cathy Hosino. Title should come from HR rather than form." + hilary)); | |
} | |
break; | |
case "displayContact": | |
if (widgetOutputs[child].value) { | |
email.push((subjPre + "Contact " + app.user.email + " for Additional Information" + subjPost)); | |
email.push(("Contact " + app.user.email + " for additional information about " + fullName + hilary)); | |
} | |
break; | |
default: | |
break; | |
} | |
if (email.length > 2) | |
emails.push(email); | |
// console.log(widgetOutputs[child].name + " " + widgetOutputs[child].value); | |
} | |
/* Communicate Phone Info to Susana */ | |
if (widgetOutputs.displayNeedsPhone.value || widgetOutputs.needsVoicemail.value) | |
emails.push([helpdesk,cc,(subjPre + "Send Phone Extension Info to Susana" + subjPost),("Send extension info to Susana." + hilary)]); | |
/* Communications email */ | |
emails.push([comms,cc,("New " + title + subjPost),("New employee " + fullName + " is starting on " + startDate + " as a " + title + "." + disclaimer)]); | |
/* Parking email */ | |
if (widgetOutputs.displayIsStudent.value === false || widgetOutputs.displayIsStudent.visible === false) | |
emails.push([parking,cc,(subjPre + "Parking Assignment Needed" + subjPost),(subjPre + " " + fullName + parkingInfo + ", will be starting on " + startDate + disclaimer)]); | |
/* Key email */ | |
if (widgetOutputs.needsKeys.value && (widgetOutputs.displayIsStudent.visible === false || widgetOutputs.displayIsStudent.value === false)) | |
emails.push([keys,cc,(subjPre + "Building Keys Needed for " + widgetOutputs.keyAreas.value + subjPost),(subjPre + fullName + parkingInfo + ", will be starting on " + startDate + " and will need keys for " + widgetOutputs.keyAreas.value + disclaimer)]); | |
/* Info to Advancement */ | |
if (notifyAdvancement(widgetOutputs.roleSelect.value)) | |
emails.push([devo,cc,("New " + title + subjPost),("New employee " + fullName + " is starting on " + startDate + " as a " + title + "." + disclaimer)]); | |
/* Uncomment the following line to have email info display in debugging console */ | |
//console.log(emails); | |
/* Comment the following line to stop app from actually sending emails */ | |
return emails; | |
} | |
function sendEmailMessage(sendButton) { | |
if (!app.pages.HiringPage.descendants.inputPanel.validate()) { | |
return; | |
} | |
//var pageWidgets = sendButton.root.descendants; | |
var props = sendButton.root.properties; | |
props.sendingEmail = true; | |
google.script.run | |
.withSuccessHandler(function() { | |
// cleanEmailForm(pageWidgets); | |
// app.datasources.RemainingDailyQuota.load(); | |
props.sendingEmail = false; | |
}) | |
.withFailureHandler(function(err) { | |
console.error(JSON.stringify(err)); | |
props.sendingEmail = false; | |
}) | |
.sendEmails( | |
assembleEmails() | |
); | |
} | |
function enableHire() { | |
// Enable the hiring button only after enough information has been filled out | |
var inputs = app.pages.HiringPage.descendants; | |
if (inputs.firstName.value !== null && inputs.lastName.value !== null && inputs.title.value !== null && inputs.startDate.value !== null) { | |
if (inputs.divisionSelect.values[inputs.divisionSelect.values.length - 1] == "Office" && inputs.officeLocation.value === null) | |
return false; | |
return true; | |
} | |
return false; | |
} | |
function confirmDivisions(divisions) { | |
var o = "Working in " + printList(app.pages.HiringPage.descendants.divisionSelect.values) + " division"; | |
if (divisions.length > 1) | |
o += "s"; | |
return o; | |
} | |
function receiveList() { | |
var widgetOutputs = app.pages.HiringPage.descendants; | |
var r = []; | |
var child; | |
for (child in widgetOutputs) { | |
switch (widgetOutputs[child].name) { | |
case "displayNeedsComputer": | |
if (widgetOutputs[child].value) | |
r.push("an HRS computer"); | |
break; | |
case "displayNeedsEmail": | |
if (widgetOutputs[child].value) | |
r.push("an HRS email address"); | |
break; | |
case "displayNeedsKeyfob": | |
if (widgetOutputs[child].value) | |
r.push("a key fob to enter campus"); | |
break; | |
case "displayNeedsPhone": | |
if (widgetOutputs[child].value) | |
r.push("a desk phone"); | |
else { | |
if (widgetOutputs.needsVoicemail.value) | |
r.push("a voicemail box"); | |
} | |
break; | |
case "displayNeedsPortal": | |
if (widgetOutputs[child].value) | |
r.push("access to the Employee Portal"); | |
break; | |
default: | |
break; | |
} | |
} | |
if (r.length > 0) | |
return "Employee needs " + printList(r); | |
return ""; | |
} |
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 sendEmails(emailArray) { | |
var email; | |
for (email in emailArray) { | |
try { | |
MailApp.sendEmail({ | |
to: emailArray[email][0], | |
cc: emailArray[email][1], | |
subject: emailArray[email][2], | |
htmlBody: emailArray[email][3] | |
}); | |
} catch(e) { | |
console.error(JSON.stringify(e)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment