var vm; var reportdata; var reportlayout; var layoutStyle = 0; var layoutDivider = 0; var layoutSpacing = 1; var layoutPicturesDisplay = 0; var layoutCaptionImages = false; var layoutHighlightColor = ""; var mediasdata = []; $(function () { $("#host_header").find(".button").remove(); $("#spanUserName").remove(); checkBrowser(); if (teamintelligence) { $('.assettr').remove(); $(".assettrmobile").remove(); } vm = new Vue({ el: '#divreport', data: { report: { Asset: {}, Template: {}, ReportLayout: {} } }, methods: { reload: function (data) { this.report = data; } } }); GetInspectionReport(); }); function checkBrowser() { if (isMobile()) { $(".logo").remove(); $(".logoright").remove(); $(".headernote").remove(); $("#host_header").css("text-align", "left").css("min-width", "unset"); $("#divreport").css("width", "unset"); //$("#button-edit").remove(); $("#button-print").remove(); $("#button-dl").css("margin-right", 10); $(".assettr").remove(); $("#tdiissues").attr("colspan", "2"); $("#tdpages").attr("colspan", "2"); //$(".assettrmobile").children().eq(0).css("width", 130); //$(".assettrmobile").children().eq(1).css("width", "auto"); $(".assettrmobile").show(); } else { $(".assettrmobile").remove(); } } function GetInspectionReport() { showmaskbg(true); var p = JSON.stringify([teamintelligence, htmlencode(reportid)]); inspectionrequest("GetInspectionReport", p, function (data) { showmaskbg(false); if (!data) { showAlert(GetTextByKey("P_IPT_INSPECTIONCANNOTBEFOUND", 'Inspection cannot be found.'), GetTextByKey("P_IPT_ERROR", 'Error')); $(".function_title").remove(); return; } if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_IPT_ERROR", 'Error')); } else { reportdata = data; reportlayout = data.ReportLayout; if (reportlayout) { layoutStyle = parseInt(reportlayout.Style); layoutDivider = parseInt(reportlayout.Divider); layoutSpacing = parseInt(reportlayout.Spacing); layoutPicturesDisplay = parseInt(reportlayout.PicturesDisplay); layoutCaptionImages = reportlayout.CaptionImages; layoutHighlightColor = reportlayout.HighlightColor; if (layoutStyle == 2) layoutPicturesDisplay = 1; }; vm.reload(data); showReportLayout(data.ReportLayout); if (data.Template.DisplayInspectionIssues) showIdentifiedQuestions(data.IdentifiedQuestions); showPages(data); showSignature(data); if (layoutPicturesDisplay == 1 && mediasdata && mediasdata.length > 0) { showMedias(); } } }, function (err) { showmaskbg(false); }); } function showReportLayout(layout) { $('#reportlayoutlogo').hide(); $('#reportlayoutcenterlogo').hide(); $('#reportlayoutrightlogo').hide(); $('.td_pageheaderleft').html(''); $('.td_pageheadercenter').html(''); $('.td_pageheaderright').html(''); $('.td_pagefooterleft').html(''); $('.td_pagefootercenter').html(''); $('.td_pagefooterright').html(''); if (layout) { $('.td_pageheaderleft').html(layout.PageHeaderLeft); $('.td_pageheadercenter').html(layout.PageHeaderCenter); $('.td_pageheaderright').html(layout.PageHeaderRight); $('.td_pagefooterleft').html(layout.PageFooterLeft); $('.td_pagefootercenter').html(layout.PageFooterCenter); $('.td_pagefooterright').html(layout.PageFooterRight); $('#reportlayoutlogo').show(); $('#reportlayoutcenterlogo').show(); $('#reportlayoutrightlogo').show(); if (layout.LOGO && layout.LOGO.length > 0) { var jpeg = layout.LOGO; if (typeof (layout.LOGO) !== "string") { jpeg = arrayBufferToBase64(layout.LOGO); } $('#reportlayoutlogo').attr('src', 'data:image/png;base64,' + jpeg); } if (layout.CenterLOGO && layout.CenterLOGO.length > 0) { var jpeg = layout.CenterLOGO; if (typeof (layout.CenterLOGO) !== "string") { jpeg = arrayBufferToBase64(layout.CenterLOGO); } $('#reportlayoutcenterlogo').attr('src', 'data:image/png;base64,' + jpeg); } if (layout.RightLOGO && layout.RightLOGO.length > 0) { var jpeg = layout.RightLOGO; if (typeof (layout.RightLOGO) !== "string") { jpeg = arrayBufferToBase64(layout.RightLOGO); } $('#reportlayoutrightlogo').attr('src', 'data:image/png;base64,' + jpeg); } } } function arrayBufferToBase64(buffer) { var binary = ''; var bytes = new Uint8Array(buffer); var len = bytes.byteLength; for (var i = 0; i < len; i++) { binary += String.fromCharCode(bytes[i]); } return window.btoa(binary); } function showIdentifiedQuestions(questions) { if (!questions || questions.length == 0) return; var content = $('
'); content.append($('
' + GetTextByKey('P_IPT_IDENTIFIEDISSUES', 'IDENTIFIED ISSUES') + '
')); if (questions && questions.length > 0) { if (layoutStyle == 1 || layoutStyle == 2) { var qcontent = $('
'); content.append(qcontent); createQuestionContent1(qcontent, questions, true); if (layoutDivider == 1)//Line qcontent.addClass('question_line'); else if (layoutDivider == 2)//Grid qcontent.addClass('question_table_grid'); qcontent.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } else createQuestionContent1(content, questions, true); } else content.append($('
').text(GetTextByKey("P_IPT_NOQUESTIONS", 'No Questions'))); $('#divquestions').append(content); } function showSeverityLevel(level) { if (layoutStyle == 1 || layoutStyle == 2) return ""; var levertext = GetTextByKey("P_IPT_SEVERITYLEVEL_COLON", "Severity Level: "); if (level === 0) levertext = ""; if (level === 1) levertext += GetTextByKey("P_IPT_SL_LOW", "Low"); else if (level === 2) levertext += GetTextByKey("P_IPT_SL_MEDIUM", "Medium"); else if (level === 3) levertext += GetTextByKey("P_IPT_SL_HIGH", "High"); return levertext; } function showPages(report) { var pages = report.Template.Pages; var pagescontent = $('
'); pagescontent.append($('
' + GetTextByKey("P_IPT_INSPECTIONDETAIL", "INSPECTION DETAIL") + '
')); if (layoutStyle == 1 || layoutStyle == 2) { var content = $('
'); pagescontent.append(content); if (layoutDivider == 1)//Line content.addClass('question_line'); else if (layoutDivider == 2)//Grid content.addClass('question_table_grid'); content.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); for (var i = 0; i < pages.length; i++) { var p = pages[i]; createPage(content, p); } } else { for (var i = 0; i < pages.length; i++) { var p = pages[i]; createPage(pagescontent, p); } } $('#divpages').append(pagescontent); } function showSignature(report) { if (report && report.SignatureUrl && report.SignatureUrl != "") { var divsign = $('#divsign'); divsign.append($('
' + GetTextByKey("P_IPT_SIGNATURE", "Signature") + '
')); var div_pic = $('
'); divsign.append(div_pic); var pic = $('').attr('src', report.SignatureUrl); div_pic.append(pic); if (layoutDivider == 1)//Line div_pic.addClass('question_line'); else if (layoutDivider == 2)//Grid div_pic.addClass('question_div_grid'); div_pic.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } } function showMedias() { var content = $('
'); content.append($('
Required Images
')); var media_div = $('
'); content.append(media_div); for (var i = 0; i < mediasdata.length; i++) { var m = mediasdata[i]; var piccontent = createMedias(m); media_div.append(piccontent); } $('#divpages').append(content); } function createMedias(m) { var piccontent = $('
'); if (['.mp4', '.mov'].indexOf(m.FileType.toLowerCase()) >= 0) { var v = $('
'); v.click(m.Url, function (e) { window.open(e.data, "_blank") }); piccontent.append(v); if (layoutCaptionImages) { var div_caption = $('
').attr('title', m.FileName); piccontent.append(div_caption); var span_caption = $('').text(m.FileName); div_caption.append(span_caption); } } else { var pic = $('').attr('src', m.ThumbnailUrl); pic.click(m.Url, function (e) { window.open(e.data, "_blank") }); piccontent.append(pic); if (layoutCaptionImages) { var div_caption = $('
').attr('title', m.FileName);; piccontent.append(div_caption); var span_caption = $('').text(m.FileName); div_caption.append(span_caption); } } return piccontent; } var lastdisplaypageid = null; function createPage(content, page) { if (layoutStyle == 1 || layoutStyle == 2) { if (page.DisplayOnReport) { var trpage = $(''); content.append(trpage); var tdpage = ""; if (layoutStyle == 1) tdpage = $('') else tdpage = $('') trpage.append(tdpage); tdpage.append($('').text(page.DisplayText)); } } else { if (page.DisplayOnReport) { lastdisplaypageid = page.Id; var divpage = $('
'); content.append(divpage); var btnpage = $(''); btnpage.click(page.Id, function (e) { var icon = $(this); if (icon.hasClass('iconangleright')) { icon.removeClass('iconangleright').addClass('iconangledown'); //icon.parent().next().show(); $(".page" + e.data).show(); $(".page" + e.data).find("em").removeClass('iconangleright').addClass('iconangledown'); } else { icon.removeClass('iconangledown').addClass('iconangleright'); //icon.parent().next().hide(); $(".page" + e.data).hide(); $(".page" + e.data).find("em").removeClass('iconangledown').addClass('iconangleright'); } }); divpage.append(btnpage); divpage.append($('').text(page.DisplayText)); } } createSectionContent(content, page, lastdisplaypageid); } var lastdisplaysectionid = null; function createSectionContent(content, page, lastdisplaypageid) { if (layoutStyle == 1 || layoutStyle == 2) { if (page.Sections && page.Sections.length > 0) { for (var i = 0; i < page.Sections.length; i++) { var s = page.Sections[i]; var condmatched = checkConditional(s.Conditional) if (s.DisplayOnReport && condmatched) { var trsection = $(''); content.append(trsection); var tdsection = $(''); if (layoutStyle == 1) tdsection = $('') else tdsection = $('') trsection.append(tdsection); tdsection.append($('').text(s.DisplayText)); } if (condmatched) createQuestionContent(content, s); } } } else { if (page.Sections && page.Sections.length > 0) { for (var i = 0; i < page.Sections.length; i++) { var s = page.Sections[i]; if (s.DisplayOnReport && checkConditional(s.Conditional)) { lastdisplaysectionid = s.Id; var divsection = $('
'); content.append(divsection); var btnsection = $(''); btnsection.click(s.Id, function (e) { var icon = $(this); if (icon.hasClass('iconangleright')) { icon.removeClass('iconangleright').addClass('iconangledown'); $(".section" + e.data).show(); //icon.parent().next().show(); } else { icon.removeClass('iconangledown').addClass('iconangleright'); //icon.parent().next().hide(); $(".section" + e.data).hide(); } }); divsection.append(btnsection); if (lastdisplaypageid) divsection.addClass("page" + lastdisplaypageid); var ispic = false; if (s.StaticPictures && s.StaticPictures.length > 0) { ispic = true; var div_pic = $(''); createPictures(s.StaticPictures, div_pic); divsection.append(div_pic); divsection.append('
'); } var span_title = $('').text(s.DisplayText); if (ispic) span_title.css('margin-left', 24); divsection.append(span_title); } createQuestionContent(content, s, lastdisplaysectionid, lastdisplaypageid); } } else content.append($('
').text('No Sections')); } } function createQuestionContent(content, section, lastdisplaysectionid, lastdisplaypageid) { if (section.Questions && section.Questions.length > 0) { createQuestionContent1(content, section.Questions, false, lastdisplaysectionid, lastdisplaypageid); } else content.append($('
').text(GetTextByKey("P_IPT_NOQUESTIONS", 'No Questions'))); return content; } function createQuestionContent1(content, questions, isidentified, lastdisplaysectionid, lastdisplaypageid) { if (questions && questions.length > 0) { if (layoutStyle == 1) {//Compressed for (var i = 0; i < questions.length; i++) { var q = questions[i]; if (ignoreQuestion(q, isidentified) || !checkConditional(q.Conditional)) continue; var tr_question = $(''); content.append(tr_question); tr_question.append($('').text(q.DisplayText)); var td_answer = $(''); tr_question.append(td_answer); createAnswerContent(td_answer, q, isidentified); var td_comment = $(''); tr_question.append(td_comment); var comment = td_answer.data('comment'); if (comment && comment != "") { var div_comment = $('
').html(replaceHtmlText(comment)); td_comment.append(div_comment); div_comment.css('color', (q.IsImportant && layoutHighlightColor) ? layoutHighlightColor : "#808080"); } if (q.IsImportant && layoutHighlightColor) tr_question.css('color', layoutHighlightColor); } } else if (layoutStyle == 2) {//Split var tr_question = ""; var qindex = 0; for (var i = 0; i < questions.length; i++) { var q = questions[i]; if (ignoreQuestion(q, isidentified) || !checkConditional(q.Conditional)) continue; if (qindex % 2 == 0) { tr_question = $(''); content.append(tr_question); } var td_question = $('').text(q.DisplayText); tr_question.append(td_question); var td_answer = $(''); tr_question.append(td_answer); createAnswerContent(td_answer, q, isidentified); if (q.IsImportant && layoutHighlightColor) { td_question.css('color', layoutHighlightColor); td_answer.css('color', layoutHighlightColor); } qindex++; } if (qindex % 2 != 0) { tr_question.append($('')); } } else { for (var i = 0; i < questions.length; i++) { var q = questions[i]; if (ignoreQuestion(q, isidentified) || !checkConditional(q.Conditional)) continue; var tab_question = $('
'); if (lastdisplaysectionid) tab_question.addClass("section" + lastdisplaysectionid); if (lastdisplaypageid)//没有显示Section的时候设置PageID tab_question.addClass("page" + lastdisplaypageid); content.append(tab_question); var tr_question = $(''); tab_question.append(tr_question); var td_question = $(''); tr_question.append(td_question); var div_question = $('
'); td_question.append(div_question); var div_title = $('
').text(q.DisplayText); div_question.append(div_title); if (q.StaticPictures && q.StaticPictures.length > 0) { var div_pic = $('
'); div_pic = createPictures(q.StaticPictures, div_pic); div_question.append(div_pic) } tr_question = $(''); tab_question.append(tr_question); var td_answer = $(''); tr_question.append(td_answer); createAnswerContent(td_answer, q, isidentified); if (layoutDivider == 1)//Line tab_question.addClass('question_standard_table_line'); else if (layoutDivider == 2)//Grid tab_question.addClass('question_standard_table_grid'); tab_question.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); if (q.IsImportant && layoutHighlightColor) { tab_question.css('color', layoutHighlightColor); div_question.css('color', layoutHighlightColor); } } } content.find('.answer').each(function () { var div_answer = $(this); if (layoutStyle == 1 || layoutStyle == 2) { div_answer.addClass('table_content'); } }); content.find('.div_media').each(function () { var div_media = $(this); if (layoutStyle == 1 || layoutStyle == 2) { div_media.css('padding-left', '3px'); } }); } return content; } function createPictures(pictures, p) { for (var i = 0; i < pictures.length; i++) { var pic = pictures[i]; var img = $('').attr('src', pic.Url).attr('title', pic.Name); img.click(pic.Url, function (e) { window.open(e.data, "_blank") }); $(p).append(img); } return p; } function ignoreQuestion(q, isidentified) { var ignore = false; if (q.QuestionType == 10 || (q.QuestionType == 15 && q.SubType == 15)) {//Picture var hasPicture = false; if (reportdata && reportdata.Answers) { for (var i = 0; i < reportdata.Answers.length; i++) { var a = reportdata.Answers[i]; if (a.QuestionId.toLowerCase() == q.Id.toLowerCase()) { if (reportdata.Medias && reportdata.Medias.length > 0) { for (var j = 0; j < reportdata.Medias.length; j++) { var m = reportdata.Medias[j]; if (m.AnswerId.toLowerCase() == a.Id.toLowerCase()) { if (layoutPicturesDisplay == 1)//Displayed At Bottom { if (isidentified == false) mediasdata.push(m); } else hasPicture = true; } } } } } } ignore = !hasPicture; } else ignore = false; return ignore; } function checkConditional(cond) { if (!cond) return true; var qid = cond.QuestionId.toLowerCase(); if (qid == "and") { for (let scond of cond.SubItems) { var r = checkConditional(scond); if (!r) return false; } return true; } else if (qid == "or") { for (let scond of cond.SubItems) { var r = checkConditional(scond); if (r) return true; } return false; } else { var condquestion = getQuestionAndSection(cond.QuestionId); if (!condquestion) return false; if (!condquestion.Question || !checkConditional(condquestion.Question.Conditional)) return false; if (!condquestion.Section || !checkConditional(condquestion.Section.Conditional)) return false; if (!cond.Value) return false; var ans = reportdata.Answers.find(c => c.QuestionId.toLowerCase() == cond.QuestionId.toLowerCase()); if (ans == null) return false; var condValue = Number(cond.Value); switch (cond.Operator) { case "gt"://> return ans.AsDouble > condValue; case "gteq"://>= return ans.AsDouble >= condValue; case "lt"://< return ans.AsDouble < condValue; case "lteq"://<= return ans.AsDouble <= condValue; case "between"://between var condValue1 = Number(cond.Value1); return ans.AsDouble >= condValue && ans.AsDouble <= condValue1; case "in"://in if (!ans.SelectedItems || ans.SelectedItems.length == 0) return false; var condvs = cond.Value.toLowerCase().split(';'); for (let item of ans.SelectedItems) { var sv = item.Value; if (condquestion.Question.QuestionType == 19 || condquestion.Question.QuestionType == 5) sv = item.Text; if (!sv || condquestion.Question.LookupSource != 0) sv = item.Text; if (condvs.indexOf(sv.toLowerCase()) >= 0) return true; } return false; case "noteq": var v = ""; if (condquestion.Question.QuestionType == 5// QuestionTypes.YesOrNo || condquestion.Question.QuestionType == 8//QuestionTypes.DropDown || condquestion.Question.QuestionType == 9//QuestionTypes.List || condquestion.Question.QuestionType == 19) {//QuestionTypes.AssetStatus) if (!ans.SelectedItems || ans.SelectedItems.length == 0) return false; if (ans.SelectedItems.length > 1) return true; v = ans.SelectedItems[0].Value; if (!v || condquestion.Question.QuestionType == 19 || condquestion.Question.QuestionType == 5 || condquestion.Question.LookupSource != 0) v = ans.SelectedItems[0].Text; } else v = ans.Result; return cond.Value.toLowerCase() != v.toLowerCase() && ans.AsDouble != condValue; default: //= var v = ""; if (condquestion.Question.QuestionType == 5// QuestionTypes.YesOrNo || condquestion.Question.QuestionType == 8//QuestionTypes.DropDown || condquestion.Question.QuestionType == 9//QuestionTypes.List || condquestion.Question.QuestionType == 19) {//QuestionTypes.AssetStatus) if (!ans.SelectedItems || ans.SelectedItems.length != 1) return false; v = ans.SelectedItems[0].Value; if (!v || condquestion.Question.QuestionType == 19 || condquestion.Question.QuestionType == 5 || condquestion.Question.LookupSource != 0) v = ans.SelectedItems[0].Text; } else v = ans.Result; return cond.Value.toLowerCase() == v.toLowerCase() || ans.AsDouble == condValue; } } } function getQuestionAndSection(questionid) { for (var p of reportdata.Template.Pages) { for (var s of p.Sections) { for (var q of s.Questions) { if (q.Id.toLowerCase() == questionid.toLowerCase()) return { Question: q, Section: s }; } } } return null; } function createAnswerContent(p, q, isidentified) { var leveltext = showSeverityLevel(q.SeverityLevel); var label_level = $('').text(leveltext); if (reportdata && reportdata.Answers) { for (var i = 0; i < reportdata.Answers.length; i++) { var a = reportdata.Answers[i]; if (a.QuestionId.toLowerCase() == q.Id.toLowerCase()) { p.data('comment', a.Comment); if ([5, 8, 9, 10, 14, 15, 19].indexOf(q.QuestionType) < 0 || (q.QuestionType == 15 && q.SubType != 15)) {//except YesOrNo/DropDown/MultipleChoice/Picture/FuelRecords var result = a.Result; if (result == null) { result = ''; } if (q.QuestionType == 6 && result.indexOf(' ') >= 0)//Date do not show time result = result.split(' ')[0]; if (q.QuestionType == 11//Odometer || q.QuestionType == 18 //FuelUsed || q.QuestionType == 12//EngineHours || q.QuestionType == 13//FuelRemaining || (q.QuestionType == 15 && q.SubType == 8)//FuelRecords Odometer || (q.QuestionType == 15 && q.SubType == 10))//FuelRecords Quantity result += " " + convertUnits(a.Units); var div_answer = $('
').data('isimportant', q.IsImportant); if (q.QuestionType == 1 || (q.QuestionType == 15 && q.SubType == 14)) p.append(div_answer.html(replaceHtmlText(result))); else if (q.QuestionType == 17 && q.TextToCompare != null && result.toLowerCase() != q.TextToCompare.toLowerCase()) // BarCodeValidate p.append(div_answer .append($('').text(result)) .append($('').text('(' + q.TextToCompare + ')')) ); else p.append(div_answer.text(result)); div_answer.append(label_level); p.append(item); if (layoutStyle == 0) p.append("
"); } else if (q.QuestionType == 5) {//YesOrNo if (a.SelectedItems && a.SelectedItems.length > 0) { var item = $('
').data('isimportant', q.IsImportant); var div_bg = $('
'); var label = $('