var nAttachments=1; var nNoteAttachments=1; var selectchanged=false; var ie=false; if (document.all) ie=true; var aSelectedSupports=new Array(); var aSelectedClients=new Array(); var aSelectedUsers=new Array(); var aSelectedProjects=new Array(); var lastEditor='comment'; var AdvancedOptionsTR=new Array('subject', 'project_id', 'private', 'pre_approved_hours', 'time_work', 'time_fix', 'time_charge', 'pre_approved_hours', 'client_priority', 'real_priority', 'support_hours_header', 'support_hours_0', 'supporthours_button', 'waitfor'); var newtickettemplateloaded=false; var commentFormChanged = false; $(document).ready(function() { $('#filter_form select').change(function(e){selectchange(e)}); $('[class^=support_hours_]').addClass('support_hours'); if ($('#filter_form select[name="client"]').size()>0) { $('#filter_form select[name="user"]').click(function(){ if ($('#advanced_search:visible').size()>0) { for (i=0; i0) { for (i=0; i0) { window.onbeforeunload = function() { if (commentFormChanged) { return "You've made the changes to the form.\nClicking Okay button will cancel changes you've made."; } } }; }); function setFormChanged() { commentFormChanged = true; } function remove_attachment(button, note) { if ($('tr.'+note).size()<2) { add_attachment(note, true); $(button).parent().parent().parent().remove(); } else { $(button).parent().parent().parent().remove(); add_attachment(note, false); } } function add_attachment(note, forceadd) { shownew = true; $('tr.'+note+' td input[type="file"]').each(function(){ if ($(this).val()=='') { shownew = false } }); if (shownew || forceadd) { if (note=='noteattachment') nCount=nNoteAttachments; else nCount=nAttachments; $('tr.'+note+'_0').removeClass(note+'_0').addClass(note); $('tr.'+note+':first').clone(true).addClass(note+'_'+(nCount)).insertAfter($('tr.'+note+':last')); $('tr.'+note+'_'+nCount+' td input').attr('name',note+'['+nCount+'][file]').val(''); $('tr.'+note+'_'+nCount+' td strong').css('visibility','hidden'); $('tr.'+note+'_'+nCount+' td strong input').val('Delete'); $('tr.'+note+'_'+nCount+' td input.inp_filetitle').attr('name',note+'['+nCount+'][title]'); $('tr.'+note+'_'+nCount).removeClass(note+'_'+nCount); if (note=='noteattachment') nNoteAttachments++; else nAttachments++; } $('tr.'+note+' td input[type="file"]').each(function(){ if ($(this).val()!='') { $(this).parent().children('strong').css('visibility','visible'); } }); } function assignticket() { $("#form_ticket input[name='action']").val('assign'); } function hideattachments() { $("#form_ticket table.form_tbl tr.comment").hide(); $("#form_ticket table.form_tbl tr.attachment_static").hide(); $("#form_ticket table.form_tbl tr.attachment_0").hide(); $("#form_ticket table.form_tbl tr.internal_note").hide(); $("#form_ticket table.form_tbl tr.noteattachment_static").hide(); $("#form_ticket table.form_tbl tr.noteattachment_0").hide(); } function hideoptions() { $('input[name="options"][value="resolve"]').hide(); $('label[for="'+$('input[name="options"][value="resolve"]').attr('id')+'"]').hide(); if ($('.commentheader').size() == 0) { $('input[name="options"][value="waitforclient"]').hide(); $('label[for="'+$('input[name="options"][value="waitforclient"]').attr('id')+'"]').hide(); } } function showeditoreditedcomment() { edit($('#form_ticket_edit input:hidden[name="edit_id"]').val()); } function showeditorcomment() { showeditor('comment', ''); } function showeditorinternal_note() { showeditor('internal_note', ''); } function showeditor(note, commenttext, append) { if (note=='internal_note') { noteattachment='note'; if (commenttext != '' && commenttext != undefined) { $('#form_ticket table.form_tbl tr.internal_note textarea').val(commenttext); } ointernal_note.ReplaceTextarea() ; } else { noteattachment=''; if (commenttext != '' && commenttext != undefined) { if (append) { commenttext += $('#form_ticket table.form_tbl tr.comment textarea').val(); } $('#form_ticket table.form_tbl tr.comment textarea').val(commenttext); } ocomment.ReplaceTextarea() ; $('input[name="options"][value="resolve"]').show(); $('input[name="options"][value="waitforclient"]')./*show().*/attr('checked','checked'); $('label[for="'+$('input[name="options"][value="resolve"]').attr('id')+'"]').show(); /*$('label[for="'+$('input[name="options"][value="waitforclient"]').attr('id')+'"]').show();*/ } var cHeader=$('tr.'+note+'header td a').hide().html(); $('tr.'+note+'header td a').after(cHeader); $("#form_ticket table.form_tbl tr."+note).show(); $('#form_ticket table.form_tbl tr.'+noteattachment+'attachment_static').show(); $('#form_ticket table.form_tbl tr.'+noteattachment+'attachment_0').show(); $.scrollTo("#form_ticket table.form_tbl tr."+note); } function hideadvancedoptions() { for (i=1; i<=supporthoursrows; i++) AdvancedOptionsTR.push('support_hours_'+i); for (i in AdvancedOptionsTR) $("#form_ticket table.form_tbl tr."+AdvancedOptionsTR[i]).hide(); $("#form_ticket table.form_tbl tr.support_hours_clone").hide(); if (! $("#form_ticket table.form_tbl tr.drafttext td").html()) $("#form_ticket table.form_tbl tr.drafttext").hide(); $(".ticket_form").show(); } function toggleadvancedoptions() { for (i in AdvancedOptionsTR) $("#form_ticket table.form_tbl tr."+AdvancedOptionsTR[i]).toggle(); if ($('#form_ticket table.form_tbl tr.subject:visible').size()>0) $('.ticket_form h2 a').html('Hide advanced options'); else $('.ticket_form h2 a').html('Show advanced options'); } function addsupporthours() { supporthoursrows++; var cHtml=$('.support_hours_clone').clone().html(); cHtml=String(cHtml).replace(/support_hours_clone/g, "support_hours["+supporthoursrows+"]"); $('.supporthours_button').before(''+cHtml+''); AdvancedOptionsTR.push('support_hours_'+supporthoursrows); d=new Date(); $('select[name="support_hours['+supporthoursrows+'][date][M]"]').val(d.getMonth()+1); $('select[name="support_hours['+supporthoursrows+'][date][d]"]').val(d.getDate()); $('select[name="support_hours['+supporthoursrows+'][date][Y]"]').val(d.getFullYear()); } function showsubscribers() { $('#subscribers').slideToggle('slow'); } function setsubscribestatus(ticket_id, user_id) { var status=1; if ($('#user'+user_id).hasClass('subscribe_on')) status=0; $('#user'+user_id).removeClass('subscribe_on').removeClass('subscribe_off').addClass('subscribe_wait'); $.post('ticket/'+ticket_id, { action: 'subscribe', user_id:user_id, set:status}, function(data) { if (data=='ok') { $('#user'+user_id).removeClass('subscribe_wait'); if (status) $('#user'+user_id).addClass('subscribe_on'); else $('#user'+user_id).addClass('subscribe_off'); } }); } function showform() { $('.form_ticket .form_tbl tr:eq(0)').show(); $('.form_ticket .form_tbl tr:eq(1)').show(); $('.form_ticket .form_tbl tr.submit_grp strong.blue input').click(function(){commentFormChanged = false;}); $('.form_ticket .form_tbl tr.submit_grp strong.red input').click(function(){ commentFormChanged = false; location.href = BASE_URL + '/ticket?action=cancel'; }); } function showallform(cRowClass, cAnotherRowClass) { if (($('input[name="'+cRowClass+'_id"]:visible:checked').length>0 && $('input[name="'+cAnotherRowClass+'_id"]:checked').length>0)) { $('.form_ticket .form_tbl tr').show(); $('.'+cRowClass+' div').hide(); $('input[name="'+cRowClass+'_id"]:checked').parent().parent().show(); $('input[name="'+cRowClass+'_id"]:checked').parent().show(); $('input[name="'+cRowClass+'_id"]').hide(); if ($('tr.'+cRowClass+' td:eq(1) strong').length==0) { $('tr.'+cRowClass+' td:eq(1)').append(''); } if (!newtickettemplateloaded) { $('.'+cAnotherRowClass+' div').hide(); $('input[name="'+cAnotherRowClass+'_id"]:checked').parent().parent().show(); $('input[name="'+cAnotherRowClass+'_id"]:checked').parent().show(); $('input[name="'+cAnotherRowClass+'_id"]').hide(); if ($('input[name="'+cAnotherRowClass+'_id"]').length>1) $('tr.'+cAnotherRowClass+' td:eq(1)').append(''); $.post('ticket', {action:'template', project_id: $('input[name="project_id"]:checked').val(), requesttype_id: $('input[name="request_type_id"]:checked').val()}, function(data){ var template = eval('(' + data + ')'); if (template.template_text!='') { var oEditor = FCKeditorAPI.GetInstance('description') ; oEditor.InsertHtml(template.template_text); } }); $.post('ticket', {action:'projecthours', project_id: $('input[name="project_id"]:checked').val()}, function(data){ var data = eval('(' + data + ')'); $('.pre_approved_hours input').val(data.hours) if (data.display!='y') $('.pre_approved_hours').hide(); }); newtickettemplateloaded=true; $('tr.project td:eq(0)').html('*Project'); $('tr.request_type td:eq(0)').html('*Ticket Type'); } } } function hideradiooptions(cClassName) { $('.'+cClassName+' div').hide(); $('input[name="'+cClassName+'_id"]:checked').parent().parent().show(); $('input[name="'+cClassName+'_id"]:checked').parent().show(); $('input[name="'+cClassName+'_id"]').hide(); if ($('tr.'+cClassName+' td:eq(1) strong').length==0) { $('tr.'+cClassName+' td:eq(1)').append(''); } } function showradiooptions(cClassName) { $('.'+cClassName+' div').show(); $('.'+cClassName+' input').show(); $('.'+cClassName+' strong').remove(); } function initNewTicketForm() { showallform('request_type','project'); if ($('input[name="priority_id"]:checked').size()>0) { hideradiooptions('priority'); } } function showoptions(clearclient) { if ($('#filter_form #main_search input[name="advanced"]').val()!='Hide Advanced Search Options') { $('#filter_form #main_search select').each(function(i){ if ((this.name.substr(this.name.length-2))=='[]') this.name=this.name.substr(0,this.name.length-2); }).attr('size',5).attr('multiple','multiple'); $('#filter_form #main_search select option:first-child').remove(); $('#filter_form #main_search div.ticketfilter span').show(); $('#filter_form #main_search input[name="advanced"]').val('Hide Advanced Search Options'); $('#filter_form #main_search input[name="cancel_btn"]').parent().remove(); hiddenSearch=document.createElement('input'); hiddenSearch.type='hidden'; hiddenSearch.value='Search'; hiddenSearch.name='submit_btn'; $('#filter_form #form_ticket').append(hiddenSearch); $('#form_search #srch_inp').attr("disabled","disabled"); $('#form_search #go_inp').attr("disabled","disabled"); if ($.browser.msie && $.browser.version<7) { if ($('#filter_form #main_search select[name="client"]').length) { if (clearclient) { $('#filter_form #main_search select[name="client"] option:selected').each(function() { this.selected=false; }); } refreshclient(false); refreshsupport(false); } else { refreshuser(false); refreshproject(false); } } $('#advanced_search').slideDown('slow'); } else { document.location.href='ticket'; } } function selectchange(e) { if ($('#advanced_search').is(':hidden')) { /*if (e.target.name=='status') { if (e.target.form.client) e.target.form.client.value=-1; if (e.target.form.support) e.target.form.support.value=-1; e.target.form.user.value=-1; e.target.form.project.value=-1; } else if (e.target.name=='client') { e.target.form.user.value=-1; e.target.form.project.value=-1; }*/ e.target.form.submit() } else { selectchanged=true; if (e.target.form.client && e.target.name=='status') { refreshclient(true); refreshsupport(true); } if (e.target.name=='client' || (!e.target.form.client && e.target.name=='status')) { refreshuser(true); refreshproject(true); } } } function refreshsupport(savecurrentselect) { cStatuses=''; $('#main_search select[name="status"] option:selected').each(function(){cStatuses+=this.value+',';}); if (cStatuses=='') $('#main_search select[name="status"] option').each(function(){cStatuses+=this.value+',';}); aSelectedSupports=new Array(); if (savecurrentselect) $('#main_search select[name="support"] option:selected').each(function(){aSelectedSupports.push(this.value);}); $('#main_search select[name="support"]').attr("disabled","disabled"); $.post('ticket', {action:'support', statuses: cStatuses}, function(data){ $('#main_search select[name="support"]').empty(); supportselect=$('#main_search select[name="support"]').get(0); support = eval('(' + data + ')'); for (i in support) { selected=false; for (j=0; j0) { $('.comment'+ticket_id).remove(); $(alink).html('Show Comments'); } else { $.post('ticket',{action:'post', id:ticket_id, searchtext:search}, function(data){ if (data.length>0) { currentRow=alink.parentNode.parentNode; var data = eval('(' + data + ')'); for (i=0; igo to comment by " + data[i]['user_name'] + "
" + data[i]['changed'] + " - " + data[i]['ago'] + "ago
" + data[i]['description'] + "
"; } $(alink).html('Hide Comments'); } }) } } function shownote() { $('.searchnote').toggle(); } function quote(id) { traversing = '#form_ticket table.form_tbl tr.'; if ($(traversing+"comment:visible").size()+$(traversing+"internal_note:visible").size()==0) { if ($(traversing+"comment").size()) { showeditor('comment',getQuotedText(id), true); } else { showeditor('internal_note',getQuotedText(id), true); } } else { var oEditor = FCKeditorAPI.GetInstance(lastEditor) ; oEditor.InsertHtml(getQuotedText(id)); $.scrollTo('tr.'+lastEditor,1000); } } function edit(id) { $('#editedComment___Frame').remove(); $('#form_ticket_edit .comment').show(); $('#form_ticket_edit input:hidden[name="edit_id"]').val(id); $('#comment' + id).after($('#comment_editor')); $('#comment_editor').show(); $('#comment_editor textarea').val($('#comment' + id).html()); oeditedComment.ReplaceTextarea(); $('#comment' + id).hide(); } function FCKeditor_OnComplete(editorInstance) { editorInstance.Events.AttachEvent( 'OnFocus', dosave) ; if (!FCKeditorAPI.GetInstance(lastEditor)) { lastEditor='internal_note'; } editorInstance.Events.AttachEvent('OnSelectionChange', function(editorInstance){ if (editorInstance.IsDirty()) { commentFormChanged = true; } }); editorInstance.Focus(); } function dosave(editorInstance) { lastEditor=editorInstance.Name; } function getQuotedText(id) { var txt = ''; if (window.getSelection) txt = window.getSelection(); else if (document.selection) txt = document.selection.createRange().text; else if (document.getSelection) txt = document.getSelection(); if (!String(txt).length) { txt = $('#comment'+id).html(); txt=String(txt).replace(/\n/gi,""); txt=String(txt).replace(/<\/p>/gi,"\n"); txt=String(txt).replace(/<\/p>/gi,"\n"); txt=String(txt).replace(//gi,"\n"); txt=String(txt).replace(/<\/p>/gi,"\n"); txt=String(txt).replace(/<\/?[^>]+>/gi, ''); txt=String(txt).replace(/ /gi, ' '); txt=String(txt).replace(/\s*$/g, ""); } sCite=String(txt); cText='>'; var wrapStr = ' ,!;'; var j = 0; for (i=0; i 70 && j < sCite.length && wrapStr.indexOf(symb) > -1)){ cText += '
>'; j = 0; } } return cText+'
'; } function savedraftajax() { oCommentEditor = FCKeditorAPI.GetInstance('comment'); if (oCommentEditor) { autoform=$('#autosaveform').get(0); ticketform=$('#form_ticket').get(0); for (i=0; i0) { $('#form_ticket').get(0).action.value='close'; } else if($('.option_grp input:checked').val()) { $('#form_ticket').get(0).action.value=$('.option_grp input:checked').val(); } else { $('#form_ticket').get(0).action.value='addcomment'; } } function setSaveButtonTitle(title) { if (title) { if (title=='Save and ASSIGN') { if ($('.option_grp select[name="assignto_user"] option:selected').val()==current_user_id) { $('.submit_grp input[name="post"]').val('Save and ACCEPT'); } else if($('.option_grp select[name="assignto_user"] option:selected').val()!=current_support_user_id) { $('.submit_grp input[name="post"]').val('Save and REASSIGN'); } else if(current_support_user_id==0) { $('.submit_grp input[name="post"]').val(title); } else { $('.submit_grp input[name="post"]').val('Save'); } } else { $('.submit_grp input[name="post"]').val(title); } } else { if ($('.close_ticket input:checked').length>0) { $('.submit_grp input[name="post"]').val('Save and CLOSE'); } else { $('.submit_grp input[name="post"]').val('Save'); } } } function supportSelectClick() { $('.option_grp input[name="options"][value="assignto"]').attr('checked','checked'); setSaveButtonTitle('Save and ASSIGN'); }