! I broke everything when m...
nas authored 13 years ago
|
1) /* Javascript for the main Helpdesk */
2)
3) /* The privacy toggle in AJAX */
4) function shd_privacyControl(oOpts)
5) {
6) shd_privacyControl.prototype.opts = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
|
! Minor code formatting cle...
gruffen authored 13 years ago
|
7) if (window.addEventListener)
|
! I broke everything when m...
nas authored 13 years ago
|
8) window.addEventListener('load', shd_privacyControl.prototype.init, false);
|
! Minor code formatting cle...
gruffen authored 13 years ago
|
9) else if (window.attachEvent)
|
! I broke everything when m...
nas authored 13 years ago
|
10) window.attachEvent('onload', shd_privacyControl.prototype.init);
11) }
12)
13) shd_privacyControl.prototype.init = function ()
14) {
15) var oDiv = document.getElementById(shd_privacyControl.prototype.opts.sSrcA);
16) if (oDiv != null)
17) oDiv.onclick = shd_privacyControl.prototype.action;
18) }
19)
20) shd_privacyControl.prototype.action = function ()
21) {
22) ajax_indicator(true);
23) getXMLDocument(shd_privacyControl.prototype.opts.sUrl + ';' + shd_privacyControl.prototype.opts.sSession, shd_privacyControl.prototype.callback);
24) return false;
25) }
26)
27) shd_privacyControl.prototype.callback = function (oRecvd)
28) {
29) ajax_indicator(false);
30) if (oRecvd)
31) {
32) var errors = oRecvd.getElementsByTagName('error');
33) if (errors.length > 0)
34) {
35) var msg = "";
36) for (var i = 0; i < errors.length; i++)
37) msg += errors[i].firstChild.nodeValue + "\n";
38) alert(msg);
39) }
40) else
41) {
42) var msg = oRecvd.getElementsByTagName('message');
43) if (msg.length > 0)
44) {
45) var oSpan = document.getElementById(shd_privacyControl.prototype.opts.sDestSpan);
46) oSpan.firstChild.nodeValue = msg[0].firstChild.nodeValue;
47) }
48) }
49) }
50) else
51) if (confirm(shd_ajax_problem))
52) window.location = smf_scripturl + '?action=helpdesk;sa=privacychange;ticket=' + shd_privacyControl.prototype.opts.ticket + ';' + shd_privacyControl.prototype.opts.sSession;
53)
54) return false;
55) }
56)
57) /* The urgency doodad */
58) function shd_urgencyControl(oOpts)
59) {
60) shd_urgencyControl.prototype.opts = oOpts; // attaches to the link, but it doesn't exist until after DOM is loaded!
|
! Minor code formatting cle...
gruffen authored 13 years ago
|
61) if (window.addEventListener)
|
! I broke everything when m...
nas authored 13 years ago
|
62) window.addEventListener('load', shd_urgencyControl.prototype.init, false);
|
! Minor code formatting cle...
gruffen authored 13 years ago
|
63) else if (window.attachEvent)
|
! I broke everything when m...
nas authored 13 years ago
|
64) window.attachEvent('onload', shd_urgencyControl.prototype.init);
65) }
66)
67) shd_urgencyControl.prototype.init = function ()
68) {
69) for (var i in shd_urgencyControl.prototype.opts.aButtonOps)
70) {
|
Make sure the property exis...
jdarwood007 authored 7 years ago
|
71) if (!shd_urgencyControl.prototype.opts.aButtonOps.hasOwnProperty(i))
72) continue;
73)
|
! I broke everything when m...
nas authored 13 years ago
|
74) var oDiv = document.getElementById('urglink_' + shd_urgencyControl.prototype.opts.aButtonOps[i]);
75) if (oDiv != null && i == 'up')
76) oDiv.onclick = shd_urgencyControl.prototype.actionUp;
|
! Minor code formatting cle...
gruffen authored 13 years ago
|
77) else if (oDiv != null && i == 'down')
|
! I broke everything when m...
nas authored 13 years ago
|
78) oDiv.onclick = shd_urgencyControl.prototype.actionDown; // I *did* try to make this a single parameterised function but it always fired when it wasn't supposed to
79) }
80) }
81)
82) shd_urgencyControl.prototype.actionUp = function ()
83) {
84) return shd_urgencyControl.prototype.action('up');
85) }
86)
87) shd_urgencyControl.prototype.actionDown = function ()
88) {
89) return shd_urgencyControl.prototype.action('down');
90) }
91)
92) shd_urgencyControl.prototype.action = function (direction)
93) {
94) ajax_indicator(true);
95) shd_urgencyControl.prototype.opts.direction = direction;
96) getXMLDocument(shd_urgencyControl.prototype.opts.sUrl + shd_urgencyControl.prototype.opts.aButtonOps[direction] + ';' + shd_urgencyControl.prototype.opts.sSession, shd_urgencyControl.prototype.callback);
97) return false;
98) }
99)
100) shd_urgencyControl.prototype.callback = function (oRecvd)
101) {
102) ajax_indicator(false);
103) if (oRecvd)
104) {
105) var errors = oRecvd.getElementsByTagName('error');
106) if (errors.length > 0)
107) {
108) var msg = "";
109) for (var i = 0; i < errors.length; i++)
110) msg += errors[i].firstChild.nodeValue + "\n";
111) alert(msg);
112) }
113) else
114) {
115) var msg = oRecvd.getElementsByTagName('message');
116) if (msg.length > 0)
117) {
118) var oSpan = document.getElementById(shd_urgencyControl.prototype.opts.sDestSpan);
119) setInnerHTML(oSpan, msg[0].firstChild.nodeValue);
120) }
121) // Now to reset the buttons
122) var btn_set = [ "increase", "decrease" ];
123)
124) for (var i in btn_set)
125) {
126) var oBtn = oRecvd.getElementsByTagName(btn_set[i]);
127) var oSpan = document.getElementById('urgency_' + btn_set[i]);
128) setInnerHTML(oSpan, (oBtn.length != 0 ? oBtn[0].firstChild.nodeValue : ''));
129) }
130) // Attach JS events to new links
131) shd_urgencyControl.prototype.init();
132) }
133) }
134) else
135) if (confirm(shd_ajax_problem))
136) window.location = smf_scripturl + '?action=helpdesk;sa=urgencychange;ticket=' + shd_urgencyControl.prototype.opts.ticket + ';change=' + shd_urgencyControl.prototype.opts.aButtonOps[shd_urgencyControl.prototype.opts.direction] + ';' + shd_urgencyControl.prototype.opts.sSession;
137)
138) return false;
139) }
140)
141) /* Attachment selector, based on http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/
142) * The code below is modified under the MIT licence, http://the-stickman.com/using-code-from-this-site-ie-licence/ not reproduced here for
143) * convenience of users using this software (as this is an active downloaded file) */
144) function shd_attach_select(oOptions)
145) {
146) shd_attach_select.prototype.opts = oOptions;
147) shd_attach_select.prototype.count = 0;
148) shd_attach_select.prototype.id = 0;
149) shd_attach_select.prototype.max = (oOptions.max) ? oOptions.max : -1;
150) shd_attach_select.prototype.addElement(document.getElementById(shd_attach_select.prototype.opts.file_item));
151) };
152)
153) shd_attach_select.prototype.addElement = function (element)
154) {
155) // Make sure it's a file input element, ignore it if not
156) if (element.tagName == 'INPUT' && element.type == 'file')
157) {
158) element.name = 'file_' + this.id++;
159) element.multi_selector = this;
160) element.onchange = function()
161) {
162) if (element.value == '')
163) return;
164)
165) // Check if it's a valid extension (if we're checking such things)
166) if (!shd_attach_select.prototype.checkExtension(element.value))
167) {
168) alert(shd_attach_select.prototype.opts.message_ext_error_final);
169) element.value = '';
170) return;
171) }
172)
173) var new_element = document.createElement('input');
174) new_element.type = 'file';
175) new_element.className = 'input_file';
176) new_element.setAttribute('size', '60');
177)
178) // Add new element, update everything
179) this.parentNode.insertBefore(new_element, this);
180) this.multi_selector.addElement(new_element);
181) this.multi_selector.addListRow(this);
182)
183) // Hide this: we can't use display:none because Safari doesn't like it
184) this.style.position = 'absolute';
185) this.style.left = '-1000px';
186) };
187)
188) this.count++;
189) shd_attach_select.prototype.current_element = element;
190) this.checkActive();
191) }
192) };
193)
194) shd_attach_select.prototype.checkExtension = function (filename)
195) {
196) if (!shd_attach_select.prototype.opts.attachment_ext)
197) return true; // we're not checking
198)
199) if (!filename || filename.length == 0)
200) {
201) shd_attach_select.prototype.opts.message_ext_error_final = shd_attach_select.prototype.opts.message_ext_error.replace(' ({ext})', '');
202) return false; // pfft, didn't specify anything
203) }
204)
205) var dot = filename.lastIndexOf(".");
206) if (dot == -1)
207) {
208) shd_attach_select.prototype.opts.message_ext_error_final = shd_attach_select.prototype.opts.message_ext_error.replace(' ({ext})', '');
209) return false; // no extension
210) }
211)
212) var ext = (filename.substr(dot + 1, filename.length)).toLowerCase();
213) var arr = shd_attach_select.prototype.opts.attachment_ext;
214) var func = Array.prototype.indexOf ?
215) function(arr, obj) { return arr.indexOf(obj) !== -1; } :
216) function(arr, obj) {
|
! Minor code formatting cle...
gruffen authored 13 years ago
|
217) for (var i = -1, j = arr.length; ++i < j;)
218) if (arr[i] === obj) return true;
|
! I broke everything when m...
nas authored 13 years ago
|
219) return false;
220) };
221) var value = func(arr, ext);
222) if (!value)
223) shd_attach_select.prototype.opts.message_ext_error_final = shd_attach_select.prototype.opts.message_ext_error.replace('{ext}', ext);
224)
225) return value;
226) }
227)
228) shd_attach_select.prototype.addListRow = function (element)
229) {
230) var new_row = document.createElement('div');
231) var new_row_button = document.createElement('input');
232) new_row_button.type = 'button';
233) new_row_button.value = this.opts.message_txt_delete;
|
Catching the core changes a...
Mert ALINBAY authored 6 years ago
|
234) new_row_button.className = 'button';
|
! I broke everything when m...
nas authored 13 years ago
|
235) new_row.element = element;
236)
237) new_row_button.onclick = function ()
238) {
239) // Remove element from form
240) this.parentNode.element.parentNode.removeChild(this.parentNode.element);
241) this.parentNode.parentNode.removeChild(this.parentNode);
242) this.parentNode.element.multi_selector.count--;
243) shd_attach_select.prototype.checkActive();
244) return false;
245) };
246)
247) new_row.innerHTML = element.value + ' ';
248) new_row.appendChild(new_row_button);
249) document.getElementById(this.opts.file_container).appendChild(new_row);
250) };
251)
252) shd_attach_select.prototype.checkActive = function()
253) {
254) var elements = document.getElementsByTagName('input');
255) var session_attach = 0;
|
Fix up some more code issue...
jdarwood007 authored 7 years ago
|
256) for (var i in elements)
|
! I broke everything when m...
nas authored 13 years ago
|
257) {
258) if (elements[i] && elements[i].type == 'checkbox' && elements[i].name == 'attach_del[]' && elements[i].checked == true)
259) session_attach++;
260) }
261)
262) var flag = !(shd_attach_select.prototype.max == -1 || (this.max >= (session_attach + shd_attach_select.prototype.count)));
263) shd_attach_select.prototype.current_element.disabled = flag;
264) }
265)
266) /* Quick reply stuff */
267)
268) function QuickReply(oOptions)
269) {
270) this.opt = oOptions;
271) this.bCollapsed = this.opt.bDefaultCollapsed;
272) }
273)
274) // When a user presses quote, put it in the quick reply box (if expanded).
275) QuickReply.prototype.quote = function (iMessageId, sSessionId, sSessionVar, bTemplateUpgraded)
276) {
277) // Add backwards compatibility with old themes.
278) if (sSessionVar == true)
279) {
280) bTemplateUpgraded = true;
281) sSessionVar = 'sesc';
282) }
283)
284) if (this.bCollapsed)
285) {
286) // This is for compatibility.
287) if (bTemplateUpgraded)
288) return true;
289) else
290) {
291) window.location.href = smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=reply;quote=' + iMessageId + ';ticket=' + this.opt.iTicketId + '.' + this.opt.iStart + ';' + sSessionVar + '=' + sSessionId;
292) return false;
293) }
294) }
295) else
296) {
297) // Doing it the XMLhttp way?
298) if (window.XMLHttpRequest)
299) {
300) ajax_indicator(true);
301) getXMLDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=quote;quote=' + iMessageId + ';' + sSessionVar + '=' + sSessionId + ';xml' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onQuoteReceived);
302) }
303)
304) // Move the view to the quick reply box.
305) if (navigator.appName == 'Microsoft Internet Explorer')
306) window.location.hash = this.opt.sJumpAnchor;
307) else
308) window.location.hash = '#' + this.opt.sJumpAnchor;
309)
310) return false;
311) }
312) }
313)
314) // This is the callback function used after the XMLhttp request.
315) QuickReply.prototype.onQuoteReceived = function (oXMLDoc)
316) {
317) var sQuoteText = '';
318)
319) for (var i = 0; i < oXMLDoc.getElementsByTagName('quote')[0].childNodes.length; i++)
320) sQuoteText += oXMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue;
321)
322) oEditorHandle_shd_message.insertText(sQuoteText, false, true);
323)
324) ajax_indicator(false);
325) }
326)
327) // The function handling the swapping of the quick reply.
328) QuickReply.prototype.swap = function ()
329) {
330) document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
331) document.getElementById(this.opt.sContainerId).style.display = this.bCollapsed ? '' : 'none';
332) document.getElementById(this.opt.sFooterId).style.display = this.bCollapsed ? '' : 'none';
|
! grid_header was all broke...
nas authored 13 years ago
|
333) document.getElementById(this.opt.sHeaderId).setAttribute('class', (this.bCollapsed ? 'title_bar grid_header' : 'title_bar'));
|
! I broke everything when m...
nas authored 13 years ago
|
334)
335) this.bCollapsed = !this.bCollapsed;
336) }
337)
|
+ Canned replies @ Known is...
gruffen authored 12 years ago
|
338) function CannedReply(oOptions)
339) {
340) this.opt = oOptions;
341) document.getElementById("canned_replies").style.display = "";
342) }
343)
344) CannedReply.prototype.getReply = function ()
345) {
346) var iReplyId = document.getElementById('canned_replies_select').value;
347) if (!iReplyId || parseInt(iReplyId, 10) < 1)
348) return false;
349)
350) // Doing it the XMLhttp way?
351) if (window.XMLHttpRequest)
352) {
353) ajax_indicator(true);
354) getXMLDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=canned;ticket=' + this.opt.iTicketId + ';reply=' + iReplyId + ';' + this.opt.sSessionVar + '=' + this.opt.sSessionId + ';xml' + ';mode=' + (oEditorHandle_shd_message.bRichTextEnabled ? 1 : 0), this.onReplyReceived);
355) }
356)
357) return false;
358) }
359)
360) // This is the callback function used after the XMLhttp request.
361) CannedReply.prototype.onReplyReceived = function (oXMLDoc)
362) {
363) var sQuoteText = '';
364)
365) for (var i = 0; i < oXMLDoc.getElementsByTagName('quote')[0].childNodes.length; i++)
366) sQuoteText += oXMLDoc.getElementsByTagName('quote')[0].childNodes[i].nodeValue;
367)
368) oEditorHandle_shd_message.insertText(sQuoteText, false, true);
369)
370) ajax_indicator(false);
371) }
372)
|
! I broke everything when m...
nas authored 13 years ago
|
373) // The quick jump function
374) function shd_quickTicketJump(id_ticket)
375) {
376) window.location.href = smf_prepareScriptUrl(smf_scripturl) + '?action=helpdesk;sa=ticket;ticket=' + id_ticket;
377) return false;
378) }
379)
380) /* The action log in tickets - Not much. */
381)
382) function ActionLog(oOptions)
383) {
384) this.opt = oOptions;
|
! Ticket action log should...
gruffen authored 12 years ago
|
385) this.bCollapsed = false;
386) document.getElementById(this.opt.sImageId).style.display = '';
387) return false;
|
! I broke everything when m...
nas authored 13 years ago
|
388) }
389)
390) // The function handling the swapping of the ticket log.
391) ActionLog.prototype.swap = function ()
392) {
393) document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
394) document.getElementById(this.opt.sContainerId).style.display = this.bCollapsed ? '' : 'none';
|
! grid_header was all broke...
nas authored 13 years ago
|
395) document.getElementById(this.opt.sHeaderId).setAttribute('class', (this.bCollapsed ? 'title_bar grid_header' : 'title_bar'));
|
! I broke everything when m...
nas authored 13 years ago
|
396)
397) this.bCollapsed = !this.bCollapsed;
398) }
|
+ Custom fields should now...
cookiemonster authored 13 years ago
|
399)
400) function CustomFields(oOptions)
401) {
402) this.opt = oOptions;
403) this.bCollapsed = false;
404) }
405)
406) // Expand and collapse the additional information block
407) CustomFields.prototype.infoswap = function ()
408) {
409) document.getElementById(this.opt.sImageId).src = this.opt.sImagesUrl + "/" + (this.bCollapsed ? this.opt.sImageCollapsed : this.opt.sImageExpanded);
410) document.getElementById(this.opt.sContainerId).style.display = this.bCollapsed ? '' : 'none';
411) document.getElementById(this.opt.sFooterId).style.display = this.bCollapsed ? '' : 'none';
412) document.getElementById(this.opt.sHeaderId).setAttribute('class', (this.bCollapsed ? 'title_bar grid_header' : 'title_bar'));
413)
414) this.bCollapsed = !this.bCollapsed;
|
+ AJAX assignment [Feature 61]
gruffen authored 13 years ago
|
415) }
416)
417) /* AJAX assignment */
418) function AjaxAssign(oOptions)
419) {
420) this.opt = oOptions;
421) this.bCollapsed = true;
422)
423) // Insert the expand/collapse button
|
Catching the core changes a...
Mert ALINBAY authored 6 years ago
|
424) document.getElementById(this.opt.sId).innerHTML = '<img src="' + this.opt.sImagesUrl + "/" + this.opt.sImageCollapsed + '" id="assign_' + this.opt.sSelf + '" class="shd_assign_button" onclick="' + this.opt.sSelf + '.click();">';
|
+ AJAX assignment [Feature 61]
gruffen authored 13 years ago
|
425) }
426)
427) AjaxAssign.prototype.click = function ()
428) {
429) if (this.bCollapsed)
430) this.expand();
431) else
432) this.collapse();
433) }
434)
435) AjaxAssign.prototype.expand = function ()
436) {
437) this.bCollapsed = false;
438) var img = document.getElementById('assign_' + this.opt.sSelf);
439) img.setAttribute('src', this.opt.sImagesUrl + "/" + this.opt.sImageExpanded);
440)
441) // Fetch the list of items
442) ajax_indicator(true);
443) getXMLDocument.call(this, smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=assign;ticket=' + this.opt.iTicketId + ';' + sSessV + '=' + sSessI, this.expand_callback);
444) }
445)
446) AjaxAssign.prototype.expand_callback = function (XMLDoc)
447) {
448) // Receive the list of assignees
449) ajax_indicator(false);
450) var errors = XMLDoc.getElementsByTagName('error');
451) if (errors.length > 0)
452) {
453) alert(errors[0].childNodes[0].nodeValue);
454) this.collapse();
455) }
456) else
457) {
458) var assign_list = document.getElementById(this.opt.sListId);
459) assign_list.innerHTML = '';
460) assign_list.setAttribute('style', 'display:block');
|
! Minor code formatting cle...
gruffen authored 13 years ago
|
461)
|
+ AJAX assignment [Feature 61]
gruffen authored 13 years ago
|
462) var elements = XMLDoc.getElementsByTagName('member');
463) // We could, in all honesty, sit and build the content normally with document.createElement.
464) // But really, this is quicker, not just for us but for the browser too.
465) var newhtml = '';
466) for (var i = 0, n = elements.length; i < n; i++)
467) {
468) newhtml += '<li class="shd_assignees" onclick="' + this.opt.sSelf + '.assign(' + elements[i].getAttribute('uid') + ');">';
|
! Display little admin/staf...
gruffen authored 13 years ago
|
469) if (elements[i].getAttribute('admin'))
|
Catching the core changes a...
Mert ALINBAY authored 6 years ago
|
470) newhtml += '<img src="' + smf_default_theme_url + '/images/simpledesk/' + (elements[i].getAttribute('admin') == 'yes' ? 'admin' : 'staff') + '.png" alt="" class="shd_smallicon"> ';
|
+ AJAX assignment [Feature 61]
gruffen authored 13 years ago
|
471) newhtml += elements[i].childNodes[0].nodeValue + '</li>';
472) }
473)
474) assign_list.innerHTML = newhtml;
475) }
476) }
477)
478) AjaxAssign.prototype.assign = function (uid)
479) {
480) // Click handler for the assignment list, to issue the assign
481) ajax_indicator(true);
482) getXMLDocument.call(this, smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=helpdesk;sa=ajax;op=assign2;ticket=' + this.opt.iTicketId + ';to_user=' + uid + ';' + sSessV + '=' + sSessI, this.assign_callback);
483) }
484)
485) AjaxAssign.prototype.assign_callback = function(XMLDoc)
486) {
487) // Click handler callback for assignment, to handle once the request has been made
488) ajax_indicator(false);
489) this.collapse();
490) var errors = XMLDoc.getElementsByTagName('error');
491) if (errors.length > 0)
492) alert(errors[0].childNodes[0].nodeValue);
493) else
494) {
495) var elements = XMLDoc.getElementsByTagName('assigned');
496) document.getElementById(this.opt.sAssignedSpan).innerHTML = elements[0].childNodes[0].nodeValue;
497) }
498) this.collapse();
499) }
500)
501) AjaxAssign.prototype.collapse = function ()
502) {
503) this.bCollapsed = true;
504) var assign_list = document.getElementById(this.opt.sListId);
505) assign_list.innerHTML = '';
506) assign_list.setAttribute('style', 'display:none');
507)
508) var img = document.getElementById('assign_' + this.opt.sSelf);
509) img.setAttribute('src', this.opt.sImagesUrl + "/" + this.opt.sImageCollapsed);
|