forked from sethreno/cxm_grease
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcxm.user.js
More file actions
276 lines (239 loc) · 7.68 KB
/
Copy pathcxm.user.js
File metadata and controls
276 lines (239 loc) · 7.68 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
// ==UserScript==
// @name Simplify CXM
// @namespace sethreno
// @include http://cxm.rosnet.com:8080/CXM/*
// @include http://192.168.0.68:8080/CXM/*
// @description Make CXM UI bearable.
// @updateURL https://github.com/sethreno/cxm_grease/raw/master/cxm.user.js
// @version 5
// @grant none
// @require https://cdn.rawgit.com/showdownjs/showdown/1.2.2/dist/showdown.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.7/highlight.min.js
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js
// @run-at document-start
// ==/UserScript==
// this has to run before cxm scripts run
var showdownConverter = new showdown.Converter();
function hackForStringLiteral(f) {
return f.toString().
replace(/^[^\/]+\/\*!?/, '').
replace(/\*\/[^\/]+$/, '');
}
var css = hackForStringLiteral(function () {/*!
#cxm_grease {
font-family: Helvetica;
font-size: 140%;
padding-top: 40px;
}
#cxm_grease .menu {
padding: 5px;
background-color: #A03030;
color: white;
position: fixed;
top: 10px;
left: 10px;
right: 10px;
}
#cxm_grease .ticket, #cxm_grease .note {
margin: 10px;
border: 1px solid;
}
#cxm_grease .ticket > h3, #cxm_grease .note > h3 {
padding: 5px;
background-color: #2e4272;
color: white;
}
#cxm_grease .ticket > div.assignee {
float:right;
display: inline-block;
padding:5px;
color: white;
}
#cxm_grease .ticket p, #cxm_grease .note p, #cxm_grease .ticket .attachments a {
padding: 5px;
}
#cxm_grease .ticket .attachments {
margin: 5px;
}
#cxm_grease .ticket h3 span:first-child {
display: block;
}
#cxm_grease .ticket h3 span:not(:first-child):not(:last-child):after {
content: " :: ";
}
#cxm_grease .menu span:not(:last-child):after {
content: " :: ";
}
#cxm_grease .note h3 span:not(:last-child):after {
content: " :: ";
}
#cxm_grease .menu a, #cxm_grease .ticket h3 a, #cxm_grease .note h3 a {
color: white;
}
#cxm_grease .note p h1 { font-size: 200%; }
#cxm_grease .note p h2 { font-size: 175%; }
#cxm_grease .note p h3 { font-size: 150%; }
#cxm_grease .note p h4 { font-size: 125%; }
#cxm_grease .note p h5 { font-size: 100%; }
#cxm_grease .note p em { font-style: italic; }
#cxm_grease .note p strong { font-weight: bold; }
#cxm_grease .note p ul li {
list-style-type: disc;
}
#cxm_grease .note p ol li {
list-style-type: decimal;
}
#cxm_grease .note p blockquote {
margin-bottom: 18px;
border-left: 5px solid #EEE;
padding-left: 15px;
}
#cxm_grease .note p img {
display: inline-block;
}
*/});
var $div = [];
document.onreadystatechange = function () {
var state = document.readyState
console.log("ready state: " + state);
if (state == 'interactive') {
supportTicketLink();
}
}
function loadComplete() {
if ($('#loadingOverlay').is(':visible') || $("#ticketID").val() === undefined) return; // sill loading
clearInterval(timer);
var id = $("#ticketID").val();
if (id === undefined) {
console.log("couldn't find ticket id, aborting");
$('.appLayout').show();
return;
}
$('<style type="text/css">' + css + '</style>').appendTo('head');
$('<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.7/styles/zenburn.min.css">').appendTo('head');
$div = $('<div id="cxm_grease" />').prependTo('body');
$('.appLayout').hide();
createMenuDiv();
createTicketDiv(id);
createNoteDivs();
// show ticket url
var url = "http://" + window.location.hostname + ":8080/CXM/entity/#ticket=" + id;
window.history.pushState("", "", url);
}
var timer = setInterval(loadComplete, 100);
function supportTicketLink() {
//http://192.168.0.68:8080/CXM/entity/#ticket=15-19162
//http://cxm.rosnet.com:8080/CXM/entity/#ticket=19162
if (!window.location.hash) return;
if (window.location.hash.indexOf("#ticket=") != 0) return;
console.log("handling ticket link");
var id = window.location.hash.split("=")[1];
if (id.indexOf("-") != -1) {
id = id.split("-")[1];
}
$("<form/>")
.attr("action", "/CXM/entity/getEntityDetails")
.attr("method", "POST")
.append($("<input/>").attr("type", "hidden").attr("name", "entityId").attr("value", id))
.append($("<input/>").attr("type", "hidden").attr("name", "moduleUname").attr("value", "Ticket"))
.append($("<input/>").attr("type", "hidden").attr("name", "forView").attr("value", "false"))
.append($("<input/>").attr("type", "hidden").attr("name", "parentModName").attr("value", ""))
.append($("<input/>").attr("type", "hidden").attr("name", "parentInstanceId").attr("value", "0"))
.append($("<input/>").attr("type", "hidden").attr("name", "extendedFromModuleUName").attr("value", ""))
.append($("<input/>").attr("type", "hidden").attr("name", "extendeFromModuleInstanceId").attr("value", "0"))
.appendTo($(document.body))
.submit();
}
function createMenuDiv() {
$div.append($("<div/>")
.addClass("menu")
.append($("<span/>").append($("<a/>")
.attr("href", "#").text("toggle cxm ui")
.click(function () { $(".appLayout").toggle(); })))
.append($("<span/>").append($("<a/>")
.attr("href", "#").text("refresh")
.click(refreshEntity)))
.append($("<span/>").append($("<a/>")
.attr("href", "#").text("add note")
.click(function () {
$("span[widgetid='ticketLineItemBtn']").find("input").click();
})))
.append($("<span/>").append($("<a/>")
.attr("href", "#").text("assign")
.click(function () { alert("not implemented yet"); })))
);
}
function createTicketDiv(id) {
var title = $("#ticketTitle").val();
var recieved = $("#recdDate").val() + ' ' + $("#recdTime").val();
var account = $("#skipaccount").val();
var site = $("#skipsite").val();
var location = $("#skiplocation").val();
var assignee = $('#assignedTo').val();
openSubmodule('attachments', true); // make attachments available
$div.append($("<div />")
.addClass("ticket")
.append($("<div class='assignee' />").text(" Assigned: " + assignee))
.append($("<h3/>")
.append($("<span/>").text(id + " " + title))
.append($("<span/>").text(recieved))
.append($("<span/>").text(account + " " + site + " " + location))
)
.append($("<div/>").addClass("attachments")
.append($("td.field-attachmentName").find("a")))
.append($("<p/>").append(
$("#probDesc_iframe").contents().find("#dijitEditorBody")
.clone()
.attr('contenteditable', 'false')
.attr('id', 'dijitEditorBodyClone')
))
);
$(".btnCloseAttachment").find("input").click(); // back to default tab
}
function createNoteDivs() {
var notes = [];
// gt(0) - the first element is a header row
$('.field-ttproblem:gt(0)').each(function (index) {
var note = { text: $(this).text() };
notes.push(note);
});
$('.field-ttresolution:gt(0)').each(function (index) {
var note = notes[index];
if (note.text.length > 0 && $(this).text().length > 0) {
note.text += "\n";
}
note.text += $(this).text();
});
$('.field-ttworkby:gt(0)').each(function (index) {
notes[index].user = $(this).text();
});
$('.field-ttdate:gt(0)').each(function (index) {
notes[index].date = $(this).text();
});
$('.field-ttstart:gt(0)').each(function (index) {
notes[index].date += " " + $(this).text();
});
$('.field-ttid:gt(0)').each(function (index) {
notes[index].id = $(this).text();
});
for (var i = 0; i < notes.length; i++) {
var text = notes[i].text;
text = text.replace(/\n/g, " \n");
var onclick = "clickEditFormtroubleViewGrid(" + notes[i].id + ",'view')";
$div.append($("<div/>")
.addClass("note")
.append($("<h3/>")
.append($("<span/>").text(notes[i].date))
.append($("<span/>").text(notes[i].user))
.append($("<span/>")
.append($('<a onclick="' + onclick + '"/>')
.attr("href", "#").text("view")
)))
.append($("<p/>")
.html(showdownConverter.makeHtml(text)))
);
}
$('pre code').each(function (i, block) {
hljs.highlightBlock(block);
});
}