axelson / ITS

Scripts and files for my job at ITS

This URL has Read+Write access

ITS / jason_simp.user.js
100644 192 lines (165 sloc) 6.679 kb
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// ==UserScript==
// @name Jason SIMP
// @namespace jaxelson.com
// @description SIMP Scripts v2.01
// @include http://web06.its.hawaii.edu/simp/*
// @include http://www.hawaii.edu/simp/*
// ==/UserScript==
 
// Globals
var SEARCH_BOX_ID = "search_str";
 
//13932 SIMP test ticket
 
 
if(window.location.href.search("tckt_id=") == -1) {
       //addSearchOptions();
} else {
       addMMButton();
}
 
// Functions
 
// Add button to copy information to paste into Meeting Maker (MM) job
function addMMButton() {
       var button = document.createElement("button");
       button.type = "button";
       button.innerHTML = "CopyForMM";
       button.id = "SIMP_button";
       button.style.cursor = "pointer";
       button.addEventListener("click", function(e) { showMMInfo(); }, false);
 
       var section = document.getElementById("submit_section");
       section.appendChild(button);
}
 
// Add extra search options to SIMP main page
function addSearchOptions() {
       console.log("addSearchOptions: enter");
 
       var searchOptions=document.createElement("select");
       searchOptions.id="quickAdvancedSearchDropDown";
       searchOptions.addEventListener("change", doQuickAdvancedSearch, true);
       searchOptions.options[0] = new Option("Select an advanced option", "");
       searchOptions.options[1] = new Option("Ticket Number", "TicketNumber");
       searchOptions.options[2] = new Option("Customer UH Username",
"CustomerUHUsername");
       searchOptions.options[3] = new Option("Last Name", "LastName");
       searchOptions.options[4] = new Option("First Name", "FirstName");
       searchOptions.options[5] = new Option("ITS Username", "ITSUsername");
       document.getElementById("tcktFilterFrm").appendChild(searchOptions);
}
 
// Add radio buttons to choose search type
function doQuickAdvancedSearch(e) {
   var searchType = e.target.value;
   console.log("doQuickAdvancedSearch("+ searchType +")");
   var searchStr = "?cmd=search"
                  +"&clear=true"
                  +"&advanced=true";
   switch(searchType) {
       case "TicketNumber":
           searchStr = "index.php?cmd=retrieveTTicket&tckt_id="
           break;
       case "CustomerUHUsername":
           searchStr += "&filterCustomerUsername=";
           break;
       case "LastName":
           searchStr += "&filterCustomerLast=";
           break;
       case "FirstName":
           searchStr += "&filterCustomerFirst=";
           break;
       case "ITSUsername":
           searchStr += "&filterCreatedUsername=";
           break;
       default:
           fatalError("doSearch error, searchType not expected
(searchType="+ searchType +")");
   }
 
   searchStr += getValueById(SEARCH_BOX_ID);
 
   window.location.href = searchStr;
}
 
 
// Show the Meeting Maker information
function showMMInfo() {
       console.log("showMMInfo: Enter function");
       //*
       var text="";
 
       // Fill variables relating to all ticket fields
       var TicketNumber = getValueById("tckt_id");
       var UHUsername = getValueById("ppl_uhusername");
       var PhoneNumber = getValueById("ppl_ofc_phone");
       var FirstName = getValueById("ppl_name_first");
       var LastName = getValueById("ppl_name_last");
       var Building = getBuildingName();
       var RoomNumber = getValueById("ppl_room_num");
       var ProblemDescription = getTicketDescription();
       var ProblemSolution = getProblemSolution();
       var HelpDeskUserName = getHelpDeskUserName();
 
       //*/
       text += "Username: " + UHUsername;
       text += "\nName: " + FirstName + " " + LastName;
       text += "\nTicket: " + TicketNumber;
       text += "\nPhone: " + PhoneNumber;
       text += "\nBuilding: " + Building + " room " + RoomNumber;
       text += "\n\n";
       text += "***************************\n";
       text += "* Problem Description *\n";
       text += "***************************\n";
       text += ProblemDescription;
       text += "\n\n\n";
       text += "************************\n";
       text += "* Problem Solution *\n";
       text += "************************\n";
       text += ProblemSolution;
       text += "\n\n";
       text += "This Meeting Maker job was posted by "+ HelpDeskUserName;
               text += " on "+ Date();
 
       alert(text);
}
 
// Get the raw text of the Problem Solution
function getProblemSolution() {
       var text="\n";
       var tckt_history = document.getElementById("tckt_history_section").childNodes;
       for(var i=tckt_history.length-2; i>=5 ;i-=2) {
               //console.log("info: "+
tckt_history[i].childNodes[5].childNodes[1].textContent);
               text += getFormattedEntry(tckt_history[i].childNodes);
               text += "\n\n";
       }
 
       return text;
       function getFormattedEntry(div) {
               console.log("getFormattedEntry: div "+ div);
               var description = div[1].textContent;
               var author = div[3].textContent;
               var time = div[5].textContent;
               time = time.slice(3); //Remove "on " from start of string
 
               return time + " " + author + "\n" + description;
       }
}
 
// Get the DOM value by the elements id
function getValueById(id) {
       console.log("getElementById: id="+ id);
       return document.getElementById(id).value
}
 
function getBuildingName() {
       var name = "bldg_id";
       var buildingForm = document.getElementsByName(name)[0]
       return buildingForm[buildingForm.selectedIndex].label;
}
 
// Get the username of the help desk user pasting the job
function getHelpDeskUserName() {
       var logoutButtonString =
document.getElementById("link-logout").firstChild.innerHTML;
       // logoutButtonString now has form "LOGOUT [username]"
       logoutButtonString = String(logoutButtonString.match(/\[.*\]/));
       return logoutButtonString.match(/[a-z]+/);
}
 
// Get the text of the SIMP ticket description field
function getTicketDescription() {
       console.log("getTicketDescription:");
       var id="";
 
       // If Ticket Description is read-only element is called tckt_descr_ro
otherwise called tckt_descr
       if( document.getElementById("tckt_descr") ) {
               return document.getElementById("tckt_descr").value;
       } else {
               return document.getElementById("tckt_descr_ro").innerHTML;
       }
}
 
function fatalError(messageInfo) {
       alert("An error has occured in the Greasemonkey script running on
this page. If this is causing a problem, disable the script by
clicking on the brown monkey in the lower right-hand corner of the
browser. More information is below.\n\n"+ messageInfo);
}