function getComments(reset) { if (reset) { resetComments(); } if (!workorderid || workorderid == "") return; $('#mask_over_bg').show(); worequest("GetComments", workorderid, function (data) { $('#mask_over_bg').hide(); if (typeof (data) === "string") { return; } $("#li_comments").data("loaded", true); internal?.load(data); }, function (err) { $('#mask_over_bg').hide(); }); } function showComment(comment, isfirst) { var commoentctrl = $("#divcomments"); var div = $("
").appendTo(commoentctrl); if (isfirst) div.css("margin-top", 0); var divuser = $("
").appendTo(div); divuser.append($("
").text(comment.UserName)); divuser.append($("
").text(comment.SubmitDateStr)); var divcontent = $("
").appendTo(div); var contentctrl = $("
"); divcontent.append(contentctrl); contentctrl.html(replaceHtmlText(comment.Comment)); if (comment.FollowUp && comment.FollowUp !== "") { var sendto = ""; var emails = comment.FollowUp.split(';'); if (emails && emails.length > 0) { for (var i = 0; i < emails.length; i++) { sendto += emails[i] + "\r\n"; } } if (sendto !== "") sendto = GetTextByKey("P_WO_SENTTO_COLON", "Sent To :") + "\r\n" + sendto; var div_status = $("
").text(GetTextByKey('P_WO_SENT', 'Sent')).attr('title', sendto); divcontent.append(div_status); } } function addWorkOrderComment(comment) { if ($.trim(comment) == "") { //showAlert(GetTextByKey("P_FR_PLEASEINPUTTHECOMMENT", "Please input the comment."), GetTextByKey("P_WO_ERROR", 'Error')); return; } $('#mask_over_bg').show(); var url = 'Maintenance/AddWorkOrder.aspx'; var method = 'SendInternalComments'; var data = new FormData(); data.append('MethodName', method); data.append('WorkorderId', workorderid); data.append('Comment', encodeURIComponent(comment)); //data.append('Emails', JSON.stringify(emailaddress)); //data.append('Phones', JSON.stringify(phonenumbers)); var file = internal?.file; if (file != null) { data.append('Attachment', file); } $.ajax({ url: _network.root + url, type: 'POST', dataType: 'json', processData: false, contentType: false, cache: false, data: data, success: function (data) { $('#mask_over_bg').hide(); if (data !== "") { showAlert(data, GetTextByKey("P_WO_ERROR", 'Error')); if (typeof internal !== 'undefined') { internal.loading = false; } return; } if (typeof internal !== 'undefined') { internal.text = ''; internal.file = null; internal.loading = false; } $('#commentsinputcount').text("0/" + $('#dialog_comments').attr("maxlength")); getComments(); }, error: function (request, textStatus, errorThrown) { $('#mask_over_bg').hide(); if (typeof internal !== 'undefined') { internal.loading = false; } } }); } function resetComments() { if (typeof internal !== 'undefined') { internal.text = ''; internal.load(); } } var communicationsLoading = false; var communicationsLoadingWaitCount = 0; /**Communication */ function getCommunications(reset) { if (reset) { resetCommunications(); } if (communicationsLoading) { communicationsLoadingWaitCount++; return; } communicationsLoading = true; if (!workorderid || workorderid == "") return; $('#mask_over_bg').show(); worequest("GetCommunications", workorderid, function (data) { communicationsLoading = false; $('#mask_over_bg').hide(); if (typeof (data) === "string") { return; } $("#li_communications").data("loaded", true); customer?.load(data, customercontacts, followers); if (communicationsLoadingWaitCount > 0) { communicationsLoadingWaitCount = 0; getCommunications(reset); } }, function (err) { communicationsLoading = false; if (communicationsLoadingWaitCount > 0) { communicationsLoadingWaitCount = 0; getCommunications(reset); } $('#mask_over_bg').hide(); }); } function addWorkOrderCommunication() { var pmemails = customer?.contacts; if (pmemails == null || pmemails.length === 0) { if (typeof customer !== 'undefined') customer.loading = false; showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEPHONENUMBEROREMAL", "Please input the phone number or email."), GetTextByKey("P_WO_ERROR", 'Error')); return; } var comm = customer?.text; if ($.trim(comm) == "") { if (typeof customer !== 'undefined') customer.loading = false; showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEMESSAGE", "Please input the message."), GetTextByKey("P_WO_ERROR", 'Error')); return; } var includeStatusLink = customer?.statusLink; $('#mask_over_bg').show(); var url = 'Maintenance/AddWorkOrder.aspx'; var method = 'AddWorkOrderCommunication'; var data = new FormData(); data.append('MethodName', method); data.append('WorkorderId', workorderid); data.append('PMEmails', JSON.stringify(pmemails)); data.append('Comment', encodeURIComponent(comm)); data.append('IncludeStatusLink', includeStatusLink ? "1" : "0"); var file = customer?.file; if (file != null) { data.append('Attachment', file); } $.ajax({ url: _network.root + url, type: 'POST', dataType: 'json', processData: false, contentType: false, cache: false, data: data, success: function (data) { $('#mask_over_bg').hide(); if (typeof customer !== 'undefined') customer.loading = false; if (data !== "") { showAlert(data, GetTextByKey("P_WO_ERROR", 'Error')); return; } if (typeof customer !== 'undefined') { customer.text = ''; customer.file = null; } $('#msginputcount').text("0/" + $('#dialog_communications').attr("maxlength")); getCommunications(); }, error: function (request, textStatus, errorThrown) { $('#mask_over_bg').hide(); if (typeof customer !== 'undefined') { customer.loading = false; } if (request?.readyState == 0) { console.log(request); } else { writelog_ironintel("onAddMessage", url + ".-1." + method + "." + JSON.stringify(param), JSON.stringify(request), textStatus + errorThrown); } } }); } function OnAddCommunication() { addWorkOrderCommunication(); } function resetCommunications() { if (typeof customer !== 'undefined') { customer.text = ''; customer.load(); } }