7326f05e30b05c38fb7101b80a4eece2a1a8f784
nas ! I broke everything when m...

nas authored 13 years ago

1) /* Javascript for the main Helpdesk */
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

2) /*global ajax_indicator smf_prepareScriptUrl smf_scripturl sceditor shd_sendJSONDocument in_array shd_quickTicketJump shd_ajax_problem shd_quickTicketJump oEditorHandle_shd_message*/
nas ! I broke everything when m...

nas authored 13 years ago

3) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

4) /* Implant a JSON handler for Ajax */
5) function shd_getJSONDocument(sUrl, funcCallback, sMethod)
6) {
7) 	ajax_indicator(true);
8) 
9) 	if (typeof(sMethod) == 'undefined')
10) 		sMethod = 'GET';
11) 
12) 	var oMyDoc = $.ajax({
13) 		method: sMethod,
14) 		url: sUrl,
15) 		cache: false,
16) 		dataType: 'json',
17) 		success: function(responseJSON) {
18) 			if (typeof(funcCallback) != 'undefined')
19) 			{
20) 				ajax_indicator(false);
21) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

22) 				funcCallback.call(this, responseJSON);
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

23) 			}
24) 		},
25) 	});
26) 
27) 	return oMyDoc;
28) }
29) 
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

30) // eslint-disable-next-line no-unused-vars
jdarwood007 Add support to preview cann...

jdarwood007 authored 5 years ago

31) function shd_sendJSONDocument(sUrl, oData, funcCallback)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

32) {
jdarwood007 Add support to preview cann...

jdarwood007 authored 5 years ago

33) 	ajax_indicator(true);
34) 
35) 	var oMyDoc = $.ajax({
36) 		method: 'POST',
37) 		url: sUrl,
38) 		cache: false,
39) 		dataType: 'json',
40) 		data: oData,
41) 		success: function(responseJSON) {
42) 			if (typeof(funcCallback) != 'undefined')
43) 			{
44) 				ajax_indicator(false);
45) 
46) 				funcCallback.call(this, responseJSON);
47) 			}
48) 		},
49) 	});
50) 
51) 	return oMyDoc;
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

52) }
53) 
nas ! I broke everything when m...

nas authored 13 years ago

54) /* The privacy toggle in AJAX */
55) function shd_privacyControl(oOpts)
56) {
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

57) 	this.opt = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

58) 	$(document).ready(this.init.bind(this));
nas ! I broke everything when m...

nas authored 13 years ago

59) }
60) 
61) shd_privacyControl.prototype.init = function ()
62) {
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

63) 	$('#' + this.opt.sSrcA).on('click', this.action.bind(this));
nas ! I broke everything when m...

nas authored 13 years ago

64) }
65) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

66) shd_privacyControl.prototype.action = function (e)
nas ! I broke everything when m...

nas authored 13 years ago

67) {
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

68) 	e.preventDefault();
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

69) 	shd_getJSONDocument(this.opt.sUrl + ';' + this.opt.sSession, this.callback.bind(this));
nas ! I broke everything when m...

nas authored 13 years ago

70) 	return false;
71) }
72) 
73) shd_privacyControl.prototype.callback = function (oRecvd)
74) {
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

75) 	if (oRecvd && oRecvd.success === false)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

76) 		alert(oRecvd.error);
77) 	else if (oRecvd && oRecvd.message)
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

78) 		$('#' + this.opt.sDestSpan).html(oRecvd.message);
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

79) 	else if (confirm(shd_ajax_problem))
80) 		window.location = smf_scripturl + '?action=helpdesk;sa=privacychange;ticket=' + this.opt.ticket + ';' + this.opt.sSession;
nas ! I broke everything when m...

nas authored 13 years ago

81) 
82) 	return false;
83) }
84) 
85) /* The urgency doodad */
86) function shd_urgencyControl(oOpts)
87) {
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

88) 	this.opt = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

89) 	$(document).ready(this.init.bind(this));
nas ! I broke everything when m...

nas authored 13 years ago

90) }
91) 
92) shd_urgencyControl.prototype.init = function ()
93) {
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

94) 	for (var i in this.opt.aButtonOps)
nas ! I broke everything when m...

nas authored 13 years ago

95) 	{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

96) 		if (!Object.prototype.hasOwnProperty.call(this.opt.aButtonOps, i))
jdarwood007 Make sure the property exis...

jdarwood007 authored 7 years ago

97) 			continue;
98) 
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

99) 		var oDiv = $('#urglink_' + this.opt.aButtonOps[i]);
jdarwood007 Stricter checking on javasc...

jdarwood007 authored 6 years ago

100) 		if (oDiv !== null && i == 'up')
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

101) 			oDiv.on('click', this.actionUp.bind(this));
jdarwood007 Stricter checking on javasc...

jdarwood007 authored 6 years ago

102) 		else if (oDiv !== null && i == 'down')
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

103) 			oDiv.on('click', this.actionDown.bind(this)); // I *did* try to make this a single parameterised function but it always fired when it wasn't supposed to
nas ! I broke everything when m...

nas authored 13 years ago

104) 	}
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

105) 
106) 	// Setup the assign by list option.
107) 	this.bCollapsed = true;
108) 	this.opt.sUrlExpand = smf_prepareScriptUrl(smf_scripturl) + 'action=helpdesk;sa=ajax;op=urgencylist;ticket=' + this.opt.iTicketId;
109) 	this.opt.sUrlAssign = smf_prepareScriptUrl(smf_scripturl) + 'action=helpdesk;sa=ajax;op=urgency;assign;ticket=' + this.opt.iTicketId;
110) 	$('#' + this.opt.sSelectButtonId).html('<img src="' + this.opt.sImageCollapsed + '" id="urgency_' + this.opt.sSelf + '" class="shd_urgency_button">');
111) 	$('.shd_ticketdetails').on('click', '#urgency_' + this.opt.sSelf, this.clickList.bind(this));
112) 
nas ! I broke everything when m...

nas authored 13 years ago

113) }
114) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

115) shd_urgencyControl.prototype.actionUp = function (e)
nas ! I broke everything when m...

nas authored 13 years ago

116) {
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

117) 	e.preventDefault();
118) 	return this.action('up');
nas ! I broke everything when m...

nas authored 13 years ago

119) }
120) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

121) shd_urgencyControl.prototype.actionDown = function (e)
nas ! I broke everything when m...

nas authored 13 years ago

122) {
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

123) 	e.preventDefault();
124) 	return this.action('down');
nas ! I broke everything when m...

nas authored 13 years ago

125) }
126) 
127) shd_urgencyControl.prototype.action = function (direction)
128) {
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

129) 	this.direction = direction;
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

130) 	shd_getJSONDocument(this.opt.sUrl + this.opt.aButtonOps[direction] + ';' + this.opt.sSession, this.callback.bind(this));
nas ! I broke everything when m...

nas authored 13 years ago

131) 	return false;
132) }
133) 
134) shd_urgencyControl.prototype.callback = function (oRecvd)
135) {
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

136) 	if (oRecvd && oRecvd.success === false)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

137) 		alert(oRecvd.error);
138) 	else if (oRecvd && oRecvd.message)
nas ! I broke everything when m...

nas authored 13 years ago

139) 	{
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

140) 		$('#' + this.opt.sDestSpan).html(oRecvd.message);
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

141) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

142) 		var btn_set = ['increase', 'decrease'];
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

143) 		for (var i in btn_set)
nas ! I broke everything when m...

nas authored 13 years ago

144) 		{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

145) 			if (!Object.prototype.hasOwnProperty.call(btn_set, i))
jdarwood007 Additional cleanups

jdarwood007 authored 5 years ago

146) 				continue;
147) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

148) 			var oBtn = oRecvd[btn_set[i]];
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

149) 			$('#urgency_' + btn_set[i]).html(oBtn ? oBtn : '');
nas ! I broke everything when m...

nas authored 13 years ago

150) 		}
151) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

152) 		// Attach JS events to new links
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

153) 		this.init();
nas ! I broke everything when m...

nas authored 13 years ago

154) 	}
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

155) 	else if (confirm(shd_ajax_problem))
156) 		window.location = smf_scripturl + '?action=helpdesk;sa=urgencychange;ticket=' + this.opt.iTicketId + ';change=' + this.opt.aButtonOps[this.direction] + ';' + this.opt.sSession;
nas ! I broke everything when m...

nas authored 13 years ago

157) 
158) 	return false;
159) }
160) 
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

161) shd_urgencyControl.prototype.clickList = function ()
162) {
163) 	if (this.bCollapsed)
164) 		this.expandList();
165) 	else
166) 		this.collapseList();
167) }
168) 
169) shd_urgencyControl.prototype.expandList = function ()
170) {
171) 	this.bCollapsed = false;
172) 	$('#urgency_' + this.opt.sSelf).attr('src', this.opt.sImageExpanded);
173) 
174) 	// Fetch the list of items
175) 	shd_getJSONDocument(this.opt.sUrlExpand + ';' + this.opt.sSession, this.expandList_callback.bind(this));
176) }
177) 
178) shd_urgencyControl.prototype.expandList_callback = function (oRecvd)
179) {
180) 	if (oRecvd && oRecvd.success === false)
181) 		alert(oRecvd.error);
182) 	else if (oRecvd && oRecvd.urgencies)
183) 	{
184) 		$('#' + this.opt.sSelectListId).show();
185) 
186) 		var newhtml = '';
187) 		var cur = 0;
188) 		for (var i in oRecvd.urgencies)
189) 		{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

190) 			if (!Object.prototype.hasOwnProperty.call(oRecvd.urgencies, i))
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

191) 				continue;
192) 
193) 			cur = oRecvd.urgencies[i];
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

194) 			var selected = cur.selected ? ' selected="selected"' : '';
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

195) 			newhtml += '<option class="shd_urgencies" data-id="' + cur.id + '"' + selected + '>' + cur.name + '</option>';
196) 		}
197) 
198) 		$('#' + this.opt.sSelectListId).html(newhtml);
199) 		$('#' + this.opt.sSelectListId).on('change', this.assignUrgency.bind(this));
200) 	}
201) }
202) 
203) shd_urgencyControl.prototype.assignUrgency = function (e)
204) {
205) 	// Click handler for the assignment list, to issue the assign
206) 	ajax_indicator(true);
207) 
208) 	var selectedIndex = e.currentTarget.selectedIndex;	
209) 	shd_getJSONDocument(this.opt.sUrlAssign + ';urgency=' + e.currentTarget[selectedIndex].dataset.id + ';'+ this.opt.sSession, this.assignUrgencyCallback.bind(this));
210) }
211) 
212) shd_urgencyControl.prototype.assignUrgencyCallback = function(oRecvd)
213) {
214) 	// Click handler callback for assignment, to handle once the request has been made
215) 	this.collapseList();
216) 
217) 	if (oRecvd && oRecvd.success === false)
218) 		alert(oRecvd.error);
219) 	else if (oRecvd && oRecvd.message)
220) 		document.getElementById(this.opt.sDestSpan).innerHTML = oRecvd.message;
221) }
222) 
223) shd_urgencyControl.prototype.collapseList = function ()
224) {
225) 	this.bCollapsed = true;
226) 	$('#' + this.opt.sSelectListId).hide().html();
227) 	$('#urgency_' + this.opt.sSelf).attr('src', this.opt.sImageCollapsed);
228) }
229) 
230) 
nas ! I broke everything when m...

nas authored 13 years ago

231) /* Attachment selector, based on http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
232) * The code below is modified under the MIT licence, http://the-stickman.com/using-code-from-this-site-ie-licence/ not reproduced here for
233) * convenience of users using this software (as this is an active downloaded file) */
234) function shd_attach_select(oOptions)
235) {
236) 	shd_attach_select.prototype.opts = oOptions;
237) 	shd_attach_select.prototype.count = 0;
238) 	shd_attach_select.prototype.id = 0;
239) 	shd_attach_select.prototype.max = (oOptions.max) ? oOptions.max : -1;
240) 	shd_attach_select.prototype.addElement(document.getElementById(shd_attach_select.prototype.opts.file_item));
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

241) }
nas ! I broke everything when m...

nas authored 13 years ago

242) 
243) shd_attach_select.prototype.addElement = function (element)
244) {
245) 	// Make sure it's a file input element, ignore it if not
246) 	if (element.tagName == 'INPUT' && element.type == 'file')
247) 	{
248) 		element.name = 'file_' + this.id++;
249) 		element.multi_selector = this;
250) 		element.onchange = function()
251) 		{
252) 			if (element.value == '')
253) 				return;
254) 
255) 			// Check if it's a valid extension (if we're checking such things)
256) 			if (!shd_attach_select.prototype.checkExtension(element.value))
257) 			{
258) 				alert(shd_attach_select.prototype.opts.message_ext_error_final);
259) 				element.value = '';
260) 				return;
261) 			}
262) 
263) 			var new_element = document.createElement('input');
264) 			new_element.type = 'file';
265) 			new_element.className = 'input_file';
266) 			new_element.setAttribute('size', '60');
267) 
268) 			// Add new element, update everything
269) 			this.parentNode.insertBefore(new_element, this);
270) 			this.multi_selector.addElement(new_element);
271) 			this.multi_selector.addListRow(this);
272) 
273) 			// Hide this: we can't use display:none because Safari doesn't like it
274) 			this.style.position = 'absolute';
275) 			this.style.left = '-1000px';
276) 		};
277) 
278) 		this.count++;
279) 		shd_attach_select.prototype.current_element = element;
280) 		this.checkActive();
281) 	}
282) };
283) 
284) shd_attach_select.prototype.checkExtension = function (filename)
285) {
286) 	if (!shd_attach_select.prototype.opts.attachment_ext)
287) 		return true; // we're not checking
288) 
jdarwood007 Stricter checking on javasc...

jdarwood007 authored 6 years ago

289) 	if (!filename || filename.length === 0)
nas ! I broke everything when m...

nas authored 13 years ago

290) 	{
291) 		shd_attach_select.prototype.opts.message_ext_error_final = shd_attach_select.prototype.opts.message_ext_error.replace(' ({ext})', '');
292) 		return false; // pfft, didn't specify anything
293) 	}
294) 
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

295) 	var dot = filename.lastIndexOf('.');
nas ! I broke everything when m...

nas authored 13 years ago

296) 	if (dot == -1)
297) 	{
298) 		shd_attach_select.prototype.opts.message_ext_error_final = shd_attach_select.prototype.opts.message_ext_error.replace(' ({ext})', '');
299) 		return false; // no extension
300) 	}
301) 
302) 	var ext = (filename.substr(dot + 1, filename.length)).toLowerCase();
303) 	var arr = shd_attach_select.prototype.opts.attachment_ext;
304) 	var func = Array.prototype.indexOf ?
305) 		function(arr, obj) { return arr.indexOf(obj) !== -1; } :
306) 		function(arr, obj) {
gruffen ! Minor code formatting cle...

gruffen authored 13 years ago

307) 			for (var i = -1, j = arr.length; ++i < j;)
308) 				if (arr[i] === obj) return true;
nas ! I broke everything when m...

nas authored 13 years ago

309) 			return false;
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

310) 		};
nas ! I broke everything when m...

nas authored 13 years ago

311) 	var value = func(arr, ext);
312) 	if (!value)
313) 		shd_attach_select.prototype.opts.message_ext_error_final = shd_attach_select.prototype.opts.message_ext_error.replace('{ext}', ext);
314) 
315) 	return value;
316) }
317) 
318) shd_attach_select.prototype.addListRow = function (element)
319) {
320) 	var new_row = document.createElement('div');
321) 	var new_row_button = document.createElement('input');
322) 	new_row_button.type = 'button';
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

323) 	new_row_button.value = this.opt.message_txt_delete;
Mert ALINBAY Catching the core changes a...

Mert ALINBAY authored 6 years ago

324) 	new_row_button.className = 'button';
nas ! I broke everything when m...

nas authored 13 years ago

325) 	new_row.element = element;
326) 
327) 	new_row_button.onclick = function ()
328) 	{
329) 		// Remove element from form
330) 		this.parentNode.element.parentNode.removeChild(this.parentNode.element);
331) 		this.parentNode.parentNode.removeChild(this.parentNode);
332) 		this.parentNode.element.multi_selector.count--;
333) 		shd_attach_select.prototype.checkActive();
334) 		return false;
335) 	};
336) 
337) 	new_row.innerHTML = element.value + '&nbsp; &nbsp;';
338) 	new_row.appendChild(new_row_button);
jdarwood007 Add ability to change ticke...

jdarwood007 authored 5 years ago

339) 	document.getElementById(this.opt.file_container).appendChild(new_row);
nas ! I broke everything when m...

nas authored 13 years ago

340) };
341) 
342) shd_attach_select.prototype.checkActive = function()
343) {
344) 	var elements = document.getElementsByTagName('input');
345) 	var session_attach = 0;
jdarwood007 Fix up some more code issue...

jdarwood007 authored 7 years ago

346) 	for (var i in elements)
nas ! I broke everything when m...

nas authored 13 years ago

347) 	{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

348) 		if (!Object.prototype.hasOwnProperty.call(elements, i))
jdarwood007 Additional cleanups

jdarwood007 authored 5 years ago

349) 			continue;
350) 
jdarwood007 Stricter checking on javasc...

jdarwood007 authored 6 years ago

351) 		if (elements[i] && elements[i].type == 'checkbox' && elements[i].name == 'attach_del[]' && elements[i].checked === true)
nas ! I broke everything when m...

nas authored 13 years ago

352) 			session_attach++;
353) 	}
354) 
355) 	var flag = !(shd_attach_select.prototype.max == -1 || (this.max >= (session_attach + shd_attach_select.prototype.count)));
356) 	shd_attach_select.prototype.current_element.disabled = flag;
357) }
358) 
359) /* Quick reply stuff */
360) function QuickReply(oOptions)
361) {
362) 	this.opt = oOptions;
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

363) 	$(this.opt.sRepliesSelector + ', ' + this.opt.sFirstPostSelector).on('click', this.quote.bind(this));
nas ! I broke everything when m...

nas authored 13 years ago

364) }
365) 
366) // When a user presses quote, put it in the quick reply box (if expanded).
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

367) QuickReply.prototype.quote = function (e)
nas ! I broke everything when m...

nas authored 13 years ago

368) {
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

369) 	e.preventDefault();
jdarwood007 Typos

jdarwood007 authored 5 years ago

370) 	this.iMessageId = e.currentTarget.dataset.id;
jdarwood007 Stricter checking on javasc...

jdarwood007 authored 6 years ago

371) 
jdarwood007 Typos

jdarwood007 authored 5 years ago

372) 	shd_getJSONDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=quote;quote=' + this.iMessageId + ';' + this.opt.sSession + ';json' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onQuoteReceived.bind(this));
nas ! I broke everything when m...

nas authored 13 years ago

373) 
jdarwood007 Stricter checking on javasc...

jdarwood007 authored 6 years ago

374) 	// Move the view to the quick reply box.
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

375) 	window.location.hash = navigator.appName == 'Microsoft Internet Explorer' ? this.opt.sJumpAnchor : '#' + this.opt.sJumpAnchor;
jdarwood007 Stricter checking on javasc...

jdarwood007 authored 6 years ago

376) 	return false;
nas ! I broke everything when m...

nas authored 13 years ago

377) }
378) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

379) // This is the callback function used after the json request.
380) QuickReply.prototype.onQuoteReceived = function (oRecvd)
nas ! I broke everything when m...

nas authored 13 years ago

381) {
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

382) 	if (oRecvd && oRecvd.success === true && oRecvd.message)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

383) 		oEditorHandle_shd_message.insertText(oRecvd.message, false, true);
nas ! I broke everything when m...

nas authored 13 years ago

384) }
385) 
386) 
gruffen + Canned replies @ Known is...

gruffen authored 12 years ago

387) function CannedReply(oOptions)
388) {
389) 	this.opt = oOptions;
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

390) 	$('#' + this.opt.sCannedRepliesContainerId).show();
391) 	$('#' + this.opt.sCannedRepliesContainerId + ' input.button').on('click', this.getReply.bind(this));
gruffen + Canned replies @ Known is...

gruffen authored 12 years ago

392) }
393) 
jdarwood007 Typos

jdarwood007 authored 5 years ago

394) CannedReply.prototype.getReply = function ()
gruffen + Canned replies @ Known is...

gruffen authored 12 years ago

395) {
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

396) 	var iReplyId = $('#' + this.opt.sSelectContainerId).val();
gruffen + Canned replies @ Known is...

gruffen authored 12 years ago

397) 	if (!iReplyId || parseInt(iReplyId, 10) < 1)
398) 		return false;
399) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

400) 	shd_getJSONDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=canned;ticket=' + this.opt.iTicketId + ';reply=' + iReplyId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';json' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onReplyReceived.bind(this));
gruffen + Canned replies @ Known is...

gruffen authored 12 years ago

401) 
402) 	return false;
403) }
404) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

405) // This is the callback function used after the json request.
406) CannedReply.prototype.onReplyReceived = function (oRecvd)
gruffen + Canned replies @ Known is...

gruffen authored 12 years ago

407) {
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

408) 	if (oRecvd && oRecvd.success === true && oRecvd.message)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

409) 		oEditorHandle_shd_message.insertText(oRecvd.message, false, true);
gruffen + Canned replies @ Known is...

gruffen authored 12 years ago

410) }
411) 
nas ! I broke everything when m...

nas authored 13 years ago

412) // The quick jump function
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

413) // eslint-disable-next-line no-unused-vars
nas ! I broke everything when m...

nas authored 13 years ago

414) function shd_quickTicketJump(id_ticket)
415) {
416) 	window.location.href = smf_prepareScriptUrl(smf_scripturl) + '?action=helpdesk;sa=ticket;ticket=' + id_ticket;
417) 	return false;
418) }
419) 
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

420) /* AJAX assignment */
421) function AjaxAssign(oOptions)
422) {
423) 	this.opt = oOptions;
424) 	this.bCollapsed = true;
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

425) 	this.opt.sUrlExpand = smf_prepareScriptUrl(smf_scripturl) + 'action=helpdesk;sa=ajax;op=assign;ticket=' + this.opt.iTicketId;
426) 	this.opt.sUrlAssign = smf_prepareScriptUrl(smf_scripturl) + 'action=helpdesk;sa=ajax;op=assign2;ticket=' + this.opt.iTicketId;
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

427) 
428) 	// Insert the expand/collapse button
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

429) 	$('#' + this.opt.sId).html('<img src="' + this.opt.sImageCollapsed + '" id="assign_' + this.opt.sSelf + '" class="shd_assign_button">');
430) 	$('.shd_ticketdetails').on('click', '#assign_' + this.opt.sSelf, this.click.bind(this));
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

431) }
432) 
433) AjaxAssign.prototype.click = function ()
434) {
435) 	if (this.bCollapsed)
436) 		this.expand();
437) 	else
438) 		this.collapse();
439) }
440) 
441) AjaxAssign.prototype.expand = function ()
442) {
443) 	this.bCollapsed = false;
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

444) 	$('#assign_' + this.opt.sSelf).attr('src', this.opt.sImageExpanded);
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

445) 
446) 	// Fetch the list of items
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

447) 	shd_getJSONDocument(this.opt.sUrlExpand + ';' + this.opt.sSession, this.expand_callback.bind(this));
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

448) }
449) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

450) AjaxAssign.prototype.expand_callback = function (oRecvd)
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

451) {
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

452) 	if (oRecvd && oRecvd.success === false)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

453) 		alert(oRecvd.error);
454) 	else if (oRecvd && oRecvd.members)
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

455) 	{
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

456) 		$('#' + this.opt.sListId).show();
gruffen ! Minor code formatting cle...

gruffen authored 13 years ago

457) 
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

458) 		var newhtml = '';
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

459) 		var cur = 0;
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

460) 		for (var i in oRecvd.members)
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

461) 		{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

462) 			if (!Object.prototype.hasOwnProperty.call(oRecvd.members, i))
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

463) 				continue;
464) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

465) 			cur = oRecvd.members[i];
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

466) 			newhtml += '<li class="shd_assignees" data-uid="' + cur.uid + '"><img src="' + (cur.admin == 'yes' ? this.opt.sImageAdmin : this.opt.sImageStaff) + '" alt="" class="shd_smallicon">' + cur.name + '</li>';
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

467) 		}
468) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

469) 		$('#' + this.opt.sListId).html(newhtml);
470) 		$('#' + this.opt.sListId).on('click', 'li.shd_assignees', this.assign.bind(this));
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

471) 	}
472) }
473) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

474) AjaxAssign.prototype.assign = function (e)
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

475) {
476) 	// Click handler for the assignment list, to issue the assign
477) 	ajax_indicator(true);
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

478) 
479) 	shd_getJSONDocument(this.opt.sUrlAssign + ';to_user=' + e.currentTarget.dataset.uid + ';'+ this.opt.sSession, this.assign_callback.bind(this));
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

480) }
481) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

482) AjaxAssign.prototype.assign_callback = function(oRecvd)
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

483) {
484) 	// Click handler callback for assignment, to handle once the request has been made
485) 	this.collapse();
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

486) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

487) 	if (oRecvd && oRecvd.success === false)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

488) 		alert(oRecvd.error);
489) 	else if (oRecvd && oRecvd.assigned)
490) 		document.getElementById(this.opt.sAssignedSpan).innerHTML = oRecvd.assigned;
gruffen + AJAX assignment [Feature 61]

gruffen authored 13 years ago

491) }
492) 
493) AjaxAssign.prototype.collapse = function ()
494) {
495) 	this.bCollapsed = true;
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

496) 	$('#' + this.opt.sListId).hide().html();
497) 	$('#assign_' + this.opt.sSelf).attr('src', this.opt.sImageCollapsed);
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

498) }
499) 
500) /* Ajax Notifications List */
501) function shd_notifications(iTicketId, oOptions)
502) {
503) 	this.ticketId = iTicketId;
504) 	this.opt = oOptions;
505) 	this.init();
506) 	return false;
507) }
508) 
509) shd_notifications.prototype.init = function ()
510) {
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

511) 	$('#' + this.opt.sLinkId).on('click', this.receiveNotifications.bind(this));
512) 	$('#' + this.opt.sContainerId).show();
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

513) }
514) 
515) shd_notifications.prototype.receiveNotifications = function ()
516) {
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

517) 	shd_getJSONDocument(smf_prepareScriptUrl(smf_scripturl) + 'action=helpdesk;sa=ajax;op=notify;ticket=' + this.ticketId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + (this.opt.sPinglist ? ';' + this.opt.sPinglist : ''), this.onReceiveNotifications.bind(this));
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

518) 	return false;
519) }
520) 
521) shd_notifications.prototype.onReceiveNotifications = function (oRecvd)
522) {
523) 	if (typeof(oRecvd) == 'undefined')
524) 		return;
525) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

526) 	if (oRecvd && oRecvd.success === false)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

527) 		alert(oRecvd.error);
528) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

529) 	var newhtml = ''; var temphtml = ''; var member = ''; var subtemplate = '';
530) 	var cur = 0; var i = 0; var j = 0; var k = 0;
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

531) 	var template = this.opt.oMainTemplate;
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

532) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

533) 	if (oRecvd.being_notified)
534) 	{
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

535) 		subtemplate = this.opt.oNotifiedTemplate;
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

536) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

537) 		temphtml = '';
538) 		for (i in oRecvd.being_notified)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

539) 		{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

540) 			if (!Object.prototype.hasOwnProperty.call(oRecvd.being_notified, i))
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

541) 				continue;
542) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

543) 			cur = oRecvd.being_notified[i];
544) 			member = subtemplate.replace('%name%', cur);
545) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

546) 			temphtml += member;
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

547) 		}
548) 
549) 		newhtml = template.replace('%title%', oRecvd.being_notified_txt).replace('%subtemplate%', temphtml);
550) 	}
551) 
552) 	if (oRecvd.optional)
553) 	{
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

554) 		subtemplate = this.opt.oOptionalTemplate;
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

555) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

556) 		temphtml = '';
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

557) 		for (i in oRecvd.optional)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

558) 		{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

559) 			if (!Object.prototype.hasOwnProperty.call(oRecvd.optional, i))
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

560) 				continue;
561) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

562) 			cur = oRecvd.optional[i];
563) 
564) 			member = subtemplate.replace('%name%', cur);
565) 			member = member.replace('%index%', i);
566) 			member = member.replace('%index%', i);
567) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

568) 			for (j in oRecvd.selected)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

569) 			{
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

570) 				k = oRecvd.selected[j];
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

571) 				member = member.replace('%checked%', i == k ? ' checked' : '');
572) 			}
573) 
574) 			temphtml += member;
575) 		}
576) 
577) 		newhtml += template.replace('%title%', oRecvd.optional_txt).replace('%subtemplate%', temphtml);
578) 	}
579) 
580) 	if (oRecvd.optional_butoff)
581) 	{
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

582) 		subtemplate = this.opt.oOptionalOffTemplate;
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

583) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

584) 		temphtml = '';
585) 		for (i in oRecvd.optional_butoff)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

586) 		{
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

587) 			if (!Object.prototype.hasOwnProperty.call(oRecvd.optional_butoff, i))
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

588) 				continue;
589) 
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

590) 			cur = oRecvd.optional_butoff[i];
591) 			member = subtemplate.replace('%name%', cur);
592) 			member = member.replace('%index%', i);
593) 			member = member.replace('%index%', i);
594) 
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

595) 			for (j in oRecvd.selected)
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

596) 			{
jdarwood007 Fix a custom item order bug

jdarwood007 authored 5 years ago

597) 				k = oRecvd.selected[j];
jdarwood007 Convert over to JSON from X...

jdarwood007 authored 5 years ago

598) 				member = member.replace('%checked%', i == k ? ' checked' : '');
599) 			}
600) 
601) 			temphtml += member;
602) 		}
603) 
604) 		newhtml += template.replace('%title%', oRecvd.optional_butoff_txt).replace('%subtemplate%', temphtml);
605) 	}
606) 
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

607) 	$('#' + this.opt.sContainerId).html(newhtml);
608) }
609) 
610) /* Go Advanced Handling */
611) function goAdvanced(oOptions)
612) {
613) 	this.opt = oOptions;
614) 	$('#' + this.opt.sAdvancedContainerId).on('click', this.click.bind(this));
615) 
616) 	$(document).ready(this.init.bind(this));
617) }
618) 
jdarwood007 Typos

jdarwood007 authored 5 years ago

619) goAdvanced.prototype.init = function()
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

620) {
621) 	$('#' + this.opt.sBbcContainerId +
622) 		', .' + this.opt.sBbcContainerEditorClass +
623) 		', #' + this.opt.sSmileyContainerId +
624) 		', .' + this.opt.sSmileyContainerEditorClass +
625) 		', .' + this.opt.sAttachContainerId +
626) 		', #' + this.opt.sAdditionalOptionsContainerId
Jeremy D Fix some Javascript errors...

Jeremy D authored 3 years ago

627) 	).hide();
jdarwood007 Cleanup Templates

jdarwood007 authored 5 years ago

628) }
629) 
630) goAdvanced.prototype.click = function(e)
631) {
632) 	e.preventDefault();
633) 
634) 	$('#' + this.opt.sBbcContainerId + ', .' + this.opt.sBbcContainerEditorClass).css('display', this.opt.bAllowBBC ? '' : 'none');
635) 	$('#' + this.opt.sSmileyContainerId + ', .' + this.opt.sSmileyContainerEditorClass).css('display', this.opt.bAllowSmileys ? '' : 'none');
636) 	$('#' + this.opt.sAttachContainerId).css('display', this.opt.bAllowAttach ? '' : 'none');
637) 	$('#' + this.opt.sAdditionalOptionsContainerId).show();
638) 	$('#' + this.opt.sAdvancedContainerId).hide();
639) }
640) 
641) /* Department Filters */
642) function shd_dept_filter(oOptions)
643) {
644) 	this.opt = oOptions;
645) 	$('#' + this.opt.sSelectContainerId).on('change', this.startFilter.bind(this));
646) }
647) 
648) shd_dept_filter.prototype.startFilter = function ()
649) {
650) 	this.displayed = false;
651) 	$(this.opt.oFields).each(this.filterDept.bind(this));
652) }
653) 
jdarwood007 Typos

jdarwood007 authored 5 years ago

654) shd_dept_filter.prototype.filterDept = function (index)