<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AssetLocationHis.aspx.cs" Inherits="AssetLocationHis" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title></title>
    <style>
        html,
        body {
            /*font-family: sans-serif;*/
            padding: 0;
            margin: 0;
            height: 100%;
            width: 100%;
        }

        #layout {
            position: absolute;
            right: 320px;
            left: 0;
            top: 0;
            bottom: 0;
        }

        #divsetting {
            position: absolute;
            width: 320px;
            height: 35%;
            right: 0;
            top: 0;
            bottom: 0;
        }

        #content {
            width: 100%;
            top: 0px;
            bottom: 0;
            margin: 0;
            position: fixed;
            /*color: #6b6b6b;*/
            overflow: auto;
        }

        #parameter_left {
            background: #f4f4f4;
            height: 100%;
            width: 200px;
            float: left;
            color: #000;
            position: relative;
        }

        div {
            cursor: default;
        }
    </style>
    <style type="text/css">
        .data-grid {
            height: 100%;
            font-size: 12px !important;
            font-family: "Segoe UI","Segoe UI Web (West European)","Segoe UI",-apple-system,BlinkMacSystemFont,"Roboto","Helvetica Neue",sans-serif !important;
        }
    </style>
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../css/default.css")%>" type="text/css" />
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../css/split_sub.css")%>" type="text/css" />
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../css/split_sub.css")%>" />
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../css/mapview.css")%>" />
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../css/editmultiselect.css")%>" />
    <link rel="stylesheet" href="https://js.arcgis.com/3.40/esri/css/esri.css" />
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../css/jquery.datetimepicker.css")%>" />
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../css/playbar.css")%>" />
    <link type="text/css" href="<%=GetFileUrlWithVersion("../js/components/css/gridview.css") %>" rel="stylesheet" />
    <link type="text/css" href="<%=GetFileUrlWithVersion("../css/override.css") %>" rel="stylesheet" />
    <link href="<%=GetFileUrlWithVersion("../css/panel.css")%>" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="<%=GetFileUrlWithVersion("../fic/fic/css/form.css")%>" />

    <script src="<%=GetFileUrlWithVersion("../js/jquery-" + (JQueryVersion ?? "3.6.0") + ".min.js")%>" type="text/javascript"></script>
    <script src="<%=GetFileUrlWithVersion("../js/utility.js")%>" type="text/javascript"></script>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../js/components/gridview.js") %>"></script>
    <script src="<%=GetFileUrlWithVersion("../fic/js/utility.js")%>" type="text/javascript"></script>
    <script type="text/javascript" src="<%=GetFileUrlWithVersion("../fic/fic/js/controls/form.js") %>"></script>

    <script>
        var GridView = window.GridView || window['g5-gridview'];
        //必须放在地图js之前
        var dojoConfig = {
            paths: {
                extras1: location.pathname.replace(/\/[^/]+$/, "") + "/../js/mapview"
            },
            cacheBust: true
        };
    </script>
    <script src="<%=GetFileUrlWithVersion("../js/cookie.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/jquery.datetimepicker.full.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/vue.min.js")%>"></script>
    <script>Vue.config.productionTip = false; Vue.config.silent = true;</script>
    <script src="https://js.arcgis.com/3.40"></script>
    <%--<script src="<%=GetFileUrlWithVersion("js/mapinit3.19.js")%>"></script>--%>
    <script src="<%=GetFileUrlWithVersion("../js/language.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/mapview/asset.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/mapview/maphelper.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/mapview/mapview.js")%>"></script>
    <script src="<%=GetFileUrlWithVersion("../js/mapview/playbar.js")%>"></script>
    <script type="text/javascript">
        _network.root = '<%=Page.ResolveUrl("~/")%>';
        var currentdate = "<%=CurrentDate %>";
        var MachineID;

        var isMapLoaded = false;
        var leftCtrlWidth = 390;
        var rightCtrlWidth = 280;
        var mapHelper;
        var machineAlert;
        var userParams = undefined;
        var assetObject = undefined;

        var notShowDetail = true;
        var notShowIcons = true;
        //enableInfoWindow = false;
        var Datasource = "";

        var PopupViewShowing = false;

        var serVersion = "";
        var enableSmartWitness = <%=EnableSmartWitness?"true":"false"%>;

        _network.assetmapviewquery = function (method, param, callback, error, nolog) {
            _network.request("AssetView/AssetMapView.aspx?tp=ashx", -1, method, param, callback, error, nolog);
        }

        function init() {
            loadMap();
        }

        function loadMap() {
            mapHelper = new MapHelper(onMapInitialized);
            mapHelper.notShowInfoWindow = true;
            assetObject = new AssetObject(mapHelper);
        }

        function onMapInitialized() {
            isMapLoaded = true;
            initData(onDataInitialized);
        }

        function initData(callback) {
            $("#historyCtrl").show();//所有类型站点都显示Show History
            //$("#contentCtrl").css("bottom", "184px");

            $("#autoRecenterDiv").show();

            //assetObject.getContractor(callback);
            if (callback)
                callback();
        }

        function onDataInitialized() {
            isMapLoaded = true;
            refreshData();
        }

        function refreshData() {
            try {
                assetObject.getCompanyLocations();
                getJobSites();
            }
            catch (e) {
            }
        }

        function getJobSites() {
            var ctr = $("#selContractor").val();
            if (!ctr) ctr = "";

            var item = {
                'IsAutoRefresh': false,
                'ContractorID': ctr,
                'SearchText': '',
                'Onroad': '-1',
            };
            _network.mapviewquery("GetJobSites", JSON.stringify(item), function (data) {
                if (data != "-1") {
                    for (var i = 0; i < data.length; i++) {
                        var js = data[i];
                        mapHelper.showJobSite(js);
                    }
                }
            }, function () {
            });
        }

        function getlocationhis(cid, aid, name) {
            var lcid = $("#selContractor").val();
            if (lcid != cid)
                getJobSites();

            $("#selContractor").val(cid);
            MachineID = aid;
            var e = {
                data: { CompanyID: cid, ID: aid, DisplayName: name }
            };
            locationHistoryClick(e);
        }

        function GetLanguageByCookie() {
            var lang = getCookie('<%=Common.LanguageCookieName%>');
            if (lang == null) {
                return "en-us";
            } else {
                return lang;
            }
        }

        $(function () {
            _fleet.currentLang = GetLanguageByCookie();
            $("#content").applyFleetLanguageText(true);
            init();
            initPlayBar();

            $("#btnLoadLocationHistory").click(null, function (e) {
                //locationHistoryClick();
                getLocationHistory();
            });
            $('#btnQuickLoadLocationHistory').click(null, function () {
                getLocationHistory(true);
            });

            $("#btnClearLocationHistory").click(null, function (e) {
                clearLocationHistory();
                $("#locationhistoryDiv").hide();
                $("#tripDiv").hide();
            });

            $('#btnLoadTrip').click(null, function () {
                getLocationHistory(true);
                openTrips(true);
            });

            $("#btnClearTrip").click(null, function (e) {
                $("#tripDiv").hide();
                $("#tbTrips").empty();
            });


            $("#showDealerLocationsDiv").click(null, function (e) {
                if ($("#showDealerLocationsDiv").attr("state") == "0") {
                    assetObject.showLocations();
                    $("#showDealerLocationsDiv").attr("state", "1").attr("title", GetTextByKey("P_MV_TURNOFFDEALERLOCATIONS", "Turn Off Dealer Locations"));
                }
                else {
                    assetObject.clearLocations();
                    $("#showDealerLocationsDiv").attr("state", "0").attr("title", GetTextByKey("P_MV_TURNONDEALERLOCATIONS", "Turn On Dealer Locations"));
                }
            });

            $("#basemapgalleryDiv").click(null, function (e) {
                $("#basemapGallery").show();
            });

            $("#dateTo").datetimepicker({
                timepicker: false,
                format: 'm/d/Y',
                scrollMonth: false,
                scrollTime: false,
                scrollInput: false,
            });
            $("#dateFrom").datetimepicker({
                timepicker: false,
                format: 'm/d/Y',
                scrollMonth: false,
                scrollTime: false,
                scrollInput: false,
            });

            $("#dialog_timeperiod").change(null, function (e) {
                currentdate = getCurrentDate();
                var timeperiod = $("#dialog_timeperiod").val();
                var disabled = false;

                if (timeperiod !== "4") {
                    disabled = true;
                    var time = new Date(currentdate);
                    var nowtime = new Date(currentdate);
                    var hours = nowtime.getHours();
                    var minutes = nowtime.getMinutes();
                    if (timeperiod === "2") {
                        time.setDate(time.getDate() - 1);
                        nowtime.setDate(nowtime.getDate() - 1);
                    }
                    else if (timeperiod === "3") {
                        time.setDate(time.getDate() - 6);
                    }
                    else if (timeperiod === "5") {
                        time.setDate(time.getDate() - 1);
                    }

                    time = time.getMonth() + 1 + "/" + time.getDate() + "/" + time.getFullYear();
                    nowtime = nowtime.getMonth() + 1 + "/" + nowtime.getDate() + "/" + nowtime.getFullYear();
                    $('#dateFrom').val(time);
                    $('#dateTo').val(nowtime);
                    $('#dialog_starttimehour').val('00');
                    $('#dialog_starttimeminute').val('00');
                    $('#dialog_endtimehour').val('23');
                    $('#dialog_endtimeminute').val('59');

                    if (timeperiod === "5") {
                        var s_minutes = minutes + 1;
                        var s_hours = hours;

                        if (minutes == 59) {
                            s_hours = s_hours + 1;
                            s_minutes = 0;
                        }

                        $('#dialog_starttimehour').val(setTimeSelect(s_hours));
                        $('#dialog_starttimeminute').val(setTimeSelect(s_minutes));
                        $('#dialog_endtimehour').val(setTimeSelect(hours));
                        $('#dialog_endtimeminute').val(setTimeSelect(minutes));
                    }
                }
            });
            //$("#splitIcon").click();
            initTime();
            var time = new Date(currentdate);
            time = (time.getMonth() + 1) + "/" + time.getDate() + "/" + time.getFullYear();
            $('#dateFrom').val(time);
            $('#dateTo').val(time);
            $('#dialog_starttimehour').val('00');
            $('#dialog_starttimeminute').val('00');
            $('#dialog_endtimehour').val('23');
            $('#dialog_endtimeminute').val('59');
        });

        function setTimeSelect(time) {
            if (time.toString().length == 1)
                return "0" + time;
            else
                return time.toString();
        }

        function initTime() {
            var c = $('#dialog_starttimehour');
            for (var i = 0; i < 24; i++) {
                if (i < 10)
                    c.append($("<option></option>").val("0" + i).text("0" + i))
                else
                    c.append($("<option></option>").val(i).text(i))
            }
            c = $('#dialog_starttimeminute');
            for (var i = 0; i < 60; i++) {
                if (i < 10)
                    c.append($("<option></option>").val("0" + i).text("0" + i))
                else
                    c.append($("<option></option>").val(i).text(i))
            }
            c = $('#dialog_endtimehour');
            for (var i = 0; i < 24; i++) {
                if (i < 10)
                    c.append($("<option></option>").val("0" + i).text("0" + i))
                else
                    c.append($("<option></option>").val(i).text(i))
            }
            c = $('#dialog_endtimeminute');
            for (var i = 0; i < 60; i++) {
                if (i < 10)
                    c.append($("<option></option>").val("0" + i).text("0" + i))
                else
                    c.append($("<option></option>").val(i).text(i))
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="content" style="margin-top: 2px;">
            <input id="selContractor" type="hidden" />
            <div id="layout">
                <div>
                    <div id="mapView">
                    </div>
                    <div id="basemapgalleryDiv">
                        <div id="basemapImg"></div>
                        <div id="basemapTitle"></div>
                    </div>
                    <div id="basemapGallery"></div>
                </div>
                <div id="showDealerLocationsDiv" style="display: none; top: 90px;" state="1" title="Turn Off Dealer Locations" data-title-lgid="P_MV_TURNOFFDEALERLOCATIONS">
                    <%=Logo1 %>
                </div>
            </div>
            <div id="divsetting">
                <table style="line-height: 25px;">
                    <tr>
                        <td style="padding-left: 5px;" data-lgid="P_MV_ASSET_COLON">Asset:</td>
                        <td><span id="spMachineName" data-lgid="P_MV_NOASSETSELECTED">No asset selected.</span></td>
                    </tr>
                    <tr>
                        <td style="padding-left: 5px;" data-lgid="P_MV_TIMEPERIOD_COLON">Time Period:</td>
                        <td>
                            <select id="dialog_timeperiod" tabindex="12" style="width: 90px; height: 22px;">
                                <option value="1" selected="selected" data-lgid="P_MV_TODAY">Today</option>
                                <option value="5" data-lgid="P_MV_LAST24HOURS">Last 24 Hours</option>
                                <option value="2" data-lgid="P_MV_PRIORDAY">Prior Day</option>
                                <option value="3" data-lgid="P_MV_LAST7DAYS">Last 7 Days</option>
                                <option value="4" data-lgid="P_MV_CUSTOM">Custom</option>
                            </select></td>
                    </tr>
                    <tr>
                        <td style="padding-left: 5px;" data-lgid="P_MV_FROM_COLON">From:</td>
                        <td>
                            <input type="text" id="dateFrom" maxlength="12" tabindex="27" style="width: 70px;" />
                            <select id="dialog_starttimehour" style="width: 48px; margin-left: 3px;" tabindex="3"></select><span style="font-weight: bold;">&nbsp;:&nbsp;</span>
                            <select id="dialog_starttimeminute" style="width: 48px; margin-left: 0;" tabindex="4"></select>
                        </td>

                    </tr>
                    <tr>
                        <td style="padding-left: 5px;" data-lgid="P_MV_TO_COLON">To:</td>
                        <td>
                            <input type="text" id="dateTo" maxlength="12" tabindex="27" style="width: 70px;" />
                            <select id="dialog_endtimehour" style="width: 48px; margin-left: 3px;" tabindex="5"></select><span style="font-weight: bold;">&nbsp;:&nbsp;</span>
                            <select id="dialog_endtimeminute" style="width: 48px; margin-left: 0;" tabindex="6"></select>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: center; width: 180px;">
                            <div id="divPlayBar" style="background-color: #C0C0C0;"></div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="text-align: right;">
                            <input id="chkExclude00Loc" style="display: none" checked="checked" type="checkbox" /><span style="margin-right: 10px; display: none" data-lgid="P_MV_TO_EXCLUDE00LOCATIONS">Exclude 0,0 Locations</span>
                            <%--<input type="button" value="Quick Load" data-lgid="P_MV_QUICKLOAD" id="btnQuickLoadLocationHistory" />--%>
                            <%--<input type="button" value="Playback" data-lgid="P_MV_PLAYBACK" id="btnLoadLocationHistory" />--%>
                            <%--<span class="clearbtn" id="btnClearLocationHistory" style="margin-left: 5px;"></span>--%>
                            <%--<input type="button" value="Clear" data-lgid="P_MV_CLEAR" id="btnClearLocationHistory" />
                            <input type="button" value="Trip" data-lgid="P_MV_TRIP" id="btnLoadTrip" style="display: none;" />--%>
                            <%--<span id="btnQuickLoadLocationHistory" class="QuickLoad" style="margin-left: 6px;" title="Quick Load/Skip to End" data-title-lgid="P_MV_QUICKLOADSKIPTOEND"></span>--%>
                            <span id="btnHisLoading" class="QuickLoading" style="margin-left: 6px; display: none;"></span>
                            <span id="btnLoadTrip" class="TripReport" style="margin-left: 6px;" title="Trip Report" data-title-lgid="P_MV_TRIPREPORT"></span>
                            <span class="clearbtn" id="btnClearLocationHistory" style="margin-left: 6px;" title="Clear" data-title-lgid="P_MV_CLEAR"></span>

                        </td>
                    </tr>
                </table>
            </div>
            <div id="tripDiv" style="display: none;">
                <div>
                    <span class="clearbtn" id="btnClearTrip" style="float: right; padding: 5px;"></span>
                </div>
                <div style="position: absolute; top: 30px; bottom: 0; right: 0; overflow: auto; width: 100%;">
                    <table id="tbTrips" style="line-height: 24px; border-collapse: collapse; border-spacing: 0; width: 100%;">
                    </table>
                </div>
            </div>

            <div id="mask_bg" style="display: none;"><div class="loading c-spin"></div></div>
        </div>
    </form>
</body>
</html>