<%@ Page Title="" Language="C#" MasterPageFile="~/IronIntelMasterPage.master" AutoEventWireup="true" CodeFile="InspectionChangeHistory.aspx.cs" Inherits="InspectionChangeHistory" %>

<asp:Content ID="Content1" ContentPlaceHolderID="holder_head" runat="Server">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link href="<%=GetFileUrlWithVersion("css/sections.css")%>" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .fa {
            display: inline-block;
            font: normal normal normal 14px/1 FontAwesome;
            font-size: inherit;
            text-rendering: auto;
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }

        .icon-settings {
            width: 20px;
            height: 20px;
        }

            .icon-settings::before {
                content: '\f0ae';
            }
    </style>
    <style>
        .maintable {
            border-collapse: collapse;
            width: 98%;
            page-break-inside: avoid;
            margin-left: 1%;
            line-height: 24px;
            table-layout: fixed;
        }

            .maintable td {
                /*border: 1px solid #a9a9a9;*/
                padding-left: 3px;
                padding-right: 3px;
            }

            .maintable .mainlabel {
                font-weight: bold;
                text-align: right;
            }
    </style>
    <script data-main="<%=GetFileUrlWithVersion("js/view-main.js")%>" src="<%=GetFileUrlWithVersion("../js/lib/require-2.3.6.min.js")%>"></script>
    <script type="text/javascript">
        var reportid = "<%=ReportID %>";
        var teamintelligence =<%=TeamIntelligence ?"true":"false"%>;
        var isAdmin = <%=IsAdminOrSuper ? "true" : "false"%>;

        function inspectionrequest(method, param, callback, error) {
            _network.request("Inspection/InspectionChangeHistory.aspx", -1, method, param, callback, error || function (e) {
                showAlert(GetTextByKey('P_IPT_PAGEERROR', 'An unknown error occurred.  Please refresh page.'), GetTextByKey('P_IPT_QUERY', 'Query'));
            });
        }

        function OnRefresh() {
            showloading(true);
            var p = JSON.stringify([teamintelligence, reportid]);
            inspectionrequest("GetInspectHistoryItems", p, function (data) {
                showloading(false);
                if (typeof (data) === "string") {
                    showAlert(data, GetTextByKey("P_MR_ERROR", 'Error'));
                    return;
                }
                showInspections(data);
            }, function (err) {
                showloading(false);
            });
        }

        function OnExport() {
            var p = JSON.stringify([teamintelligence, reportid]);
            window.open("../ExportToFile.aspx?type=inspecthis&t=" + htmlencode(p));
        }

        function showInspections(data) {
            var rows = [];
            for (var i = 0; i < data.length; i++) {
                var r = data[i];
                var statustext = "";
                if (r.Status == 0)
                    statustext = 'Draft';
                else if (r.Status == 1)
                    statustext = 'Committed';
                for (var j in r) {
                    if (j === "Status") {
                        r[j] = { DisplayValue: statustext, Value: r[j] };
                    } else if (j === "CommitTimeLocal") {
                        r[j] = { DisplayValue: r["CommitTimeLocalStr"], Value: r[j] };
                    } else if (j === "LastUpdatedTimeLocal") {
                        r[j] = { DisplayValue: r["LastUpdatedTimeLocalStr"], Value: r[j] };
                    } else if (j === "VisibleToCustomer") {
                        r[j] = { DisplayValue: r["VisibleToCustomer"] ? "Yes" : "No", Value: r[j] };
                    }
                }
                var fr = { Values: r };
                rows.push(fr);
            }

            grid_dt.setData(rows);
        }

        var grid_dt;
        function InitGridData() {
            grid_dt = new GridView('#inspectlist');
            grid_dt.lang = {
                all: GetTextByKey("P_GRID_ALL", "(All)"),
                ok: GetTextByKey("P_GRID_OK", "OK"),
                reset: GetTextByKey("P_GRID_RESET", "Reset")
            };
            var list_columns = [
                { name: 'LastUpdatedByUserName', caption: GetTextByKey("P_IPT_USERNAME", "User Name"), valueIndex: 'LastUpdatedByUserName', css: { 'width': 300, 'text-align': 'left' } },
                { name: 'LastUpdatedTimeLocal', caption: GetTextByKey("P_IPT_DATETIME", "Date Time"), valueIndex: 'LastUpdatedTimeLocal', css: { 'width': 150, 'text-align': 'left' } },
                { name: 'VIN', caption: GetTextByKey("P_IPT_VINSN", "VIN/SN"), valueIndex: 'VIN', css: { 'width': 200, 'text-align': 'left' } },
                { name: 'AssetName', caption: GetTextByKey("P_IPT_ASSETNAME", "Asset Name"), valueIndex: 'AssetName', css: { 'width': 250, 'text-align': 'left' } },
                { name: 'WorkOrderNumber', caption: GetTextByKey("P_IPT_WORKORDER", "Work Order #"), valueIndex: 'WorkOrderNumber', css: { 'width': 200, 'text-align': 'left' } }
            ];
            var columns = [];
            // head
            for (var hd in list_columns) {
                var col = {};
                col.name = list_columns[hd].name;
                col.caption = list_columns[hd].caption;
                col.visible = true;
                col.sortable = true;
                col.width = list_columns[hd].css.width;
                col.align = list_columns[hd].css["text-align"]
                col.key = list_columns[hd].valueIndex;
                col.allowFilter = list_columns[hd].allowFilter;
                columns.push(col);
            }
            grid_dt.canMultiSelect = false;
            grid_dt.columns = columns;
            grid_dt.init();

        }

        $(function () {
            $("#content").applyFleetLanguageText();
            InitGridData();

            OnRefresh();

            $(window).resize(function () {
                $("#inspectlist").css("height", $(window).height() - $("#inspectlist").offset().top - 4);
                grid_dt && grid_dt.resize();
            }).resize();

            if (!canExport) {
                $('#spExport').hide();
            }
        });

    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="holder_content" runat="Server">
    <div id="recordcontent" style="padding: 0px; margin: 0px;">
        <div class="page_title" data-lgid="P_IPT_INSPECTIONCHANGEHISTORY">Inspection Change History</div>
        <div class="function_title">
            <span class="sbutton iconrefresh" onclick="OnRefresh();" data-lgid="P_MR_REFRESH">Refresh</span>
            <span id="spExport" class="sbutton iconexport" onclick="OnExport();" data-lgid="P_MR_EXPORTTOEXCEL">Export to Excel</span>
        </div>
        <div class="clear"></div>
        <div id="inspectlist"></div>
    </div>
    <div id="mask_bg" style="display: none;"><div class="loading c-spin"></div></div>

</asp:Content>