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

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="../css/jquery.datetimepicker.css" rel="stylesheet" />
    <style type="text/css">
        .itemselcted {
            background-color: #ccc;
        }

        .itemhidden {
            display: none;
        }

        .itemsuggested {
            background-color: #ffff99;
        }

        #tbMachineTypes tbody tr:hover {
            cursor: default;
            background: #ddd;
        }

        #tbodyAssigned tr:hover {
            cursor: default;
            background: #ddd;
        }

        #tbodyUnassigned tr:hover {
            cursor: default;
            background: #ddd;
        }

        #tbodySelected tr:hover {
            cursor: default;
            background: #ddd;
        }

        #contentctrl {
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
        }

        .float_left {
            float: left;
        }

        .function_bar {
            float: right;
        }

        .user_main {
            padding: 0 4px;
        }
      

        #dialog_machines .dialog-content table td input,
        #dialog_layouts .dialog-content table td input {
            width: auto;
        }

        .dialog-content table td input[type="checkbox"] {
            border: none;
        }

        #dialog_user_randompass {
            width: auto;
            height: 16px;
            margin: 3px 4px 0 4px;
        }

        .ybutton {
            width: 80px;
            line-height: normal;
            margin-left: 6px;
            border: none;
            background: rgb(249, 189, 117);
            padding: 5px 14px;
            cursor: pointer;
        }

            .ybutton:hover {
                background: #d7690E;
            }

        .td_controller {
            vertical-align: middle;
            padding: 40px 8px;
            /*border-left: 1px solid #b0b0b0;
                border-right: 1px solid #b0b0b0;*/
        }

        .ctl_button {
            font-family: 'CalciteWebCoreIcons';
            display: block;
            margin: 6px auto;
            width: 60px;
            height: 22px;
            line-height: 21px;
            padding: 0;
        }

        .subdialog {
            width: -moz-calc(100% - 24px);
            width: -webkit-calc(100% - 24px);
            width: calc(100% - 24px);
        }

        .machine_maskbg {
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            position: absolute;
            background: #000;
            opacity: 0.2;
        }

        #machine-name {
            margin: 10px 10px 6px;
            /*color: gray;*/
            font-weight: lighter;
            font-size: 18px;
            width: 770px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    </style>
    <link href="<%=GetFileUrlWithVersion("../css/spectrum.css")%>" rel="stylesheet" type="text/css" />
    <script src="../js/spectrum.js?v=1" type="text/javascript"></script>
    <script>
        jobsitequery = function (method, param, callback, error, nolog) {
            _network.request("JobSite/DispatchChangeHistory.aspx?tp=ashx", -1, method, param, callback, error, nolog);
        }
        var IsReadOnly = <%=IsReadOnly ?"true":"false"%>;
        var _id = "<%=ID %>";
        var _sendtype = "<%=SendType %>";

        /***************************Jobsites***************************/

        function OnRefresh() {
            showloading(true);
            var p = [_sendtype, _id];

            jobsitequery("GetAssetDispatchHistory", htmlencode(JSON.stringify(p)), function (data) {
                showloading(false);
                if (typeof (data) === "string") {
                    showAlert(data, GetTextByKey("P_AM_ERROR", 'Error'));
                    return;
                }

                showDispatchList(data);
            }, function (err) {
                showloading(false);
            });
        }

        function showDispatchList(data) {
            var rows = [];
            for (var i = 0; i < data.length; i++) {
                var r = data[i];
                for (var j in r) {
                    if (j === "MoveDate")
                        r[j] = { DisplayValue: r["BeginDateStr"], Value: r[j] };
                    else if (j === "BeginDate")
                        r[j] = { DisplayValue: r["BeginDateStr"], Value: r[j] };
                    else if (j === "EndDate")
                        r[j] = { DisplayValue: r["EndDateStr"], Value: r[j] };
                    else if (j === "Completed")
                        r[j] = { DisplayValue: r["Completed"] ? GetTextByKey("P_UTILITY_YES", "Yes") : GetTextByKey("P_UTILITY_NO", "No"), Value: r[j] };
                    else if (j === "CompletedTime")
                        r[j] = { DisplayValue: r["CompletedTimeStr"], Value: r[j] };
                    else if (j === "AddedOn")
                        r[j] = { DisplayValue: r["AddedOnStr"], Value: r[j] };
                    else if (j === "DeletedOn")
                        r[j] = { DisplayValue: r["DeletedOnStr"], Value: r[j] };
                }
                rows.push(r);
            }

            grid_dt.setData(rows);
            grid_dt.refresh();
        }

        var grid_dt;
        function InitGridData() {
            grid_dt = createGridView('#dispatchlist');
            var list_columns = [
                { name: 'BeginDate', caption: GetTextByKey("P_JS_MOVEDATE", "Move Date"), valueIndex: 'BeginDate', css: { 'width': 100, 'text-align': 'left' } },
                { name: 'AssetName', caption: GetTextByKey("P_JS_ASSETNAME", "Asset Name"), valueIndex: 'AssetName', css: { 'width': 200, 'text-align': 'left' } },
                { name: 'AssetTypeName', caption: GetTextByKey("P_JS_ASSETTYPE", "Asset Type"), valueIndex: 'AssetTypeName', css: { 'width': 180, 'text-align': 'left' } },
                { name: 'AssetModelName', caption: GetTextByKey("P_JS_MODEL", "Model"), valueIndex: 'AssetModelName', css: { 'width': 180, 'text-align': 'left' } },
                { name: 'CurrentJobSiteName', caption: GetTextByKey("P_JS_FROMJOBSITE", "From Jobsite"), valueIndex: 'CurrentJobSiteName', css: { 'width': 120, 'text-align': 'left' } },
                { name: 'RequiredJobSiteName', caption: GetTextByKey("P_JS_TOJOBSITE", "To Jobsite"), valueIndex: 'RequiredJobSiteName', css: { 'width': 120, 'text-align': 'left' } },
                { name: 'Completed', caption: GetTextByKey("P_JS_MARKCOMPLETE", "Mark Complete"), valueIndex: 'Completed', css: { 'width': 100, 'text-align': 'center' } },
                { name: 'CompletedTime', caption: GetTextByKey("P_JS_COMPLETEDATE", "Completed Date"), valueIndex: 'CompletedTime', css: { 'width': 120, 'text-align': 'left' } },
                { name: 'Notes', caption: GetTextByKey("P_JS_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 200, 'text-align': 'left' } },
                { name: 'AssignedTo', caption: GetTextByKey("P_JS_ASSIGNEDTO", "Assigned To"), valueIndex: 'AssignedToAssetName', css: { 'width': 200, 'text-align': 'left' } },
                { name: 'PointOfContact', caption: GetTextByKey("P_JS_POINTOFCONTACT", "Point Of Contact"), valueIndex: 'PointOfContact', css: { 'width': 200, 'text-align': 'left' } },
                { name: 'AddedByName', caption: GetTextByKey("P_MA_ADDEDBY", "Added By"), valueIndex: 'AddedByName', css: { 'width': 150, 'text-align': 'left' } },
                { name: 'AddedOn', caption: GetTextByKey("P_MA_ADDEDON", "Added On"), valueIndex: 'AddedOn', css: { 'width': 150, 'text-align': 'left' } },
                { name: 'DeletedByName', caption: GetTextByKey("P_JS_DELETEDBY", "Deleted By"), valueIndex: 'DeletedByName', css: { 'width': 150, 'text-align': 'left' } },
                { name: 'DeletedOn', caption: GetTextByKey("P_JS_DELETEDON", "Deleted On"), valueIndex: 'DeletedOn', css: { 'width': 150, 'text-align': 'left' } },
                { name: 'DeletedNotes', caption: GetTextByKey("P_JS_DELETIONNOTES", "Deletion Notes"), valueIndex: 'DeletedNotes', 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 = list_columns[hd].visible === false ? false : 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;
                col.type = list_columns[hd].type;

                col.alwaysshow = list_columns[hd].alwaysshow;
                if (col.name === "DeletedByName" || col.name === "DeletedOn" || col.name === "DeletedNotes") {
                    col.visible = _sendtype === "0";
                }
                columns.push(col);
            }
            grid_dt.canMultiSelect = false;
            grid_dt.columns = columns;
            grid_dt.init();
        }

        $(function () {
            if (_sendtype == 0)
                $('#div_title').text(GetTextByKey("P_JS_REQUIREMENTCHANGEHISTORY", "Requirement Change History"));
            else if (_sendtype == 1)
                $('#div_title').text(GetTextByKey("P_JS_DISPATCHCHANGEHISTORY", "Dispatch Change History"));
            InitGridData();

            $(window).resize(function () {
                $("#dispatchlist").css("height", $(window).height() - $("#dispatchlist").offset().top - 14);
                grid_dt && grid_dt.resize();

            }).resize();
            OnRefresh();

        });

        function OnPrint(assignto) {
            if (!assignto)
                assignto = "";

            if (_selectdispatchids.length == 0) {
                showAlert(GetTextByKey('P_JS_PLEASESELECTDISPATCH', 'Please select Dispatch.'), GetTextByKey('P_MR_PRINT', 'Print'));
                return;
            }

            window.open("../Print.aspx?pt=2&t=" + _sendType + "&assignto=" + encodeURIComponent(assignto) + "&ids=" + JSON.stringify(_selectdispatchids));

        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="contentctrl">
        <div class="page_title" id="div_title" data-lgid="P_JS_DISPATCHCHANGEHISTORY">Dispatch Change History</div>
        <div class="search_bar">
        </div>
        <div class="function_title">
            <%--<span class="sbutton iconmail" onclick="openAssignDispatch(1);" data-lgid="P_JS_EMAIL">Email</span>--%>
            <%--<span class="sbutton iconprint" onclick="openAssignDispatch(0);" data-lgid="P_JS_PRIINT">Print</span>--%>
            <span class="sbutton iconrefresh" onclick="OnRefresh();" data-lgid="P_JS_REFRESH"></span>
        </div>
        <div id="dispatchlist"></div>
    </div>

</asp:Content>