/* ------------------------------------------------------- */ /* ---------------- Custom Action Log -------------------- */ /* ------------------------------------------------------- */ // Tested with v8.1.0.2016 // Tested with IE11, Chrome 68, Firefox 45 & Edge // Contributors: Martin Blomgren, Brian Wiest, Eric Brown // Description: Replaces to original Action Log on work item edit var timeFormat = 'MM-DD-YYYY hh:mm A'; app.custom.formTasks.add('Incident', null, function (formObj, viewModel) { formObj.boundReady(function () { CustomActionLogHandler(viewModel.AppliesToTroubleTicket); }); }); app.custom.formTasks.add('Problem', null, function (formObj, viewModel) { formObj.boundReady(function () { CustomActionLogHandler(viewModel.AppliesToTroubleTicket); }); }); app.custom.formTasks.add('ServiceRequest', null, function (formObj, viewModel) { formObj.boundReady(function () { CustomActionLogHandler(viewModel.AppliesToWorkItem); }); }); app.custom.formTasks.add('ChangeRequest', null, function (formObj, viewModel) { formObj.boundReady(function () { CustomActionLogHandler(viewModel.AppliesToWorkItem); }); }); function CustomActionLogHandler(actionLog) { ApplyStyleSheetActionLog(); AddCustomActionLog(actionLog); // hide stock action log $('div').find('[data-control-grid="actionLogGrid"]').parent().parent().hide(); // if a new comment is added actionLog.bind("change", function (e) { $('.chat').prepend(GetCommentHtml(e.items[0])); }); } function GetCommentHtml(comment) { var commentDescription = (typeof comment.Description === 'undefined' || comment.Description == null) ? 'No Comment(s) Available' : comment.Description.replace(//g, '>'); var private = comment.IsPrivate ? "private" : ""; var enteredby = (comment.EnteredBy == 'Domain\\User') ? " workflowaccnt" : ""; var html = '
  • ' + '' + '' + '' + '
    ' + '
    ' + '' + comment.EnteredBy + ' (' + comment.Title + ') ' + ' ' + moment(comment.EnteredDate).format(timeFormat) + '' + '
    ' + '

    ' + commentDescription + '

    ' + '
    ' + '
  • '; return html; } function AddCustomActionLog(comments) { var html = '
      '; if (comments != undefined) { //sort comments comments.sort(function (a, b) { return (b.EnteredDate > a.EnteredDate) ? 1 : ((a.EnteredDate > b.EnteredDate) ? -1 : 0); }); //create log entries for (i = 0; i < comments.length; i++) { if (comments[i].ClassName == "System.WorkItem.BillableTime") { } else { html += GetCommentHtml(comments[i]); } } } html += '
    '; //add custom action log to DOM $('div').find('[data-control="actionLog"]').append(html); }; function ApplyStyleSheetActionLog() { var addRule = (function (style) { var sheet = document.head.appendChild(style).sheet; return function (selector, css) { var propText = Object.keys(css).map(function (p) { return p + ":" + css[p] }).join(";"); sheet.insertRule(selector + "{" + propText + "}", sheet.cssRules.length); } })(document.createElement("style")); } /* ------------------------------------------------------- */ /* -------------- End Custom Action Log ------------------ */ /* ------------------------------------------------------- */