Last active
March 23, 2020 15:42
-
-
Save gerneio/00a9063d52f3550bf344a67506b643a6 to your computer and use it in GitHub Desktop.
Custom JavaScript/CSS for Jitbit Helpdesk for advanced features and styling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.fortechcomment, .fortechsubmittercomment { | |
border-left: 5px solid #5c9ec4; | |
border-right: 5px solid #5c9ec4; | |
background-color: #e9e9f2; | |
} | |
/*.ticketComment:has(.fortech-badge):not(.systemcomment) { | |
border-left: 5px solid #5c9ec4; | |
border-right: 5px solid #5c9ec4; | |
background-color: #e9e9f2; | |
}*/ | |
.techcomment, #divSubscribersList > div.subscriber.tech { | |
border-left: 5px solid #70c45c !important; | |
border-right: 5px solid #70c45c !important; | |
} | |
.usercomment { | |
border-left: 5px solid #e9a36b; | |
border-right: 5px solid #e9a36b; | |
} | |
.ticketComment:not(.techcomment):not(.usercomment):not(.fortechcomment):not(.systemcomment) { | |
border-left: 5px solid #e9ec23; | |
border-right: 5px solid #e9ec23; | |
} | |
/*.fortechcomment:hover .fortech-badge { | |
transition: all 1.5s ease; | |
//font-size: 13px; | |
font-weight: bold; | |
padding: 5px 10px; | |
border-radius: 20px; | |
}*/ | |
.richeditor #tbMention { | |
float: right; | |
} | |
/* #region Show subscribers when hidden */ | |
#divComments.show-subscribers-when-hidden #divSubscribersList { | |
visibility: visible; | |
} | |
#divComments.show-subscribers-when-hidden #divNewComment { | |
height: 60px; | |
width: 800px; | |
/* white-space: nowrap; */ | |
padding: 0px !important; | |
} | |
#divComments.show-subscribers-when-hidden > table > tbody > tr:first-child { | |
/* display: contents !important; */ | |
display: inline !important; | |
visibility: hidden; | |
} | |
/* #endregion */ | |
.toolbar-posfixed { | |
/* top: 20px; | |
width: 1151px; */ | |
position: fixed; | |
background: #e7e6e7; | |
box-shadow: 0 1px 12px -2px rgba(0,0,0,.15); | |
padding: 5px 5px; | |
border-radius: 3px; | |
} | |
.header-posfixed { | |
position: fixed; | |
z-index: 1000; | |
top: 0; | |
} | |
.announcementbar { | |
position: relative; | |
z-index: 1001; | |
} | |
.blink_me { | |
animation: blinker 3s linear infinite; | |
color: red; | |
font-weight: bold; | |
} | |
@keyframes blinker { | |
50% { opacity: 0; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log("Custom Script Loaded"); | |
//debugger; | |
//#region Default Tag Variables | |
/** | |
Get lastest categories --> copy($("#selCategory option").map((i, e) => e.value + ": " + e.parentNode.label + " / " + e.text).toArray()) | |
**/ | |
var defaultTags = { // empty element == ALL | |
"" : [ | |
"bug", "chargeable", "dev", "pcr", "patch", "training", | |
function() { return TicketHasExistingTag("bug") ? "bug-fixed" : null }, | |
function() { return TicketHasExistingTag("pcr") ? "pcr-implemented" : null }, | |
function() { return TicketHasExistingTag("patch") ? "patch-implemented" : null }, | |
function() { return TicketHasExistingTag("dev") ? "dev-completed" : null } | |
], | |
"400402" : [ "exchange", "office365", "google" ] | |
}; | |
//#endregion | |
var locationPath = location.pathname.toLowerCase(); | |
if (locationPath[locationPath.length - 1] == "/") | |
locationPath = locationPath.substr(0, locationPath.length -1); | |
var toolbar_currentWidth; | |
if (/**top.**/$) | |
/**top.**/$(document).ready(function () { | |
OverrideFunctions_IfExists(); | |
ChangeSearchQuery(); | |
if (locationPath.indexOf("/ticket/") > -1) { | |
console.log("Ticket page loaded"); | |
//debugger; | |
OverrideFunctions_TicketPage(); | |
AddControl_btnCollapseExpand(); | |
// Pre-load categories | |
GetCategories(); | |
setTimeout(CheckForGeneralCategory, 1000); | |
setTimeout(ShowOriginDetails, 1000); | |
$("#divOrigin").css({ "width": $("#divOrigin").parent().width(), "overflow-x": "auto" }); | |
///**top.**/$(".fortechcomment").removeClass("lightbg").addClass("darkbg"); | |
/**top.**/$(".fortechcomment").attr("title", "Viewable by Techs only"); | |
/**top.**/$(".techcomment").attr("title", "From Tech"); | |
/**top.**/$(".usercomment").attr("title", "From Submitter"); | |
/**top.**/$(".ticketComment:not(.techcomment):not(.usercomment):not(.fortechcomment):not(.systemcomment)").attr("title", "From Subscriber"); | |
/**top.**/$(".ticketComment:has(.fortech-badge):not(.systemcomment)").addClass("fortechsubmittercomment") | |
/**top.**/$("#divNewSubscriber").addClass("tech"); | |
// Add button to show all system entries | |
$(".ticketComment:not(.systemcomment) .tools") | |
.append("<li><button type=\"button\" title=\"Show all 'system' entries\" onclick=\"$('.systemcomment').parent().show()\"><i class=\"fa fa-minus-circle\"></i></button></li>"); | |
// Add close reply button from within editor | |
$("#divNewComment .editbar") | |
.append('<button tabindex="-1" class="htmlbtn fa fa-times-circle" title="Close reply (NOT SAVED)" type="button" onclick="HideNewComment()"></button>'); | |
// Add "show-subscribers-when-hidden", if reply editor not already shown | |
if (!$("#divSubscribersList").is(":visible")) | |
$("#divComments").addClass("show-subscribers-when-hidden"); | |
$("#cbTechsOnly").change(cbTechsOnly_OnChange); | |
// Add "Reply & Takeover" button, if Takeover button exists | |
if ($("form[action*='TakeOver']").length != 0) | |
$('<button class="graybutton" type="button" onclick="htmlBtnAddAndTakeover_OnClick()" id="htmlBtnAddAndTakeover" title="Reply & Takeover">Reply & Takeover</button>').insertAfter($("#htmlBtnAdd")); | |
if ($("#toolbar").length != 0) { | |
toolbar_currentWidth = $("#toolbar").width() || 600; | |
$(window).on("scroll", window_OnScroll); | |
} | |
// Add "Open RDM" button, if a company is linked | |
if ($("#lnkFromCompany").length != 0 && $("#lnkFromCompany").text() && HDApp.IsTech) { | |
$("#lnkFrom").parent().parent() | |
.append('<button id="btnOpenRDM" onclick="btnOpenRDM_OnClick()">Open RDM</button>') | |
} | |
// Add preview link for attachments IF extension is EML | |
$(".attachments a.resend[onclick*='.eml']") | |
.parent() | |
.append("<a class='resend attachment-preview' target='_blank'>[Preview]</a>").find(".attachment-preview") | |
.each(function (i, e) { | |
var id = $(e).closest("tr").attr("id"); | |
id = id.match(/\d+/gm)[0]; | |
$(e).attr("href", "../File/EmlViewer/" + id); | |
}); | |
AddResetDueDateBtn(); | |
Init_ddlTagDefaults(); | |
// Get all tags ../helpdesk/ajaxtagsearch.ashx?q=_ | |
//#region @mentions work in progress | |
//$("#divNewComment .boldbtn").parent().prepend("<input class='grey ac_input' id='tbMention' placeholder='Mention'/>"); | |
// $("#tbMention").autocomplete(HDApp.Url + 'ajaxusersearchautocomplete.ashx', { | |
// delay: 200, | |
// onItemSelect: function(li) { | |
// var userId = li.extra[0]; | |
// var userName = li.selectValue; | |
// /**var isTech = false; | |
// $.ajax({ | |
// url: HDApp.Url + "User/IsAdminOrTechInCategory/" + userId + "?categoryid=" + HDApp.CategoryId, | |
// success: function(data) { | |
// isTech = data == "1"; | |
// }, | |
// async: false | |
// }); | |
// AddSubscriber(userId, userName, isTech); | |
// **/ | |
// console.log(userId, userName, li); | |
// } | |
// }); | |
//#endregion | |
} else if (locationPath == "/helpdesk") { | |
console.log("Main helpdesk page loaded"); | |
OverrideFunctions_MainPage(); | |
// Expand Subtickets by default | |
$("a[onclick^='ShowSubtickets']").click(); | |
// Move filters to top of sidebar list | |
$("#divSavedFilters").insertBefore($("#leftsidebar").children()[0]); | |
SetFixedHeader(); | |
//CheckIfNeedToApplyFilter(); // Not working since the option choices are set after page load | |
AddDefaultFilters(); | |
LoadCategories(); | |
setTimeout(CheckForGeneralCategory_TicketList, 1000); | |
// Add ticket preview when hovering over link | |
$(".ticketRow a.ticketLink").hover(ticketLink_OnHoverIn, ticketLink_OnHoverOut); | |
CreateIconLinks(); | |
} else if (locationPath == "/helpdesk/tickets/search") { | |
SetFixedHeader(); | |
// if (!$('#divAdvancedSearch').is(":visible")) { | |
// $("#dateFrom").val("10/1/2019"); | |
// $("#searchInComments").click(); | |
// ToggleAdvancedSearch(); | |
// $("#btnSearch").click(); | |
// } | |
$("#divAdvancedSearch input[type=text]").attr("autocomplete", "off"); | |
} else if (locationPath == "/helpdesk/reporting/summary") { | |
AdjustCategoryChart(); | |
} | |
}); | |
//#region Override Functions | |
function OverrideFunctions_IfExists() { | |
if (DoSearch) { | |
var local_DoSearch = DoSearch; | |
DoSearch = function() { | |
//local_DoSearch.apply(this, arguments); | |
document.location.href = globalRootAppUrl + "Tickets/Search?btnSearch=Search&isAdvancedSearch=true&searchInComments=true&dateFrom=10%2F01%2F2019&q=" + $("#tbQuery").val(); | |
}; | |
DoSearch.local = local_DoSearch; | |
} | |
} | |
function OverrideFunctions_TicketPage() { | |
var local_ToggleEditor = ToggleEditor; | |
ToggleEditor = function() { | |
local_ToggleEditor.apply(this, arguments); | |
AddControl_DefaultTags(); | |
$('#spanCatName').text(GetCurrentCategoryPath("selCategory")); | |
CheckForGeneralCategory(); | |
AddResetDueDateBtn(); | |
}; | |
ToggleEditor.local = local_ToggleEditor; | |
var local_RemoveTag = RemoveTag; | |
RemoveTag = function() { | |
local_RemoveTag.apply(this, arguments); | |
AddControl_DefaultTags(); | |
}; | |
RemoveTag.local = local_RemoveTag; | |
var local_InitToolbar = InitToolbar; | |
InitToolbar = function() { | |
local_InitToolbar.apply(this, arguments); | |
AddControl_btnCollapseExpand(); | |
}; | |
InitToolbar.local = local_InitToolbar; | |
if (window.ShowNewComment) { | |
var local_ShowNewComment = ShowNewComment; | |
ShowNewComment = function() { | |
$("#divComments").removeClass("show-subscribers-when-hidden"); | |
local_ShowNewComment.apply(this, arguments); | |
}; | |
ShowNewComment.local = local_ShowNewComment; | |
} | |
if (window.HideNewComment) { | |
var local_HideNewComment = HideNewComment; | |
HideNewComment = function() { | |
local_HideNewComment.apply(this, arguments); | |
$("#divComments").addClass("show-subscribers-when-hidden"); | |
}; | |
HideNewComment.local = local_HideNewComment; | |
} | |
} | |
function OverrideFunctions_MainPage() { | |
var local_OnChangeCategory = OnChangeCategory; | |
OnChangeCategory = function() { | |
local_OnChangeCategory.apply(this, arguments); | |
$('.cb:checked').closest("tr") | |
.attr("data-categoryid", $("#selCategory option:selected").val()) | |
.find(".categoryName").text(GetCurrentCategoryPath("selCategory", " - ")); | |
CheckForGeneralCategory_TicketList(); | |
}; | |
OnChangeCategory.local = local_OnChangeCategory; | |
} | |
//#endregion | |
//#region Misc Functions | |
function isElementInView(element, fullyInView) { | |
var pageTop = $(window).scrollTop(); | |
var pageBottom = pageTop + $(window).height(); | |
var elementTop = $(element).offset().top; | |
var elementBottom = elementTop + $(element).height(); | |
if (fullyInView === true) { | |
return ((pageTop < elementTop) && (pageBottom > elementBottom)); | |
} else { | |
return ((elementTop <= pageBottom) && (elementBottom >= pageTop)); | |
} | |
} | |
function GetTechUsersWithIDs(selectId) { | |
var opts = $("#" + selectId + " option[value!=-1]"); | |
return opts.map(function(i, e) { | |
return { | |
UserID: e.value, | |
User: e.text | |
}; | |
}).toArray(); | |
} | |
function SetFixedHeader() { | |
var header = $("#divBigHeader"); | |
if (header.length != 0) { | |
var header_placeholder = $("<div>").attr("id", "divBigHeader_placeholder").width(header.width()).height(header.height()).insertBefore(header); | |
header.addClass("header-posfixed").css("width", header_placeholder.width()); | |
} | |
} | |
function AddResetDueDateBtn() { | |
//debugger; | |
$("#btnResetDueDate").remove(); | |
if (!$("#txDueDate").val()) return; | |
setTimeout(function() { | |
$("#spanEditDueDate a[onclick*='ClearDueDate']") | |
.clone() | |
.appendTo("#lblDueDate") | |
.attr({ | |
"onclick": "ClearDueDate();SaveDueDate();", | |
"id": "btnResetDueDate", | |
"title": "Reset Due Date" | |
}); | |
}, 1000); | |
} | |
function ChangeSearchQuery() { | |
if (!$("#tbQuery").length) return; | |
var atag = $("#tbQuery").siblings("a"); | |
atag.attr("href", atag.attr("href") + "?isAdvancedSearch=true&searchInComments=true&dateFrom=10%2F01%2F2019"); | |
} | |
//#endregion | |
//#region Category Functions | |
function GetSectionsAndCategories(selectId) { | |
var opts = $("#" + selectId + " option[value!=-1]"); | |
return opts.map(function(i, e) { | |
return new SectionCategory(e); | |
}).toArray(); | |
} | |
function GetCurrentCategoryPath(selectId, divider) { | |
divider = divider || " / "; | |
var categorySelected = $("#" + selectId + " option:selected"); | |
if (categorySelected.length == 0) return $("#spanCatName").text(); | |
if (categorySelected.parent().prop("tagName").toLowerCase() != "optgroup") return categorySelected.text(); | |
return categorySelected.parent().attr("label") + divider + categorySelected.text(); | |
} | |
function CheckForGeneralCategory() { | |
var selectedCat = $(GetSectionsAndCategories("selCategory")).filter(function(i, e) { return e.FullPath() == GetCurrentCategoryPath("selCategory"); }).get(0); | |
if (selectedCat && selectedCat.Section == "General") | |
$("#spanCatName").addClass("blink_me").attr("title", "Change to different category"); | |
else | |
$("#spanCatName").removeClass("blink_me").removeAttr("title"); | |
} | |
function CheckForGeneralCategory_TicketList() { | |
var generalCats = GetSectionsAndCategories("selCategory") | |
.filter(function(e) { return e.Section == "General"; }).map(function(e) { return e.CategoryID; }); | |
$("tr.ticketRow[data-categoryid]") | |
.find(".categoryName") | |
.removeClass("blink_me") | |
.removeAttr("title"); | |
$("tr.ticketRow[data-categoryid]") | |
.filter(function(i, e) { return generalCats.indexOf($(e).attr("data-categoryid")) > -1; }) | |
.find(".categoryName") | |
.addClass("blink_me") | |
.attr("title", "Change to different category"); | |
} | |
//#endregion | |
//#region Default Tag Functions | |
function Init_ddlTagDefaults() { | |
AddControl_DefaultTags(); | |
$("#btnSaveCategory") | |
.attr("onclick", $("#btnSaveCategory").attr("onclick") + ";btnSaveCategory_OnClick_Custom();"); | |
} | |
function AddControl_DefaultTags() { | |
//debugger; | |
var categoryId = $("#hdnCategoryId").val(); | |
var categoryPath = GetCurrentCategoryPath("selCategory"); | |
var defaultGroup = $("<optgroup>").attr("label", "Default Tags"); | |
var categoryGroup = $("<optgroup>").attr("label", categoryPath); | |
$("#ddlTagDefaults").remove(); | |
var select = $("<select>") | |
.attr("id", "ddlTagDefaults") | |
.attr("onchange", "ddlTagDefaults_OnChange(this.selectedIndex)") | |
.append($("<option>").text("Add default tag...").attr("selected", "selected")); | |
for (var p in defaultTags) { | |
if (!p || p.match("(^|,)" + categoryId + "(,|$)")) { | |
var tags = defaultTags[p].map(function(e) { return typeof e == "function" ? e() : e; }).sort(); | |
for (var t in tags) { | |
var tag = tags[t]; | |
if (tag && !ddlTagDefaults_HasExistingTag(tag) && !TicketHasExistingTag(tag)) | |
(p ? categoryGroup : defaultGroup).append($("<option>").text(tag)); | |
} | |
} | |
} | |
if (defaultGroup.find("option").length > 0) | |
select.append(defaultGroup); | |
if (categoryGroup.find("option").length > 0) | |
select.append(categoryGroup); | |
if (select.find("option").length > 1) | |
$("#tbTags_tagsinput").parent().append(select); | |
} | |
function ddlTagDefaults_HasExistingTag(tag) { | |
return $("#ddlTagDefaults option").filter(function(i, e) { return $(e).text() == tag; }).length > 0; | |
} | |
function ddlTagDefaults_OnChange(selectedIndex) { | |
if (selectedIndex == 0) return; | |
var val = $("#ddlTagDefaults").val(); | |
AddTagIfNotAlreadyAdded(val); | |
} | |
function AddTagIfNotAlreadyAdded(newTag) { | |
if (!newTag) return; | |
newTag = newTag.toLowerCase(); | |
if (!TicketHasExistingTag(newTag)) { | |
$("#tbTags").addTag(newTag + "|0"); | |
AddControl_DefaultTags(); | |
} | |
} | |
function TicketHasExistingTag(tag) { | |
tag = tag.toLowerCase(); | |
var val = $("#tbTags").val().toLowerCase(); | |
if (!val || !val.match("(^|,)" + tag + "[^-]\|/g")) return false; | |
else return true; | |
} | |
function GetTagList() { | |
var strResults = ""; | |
$.ajaxSetup({async: false}); | |
$.get("../helpdesk/ajaxtagsearch.ashx?q=_").then(function(contents) { strResults = contents; }); | |
$.ajaxSetup({async: true}); | |
return strResults.split("\r\n").map(function(e) { | |
var data = e.split("|"); | |
return { tagName : data[0], tagId : data[1] }; | |
}); | |
} | |
//#endregion | |
//#region Collapse/Expand | |
function AddControl_btnCollapseExpand() { | |
$("#btnCollapseExpand").parent().remove(); | |
$("#toolbar .tools").parent() | |
.append('<div style="padding: 0 5px;" class="tools"><button class="graybutton" title="Collapse/Expand Body" id="btnCollapseExpand" type="button" style="margin-right:0;" onclick="btnCollapseExpand_OnClick()" div="">Collapse</button></div>'); | |
btnCollapseExpand_ChangeText(); | |
} | |
function btnCollapseExpand_ChangeText() { | |
$("#btnCollapseExpand").text($("div #body").is(":visible") ? "Collapse" : "Expand"); | |
} | |
//#endregion | |
//#region Control Events | |
function btnCollapseExpand_OnClick() { | |
var divBody = $("div #body"); | |
divBody.slideToggle(250, btnCollapseExpand_ChangeText); | |
if ($(window).scrollTop() > 150) $("html, body").animate({ scrollTop: 150 }, "slow") | |
} | |
function btnSaveCategory_OnClick_Custom() { | |
AddControl_DefaultTags(); | |
} | |
function cbTechsOnly_OnChange() { | |
var firstBody = $("#rtetbNewComment").contents().find("body:first"); | |
if ($("#cbTechsOnly").is(":checked")) | |
firstBody.css("background-color","#e9e9f2").css("border-left", "5px solid #5c9ec4").css("border-right", "5px solid #5c9ec4"); | |
else | |
firstBody.css("background-color","").css("border-left", "").css("border-right", ""); | |
} | |
function htmlBtnAddAndTakeover_OnClick() { | |
$("#htmlBtnAdd").click(); | |
$("form[action*='TakeOver']").submit(); | |
$("#htmlBtnAddAndTakeover").remove(); | |
} | |
function window_OnScroll() { | |
var toolbar = $("#toolbar"); | |
var $window = $(window); | |
var topDistance = $('.realtimeBar').is(":visible") ? "20px" : "10px"; | |
if (!isElementInView(toolbar.parent())) | |
toolbar.hide(); | |
else | |
toolbar.show(); | |
if ($window.scrollLeft() > 0 || !$("div #body").is(":visible")) { | |
toolbar.removeClass("toolbar-posfixed"); | |
toolbar.css("top", "").css("width", ""); | |
return; | |
} | |
if (toolbar.outerHeight() - 10 < $window.height()) { | |
//if (document.documentElement.scrollTop > 155) { | |
//if (!isElementInView(toolbar.parent(), true)) { | |
if ($window.scrollTop() > (toolbar.parent().offset().top + 100)){ | |
toolbar.addClass("toolbar-posfixed"); | |
toolbar.css("top", topDistance).css("width", toolbar_currentWidth); | |
} | |
else { | |
toolbar.removeClass("toolbar-posfixed"); | |
toolbar.css("top", "").css("width", ""); | |
} | |
} else { | |
toolbar.removeClass("toolbar-posfixed"); | |
toolbar.css("top", "").css("width", ""); | |
} | |
} | |
function btnOpenRDM_OnClick() { | |
if (!$("#lnkFromCompany").text()) return; | |
window.open('rdm://open?Filter=' + $("#lnkFromCompany").text()); | |
} | |
function ticketLink_OnHoverIn() { | |
var current = $(this); | |
window.hover_timeout = setTimeout(function() { | |
ShowTicketPreview(current); | |
}, 1000); | |
} | |
function ticketLink_OnHoverOut() { | |
if (window.hover_timeout) { | |
clearTimeout(window.hover_timeout); | |
window.hover_timeout = null; | |
$(this).find(".ticket-preview") | |
.css("display", "none") | |
.find("iframe") | |
.attr("src", ""); | |
} | |
} | |
//#endregion | |
//#region Main helpdesk page functions | |
function CreateIconLinks() { | |
$("#divTicketsGrid .fa-user").on("click", UserIcon_OnClick); | |
$("#divTicketsGrid .fa-folder-open").on("click", CategoryIcon_OnClick); | |
} | |
function UserIcon_OnClick(e) { | |
var uPopup = $(e.toElement).siblings(".uPopup"); | |
var href = uPopup.attr("href"); | |
if (!href) return false; | |
window.open(href); | |
return false; | |
} | |
function CategoryIcon_OnClick(e) { | |
var ticketRow = $(e.toElement).parents(".ticketRow"); | |
var ticketCategoryId = ticketRow.attr("data-categoryid"); | |
if (!ticketCategoryId) return false; | |
var href = $("#divCategories a[href*='" + ticketCategoryId + "']").attr("href"); | |
if (!href) return false; | |
window.location = href; | |
return false; | |
} | |
function AddSavedFilter(filterName, filterUrl, overwrite) { | |
if (!window.filterApp || !localStorage) return; | |
var filters = window.filterApp.Filters; | |
for (var i in filters) { | |
var f = filters[i]; | |
if (f.FilterName == filterName && !overwrite) return; | |
else if (f.FilterName == filterName && overwrite) { | |
//filters.splice(i, 1); break; | |
f.FilterUrl = filterUrl; | |
return; | |
} | |
} | |
filters.unshift({ FilterName: filterName, FilterUrl: filterUrl }); | |
} | |
function RenameFilter(filterName, newName) { | |
if (!window.filterApp || !localStorage) return; | |
var filters = window.filterApp.Filters; | |
for (var i in filters) { | |
var f = filters[i]; | |
if (f.FilterName == filterName) { | |
f.FilterName = newName; | |
return true; | |
} | |
} | |
return false; | |
} | |
function AddDefaultFilters() { | |
if (!IndexPageModel.IsTech) return; | |
AddSavedFilter("Mine - All", "/helpdesk/?mode=ShowAll&handledByUserId=" + IndexPageModel.CurrentUserId, true); | |
AddSavedFilter("Mine - Closed", "/helpdesk/?mode=ShowAll&statusId=3&handledByUserId=" + IndexPageModel.CurrentUserId, true); | |
AddSavedFilter("Mine - New Cust Reply", "/helpdesk/?mode=Unclosed&badge=cust&handledByUserId=" + IndexPageModel.CurrentUserId, true); | |
AddSavedFilter("Mine - Waiting on Cust", "/helpdesk/?mode=Unclosed&badge=tech&handledByUserId=" + IndexPageModel.CurrentUserId, true); | |
var timeoutDelay = 1000; | |
if ($('#handledByUserId').children().length == 0) | |
FillTechsFilter(); | |
else | |
timeoutDelay = 0; | |
setTimeout(function() { | |
var techs = GetTechUsersWithIDs("handledByUserId"); | |
var otherTechs = []; | |
for (var i in techs) { | |
var tech = techs[i]; | |
if (tech.UserID == IndexPageModel.CurrentUserId) continue; | |
otherTechs.push(tech.UserID); | |
} | |
var query = "mode=Unclosed&subscribedOnly=true&handledByUserId=" + otherTechs.join("&handledByUserId="); | |
AddSavedFilter("Subsribed but not assigned", "/helpdesk/?" + query, true); | |
}, timeoutDelay); | |
//#region Advanced Search Queries | |
var cats = GetSectionsAndCategories("selCategory"); | |
var nonIntegrationCategories = []; | |
for (var i in cats) { | |
var cat = cats[i]; | |
if (cat.Section == "Integrations") continue; | |
nonIntegrationCategories.push(cat.CategoryID); | |
} | |
var query = "dateFrom=1%2F1%2F2019&statusId=2&statusId=1&assignedToUserId=" + IndexPageModel.CurrentUserId + "&catSelect=" + nonIntegrationCategories.join("&catSelect="); | |
AddSavedFilter("Mine - Active (non-Integrations)", "/helpdesk/Tickets/Search?" + query, true); | |
if ($.inArray(IndexPageModel.CurrentUserId, [8597643, 8597545, 8721695, 8686135]) != -1) { | |
var tags = GetTagList(); | |
var tags_tagString = tags.filter(function(e) { | |
return [ "dev", "patch", "bug", "pcr" ].indexOf(e.tagName) > -1; | |
}); | |
var tags_negativeTagString = tags.filter(function(e) { | |
return [ "dev-completed", "patch-implemented", "bug-fixed", "pcr-implemented" ].indexOf(e.tagName) > -1; | |
}); | |
var query_tagString = tags_tagString.map(function(e) { return e.tagName + "|" + e.tagId }).join(","); | |
var query_negativeTagString = tags_negativeTagString.map(function(e) { return e.tagName + "|" + e.tagId }).join(","); | |
RenameFilter("All - Todo: Bugs/Patches/PCRs", "All - Active: Dev Work"); | |
AddSavedFilter("All - Active: Dev Work", "/helpdesk/Tickets/Search?dateFrom=01%2F01%2F2019&tagString=" + encodeURI(query_tagString) + "&negativeTagString=" + encodeURI(query_negativeTagString), true); | |
} | |
//#endregion | |
} | |
function CheckIfNeedToApplyFilter() { | |
var filterInputs = $("#filterForm input[type!=hidden][type!=submit][type!=checkbox]").filter(function() { return !!this.value; }); | |
var filterOptions = $("#filterForm option:selected:not(:empty)"); | |
var btnApply = $("input[type=submit][value=Apply]"); | |
console.log(filterInputs, filterOptions, btnApply); | |
if ($('#btnResetFilter').length == 0 && btnApply.length != 0 && (filterInputs.length != 0 || filterOptions.length != 0)) { | |
console.log("Applying filter"); | |
btnApply.click(); | |
} else | |
console.log("Not applying filter"); | |
} | |
function ShowTicketPreview(parent) { | |
var innerDiv = parent.find(".ticket-preview"); | |
var outerDiv = $(".ticket-preview"); | |
var div = null, ifrm = null, img = null; | |
if (innerDiv.length == 0 && outerDiv.length == 0) { // Create | |
div = $("<div class='ticket-preview outerroundedbox'>").appendTo(parent); | |
div.css({"position": "absolute", "padding": "10px", "height": "400px", "width": "650px", "z-index": "100"}); | |
img = $('<img src="https://cdn.jitbit.com/helpdesk/images/indicator.svg" style="margin-left: 48%;">').appendTo(div); | |
ifrm = $("<iframe>").appendTo(div); | |
ifrm.css({"display": "none", "height": "400px", "width": "650px"}); | |
ifrm.on("load", function() { | |
console.log("load", arguments); | |
var ifrm_cont = ifrm.contents(); | |
ifrm_cont.find("body").html(ifrm_cont.find(".leftContent")); | |
img.css("display", "none"); | |
ifrm.css("display", ""); | |
}); | |
ifrm.attr("src", parent.attr("href")); | |
} | |
else if (innerDiv.length == 0 && outerDiv.length > 0) { // Different row, so set to new link | |
div = outerDiv; | |
div.appendTo(parent); | |
img = div.find("img"); | |
ifrm = div.find("iframe"); | |
img.css("display", ""); | |
ifrm.css("display", "none"); | |
ifrm.attr("src", parent.attr("href")); | |
} else { // Same row, just reload | |
div = innerDiv; | |
img = div.find("img"); | |
ifrm = div.find("iframe"); | |
img.css("display", ""); | |
ifrm.css("display", "none"); | |
ifrm.attr("src", parent.attr("href")); | |
} | |
var new_top = parent.offset().top + parent.height() - 5; | |
var new_left = parent.offset().left + 10; | |
div.css({"top": new_top, "left": new_left, "display": ""}); | |
} | |
//#endregion | |
//#region Classes | |
function SectionCategory(e) { | |
this.Section = $(e.parentNode).is("optgroup") ? e.parentNode.label : null; | |
this.CategoryID = e.value; | |
this.Category = e.text; | |
SectionCategory.prototype.FullPath = function() { | |
return this.Section ? this.Section + " / " + this.Category : this.Category; | |
} | |
} | |
//#endregion | |
//#region Reporting | |
function AdjustCategoryChart() { | |
if (!window.catChart) return; | |
var opts = catChart.getOption(); | |
//opts.series[0].data[0].value = 150; | |
opts.series[0].name = 'Total'; | |
opts.series[0].radius = ['55%', '70%']; | |
opts.series[0].label = { normal: { show: false } }; | |
var res = opts.series[0].data, grpd = []; | |
for (var i in res) { | |
var fnd = false; | |
var nm = res[i].name.split(" / ")[0]; | |
for (var j in grpd) { | |
if (grpd[j].name == nm) { | |
grpd[j].value += res[i].value; | |
fnd = true; | |
} | |
} | |
if (!fnd) grpd.push({ value: res[i].value, name: nm }); | |
} | |
var new_series = Object.assign({}, defaultChartOptions.series); | |
//new_series.data = [{ name: 'Tickets created', value: 1413 } ]; | |
new_series.data = grpd; | |
new_series.name = ''; | |
new_series.radius = "50%"; | |
opts.series.push(new_series); | |
catChart.setOption(opts); | |
} | |
//#endregion | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment