00001 // webtrack.js - Main SiT javascript library 00002 00003 // SiT (Support Incident Tracker) - Support call tracking system 00004 // Copyright (C) 2010 The Support Incident Tracker Project 00005 // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors 00006 // 00007 // This software may be used and distributed according to the terms 00008 // of the GNU General Public License, incorporated herein by reference. 00009 // 00010 // Javascript/ECMAscript Functions for SiT (previously known as Webtrack) by Ivan Lucas 00011 // Since v3.30 this requires prototype.js 00012 00013 var popwin; 00014 dashletrefresh = new Array(); 00015 var isIE = /*@cc_on!@*/false; 00016 var mainframe = '50%'; 00017 00027 function incident_details_window(incidentid, win, rtn) 00028 { 00029 // URL = "incident.php?popup=yes&id=" + incidentid; 00030 // URL = application_webpath + "incident_details.php?id=" + incidentid + "&win=" + win; 00031 URL = "incident_details.php?id=" + incidentid + "&win=" + win; 00032 if (popwin) 00033 { 00034 popwin.close(); 00035 } 00036 popwin = window.open(URL, "sit_popup", "toolbar=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600"); 00037 if (rtn == true) return popwin; 00038 } 00039 00040 00047 function wt_winpopup(url, mini) 00048 { 00049 if (mini=='mini') 00050 { 00051 window.open(url, "sit_minipopup", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600"); 00052 } 00053 else 00054 { 00055 window.open(url, "sit_popup", "toolbar=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600"); 00056 } 00057 } 00058 00059 00065 function confirm_action(msg) 00066 { 00067 if (msg == '') msg = 'Are you sure?'; 00068 return window.confirm(msg); 00069 } 00070 00071 00077 function help_window(helpid) 00078 { 00079 URL = application_webpath + "help.php?id=" + helpid; 00080 window.open(URL, "help_window", "toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500"); 00081 } 00082 00083 00090 function appointment(id) 00091 { 00092 00093 if ($(id).style.visibility=='visible') 00094 { 00095 $(id).style.visibility='hidden'; 00096 $(id).style.display='none'; 00097 } 00098 else 00099 { 00100 var parent = $(id).ancestors(); 00101 parent[0].makePositioned(); 00102 $(id).style.visibility='visible'; 00103 $(id).style.display='block'; 00104 } 00105 } 00106 00107 00115 function get_and_display(page, component, update) 00116 { 00117 // Do certain special things for dashlets 00118 if (component.substr(0,3) == 'win') 00119 { 00120 // Get the ID for the refresh icon so we can replace it, store the original first 00121 var refreshicon = component.replace(/win/, "refresh"); 00122 var origicon = ''; 00123 if (refreshicon != null) 00124 { 00125 if ($(refreshicon)) origicon = $(refreshicon).src; 00126 } 00127 00128 // If the dashlet content is blank, set a loading image 00129 var loaderimg = "<p align='center'><img src='"+ application_webpath +"images/ajax-loader.gif' alt=\"{$strLoading}\" /></p>"; 00130 if ($(component).innerHTML.substr(0,7) == '<script') $(component).innerHTML = loaderimg + $(component).innerHTML 00131 } 00132 00133 if (update == true) 00134 { 00135 if (dashletrefresh[component] != null) dashletrefresh[component].stop(); 00136 dashletrefresh[component] = new Ajax.PeriodicalUpdater(component, page, { 00137 method: 'get', frequency: 30, decay: 1.25, 00138 onCreate: function(){ 00139 if (refreshicon != null) 00140 { 00141 $(refreshicon).src = application_webpath + 'images/dashlet-ajax-loader.gif'; 00142 } 00143 }, 00144 onComplete: function(){ 00145 if (refreshicon != null) $(refreshicon).src = origicon; 00146 }, 00147 onLoaded: function(){ 00148 if (refreshicon != null) $(refreshicon).src = origicon; 00149 } 00150 }); 00151 } 00152 else 00153 { 00154 if (component.substr(0,3) == 'win') dashletrefresh[component].stop(); 00155 new Ajax.Updater(component, page, { 00156 method: 'get', 00157 onFailure: function() { 00158 $(component).innerHTML = 'Error: could not load data: ' + url; 00159 }, 00160 onCreate: function() { 00161 if (refreshicon != null) 00162 { 00163 $(refreshicon).src = application_webpath + 'images/dashlet-ajax-loader.gif'; 00164 } 00165 }, 00166 onComplete: function() { 00167 if (refreshicon != null) $(refreshicon).src = origicon; 00168 }, 00169 onLoaded: function() { 00170 if (refreshicon != null) $(refreshicon).src = origicon; 00171 } 00172 }); 00173 } 00174 } 00175 00176 00183 function ajax_save(page, component) 00184 { 00185 new Ajax.Request(page, { 00186 parameters: $(component).serialize(true) 00187 }); 00188 $(component).innerHTML = 'Saved'; 00189 } 00190 00191 00199 function deleteOption(object,index) 00200 { 00201 object.options[index] = null; 00202 } 00203 00204 00212 function addOption(object,text,value) 00213 { 00214 var defaultSelected = true; 00215 var selected = true; 00216 var optionName = new Option(text, value, defaultSelected, selected) 00217 object.options[object.length] = optionName; 00218 } 00219 00220 00228 function copySelected(fromObject,toObject) 00229 { 00230 for (var i=0, l=fromObject.options.length;i < l;i++) 00231 { 00232 if (fromObject.options[i].selected) 00233 { 00234 addOption(toObject,fromObject.options[i].text,fromObject.options[i].value); 00235 } 00236 } 00237 for (var i=fromObject.options.length-1;i >-1;i-- ) 00238 { 00239 if (fromObject.options[i].selected) deleteOption(fromObject,i); 00240 } 00241 } 00242 00243 00251 function copyAll(fromObject,toObject) 00252 { 00253 for (var i=0, l=fromObject.options.length;i < l;i++) 00254 { 00255 addOption(toObject,fromObject.options[i].text,fromObject.options[i].value); 00256 } 00257 for (var i=fromObject.options.length-1;i > -1;i--) 00258 { 00259 deleteOption(fromObject,i); 00260 } 00261 } 00262 00269 function populateHidden(fromObject,toObject) 00270 { 00271 var output = ''; 00272 for (var i=0, l=fromObject.options.length;i < l;i++) 00273 { 00274 output += escape(fromObject.name) + '=' + escape(fromObject.options[i].value) + '&'; 00275 } 00276 // alert(output); 00277 toObject.value = output; 00278 } 00279 00280 00285 function checkAll(formid, checkstatus) 00286 { 00287 var form = $(formid); 00288 checkboxes = form.getInputs('checkbox'); 00289 checkboxes.each(function(e) { e.checked = checkstatus}); 00290 00291 } 00292 00293 00294 var MIN_ROWS = 3 ; 00295 var MAX_ROWS = 10 ; 00296 var MIN_COLS = 40 ; 00297 var MAX_COLS = 80 ; 00298 00299 00304 function changeTextAreaLength( e ) 00305 { 00306 var txtLength = e.value.length; 00307 var numRows = 0 ; 00308 var arrNewLines = e.value.split("\n"); 00309 00310 for(var i=0; i<=arrNewLines.length-1; i++) 00311 { 00312 numRows++; 00313 if (arrNewLines[i].length > MAX_COLS-5) 00314 { 00315 numRows += Math.floor(arrNewLines[i].length/MAX_COLS) 00316 } 00317 } 00318 00319 if (txtLength == 0) 00320 { 00321 e.cols = MIN_COLS ; 00322 e.rows = MIN_ROWS ; 00323 } else 00324 { 00325 if (numRows <= 1) 00326 { 00327 e.cols = (txtLength % MAX_COLS) + 1 >= MIN_COLS ? ((txtLength % MAX_COLS) + 1) : MIN_COLS ; 00328 } 00329 else 00330 { 00331 e.cols = MAX_COLS ; 00332 e.rows = numRows > MAX_ROWS ? MAX_ROWS : numRows ; 00333 } 00334 } 00335 } 00336 00340 function resetTextAreaLength ( e ) 00341 { 00342 e.cols = MIN_COLS ; 00343 e.rows = MIN_ROWS ; 00344 } 00345 00351 function get_random() 00352 { 00353 var ranNum= Math.floor(Math.random()*1000000000000); 00354 return ranNum; 00355 } 00356 00357 00363 function update_ttna() { 00364 if ($('ttna_time').checked) 00365 { 00366 $('ttnacountdown').show(); 00367 $('timetonextaction_days').focus(); 00368 $('timetonextaction_days').select(); 00369 $('ttnadate').hide(); 00370 } 00371 00372 if ($('ttna_date').checked) 00373 { 00374 $('ttnacountdown').hide(); 00375 $('ttnadate').show(); 00376 $('timetonextaction_date').focus(); 00377 $('timetonextaction_date').select(); 00378 } 00379 00380 if ($('ttna_none').checked) 00381 { 00382 $('ttnacountdown').hide(); 00383 $('ttnadate').hide(); 00384 } 00385 } 00386 00387 00393 function addcontract_sltimed(servicelevel) 00394 { 00395 new Ajax.Request(application_webpath + 'ajaxdata.php?action=servicelevel_timed&servicelevel=' + servicelevel + '&rand=' + get_random(), 00396 { 00397 method:'get', 00398 onSuccess: function(transport) 00399 { 00400 var response = transport.responseText || "no response text"; 00401 if (transport.responseText) 00402 { 00403 if (response == 'TRUE') 00404 { 00405 $('hiddentimed').show(); 00406 $('timed').value = 'yes'; 00407 } 00408 else 00409 { 00410 $('hiddentimed').hide(); 00411 $('timed').value = 'no'; 00412 } 00413 } 00414 }, 00415 onFailure: function(){ alert('Something went wrong...') } 00416 }); 00417 } 00418 00419 00423 function addservice_showbilling(form) 00424 { 00425 /*var a = $('billtype'); 00426 alert("A: "+a.value);*/ 00427 00428 var typeValue = Form.getInputs(form,'radio','billtype').find(function(radio) { return radio.checked; }).value; 00429 // alert("B: "+typeValue); 00430 if (typeValue == 'billperunit' || typeValue == 'billperincident') 00431 { 00432 if ($('billingsection') != null) 00433 { 00434 $('billingsection').show(); 00435 } 00436 if (typeValue == 'billperunit') $('unitratesection').show(); 00437 else $('unitratesection').hide(); 00438 if (typeValue == 'billperincident') $('incidentratesection').show(); 00439 else $('incidentratesection').hide(); 00440 } 00441 else 00442 { 00443 $('billingsection').hide(); 00444 } 00445 } 00446 00447 00452 function hidecontexthelp(event) 00453 { 00454 var element = event.element(); 00455 if (element.up(1).hasClassName('helplink')) 00456 { 00457 element.style.display = 'none'; 00458 } 00459 else 00460 { 00461 element.firstDescendant().style.display = 'none'; 00462 } 00463 //element.addClassName('active'); 00464 // alert(element); 00465 element.stopObserving('blur', hidecontexthelp); 00466 element.stopObserving('click', hidecontexthelp); 00467 } 00468 00469 00474 function findPos(obj) { 00475 var curleft = curtop = 0; 00476 if (obj.offsetParent) { 00477 do { 00478 curleft += obj.offsetLeft; 00479 curtop += obj.offsetTop; 00480 00481 } while (obj = obj.offsetParent); 00482 } 00483 return [curleft,curtop]; 00484 } 00485 00486 00491 function contexthelp(elem, context, auth) 00492 { 00493 var epos = findPos(elem); 00494 span = elem.getElementsByTagName('span'); 00495 span = span[0]; 00496 $(span); 00497 $(elem); 00498 span.style.display = 'block'; 00499 00500 var vwidth = document.viewport.getWidth(); 00501 var vheight = document.viewport.getHeight(); 00502 00503 if (epos[0] + 135 > vwidth) 00504 { 00505 span.style.left = '-125px'; 00506 } 00507 else if (epos[1] + 150 > vheight) 00508 { 00509 span.style.top = '-20px'; 00510 span.style.left = '5px'; 00511 span.style.width = '250px'; 00512 } 00513 else 00514 { 00515 $(span).style.top = '1em'; 00516 $(span).style.left = '1em'; 00517 } 00518 if (span.innerHTML == '') 00519 { 00520 new Ajax.Request(application_webpath + 'ajaxdata.php?action=contexthelp&context=' + context + '&rand=' + get_random() + '&auth=' + auth, 00521 //new Ajax.Request('ajaxdata.php?action=contexthelp&context=' + context + '&rand=' + get_random(), 00522 { 00523 method:'get', 00524 onSuccess: function(transport) 00525 { 00526 var response = transport.responseText || "no response text"; 00527 if (transport.responseText) 00528 { 00529 span.innerHTML = transport.responseText; 00530 } 00531 }, 00532 onFailure: function(){ alert('Context Help Error\nSorry, we could not retrieve the help tip') } 00533 }); 00534 } 00535 span.observe('mouseout', hidecontexthelp); 00536 span.observe('click', hidecontexthelp); 00537 elem.observe('mouseout', hidecontexthelp); 00538 elem.observe('click', hidecontexthelp); 00539 } 00540 00541 00545 function jumpto() 00546 { 00547 incident_details_window(document.jumptoincident.incident.value, 'incident'+document.jumptoincident.incident.value); 00548 } 00549 00550 00554 function clearjumpto() 00555 { 00556 $('searchfield').value = ""; 00557 } 00558 00559 00560 function email_window(incidentid) 00561 { 00562 URL = application_webpath + "incident_email.php?menu=hide&id=" + incidentid; 00563 window.open(URL, "email_window", "toolbar=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600"); 00564 } 00565 00566 function close_window(incidentid) 00567 { 00568 URL = application_webpath + "incident_close.php?menu=hide&id=" + incidentid; 00569 window.open(URL, "email_window", "toolbar=yes,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=700,height=600"); 00570 } 00571 00572 function help_window(helpid) 00573 { 00574 URL = application_webpath + "help.php?id=" + helpid; 00575 window.open(URL, "help_window", "toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=500"); 00576 } 00577 00578 // INL - switch tab, see php function draw_tabs_submit() 00579 function gotab(tab) { 00580 document.actiontabs.action.value=tab; 00581 document.actiontabs.submit(); 00582 } 00583 00584 function close_page_redirect(url) 00585 { 00586 window.opener.location=url; 00587 window.close(); 00588 } 00589 00590 00595 function doSelect(select, element) 00596 { 00597 var includes = document.getElementById(element); 00598 for(i = 0; i < includes.length; i++) 00599 { 00600 includes[i].selected = select; 00601 } 00602 } 00603 00604 function groupMemberSelect(group, clear) 00605 { 00606 if (clear.toUpperCase() == "TRUE") 00607 { 00608 doSelect(false, 'include'); 00609 } 00610 00611 var includes = document.getElementById('include'); 00612 $a = $(group); 00613 for(i = 0; i < includes.length; i++) 00614 { 00615 if(includes[i].text.indexOf("("+group+")") > -1) 00616 { 00617 if ($a.checked == true) 00618 { 00619 includes[i].selected = true; 00620 } 00621 else 00622 { 00623 includes[i].selected = false; 00624 } 00625 } 00626 } 00627 } 00628 00629 function togglePlusMinus(div) 00630 { 00631 if ($(div).innerHTML == "[+]") 00632 { 00633 $(div).innerHTML = '[-]'; 00634 } 00635 else 00636 { 00637 $(div).innerHTML = '[+]'; 00638 } 00639 } 00640 00641 00647 function kbSectionCollapse() 00648 { 00649 var sections = ['summary', 'symptoms', 'cause', 'question', 'answer', 'solution', 00650 'workaround', 'status', 'additionalinformation', 'references']; 00651 00652 for (var i = 0; i < sections.length; i++) 00653 { 00654 var span = sections[i] + 'span'; 00655 var section = sections[i] + 'section'; 00656 00657 if ($(sections[i]).value.length > 0) 00658 { 00659 if ($(section).display != 'block') Effect.BlindDown(section, { duration: 0.2 }); 00660 $(span).innerHTML = '[-]'; 00661 } 00662 else 00663 { 00664 //$(section).hide(); 00665 if ($(section).display != 'none') Effect.BlindUp(section, { duration: 0.2 }); 00666 $(span).innerHTML = '[+]'; 00667 } 00668 } 00669 } 00670 00671 00680 function insertBBCode(element, tag, endtag) 00681 { 00682 if (element.length > 0) 00683 { 00684 var start = $(element).selectionStart; 00685 var end = $(element).selectionEnd; 00686 // alert('start:' + start + ' end: ' + end + 'len: ' + $(element).textLength); 00687 if ($(element).readAttribute('readonly') != 'readonly') 00688 { 00689 $(element).value = $(element).value.substring(0, start) + tag + $(element).value.substring(start, end) + endtag + $(element).value.substring(end, $(element).textLength); 00690 } 00691 } 00692 $(element).focus(); 00693 var caret = end + tag.length + endtag.length; 00694 $(element).selectionStart = caret; 00695 $(element).selectionEnd = caret; 00696 } 00697 00698 00705 function dismissNotice(noticeid, userid) 00706 { 00707 if (noticeid == 'all') var div = 'noticearea'; 00708 else var div = 'notice' + noticeid; 00709 00710 new Ajax.Request(application_webpath + 'ajaxdata.php?action=dismiss_notice¬iceid=' + noticeid + '&userid=' + userid + '&rand=' + get_random(), 00711 { 00712 method:'get', 00713 onSuccess: function(transport) 00714 { 00715 $(div).hide(); 00716 $(div).removeClassName('noticebar'); 00717 if ($$('.noticebar').length < 2) $('dismissall').hide(); 00718 }, 00719 onFailure: function(){ alert('Notice Error\nSorry, we could not dismiss the notice.') } 00720 }); 00721 } 00722 00723 00729 function toggleMenuPanel() 00730 { 00731 if ($('menupanel').style.display == 'block') 00732 { 00733 $('mainframe').style.width = mainframe; 00734 $('menupanel').style.display = 'none'; 00735 } 00736 else 00737 { 00738 mainframe = $('mainframe').style.width; 00739 $('mainframe').style.width = '80%'; 00740 $('menupanel').style.display = 'block'; 00741 } 00742 } 00743 00744 function resizeTextarea(t) 00745 { 00746 a = t.value.split('\n'); 00747 b=1; 00748 for (x=0;x < a.length; x++) 00749 { 00750 if (a[x].length >= t.cols) 00751 { 00752 b+= Math.floor(a[x].length/t.cols); 00753 } 00754 } 00755 b+= a.length; 00756 if (b > t.rows) t.rows = b; 00757 } 00758 00759 function enableBillingPeriod() 00760 { 00761 if ($('timed').checked==true) 00762 { 00763 $('engineerBillingPeriod').show(); 00764 $('customerBillingPeriod').show(); 00765 $('limit').show(); 00766 $('allow_reopen').checked=false; 00767 $('allow_reopen').disable(); 00768 } 00769 else 00770 { 00771 $('engineerBillingPeriod').hide(); 00772 $('customerBillingPeriod').hide(); 00773 $('allow_reopen').enable(); 00774 $('limit').hide(); 00775 } 00776 } 00777 00778 00779 /* ResizeableTextarea for the Prototype JavaScript framework, version 0.2 00780 * (c) 2006 Bermi Ferrer <info -a-t bermi org> 00781 * 00782 * ResizeableTextarea is freely distributable under the terms of an MIT-style license. 00783 * 00784 * Requirements: Prototype JS framework http://prototypejs.org/ 00785 * Ussage: Add this attribute to the textarea you want to resize 00786 * 00787 * onfocus="new ResizeableTextarea(this);" 00788 * 00789 /*--------------------------------------------------------------------------*/ 00790 ResizeableTextarea = Class.create(); 00791 ResizeableTextarea.prototype = { 00792 initialize: function(element, options) { 00793 this.element = $(element); 00794 this.size = parseFloat(this.element.getStyle('height') || '100'); 00795 this.options = Object.extend({ 00796 inScreen: true, 00797 resizeStep: 10, 00798 minHeight: this.size 00799 }, options || {}); 00800 Event.observe(this.element, "keyup", this.resize.bindAsEventListener(this)); 00801 if ( !this.options.inScreen ) { 00802 this.element.style.overflow = 'hidden'; 00803 } 00804 this.element.setAttribute("wrap","virtual"); 00805 this.resize(); 00806 }, 00807 resize : function(){ 00808 this.shrink(); 00809 this.grow(); 00810 }, 00811 shrink : function(){ 00812 if ( this.size <= this.options.minHeight ){ 00813 return; 00814 } 00815 if ( this.element.scrollHeight <= this.element.clientHeight) { 00816 this.size -= this.options.resizeStep; 00817 this.element.style.height = this.size+'px'; 00818 this.shrink(); 00819 } 00820 }, 00821 grow : function(){ 00822 if ( this.element.scrollHeight > this.element.clientHeight ) { 00823 if ( this.options.inScreen && (20 + this.element.offsetTop + this.element.clientHeight) > document.body.clientHeight ) { 00824 return; 00825 } 00826 this.size += (this.element.scrollHeight - this.element.clientHeight) + this.options.resizeStep; 00827 this.element.style.height = this.size+'px'; 00828 this.grow(); 00829 } 00830 } 00831 } 00832 00833 00839 function toggle_multiselect(elem) 00840 { 00841 if ($(elem).disabled) 00842 { 00843 alert('enable'); 00844 $(elem).enable(); 00845 } 00846 else 00847 { 00848 $(elem).disable(); 00849 } 00850 } 00851 00852 00861 function trow(e) 00862 { 00863 var e = e || window.event; 00864 var t = e.target || e.srcElement; 00865 // t is the element that was clicked on 00866 00867 if ($(t).down(0) && $(t).down(0).type == 'checkbox') 00868 { 00869 if (t.down(0).disabled == false) 00870 { 00871 if (t.down(0).checked == true) t.down(0).checked = false; 00872 else t.down(0).checked = true; 00873 } 00874 } 00875 else 00876 { 00877 if (t.up(0).hasClassName('shade1') || t.up(0).hasClassName('shade2')) 00878 { 00879 t.up(0).toggleClassName('notice'); 00880 } 00881 } 00882 } 00883 00884 00889 function togglecontactaddress() 00890 { 00891 var setting = false; 00892 if ($('usesiteaddress').checked == true) 00893 { 00894 setting = false; 00895 } 00896 else 00897 { 00898 setting = true; 00899 } 00900 $('address1').disabled = setting; 00901 $('address2').disabled = setting; 00902 $('city').disabled = setting; 00903 $('county').disabled = setting; 00904 $('country').disabled = setting; 00905 $('postcode').disabled = setting; 00906 }
For more help developing with SiT! see http://sitracker.org/wiki/DevelopmentHowTo