var vm; var reportdata; var reportlayout; var layoutStyle = 0; var layoutDivider = 0; var layoutSpacing = 0; 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) { 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); showIdentifiedQuestions(data.IdentifiedQuestions); showPages(data); showSignature(data); if (layoutPicturesDisplay == 1 && mediasdata && mediasdata.length > 0) { showMedias(); } } showmaskbg(false); }, 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($('
IDENTIFIED ISSUES
')); if (questions && questions.length > 0) { 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") + '
')); for (var i = 0; i < pages.length; i++) { var p = pages[i]; var pagecontent = createPage(p); pagescontent.append(pagecontent); } $('#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
')); if (layoutStyle == 1) {//Compressed var div_question = $('
'); content.append(div_question); var tr_question = ""; for (var i = 0; i < mediasdata.length; i++) { var m = mediasdata[i]; if (i % 3 == 0) { tr_question = $(''); div_question.append(tr_question); } var td_pic = $(''); tr_question.append(td_pic); var piccontent = createMedias(m); td_pic.append(piccontent); } var m_count = mediasdata.length % 3; if (m_count != 0) { for (var i = 0; i < 3 - m_count; i++) { tr_question.append($('')); } } if (layoutDivider == 1)//Line div_question.addClass('question_line'); else if (layoutDivider == 2)//Grid div_question.addClass('question_table_grid'); div_question.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } else if (layoutStyle == 2) {//Split var div_question = $('
'); content.append(div_question); var tr_question = ""; for (var i = 0; i < mediasdata.length; i++) { var m = mediasdata[i]; if (i % 4 == 0) { tr_question = $(''); div_question.append(tr_question); } var td_pic = $(''); tr_question.append(td_pic); var piccontent = createMedias(m); td_pic.append(piccontent); } var m_count = mediasdata.length % 4; if (m_count != 0) { for (var i = 0; i < 4 - m_count; i++) { tr_question.append($('')); } } if (layoutDivider == 1)//Line div_question.addClass('question_line'); else if (layoutDivider == 2)//Grid div_question.addClass('question_table_grid'); div_question.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } else { var div_question = $('
'); content.append(div_question); for (var i = 0; i < mediasdata.length; i++) { var m = mediasdata[i]; var tr_question = $(''); div_question.append(tr_question); var td_pic = $(''); tr_question.append(td_pic); var piccontent = createMedias(m); td_pic.append(piccontent); } if (layoutDivider == 1)//Line div_question.addClass('question_standard_table_line'); else if (layoutDivider == 2)//Grid div_question.addClass('question_standard_table_grid'); if (layoutSpacing == 1)//Double Space div_question.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } $('#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; } function createPage(page) { var content = $('
'); if (layoutStyle == 1 || layoutStyle == 2) { var tabpage = $('
'); content.append(tabpage); var trpage = $(''); tabpage.append(trpage); var tdpage = $(''); trpage.append(tdpage); tdpage.append($('').text(page.DisplayText)); if (layoutDivider == 1)//Line tabpage.addClass('question_line'); else if (layoutDivider == 2)//Grid tabpage.addClass('question_table_grid'); tabpage.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } else { var divpage = $('
'); content.append(divpage); var btnpage = $(''); btnpage.click(function () { var icon = $(this); if (icon.hasClass('iconangleright')) { icon.removeClass('iconangleright').addClass('iconangledown'); icon.parent().next().show(); } else { icon.removeClass('iconangledown').addClass('iconangleright'); icon.parent().next().hide(); } }); divpage.append(btnpage); divpage.append($('').text(page.DisplayText)); } var sectioncontent = createSectionContent(page); content.append(sectioncontent); return content; } function createSectionContent(page) { var content = $('
'); 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 tabsection = $('
'); content.append(tabsection); var trsection = $(''); tabsection.append(trsection); var tdsection = $(''); trsection.append(tdsection); tdsection.append($('').text(s.DisplayText)); if (layoutDivider == 1)//Line tabsection.addClass('question_line'); else if (layoutDivider == 2)//Grid tabsection.addClass('question_table_grid'); tabsection.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); var qc = createQuestionContent(s); content.append(qc); } } } else { if (page.Sections && page.Sections.length > 0) { for (var i = 0; i < page.Sections.length; i++) { var s = page.Sections[i]; var divsection = $('
'); content.append(divsection); var btnsection = $(''); btnsection.click(function () { var icon = $(this); if (icon.hasClass('iconangleright')) { icon.removeClass('iconangleright').addClass('iconangledown'); icon.parent().next().show(); } else { icon.removeClass('iconangledown').addClass('iconangleright'); icon.parent().next().hide(); } }); divsection.append(btnsection); 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); var qc = createQuestionContent(s); content.append(qc); } } else content.append($('
').text('No Sections')); } return content; } function createQuestionContent(section) { var content = $('
'); if (section.Questions && section.Questions.length > 0) { createQuestionContent1(content, section.Questions, false); } else content.append($('
').text(GetTextByKey("P_IPT_NOQUESTIONS", 'No Questions'))); return content; } function createQuestionContent1(content, questions, isidentified) { if (questions && questions.length > 0) { if (layoutStyle == 1) {//Compressed var div_question = $('
'); content.append(div_question); for (var i = 0; i < questions.length; i++) { var q = questions[i]; if (ignoreQuestion(q, isidentified)) continue; var tr_question = $(''); div_question.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 != "") { td_comment.append($('
').html(replaceHtmlText(comment))); } if (q.IsImportant && layoutHighlightColor) tr_question.css('color', layoutHighlightColor); } if (layoutDivider == 1)//Line div_question.addClass('question_line'); else if (layoutDivider == 2)//Grid div_question.addClass('question_table_grid'); div_question.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } else if (layoutStyle == 2) {//Split var div_question = $('
'); content.append(div_question); var tr_question = ""; var qindex = 0; for (var i = 0; i < questions.length; i++) { var q = questions[i]; if (ignoreQuestion(q, isidentified)) continue; if (qindex % 2 == 0) { tr_question = $(''); div_question.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($('')); } if (layoutDivider == 1)//Line div_question.addClass('question_line'); else if (layoutDivider == 2)//Grid div_question.addClass('question_table_grid'); div_question.css('line-height', layoutSpacing == 1 ? '32px' : '16px'); } else { for (var i = 0; i < questions.length; i++) { var q = questions[i]; if (ignoreQuestion(q, isidentified)) continue; var tab_question = $('
'); 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 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 == 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 = $('