$(function () { InitLocationGridData(); //InitLocationHisGridData(); }); var grid_locationdt; var grid_locationhisdt; function ShowLocations(data) { var rows = []; var hasCalamp = false; for (var i = 0; i < data.length; i++) { var r = data[i]; for (var j in r) { if (j === "IsPrimary") r[j] = r[j] === true ? "Yes" : ""; } var fr = { Values: r }; rows.push(fr); //if (r.DataSource.toLowerCase() == "calamp") // hasCalamp = true; } grid_locationdt.sortIndex = -1; grid_locationdt.sortDirection = -1; grid_locationdt.setData(rows); $("#locationlist").css("height", autoheight(grid_locationdt)); grid_locationdt && grid_locationdt.resize(); if (IsSupperAdmin && hasCalamp) { $('#btnlocationadjust').css("display", ''); } else $('#btnlocationadjust').css("display", 'none'); } function InitLocationGridData() { grid_locationdt = new GridView('#locationlist'); grid_locationdt.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; var list_columns = [ { name: 'IsPrimary', caption: GetTextByKey("P_MA_ISPRIMARY", "Is Primary"), valueIndex: 'IsPrimary', css: { 'width': 80, 'text-align': 'left' } }, { name: 'DataSourceName', caption: GetTextByKey("P_MA_DATASOURCE", "Data Source"), valueIndex: 'DataSourceName', css: { 'width': 120, 'text-align': 'left' } }, { name: 'Longitude', caption: GetTextByKey("P_MA_LONGITUDE", "Longitude"), valueIndex: 'Longitude', css: { 'width': 90, 'text-align': 'left' } }, { name: 'Latitude', caption: GetTextByKey("P_MA_LATITUDE", "Latitude"), valueIndex: 'Latitude', css: { 'width': 90, 'text-align': 'left' } }, { name: 'ReceivedDate', caption: GetTextByKey("P_MA_RECEIVEDDATE", "Received Date"), valueIndex: 'ReceivedDateStr', css: { 'width': 130, 'text-align': 'left' } }, { name: 'SetPrmary', caption: "", css: { 'width': 100, '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; if (list_columns[hd].type) { col.type = list_columns[hd].type; } if (col.name === "SetPrmary") { col.isurl = true; col.text = GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary'); col.events = { onclick: function () { openSetPrimary(2, this); } }; col.classFilter = function (e) { return "icon-col"; }; col.styleFilter = function (e) { return { display: e.IsPrimary === "Yes" ? 'none' : '' }; }; col.attrs = { 'title': GetTextByKey("P_MA_SETASPRIMARY", 'Set As Primary') }; col.visible = IsSupperAdmin; col.resizable = false; } columns.push(col); } grid_locationdt.canMultiSelect = false; grid_locationdt.columns = columns; grid_locationdt.init(); grid_locationdt.selectedrowchanged = function (rowindex) { var rowdata = grid_locationdt.source[rowindex]; if (rowdata) { } } } function InitLocationHisGridData() { grid_locationhisdt = new GridView('#locationhislist'); grid_locationhisdt.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; var list_columns = [ { name: 'DeviceAirId', caption: GetTextByKey("P_MA_DEVICEAIRID", "Device Air ID"), valueIndex: 'DeviceAirId', css: { 'width': 140, 'text-align': 'left' } }, { name: 'AsofTime', caption: GetTextByKey("P_MA_EVENTDATEUTC", "Event Date(UTC)"), valueIndex: 'EventTimeText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'AsofTime_local', caption: GetTextByKey("P_MA_EVENTDATE", "Event Date"), valueIndex: 'EventTimeLocalText', css: { 'width': 130, 'text-align': 'left' } }, { name: 'VBUS', caption: GetTextByKey("P_MA_VBUSRAW", "VBUS(Raw)"), valueIndex: 'VBUS', css: { 'width': 90, 'text-align': 'right' } }, { name: 'VBUS_Calc', caption: GetTextByKey("P_MA_VBUSCALC", "VBUS(Calc)"), valueIndex: 'VBUS_Calc', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Gps', caption: GetTextByKey("P_MA_GPSRAW", "GPS(Raw)"), valueIndex: 'Gps', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Gps_Calc', caption: GetTextByKey("P_MA_GPSCALC", "GPS(Calc)"), valueIndex: 'Gps_Calc', css: { 'width': 90, 'text-align': 'right' } }, { name: 'Unit', caption: GetTextByKey("P_MA_UNIT", "Unit"), valueIndex: 'UOM', css: { 'width': 60, 'text-align': 'right' } } ]; 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; if (list_columns[hd].type) { col.type = list_columns[hd].type; } columns.push(col); } grid_locationhisdt.canMultiSelect = false; grid_locationhisdt.columns = columns; grid_locationhisdt.init(); grid_locationhisdt.selectedrowchanged = function (rowindex) { var rowdata = grid_locationhisdt.source[rowindex]; if (rowdata) { } } } function getLocations() { grid_locationdt.setData([]); showLoading(); devicerequest("GetAssetCurrentLocation", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowLocations(data); }, function (err) { hideLoading(); }); } function getLocationHis() { grid_locationhisdt.setData([]); showLoading(); devicerequest("GetCalampLocationHistory", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowLocationHis(data); }, function (err) { hideLoading(); }); } function getLocationHisPreview() { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'Location': $('#dialogadjust_location').val(), 'UOM': $('#dialogadjust_sel_locationuom').val(), 'LocationDate': $('#dialogadjust_locationdate').val(), 'Notes': $('#dialogadjust_notes').val() }; var alerttitle = GetTextByKey("P_MA_ADJUSTLOCATION", "Adjust Location"); if (item.Location !== "") { if (isNaN(item.Location)) { showAlert(GetTextByKey("P_MA_LOCATIONFORMAERROR", 'Location format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.Location <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_LOCATIONCANNOTBEEMPTY", "Location cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } grid_locationhisdt.setData([]); showLoading(); if (item.LocationDate === "") { showAlert(GetTextByKey("P_MA_LOCATIONDATACANNOTBEEMPTY", "Location date cannot be empty."), alerttitle); $('#adjustodomask').hide(); hideLoading(); return; } var offset = $('#dialogadjust_locationtimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.LocationDate = item.LocationDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; var param = JSON.stringify(item); param = htmlencode(param); devicerequest("GetCalampLocationHistoryPreview", param, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowLocationHis(data); }, function (err) { hideLoading(); }); } function ShowLocationHis(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; for (var j in r) { if (j === "EventTimeText") r[j] = { DisplayValue: r["EventTimeText"], Value: r["AsofTime"] }; if (j === "EventTimeLocalText") r[j] = { DisplayValue: r["EventTimeLocalText"], Value: r["AsofTime_Local"] }; } var fr = { Values: r }; rows.push(fr); } grid_locationhisdt.sortIndex = -1; grid_locationhisdt.sortDirection = -1; grid_locationhisdt.setData(rows); } //************************Adjust Location**************************************// function openAdjustLocation() { $('#dialogadjust_location').val(''); $('#dialogadjust_sel_locationuom').val('Mile'); $('#dialogadjust_locationtimezone').val("UTC"); $('#dialogadjust_locationdate').val(currentdate); $('#dialogadjust_timehour').val('00'); $('#dialogadjust_timeminute').val('00'); $('#dialogadjust_notes').val(''); $('#dialog_adjustlocation .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTLOCATION", "Adjust Location")); showmaskbg(true); $('#dialog_adjustlocation') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_adjustlocation').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_adjustlocation').width()) / 2 }) .showDialog(); $('#dialogadjust_location').focus(); getLocationHis(); } function OnAdjustLocation() { $('#adjustodomask').show(); var alerttitle = GetTextByKey("P_MA_ADJUSTLOCATION", "Adjust Location"); showConfirm('Do you want to adjust the location?', alerttitle, function () { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'Location': $('#dialogadjust_location').val(), 'UOM': $('#dialogadjust_sel_locationuom').val(), 'LocationDate': $('#dialogadjust_locationdate').val(), 'Notes': $('#dialogadjust_notes').val() }; if (item.Location !== "") { if (isNaN(item.Location)) { showAlert(GetTextByKey("P_MA_LOCATIONFORMAERROR", 'Location format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.Location <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_LOCATIONCANNOTBEEMPTY", "Location cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } if (item.LocationDate === "") { showAlert(GetTextByKey("P_MA_LOCATIONDATACANNOTBEEMPTY", "Location date cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } var offset = $('#dialogadjust_locationtimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.LocationDate = item.LocationDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; showloading(true); var param = JSON.stringify(item); param = htmlencode(param); devicerequest("SaveAdjustLocation", param, function (data) { showloading(false); if (data !== 'OK') { showAlert(data, alerttitle); } else { getLocations(); showAlert(GetTextByKey("P_MA_ADJUSTLOCATIONSUCCESSFULLY", "Adjust Location Successfully."), alerttitle); } $('#dialog_adjustlocation').hideDialog(); $('#adjustodomask').hide(); }, function (err) { showloading(false); showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTLOCATION", 'Failed to adjust Location.'), alerttitle); $('#adjustodomask').hide(); }); }, function () { $('#adjustodomask').hide(); }); } function OnPreviewLocation() { getLocationHisPreview(); }