$(function () { InitIdlehourGridData(); //InitIdlehourHisGridData(); }); var grid_idlehourdt; var grid_idlehourhisdt; function ShowIdlehours(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" : ""; else if (j === "UOM") r[j] = "Hour"; } r.Hours = r.Hours.toFixed(2); var fr = { Values: r }; rows.push(fr); //if (r.DataSource.toLowerCase() == "calamp") // hasCalamp = true; } grid_idlehourdt.sortIndex = -1; grid_idlehourdt.sortDirection = -1; grid_idlehourdt.setData(rows); $("#idlehourlist").css("height", autoheight(grid_idlehourdt)); grid_idlehourdt && grid_idlehourdt.resize(); if (IsSupperAdmin && hasCalamp) { $('#btnidlehouradjust').css("display", ''); } else $('#btnidlehouradjust').css("display", 'none'); } function InitIdlehourGridData() { grid_idlehourdt = new GridView('#idlehourlist'); grid_idlehourdt.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: 'Hours', caption: GetTextByKey("P_MA_IDLEHOURS", "Idle Hours"), valueIndex: 'Hours', css: { 'width': 80, 'text-align': 'left' } }, { name: 'Units', caption: GetTextByKey("P_MA_UNITS", "Units"), valueIndex: 'UOM', css: { 'width': 80, '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(3, 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_idlehourdt.canMultiSelect = false; grid_idlehourdt.columns = columns; grid_idlehourdt.init(); grid_idlehourdt.selectedrowchanged = function (rowindex) { var rowdata = grid_idlehourdt.source[rowindex]; if (rowdata) { } } } function InitIdlehourHisGridData() { grid_idlehourhisdt = new GridView('#idlehourhislist'); grid_idlehourhisdt.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_idlehourhisdt.canMultiSelect = false; grid_idlehourhisdt.columns = columns; grid_idlehourhisdt.init(); grid_idlehourhisdt.selectedrowchanged = function (rowindex) { var rowdata = grid_idlehourhisdt.source[rowindex]; if (rowdata) { } } } function getIdlehours() { grid_idlehourdt.setData([]); showLoading(); devicerequest("GetAssetCurrentIdlehours", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowIdlehours(data); }, function (err) { hideLoading(); }); } function getIdlehourHis() { grid_idlehourhisdt.setData([]); showLoading(); devicerequest("GetCalampIdlehourHistory", contractorid + String.fromCharCode(170) + machineid, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowIdlehourHis(data); }, function (err) { hideLoading(); }); } function getIdlehourHisPreview() { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'Idlehour': $('#dialogadjust_idlehour').val(), 'UOM': $('#dialogadjust_sel_idlehouruom').val(), 'IdlehourDate': $('#dialogadjust_idlehourdate').val(), 'Notes': $('#dialogadjust_notes').val() }; var alerttitle = GetTextByKey("P_MA_ADJUSTIDLEHOUR", 'Adjust Idlehour'); if (item.Idlehour !== "") { if (isNaN(item.Idlehour)) { showAlert(GetTextByKey("P_MA_IDLEHOURFORMAERROR", 'Idlehour format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.Idlehour <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_IDLEHOURCANNOTBEEMPTY", "Idlehour cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } grid_idlehourhisdt.setData([]); showLoading(); if (item.IdlehourDate === "") { showAlert(GetTextByKey("P_MA_IDLEHOURDATACANNOTBEEMPTY", "Idlehour date cannot be empty."), alerttitle); $('#adjustodomask').hide(); hideLoading(); return; } var offset = $('#dialogadjust_idlehourtimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.IdlehourDate = item.IdlehourDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; var param = JSON.stringify(item); param = htmlencode(param); devicerequest("GetCalampIdlehourHistoryPreview", param, function (data) { hideLoading(); if (typeof (data) === "string") { showAlert(data, GetTextByKey("P_MA_ERROR", 'Error')); return; } ShowIdlehourHis(data); }, function (err) { hideLoading(); }); } function ShowIdlehourHis(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_idlehourhisdt.sortIndex = -1; grid_idlehourhisdt.sortDirection = -1; grid_idlehourhisdt.setData(rows); } //************************Adjust Idlehour**************************************// function openAdjustIdlehour() { $('#dialogadjust_idlehour').val(''); $('#dialogadjust_sel_idlehouruom').val('Mile'); $('#dialogadjust_idlehourtimezone').val("UTC"); $('#dialogadjust_idlehourdate').val(currentdate); $('#dialogadjust_timehour').val('00'); $('#dialogadjust_timeminute').val('00'); $('#dialogadjust_notes').val(''); $('#dialog_adjustidlehour .dialog-title span.title').text(GetTextByKey("P_MA_ADJUSTIDLEHOUR", 'Adjust Idlehour')); showmaskbg(true); $('#dialog_adjustidlehour') .attr('act', 'add') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_adjustidlehour').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_adjustidlehour').width()) / 2 }) .showDialog(); $('#dialogadjust_idlehour').focus(); getIdlehourHis(); } function OnAdjustIdlehour() { var alerttitle = GetTextByKey("P_MA_ADJUSTIDLEHOUR", 'Adjust Idlehour'); $('#adjustodomask').show(); showConfirm('Do you want to adjust the idlehour?', alerttitle, function () { var item = { 'CustomerID': contractorid, 'AssetID': machineid, 'Idlehour': $('#dialogadjust_idlehour').val(), 'UOM': $('#dialogadjust_sel_idlehouruom').val(), 'IdlehourDate': $('#dialogadjust_idlehourdate').val(), 'Notes': $('#dialogadjust_notes').val() }; if (item.Idlehour !== "") { if (isNaN(item.Idlehour)) { showAlert(GetTextByKey("P_MA_IDLEHOURFORMAERROR", 'Idlehour format error.'), alerttitle); $('#adjustodomask').hide(); return; } else { if (item.Idlehour <= 0) { showAlert(GetTextByKey("P_MA_ODOMETERMUSTBEGREATERTHAN0", 'ODOMeter must be greater than 0.'), alerttitle); $('#adjustodomask').hide(); return; } } } else { showAlert(GetTextByKey("P_MA_IDLEHOURCANNOTBEEMPTY", "Idlehour cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } if (item.IdlehourDate === "") { showAlert(GetTextByKey("P_MA_IDLEHOURDATACANNOTBEEMPTY", "Idlehour date cannot be empty."), alerttitle); $('#adjustodomask').hide(); return; } var offset = $('#dialogadjust_idlehourtimezone').find("option:selected").attr("offset"); item.OffsetMinute = offset; var hour = $('#dialogadjust_timehour').val(); var minute = $('#dialogadjust_timeminute').val(); item.IdlehourDate = item.IdlehourDate.replace("-", "/") + " " + hour + ":" + minute + ":" + "00"; showloading(true); var param = JSON.stringify(item); param = htmlencode(param); devicerequest("SaveAdjustIdlehour", param, function (data) { showloading(false); if (data !== 'OK') { showAlert(data, alerttitle); } else { getIdlehours(); showAlert(GetTextByKey("P_MA_ADJUSTIDLEHOURSUCCESSFULLY", "Adjust Idlehour Successfully."), alerttitle); } $('#dialog_adjustidlehour').hideDialog(); $('#adjustodomask').hide(); }, function (err) { showloading(false); showAlert(GetTextByKey("P_MA_FAILEDTOADJUSTIDLEHOUR", 'Failed to adjust Idlehour.'), alerttitle); $('#adjustodomask').hide(); }); }, function () { $('#adjustodomask').hide(); }); } function OnPreviewIdlehour() { getIdlehourHisPreview(); }