-
Notifications
You must be signed in to change notification settings - Fork 0
/
AssignRoles.js
129 lines (102 loc) · 4.49 KB
/
AssignRoles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function assignSundayPromo1() {
let cc_volunteer_old = "sundaypromo1";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignMondayPromo1() {
let cc_volunteer_old = "mondaypromo1";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignMondayPromo2() {
let cc_volunteer_old = "mondaypromo2";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignMessageLord() {
let cc_volunteer_old = "outdoor_messagelord";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignGroupCreator() {
let cc_volunteer_old = "outdoor_groupmaker";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignWeekDirector() {
let cc_volunteer_old = "Event Director";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignCragCoordinator() {
let cc_volunteer_old = "outdoor_cragcoordinator1";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignAssistantCragCoordinator() {
let cc_volunteer_old = "outdoor_assistantcragcoordinator1";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function assignCragReporter() {
let cc_volunteer_old = "outdoor_postpromo1";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
function markVolunteerClear() {
if (Browser.msgBox("This wont notify the person automatically that their roles has been cancelled - you will want to do that", Browser.Buttons.OK_CANCEL) == "ok") {
let cc_volunteer_old = "none";
let volunteer = searchEmailsSheet(cc_volunteer_old);
assignRole(volunteer, cc_volunteer_old);
}
}
function assignRole(volunteer, cc_volunteer_old ) {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Volunteering');
var active_range = sheet.getActiveRange();
var currentRow = active_range.getRowIndex();
//var currentRow = "5";
console.log("Row " + currentRow);
if(currentRow <=1){Browser.msgBox('Select an actual signup', Browser.Buttons.OK); return;}
if(currentRow >=100){Browser.msgBox('Select an actual signup', Browser.Buttons.OK); return;}
var order_id = Number(sheet.getRange(currentRow, volunteeringOrderID,1,1).getValue()); /// get submission ID 1 BV ( was 67)
var first_name = String(sheet.getRange(currentRow, volunteeringName,1,1).getValue()); /// get submission ID 1 BV ( was 67)
console.log(order_id);
if(order_id === "" || order_id === "order_id"){Browser.msgBox('No Order ID Found', Browser.Buttons.OK); return;}
if (Browser.msgBox("Assign " + volunteer.cc_volunteer + " to " +first_name + "? \n Order " + order_id, Browser.Buttons.OK_CANCEL) == "ok") {
let cc_role_assigner = Session.getActiveUser().getEmail();
let noteToOrder = "#!Assigned Role by: " + cc_role_assigner
let currentTime = new Date().getTime();
let data = {"meta_data": [
{"key": "cc_volunteer_old",
"value": volunteer.cc_volunteer_old},
{"key": "cc_volunteer",
"value": volunteer.cc_volunteer},
{"key": "cc_volunteer_role_description_sentence",
"value": volunteer.cc_volunteer_role_description_sentence},
{"key": "cc_volunteer_role_description_time",
"value": volunteer.cc_volunteer_role_description_time},
{"key": "cc_volunteer_reminder_time",
"value": volunteer.cc_volunteer_reminder_time},
{"key": "cc_volunteer_role_description_post_event_sentence",
"value": volunteer.cc_volunteer_role_description_post_event_sentence},
{"key": "cc_volunteer_role_instructions_url",
"value": volunteer.cc_volunteer_role_instructions_url},
{"key": "cc_volunteer_role_assigned_by",
"value": cc_role_assigner },
{"key": "cc_volunteer_role_assigned_at",
"value": currentTime }
],
// "status": orderstatus
};
let orderDataOutcome = pokeToWordPressOrders(data, order_id)
let orderNoteOutcome = pokeNoteToOrder(order_id, noteToOrder)
if (orderDataOutcome === "Error" || orderNoteOutcome === "Error") {
throw new Error("One or more variables contain an 'Error' string.")
return
}
var blankArray =[[volunteer.cc_volunteer]];
sheet.getRange(currentRow, volunteeringVolunteerRole,1,1).setValues(blankArray); // paste the blank variables into the cells to delete contents
}
return;
}